2019-05-28 16:57:16 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2011-01-10 19:51:47 +00:00
|
|
|
/*
|
|
|
|
* This file contains vfs inode ops for the 9P2000.L protocol.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
|
|
|
|
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/xattr.h>
|
|
|
|
#include <linux/posix_acl.h>
|
|
|
|
#include <net/9p/9p.h>
|
|
|
|
#include <net/9p/client.h>
|
|
|
|
|
|
|
|
#include "v9fs.h"
|
|
|
|
#include "v9fs_vfs.h"
|
|
|
|
#include "fid.h"
|
|
|
|
#include "cache.h"
|
|
|
|
#include "xattr.h"
|
|
|
|
#include "acl.h"
|
|
|
|
|
|
|
|
static int
|
2023-01-13 11:49:16 +00:00
|
|
|
v9fs_vfs_mknod_dotl(struct mnt_idmap *idmap, struct inode *dir,
|
2021-01-21 13:19:43 +00:00
|
|
|
struct dentry *dentry, umode_t omode, dev_t rdev);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
|
|
|
/**
|
2021-10-04 21:07:22 +00:00
|
|
|
* v9fs_get_fsgid_for_create - Helper function to get the gid for a new object
|
|
|
|
* @dir_inode: The directory inode
|
|
|
|
*
|
|
|
|
* Helper function to get the gid for creating a
|
2011-01-10 19:51:47 +00:00
|
|
|
* new file system object. This checks the S_ISGID to determine the owning
|
|
|
|
* group of the new file system object.
|
|
|
|
*/
|
|
|
|
|
2013-01-30 20:08:21 +00:00
|
|
|
static kgid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
|
2011-01-10 19:51:47 +00:00
|
|
|
{
|
|
|
|
BUG_ON(dir_inode == NULL);
|
|
|
|
|
|
|
|
if (dir_inode->i_mode & S_ISGID) {
|
|
|
|
/* set_gid bit is set.*/
|
|
|
|
return dir_inode->i_gid;
|
|
|
|
}
|
|
|
|
return current_fsgid();
|
|
|
|
}
|
|
|
|
|
Revert "fs/9p: simplify iget to remove unnecessary paths"
This reverts commit 724a08450f74b02bd89078a596fd24857827c012.
This code simplification introduced significant regressions on servers
that do not remap inode numbers when exporting multiple underlying
filesystems with colliding inodes, as can be illustrated with simple
tmpfs exports in qemu with remapping disabled:
```
# host side
cd /tmp/linux-test
mkdir m1 m2
mount -t tmpfs tmpfs m1
mount -t tmpfs tmpfs m2
mkdir m1/dir m2/dir
echo foo > m1/dir/foo
echo bar > m2/dir/bar
# guest side
# started with -virtfs local,path=/tmp/linux-test,mount_tag=tmp,security_model=mapped-file
mount -t 9p -o trans=virtio,debug=1 tmp /mnt/t
ls /mnt/t/m1/dir
# foo
ls /mnt/t/m2/dir
# bar (works ok if directry isn't open)
# cd to keep first dir's inode alive
cd /mnt/t/m1/dir
ls /mnt/t/m2/dir
# foo (should be bar)
```
Other examples can be crafted with regular files with fscache enabled,
in which case I/Os just happen to the wrong file leading to
corruptions, or guest failing to boot with:
| VFS: Lookup of 'com.android.runtime' in 9p 9p would have caused loop
In theory, we'd want the servers to be smart enough and ensure they
never send us two different files with the same 'qid.path', but while
qemu has an option to remap that is recommended (and qemu prints a
warning if this case happens), there are many other servers which do
not (kvmtool, nfs-ganesha, probably diod...), we should at least ensure
we don't cause regressions on this:
- assume servers can't be trusted and operations that should get a 'new'
inode properly do so. commit d05dcfdf5e16 (" fs/9p: mitigate inode
collisions") attempted to do this, but v9fs_fid_iget_dotl() was not
called so some higher level of caching got in the way; this needs to be
fixed properly before we can re-apply the patches.
- if we ever want to really simplify this code, we will need to add some
negotiation with the server at mount time where the server could claim
they handle this properly, at which point we could optimize this out.
(but that might not be needed at all if we properly handle the 'new'
check?)
Fixes: 724a08450f74 ("fs/9p: simplify iget to remove unnecessary paths")
Reported-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/all/20240408141436.GA17022@redhat.com/
Link: https://lkml.kernel.org/r/20240923100508.GA32066@willie-the-truck
Cc: stable@vger.kernel.org # v6.9+
Message-ID: <20241024-revert_iget-v1-4-4cac63d25f72@codewreck.org>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
2024-10-23 23:52:13 +00:00
|
|
|
static int v9fs_test_inode_dotl(struct inode *inode, void *data)
|
|
|
|
{
|
|
|
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
|
|
|
struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
|
|
|
|
|
|
|
|
/* don't match inode of different type */
|
|
|
|
if (inode_wrong_type(inode, st->st_mode))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (inode->i_generation != st->st_gen)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* compare qid details */
|
|
|
|
if (memcmp(&v9inode->qid.version,
|
|
|
|
&st->qid.version, sizeof(v9inode->qid.version)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (v9inode->qid.type != st->qid.type)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (v9inode->qid.path != st->qid.path)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Always get a new inode */
|
|
|
|
static int v9fs_test_new_inode_dotl(struct inode *inode, void *data)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int v9fs_set_inode_dotl(struct inode *inode, void *data)
|
|
|
|
{
|
|
|
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
|
|
|
struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
|
|
|
|
|
|
|
|
memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
|
|
|
|
inode->i_generation = st->st_gen;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
|
|
|
|
struct p9_qid *qid,
|
|
|
|
struct p9_fid *fid,
|
|
|
|
struct p9_stat_dotl *st,
|
|
|
|
int new)
|
2011-02-28 11:34:01 +00:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
struct inode *inode;
|
|
|
|
struct v9fs_session_info *v9ses = sb->s_fs_info;
|
Revert "fs/9p: simplify iget to remove unnecessary paths"
This reverts commit 724a08450f74b02bd89078a596fd24857827c012.
This code simplification introduced significant regressions on servers
that do not remap inode numbers when exporting multiple underlying
filesystems with colliding inodes, as can be illustrated with simple
tmpfs exports in qemu with remapping disabled:
```
# host side
cd /tmp/linux-test
mkdir m1 m2
mount -t tmpfs tmpfs m1
mount -t tmpfs tmpfs m2
mkdir m1/dir m2/dir
echo foo > m1/dir/foo
echo bar > m2/dir/bar
# guest side
# started with -virtfs local,path=/tmp/linux-test,mount_tag=tmp,security_model=mapped-file
mount -t 9p -o trans=virtio,debug=1 tmp /mnt/t
ls /mnt/t/m1/dir
# foo
ls /mnt/t/m2/dir
# bar (works ok if directry isn't open)
# cd to keep first dir's inode alive
cd /mnt/t/m1/dir
ls /mnt/t/m2/dir
# foo (should be bar)
```
Other examples can be crafted with regular files with fscache enabled,
in which case I/Os just happen to the wrong file leading to
corruptions, or guest failing to boot with:
| VFS: Lookup of 'com.android.runtime' in 9p 9p would have caused loop
In theory, we'd want the servers to be smart enough and ensure they
never send us two different files with the same 'qid.path', but while
qemu has an option to remap that is recommended (and qemu prints a
warning if this case happens), there are many other servers which do
not (kvmtool, nfs-ganesha, probably diod...), we should at least ensure
we don't cause regressions on this:
- assume servers can't be trusted and operations that should get a 'new'
inode properly do so. commit d05dcfdf5e16 (" fs/9p: mitigate inode
collisions") attempted to do this, but v9fs_fid_iget_dotl() was not
called so some higher level of caching got in the way; this needs to be
fixed properly before we can re-apply the patches.
- if we ever want to really simplify this code, we will need to add some
negotiation with the server at mount time where the server could claim
they handle this properly, at which point we could optimize this out.
(but that might not be needed at all if we properly handle the 'new'
check?)
Fixes: 724a08450f74 ("fs/9p: simplify iget to remove unnecessary paths")
Reported-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/all/20240408141436.GA17022@redhat.com/
Link: https://lkml.kernel.org/r/20240923100508.GA32066@willie-the-truck
Cc: stable@vger.kernel.org # v6.9+
Message-ID: <20241024-revert_iget-v1-4-4cac63d25f72@codewreck.org>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
2024-10-23 23:52:13 +00:00
|
|
|
int (*test)(struct inode *inode, void *data);
|
2011-07-06 11:02:31 +00:00
|
|
|
|
Revert "fs/9p: simplify iget to remove unnecessary paths"
This reverts commit 724a08450f74b02bd89078a596fd24857827c012.
This code simplification introduced significant regressions on servers
that do not remap inode numbers when exporting multiple underlying
filesystems with colliding inodes, as can be illustrated with simple
tmpfs exports in qemu with remapping disabled:
```
# host side
cd /tmp/linux-test
mkdir m1 m2
mount -t tmpfs tmpfs m1
mount -t tmpfs tmpfs m2
mkdir m1/dir m2/dir
echo foo > m1/dir/foo
echo bar > m2/dir/bar
# guest side
# started with -virtfs local,path=/tmp/linux-test,mount_tag=tmp,security_model=mapped-file
mount -t 9p -o trans=virtio,debug=1 tmp /mnt/t
ls /mnt/t/m1/dir
# foo
ls /mnt/t/m2/dir
# bar (works ok if directry isn't open)
# cd to keep first dir's inode alive
cd /mnt/t/m1/dir
ls /mnt/t/m2/dir
# foo (should be bar)
```
Other examples can be crafted with regular files with fscache enabled,
in which case I/Os just happen to the wrong file leading to
corruptions, or guest failing to boot with:
| VFS: Lookup of 'com.android.runtime' in 9p 9p would have caused loop
In theory, we'd want the servers to be smart enough and ensure they
never send us two different files with the same 'qid.path', but while
qemu has an option to remap that is recommended (and qemu prints a
warning if this case happens), there are many other servers which do
not (kvmtool, nfs-ganesha, probably diod...), we should at least ensure
we don't cause regressions on this:
- assume servers can't be trusted and operations that should get a 'new'
inode properly do so. commit d05dcfdf5e16 (" fs/9p: mitigate inode
collisions") attempted to do this, but v9fs_fid_iget_dotl() was not
called so some higher level of caching got in the way; this needs to be
fixed properly before we can re-apply the patches.
- if we ever want to really simplify this code, we will need to add some
negotiation with the server at mount time where the server could claim
they handle this properly, at which point we could optimize this out.
(but that might not be needed at all if we properly handle the 'new'
check?)
Fixes: 724a08450f74 ("fs/9p: simplify iget to remove unnecessary paths")
Reported-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/all/20240408141436.GA17022@redhat.com/
Link: https://lkml.kernel.org/r/20240923100508.GA32066@willie-the-truck
Cc: stable@vger.kernel.org # v6.9+
Message-ID: <20241024-revert_iget-v1-4-4cac63d25f72@codewreck.org>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
2024-10-23 23:52:13 +00:00
|
|
|
if (new)
|
|
|
|
test = v9fs_test_new_inode_dotl;
|
|
|
|
else
|
|
|
|
test = v9fs_test_inode_dotl;
|
|
|
|
|
|
|
|
inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode_dotl, st);
|
|
|
|
if (!inode)
|
2011-02-28 11:34:01 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2024-10-23 23:52:10 +00:00
|
|
|
if (!(inode->i_state & I_NEW))
|
|
|
|
return inode;
|
2011-02-28 11:34:01 +00:00
|
|
|
/*
|
|
|
|
* initialize the inode with the stat info
|
|
|
|
* FIXME!! we may need support for stale inodes
|
|
|
|
* later.
|
|
|
|
*/
|
Revert "fs/9p: simplify iget to remove unnecessary paths"
This reverts commit 724a08450f74b02bd89078a596fd24857827c012.
This code simplification introduced significant regressions on servers
that do not remap inode numbers when exporting multiple underlying
filesystems with colliding inodes, as can be illustrated with simple
tmpfs exports in qemu with remapping disabled:
```
# host side
cd /tmp/linux-test
mkdir m1 m2
mount -t tmpfs tmpfs m1
mount -t tmpfs tmpfs m2
mkdir m1/dir m2/dir
echo foo > m1/dir/foo
echo bar > m2/dir/bar
# guest side
# started with -virtfs local,path=/tmp/linux-test,mount_tag=tmp,security_model=mapped-file
mount -t 9p -o trans=virtio,debug=1 tmp /mnt/t
ls /mnt/t/m1/dir
# foo
ls /mnt/t/m2/dir
# bar (works ok if directry isn't open)
# cd to keep first dir's inode alive
cd /mnt/t/m1/dir
ls /mnt/t/m2/dir
# foo (should be bar)
```
Other examples can be crafted with regular files with fscache enabled,
in which case I/Os just happen to the wrong file leading to
corruptions, or guest failing to boot with:
| VFS: Lookup of 'com.android.runtime' in 9p 9p would have caused loop
In theory, we'd want the servers to be smart enough and ensure they
never send us two different files with the same 'qid.path', but while
qemu has an option to remap that is recommended (and qemu prints a
warning if this case happens), there are many other servers which do
not (kvmtool, nfs-ganesha, probably diod...), we should at least ensure
we don't cause regressions on this:
- assume servers can't be trusted and operations that should get a 'new'
inode properly do so. commit d05dcfdf5e16 (" fs/9p: mitigate inode
collisions") attempted to do this, but v9fs_fid_iget_dotl() was not
called so some higher level of caching got in the way; this needs to be
fixed properly before we can re-apply the patches.
- if we ever want to really simplify this code, we will need to add some
negotiation with the server at mount time where the server could claim
they handle this properly, at which point we could optimize this out.
(but that might not be needed at all if we properly handle the 'new'
check?)
Fixes: 724a08450f74 ("fs/9p: simplify iget to remove unnecessary paths")
Reported-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/all/20240408141436.GA17022@redhat.com/
Link: https://lkml.kernel.org/r/20240923100508.GA32066@willie-the-truck
Cc: stable@vger.kernel.org # v6.9+
Message-ID: <20241024-revert_iget-v1-4-4cac63d25f72@codewreck.org>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
2024-10-23 23:52:13 +00:00
|
|
|
inode->i_ino = QID2INO(qid);
|
|
|
|
retval = v9fs_init_inode(v9ses, inode,
|
2011-07-25 18:06:33 +00:00
|
|
|
st->st_mode, new_decode_dev(st->st_rdev));
|
2011-02-28 11:34:01 +00:00
|
|
|
if (retval)
|
|
|
|
goto error;
|
|
|
|
|
2024-10-23 23:52:12 +00:00
|
|
|
v9fs_stat2inode_dotl(st, inode, 0);
|
2024-01-02 20:33:17 +00:00
|
|
|
v9fs_set_netfs_context(inode);
|
2011-02-28 11:34:01 +00:00
|
|
|
v9fs_cache_inode_get_cookie(inode);
|
|
|
|
retval = v9fs_get_acl(inode, fid);
|
|
|
|
if (retval)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
unlock_new_inode(inode);
|
|
|
|
return inode;
|
|
|
|
error:
|
2015-07-12 14:34:29 +00:00
|
|
|
iget_failed(inode);
|
2011-02-28 11:34:01 +00:00
|
|
|
return ERR_PTR(retval);
|
2024-10-23 23:52:10 +00:00
|
|
|
|
2011-02-28 11:34:01 +00:00
|
|
|
}
|
|
|
|
|
Revert "fs/9p: simplify iget to remove unnecessary paths"
This reverts commit 724a08450f74b02bd89078a596fd24857827c012.
This code simplification introduced significant regressions on servers
that do not remap inode numbers when exporting multiple underlying
filesystems with colliding inodes, as can be illustrated with simple
tmpfs exports in qemu with remapping disabled:
```
# host side
cd /tmp/linux-test
mkdir m1 m2
mount -t tmpfs tmpfs m1
mount -t tmpfs tmpfs m2
mkdir m1/dir m2/dir
echo foo > m1/dir/foo
echo bar > m2/dir/bar
# guest side
# started with -virtfs local,path=/tmp/linux-test,mount_tag=tmp,security_model=mapped-file
mount -t 9p -o trans=virtio,debug=1 tmp /mnt/t
ls /mnt/t/m1/dir
# foo
ls /mnt/t/m2/dir
# bar (works ok if directry isn't open)
# cd to keep first dir's inode alive
cd /mnt/t/m1/dir
ls /mnt/t/m2/dir
# foo (should be bar)
```
Other examples can be crafted with regular files with fscache enabled,
in which case I/Os just happen to the wrong file leading to
corruptions, or guest failing to boot with:
| VFS: Lookup of 'com.android.runtime' in 9p 9p would have caused loop
In theory, we'd want the servers to be smart enough and ensure they
never send us two different files with the same 'qid.path', but while
qemu has an option to remap that is recommended (and qemu prints a
warning if this case happens), there are many other servers which do
not (kvmtool, nfs-ganesha, probably diod...), we should at least ensure
we don't cause regressions on this:
- assume servers can't be trusted and operations that should get a 'new'
inode properly do so. commit d05dcfdf5e16 (" fs/9p: mitigate inode
collisions") attempted to do this, but v9fs_fid_iget_dotl() was not
called so some higher level of caching got in the way; this needs to be
fixed properly before we can re-apply the patches.
- if we ever want to really simplify this code, we will need to add some
negotiation with the server at mount time where the server could claim
they handle this properly, at which point we could optimize this out.
(but that might not be needed at all if we properly handle the 'new'
check?)
Fixes: 724a08450f74 ("fs/9p: simplify iget to remove unnecessary paths")
Reported-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/all/20240408141436.GA17022@redhat.com/
Link: https://lkml.kernel.org/r/20240923100508.GA32066@willie-the-truck
Cc: stable@vger.kernel.org # v6.9+
Message-ID: <20241024-revert_iget-v1-4-4cac63d25f72@codewreck.org>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
2024-10-23 23:52:13 +00:00
|
|
|
struct inode *
|
|
|
|
v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
|
|
|
|
struct super_block *sb, int new)
|
|
|
|
{
|
|
|
|
struct p9_stat_dotl *st;
|
|
|
|
struct inode *inode = NULL;
|
|
|
|
|
|
|
|
st = p9_client_getattr_dotl(fid, P9_STATS_BASIC | P9_STATS_GEN);
|
|
|
|
if (IS_ERR(st))
|
|
|
|
return ERR_CAST(st);
|
|
|
|
|
|
|
|
inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st, new);
|
|
|
|
kfree(st);
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
|
2011-08-03 14:25:32 +00:00
|
|
|
struct dotl_openflag_map {
|
|
|
|
int open_flag;
|
|
|
|
int dotl_flag;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int v9fs_mapped_dotl_flags(int flags)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rflags = 0;
|
|
|
|
struct dotl_openflag_map dotl_oflag_map[] = {
|
|
|
|
{ O_CREAT, P9_DOTL_CREATE },
|
|
|
|
{ O_EXCL, P9_DOTL_EXCL },
|
|
|
|
{ O_NOCTTY, P9_DOTL_NOCTTY },
|
|
|
|
{ O_APPEND, P9_DOTL_APPEND },
|
|
|
|
{ O_NONBLOCK, P9_DOTL_NONBLOCK },
|
|
|
|
{ O_DSYNC, P9_DOTL_DSYNC },
|
|
|
|
{ FASYNC, P9_DOTL_FASYNC },
|
|
|
|
{ O_DIRECT, P9_DOTL_DIRECT },
|
|
|
|
{ O_LARGEFILE, P9_DOTL_LARGEFILE },
|
|
|
|
{ O_DIRECTORY, P9_DOTL_DIRECTORY },
|
|
|
|
{ O_NOFOLLOW, P9_DOTL_NOFOLLOW },
|
|
|
|
{ O_NOATIME, P9_DOTL_NOATIME },
|
|
|
|
{ O_CLOEXEC, P9_DOTL_CLOEXEC },
|
|
|
|
{ O_SYNC, P9_DOTL_SYNC},
|
|
|
|
};
|
|
|
|
for (i = 0; i < ARRAY_SIZE(dotl_oflag_map); i++) {
|
|
|
|
if (flags & dotl_oflag_map[i].open_flag)
|
|
|
|
rflags |= dotl_oflag_map[i].dotl_flag;
|
|
|
|
}
|
|
|
|
return rflags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_open_to_dotl_flags- convert Linux specific open flags to
|
|
|
|
* plan 9 open flag.
|
|
|
|
* @flags: flags to convert
|
|
|
|
*/
|
|
|
|
int v9fs_open_to_dotl_flags(int flags)
|
|
|
|
{
|
|
|
|
int rflags = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have same bits for P9_DOTL_READONLY, P9_DOTL_WRONLY
|
|
|
|
* and P9_DOTL_NOACCESS
|
|
|
|
*/
|
|
|
|
rflags |= flags & O_ACCMODE;
|
|
|
|
rflags |= v9fs_mapped_dotl_flags(flags);
|
|
|
|
|
|
|
|
return rflags;
|
|
|
|
}
|
|
|
|
|
2011-01-10 19:51:47 +00:00
|
|
|
/**
|
|
|
|
* v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
|
2023-01-13 11:49:13 +00:00
|
|
|
* @idmap: The user namespace of the mount
|
2011-01-10 19:51:47 +00:00
|
|
|
* @dir: directory inode that is being created
|
|
|
|
* @dentry: dentry that is being deleted
|
2014-06-04 23:06:26 +00:00
|
|
|
* @omode: create permissions
|
2021-10-04 21:07:22 +00:00
|
|
|
* @excl: True if the file must not yet exist
|
2011-01-10 19:51:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int
|
2023-01-13 11:49:13 +00:00
|
|
|
v9fs_vfs_create_dotl(struct mnt_idmap *idmap, struct inode *dir,
|
2021-01-21 13:19:43 +00:00
|
|
|
struct dentry *dentry, umode_t omode, bool excl)
|
2012-06-05 13:10:26 +00:00
|
|
|
{
|
2023-01-13 11:49:16 +00:00
|
|
|
return v9fs_vfs_mknod_dotl(idmap, dir, dentry, omode, 0);
|
2012-06-05 13:10:26 +00:00
|
|
|
}
|
|
|
|
|
2012-06-22 08:39:14 +00:00
|
|
|
static int
|
2012-06-05 13:10:26 +00:00
|
|
|
v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
|
2021-11-02 13:16:43 +00:00
|
|
|
struct file *file, unsigned int flags, umode_t omode)
|
2011-01-10 19:51:47 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
2013-01-30 20:08:21 +00:00
|
|
|
kgid_t gid;
|
2011-07-23 22:37:50 +00:00
|
|
|
umode_t mode;
|
2023-03-27 02:06:37 +00:00
|
|
|
int p9_omode = v9fs_open_to_dotl_flags(flags);
|
2017-01-12 09:01:17 +00:00
|
|
|
const unsigned char *name = NULL;
|
2011-01-10 19:51:47 +00:00
|
|
|
struct p9_qid qid;
|
|
|
|
struct inode *inode;
|
2011-02-28 11:34:03 +00:00
|
|
|
struct p9_fid *fid = NULL;
|
2023-03-27 02:06:37 +00:00
|
|
|
struct p9_fid *dfid = NULL, *ofid = NULL;
|
2011-02-28 11:34:03 +00:00
|
|
|
struct v9fs_session_info *v9ses;
|
2011-01-10 19:51:47 +00:00
|
|
|
struct posix_acl *pacl = NULL, *dacl = NULL;
|
2012-06-05 13:10:26 +00:00
|
|
|
struct dentry *res = NULL;
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2016-07-05 13:44:53 +00:00
|
|
|
if (d_in_lookup(dentry)) {
|
2012-06-10 21:13:09 +00:00
|
|
|
res = v9fs_vfs_lookup(dir, dentry, 0);
|
2012-06-05 13:10:26 +00:00
|
|
|
if (IS_ERR(res))
|
2012-06-22 08:39:14 +00:00
|
|
|
return PTR_ERR(res);
|
2012-06-05 13:10:26 +00:00
|
|
|
|
|
|
|
if (res)
|
|
|
|
dentry = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only creates */
|
2015-03-17 22:25:59 +00:00
|
|
|
if (!(flags & O_CREAT) || d_really_is_positive(dentry))
|
2013-02-05 08:55:05 +00:00
|
|
|
return finish_no_open(file, res);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2012-06-05 13:10:26 +00:00
|
|
|
v9ses = v9fs_inode2v9ses(dir);
|
|
|
|
|
2017-01-12 09:01:17 +00:00
|
|
|
name = dentry->d_name.name;
|
2021-11-02 13:16:43 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "name:%s flags:0x%x mode:0x%x\n",
|
2011-11-28 18:40:46 +00:00
|
|
|
name, flags, omode);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2016-05-29 19:29:26 +00:00
|
|
|
dfid = v9fs_parent_fid(dentry);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (IS_ERR(dfid)) {
|
|
|
|
err = PTR_ERR(dfid);
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
|
2012-06-22 08:39:14 +00:00
|
|
|
goto out;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* clone a fid to use for creation */
|
2016-08-03 15:12:12 +00:00
|
|
|
ofid = clone_fid(dfid);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (IS_ERR(ofid)) {
|
|
|
|
err = PTR_ERR(ofid);
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
|
2012-06-22 08:39:14 +00:00
|
|
|
goto out;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gid = v9fs_get_fsgid_for_create(dir);
|
|
|
|
|
|
|
|
mode = omode;
|
|
|
|
/* Update mode based on ACL value */
|
|
|
|
err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
|
|
|
|
if (err) {
|
2023-03-27 02:06:37 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "Failed to get acl values in create %d\n",
|
2011-11-28 18:40:46 +00:00
|
|
|
err);
|
2022-06-12 07:05:39 +00:00
|
|
|
goto out;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
2023-03-27 02:06:37 +00:00
|
|
|
|
2023-03-27 01:53:10 +00:00
|
|
|
if ((v9ses->cache & CACHE_WRITEBACK) && (p9_omode & P9_OWRITE)) {
|
2023-04-26 16:18:49 +00:00
|
|
|
p9_omode = (p9_omode & ~P9_OWRITE) | P9_ORDWR;
|
2023-03-27 02:06:37 +00:00
|
|
|
p9_debug(P9_DEBUG_CACHE,
|
|
|
|
"write-only file with writeback enabled, creating w/ O_RDWR\n");
|
|
|
|
}
|
|
|
|
err = p9_client_create_dotl(ofid, name, p9_omode, mode, gid, &qid);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (err < 0) {
|
2023-03-27 02:06:37 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in create %d\n",
|
2011-11-28 18:40:46 +00:00
|
|
|
err);
|
2022-06-12 07:05:39 +00:00
|
|
|
goto out;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
2011-02-28 11:34:08 +00:00
|
|
|
v9fs_invalidate_inode_attr(dir);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2011-01-10 20:22:21 +00:00
|
|
|
/* instantiate inode and assign the unopened fid to the dentry */
|
|
|
|
fid = p9_client_walk(dfid, 1, &name, 1);
|
|
|
|
if (IS_ERR(fid)) {
|
|
|
|
err = PTR_ERR(fid);
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
|
2022-06-12 07:05:39 +00:00
|
|
|
goto out;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
Revert "fs/9p: simplify iget to remove unnecessary paths"
This reverts commit 724a08450f74b02bd89078a596fd24857827c012.
This code simplification introduced significant regressions on servers
that do not remap inode numbers when exporting multiple underlying
filesystems with colliding inodes, as can be illustrated with simple
tmpfs exports in qemu with remapping disabled:
```
# host side
cd /tmp/linux-test
mkdir m1 m2
mount -t tmpfs tmpfs m1
mount -t tmpfs tmpfs m2
mkdir m1/dir m2/dir
echo foo > m1/dir/foo
echo bar > m2/dir/bar
# guest side
# started with -virtfs local,path=/tmp/linux-test,mount_tag=tmp,security_model=mapped-file
mount -t 9p -o trans=virtio,debug=1 tmp /mnt/t
ls /mnt/t/m1/dir
# foo
ls /mnt/t/m2/dir
# bar (works ok if directry isn't open)
# cd to keep first dir's inode alive
cd /mnt/t/m1/dir
ls /mnt/t/m2/dir
# foo (should be bar)
```
Other examples can be crafted with regular files with fscache enabled,
in which case I/Os just happen to the wrong file leading to
corruptions, or guest failing to boot with:
| VFS: Lookup of 'com.android.runtime' in 9p 9p would have caused loop
In theory, we'd want the servers to be smart enough and ensure they
never send us two different files with the same 'qid.path', but while
qemu has an option to remap that is recommended (and qemu prints a
warning if this case happens), there are many other servers which do
not (kvmtool, nfs-ganesha, probably diod...), we should at least ensure
we don't cause regressions on this:
- assume servers can't be trusted and operations that should get a 'new'
inode properly do so. commit d05dcfdf5e16 (" fs/9p: mitigate inode
collisions") attempted to do this, but v9fs_fid_iget_dotl() was not
called so some higher level of caching got in the way; this needs to be
fixed properly before we can re-apply the patches.
- if we ever want to really simplify this code, we will need to add some
negotiation with the server at mount time where the server could claim
they handle this properly, at which point we could optimize this out.
(but that might not be needed at all if we properly handle the 'new'
check?)
Fixes: 724a08450f74 ("fs/9p: simplify iget to remove unnecessary paths")
Reported-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/all/20240408141436.GA17022@redhat.com/
Link: https://lkml.kernel.org/r/20240923100508.GA32066@willie-the-truck
Cc: stable@vger.kernel.org # v6.9+
Message-ID: <20241024-revert_iget-v1-4-4cac63d25f72@codewreck.org>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
2024-10-23 23:52:13 +00:00
|
|
|
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
|
2011-01-10 20:22:21 +00:00
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err);
|
2022-06-12 07:05:39 +00:00
|
|
|
goto out;
|
2011-01-10 20:22:21 +00:00
|
|
|
}
|
2013-01-31 18:45:39 +00:00
|
|
|
/* Now set the ACL based on the default value */
|
|
|
|
v9fs_set_create_acl(inode, fid, dacl, pacl);
|
|
|
|
|
2022-06-12 07:05:39 +00:00
|
|
|
v9fs_fid_add(dentry, &fid);
|
2011-07-25 18:06:32 +00:00
|
|
|
d_instantiate(dentry, inode);
|
2011-01-10 20:22:21 +00:00
|
|
|
|
|
|
|
/* Since we are opening a file, assign the open fid to the file */
|
2018-06-08 15:44:56 +00:00
|
|
|
err = finish_open(file, dentry, generic_file_open);
|
2012-06-22 08:40:19 +00:00
|
|
|
if (err)
|
2022-06-12 07:05:39 +00:00
|
|
|
goto out;
|
2012-06-22 08:40:19 +00:00
|
|
|
file->private_data = ofid;
|
2022-12-08 02:03:32 +00:00
|
|
|
#ifdef CONFIG_9P_FSCACHE
|
2023-03-27 01:53:10 +00:00
|
|
|
if (v9ses->cache & CACHE_FSCACHE) {
|
2023-03-27 02:06:37 +00:00
|
|
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
2020-11-18 09:06:42 +00:00
|
|
|
fscache_use_cookie(v9fs_inode_cookie(v9inode),
|
|
|
|
file->f_mode & FMODE_WRITE);
|
2023-03-27 02:06:37 +00:00
|
|
|
}
|
2022-12-08 02:03:32 +00:00
|
|
|
#endif
|
2023-03-27 02:06:37 +00:00
|
|
|
v9fs_fid_add_modes(ofid, v9ses->flags, v9ses->cache, flags);
|
2022-06-12 07:05:39 +00:00
|
|
|
v9fs_open_fid_add(inode, &ofid);
|
2018-06-08 17:22:02 +00:00
|
|
|
file->f_mode |= FMODE_CREATED;
|
2012-06-05 13:10:26 +00:00
|
|
|
out:
|
2022-06-12 07:05:39 +00:00
|
|
|
p9_fid_put(dfid);
|
|
|
|
p9_fid_put(ofid);
|
|
|
|
p9_fid_put(fid);
|
2013-01-31 18:31:23 +00:00
|
|
|
v9fs_put_acl(dacl, pacl);
|
2012-06-05 13:10:26 +00:00
|
|
|
dput(res);
|
2012-06-22 08:39:14 +00:00
|
|
|
return err;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
|
2023-01-13 11:49:15 +00:00
|
|
|
* @idmap: The idmap of the mount
|
2011-01-10 19:51:47 +00:00
|
|
|
* @dir: inode that is being unlinked
|
|
|
|
* @dentry: dentry that is being unlinked
|
2014-06-04 23:06:26 +00:00
|
|
|
* @omode: mode for new directory
|
2011-01-10 19:51:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-01-13 11:49:15 +00:00
|
|
|
static int v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap,
|
2021-01-21 13:19:43 +00:00
|
|
|
struct inode *dir, struct dentry *dentry,
|
|
|
|
umode_t omode)
|
2011-01-10 19:51:47 +00:00
|
|
|
{
|
|
|
|
int err;
|
2024-10-23 23:52:11 +00:00
|
|
|
struct v9fs_session_info *v9ses;
|
2011-01-10 19:51:47 +00:00
|
|
|
struct p9_fid *fid = NULL, *dfid = NULL;
|
2013-01-30 20:08:21 +00:00
|
|
|
kgid_t gid;
|
2017-01-12 09:01:17 +00:00
|
|
|
const unsigned char *name;
|
2011-07-23 22:37:50 +00:00
|
|
|
umode_t mode;
|
2011-01-10 19:51:47 +00:00
|
|
|
struct inode *inode;
|
|
|
|
struct p9_qid qid;
|
|
|
|
struct posix_acl *dacl = NULL, *pacl = NULL;
|
|
|
|
|
2014-08-20 00:17:38 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "name %pd\n", dentry);
|
2024-10-23 23:52:11 +00:00
|
|
|
v9ses = v9fs_inode2v9ses(dir);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
|
|
|
omode |= S_IFDIR;
|
|
|
|
if (dir->i_mode & S_ISGID)
|
|
|
|
omode |= S_ISGID;
|
|
|
|
|
2016-05-29 19:29:26 +00:00
|
|
|
dfid = v9fs_parent_fid(dentry);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (IS_ERR(dfid)) {
|
|
|
|
err = PTR_ERR(dfid);
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
|
2011-01-10 19:51:47 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
gid = v9fs_get_fsgid_for_create(dir);
|
|
|
|
mode = omode;
|
|
|
|
/* Update mode based on ACL value */
|
|
|
|
err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
|
|
|
|
if (err) {
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mkdir %d\n",
|
|
|
|
err);
|
2011-01-10 19:51:47 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2017-01-12 09:01:17 +00:00
|
|
|
name = dentry->d_name.name;
|
2011-01-10 19:51:47 +00:00
|
|
|
err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
2013-01-31 18:45:39 +00:00
|
|
|
fid = p9_client_walk(dfid, 1, &name, 1);
|
|
|
|
if (IS_ERR(fid)) {
|
|
|
|
err = PTR_ERR(fid);
|
|
|
|
p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
|
|
|
|
err);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2011-01-10 19:51:47 +00:00
|
|
|
/* instantiate inode and assign the unopened fid to the dentry */
|
Revert "fs/9p: simplify iget to remove unnecessary paths"
This reverts commit 724a08450f74b02bd89078a596fd24857827c012.
This code simplification introduced significant regressions on servers
that do not remap inode numbers when exporting multiple underlying
filesystems with colliding inodes, as can be illustrated with simple
tmpfs exports in qemu with remapping disabled:
```
# host side
cd /tmp/linux-test
mkdir m1 m2
mount -t tmpfs tmpfs m1
mount -t tmpfs tmpfs m2
mkdir m1/dir m2/dir
echo foo > m1/dir/foo
echo bar > m2/dir/bar
# guest side
# started with -virtfs local,path=/tmp/linux-test,mount_tag=tmp,security_model=mapped-file
mount -t 9p -o trans=virtio,debug=1 tmp /mnt/t
ls /mnt/t/m1/dir
# foo
ls /mnt/t/m2/dir
# bar (works ok if directry isn't open)
# cd to keep first dir's inode alive
cd /mnt/t/m1/dir
ls /mnt/t/m2/dir
# foo (should be bar)
```
Other examples can be crafted with regular files with fscache enabled,
in which case I/Os just happen to the wrong file leading to
corruptions, or guest failing to boot with:
| VFS: Lookup of 'com.android.runtime' in 9p 9p would have caused loop
In theory, we'd want the servers to be smart enough and ensure they
never send us two different files with the same 'qid.path', but while
qemu has an option to remap that is recommended (and qemu prints a
warning if this case happens), there are many other servers which do
not (kvmtool, nfs-ganesha, probably diod...), we should at least ensure
we don't cause regressions on this:
- assume servers can't be trusted and operations that should get a 'new'
inode properly do so. commit d05dcfdf5e16 (" fs/9p: mitigate inode
collisions") attempted to do this, but v9fs_fid_iget_dotl() was not
called so some higher level of caching got in the way; this needs to be
fixed properly before we can re-apply the patches.
- if we ever want to really simplify this code, we will need to add some
negotiation with the server at mount time where the server could claim
they handle this properly, at which point we could optimize this out.
(but that might not be needed at all if we properly handle the 'new'
check?)
Fixes: 724a08450f74 ("fs/9p: simplify iget to remove unnecessary paths")
Reported-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/all/20240408141436.GA17022@redhat.com/
Link: https://lkml.kernel.org/r/20240923100508.GA32066@willie-the-truck
Cc: stable@vger.kernel.org # v6.9+
Message-ID: <20241024-revert_iget-v1-4-4cac63d25f72@codewreck.org>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
2024-10-23 23:52:13 +00:00
|
|
|
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
|
2024-01-05 16:52:02 +00:00
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
|
|
|
p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
|
|
|
|
err);
|
|
|
|
goto error;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
2024-01-05 16:52:02 +00:00
|
|
|
v9fs_fid_add(dentry, &fid);
|
|
|
|
v9fs_set_create_acl(inode, fid, dacl, pacl);
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
err = 0;
|
2011-02-28 11:34:05 +00:00
|
|
|
inc_nlink(dir);
|
2011-02-28 11:34:08 +00:00
|
|
|
v9fs_invalidate_inode_attr(dir);
|
2011-01-10 19:51:47 +00:00
|
|
|
error:
|
2022-06-12 07:05:39 +00:00
|
|
|
p9_fid_put(fid);
|
2013-01-31 18:31:23 +00:00
|
|
|
v9fs_put_acl(dacl, pacl);
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(dfid);
|
2011-01-10 19:51:47 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2023-01-13 11:49:12 +00:00
|
|
|
v9fs_vfs_getattr_dotl(struct mnt_idmap *idmap,
|
2021-01-21 13:19:43 +00:00
|
|
|
const struct path *path, struct kstat *stat,
|
|
|
|
u32 request_mask, unsigned int flags)
|
2011-01-10 19:51:47 +00:00
|
|
|
{
|
statx: Add a system call to make enhanced file info available
Add a system call to make extended file information available, including
file creation and some attribute flags where available through the
underlying filesystem.
The getattr inode operation is altered to take two additional arguments: a
u32 request_mask and an unsigned int flags that indicate the
synchronisation mode. This change is propagated to the vfs_getattr*()
function.
Functions like vfs_stat() are now inline wrappers around new functions
vfs_statx() and vfs_statx_fd() to reduce stack usage.
========
OVERVIEW
========
The idea was initially proposed as a set of xattrs that could be retrieved
with getxattr(), but the general preference proved to be for a new syscall
with an extended stat structure.
A number of requests were gathered for features to be included. The
following have been included:
(1) Make the fields a consistent size on all arches and make them large.
(2) Spare space, request flags and information flags are provided for
future expansion.
(3) Better support for the y2038 problem [Arnd Bergmann] (tv_sec is an
__s64).
(4) Creation time: The SMB protocol carries the creation time, which could
be exported by Samba, which will in turn help CIFS make use of
FS-Cache as that can be used for coherency data (stx_btime).
This is also specified in NFSv4 as a recommended attribute and could
be exported by NFSD [Steve French].
(5) Lightweight stat: Ask for just those details of interest, and allow a
netfs (such as NFS) to approximate anything not of interest, possibly
without going to the server [Trond Myklebust, Ulrich Drepper, Andreas
Dilger] (AT_STATX_DONT_SYNC).
(6) Heavyweight stat: Force a netfs to go to the server, even if it thinks
its cached attributes are up to date [Trond Myklebust]
(AT_STATX_FORCE_SYNC).
And the following have been left out for future extension:
(7) Data version number: Could be used by userspace NFS servers [Aneesh
Kumar].
Can also be used to modify fill_post_wcc() in NFSD which retrieves
i_version directly, but has just called vfs_getattr(). It could get
it from the kstat struct if it used vfs_xgetattr() instead.
(There's disagreement on the exact semantics of a single field, since
not all filesystems do this the same way).
(8) BSD stat compatibility: Including more fields from the BSD stat such
as creation time (st_btime) and inode generation number (st_gen)
[Jeremy Allison, Bernd Schubert].
(9) Inode generation number: Useful for FUSE and userspace NFS servers
[Bernd Schubert].
(This was asked for but later deemed unnecessary with the
open-by-handle capability available and caused disagreement as to
whether it's a security hole or not).
(10) Extra coherency data may be useful in making backups [Andreas Dilger].
(No particular data were offered, but things like last backup
timestamp, the data version number and the DOS archive bit would come
into this category).
(11) Allow the filesystem to indicate what it can/cannot provide: A
filesystem can now say it doesn't support a standard stat feature if
that isn't available, so if, for instance, inode numbers or UIDs don't
exist or are fabricated locally...
(This requires a separate system call - I have an fsinfo() call idea
for this).
(12) Store a 16-byte volume ID in the superblock that can be returned in
struct xstat [Steve French].
(Deferred to fsinfo).
(13) Include granularity fields in the time data to indicate the
granularity of each of the times (NFSv4 time_delta) [Steve French].
(Deferred to fsinfo).
(14) FS_IOC_GETFLAGS value. These could be translated to BSD's st_flags.
Note that the Linux IOC flags are a mess and filesystems such as Ext4
define flags that aren't in linux/fs.h, so translation in the kernel
may be a necessity (or, possibly, we provide the filesystem type too).
(Some attributes are made available in stx_attributes, but the general
feeling was that the IOC flags were to ext[234]-specific and shouldn't
be exposed through statx this way).
(15) Mask of features available on file (eg: ACLs, seclabel) [Brad Boyer,
Michael Kerrisk].
(Deferred, probably to fsinfo. Finding out if there's an ACL or
seclabal might require extra filesystem operations).
(16) Femtosecond-resolution timestamps [Dave Chinner].
(A __reserved field has been left in the statx_timestamp struct for
this - if there proves to be a need).
(17) A set multiple attributes syscall to go with this.
===============
NEW SYSTEM CALL
===============
The new system call is:
int ret = statx(int dfd,
const char *filename,
unsigned int flags,
unsigned int mask,
struct statx *buffer);
The dfd, filename and flags parameters indicate the file to query, in a
similar way to fstatat(). There is no equivalent of lstat() as that can be
emulated with statx() by passing AT_SYMLINK_NOFOLLOW in flags. There is
also no equivalent of fstat() as that can be emulated by passing a NULL
filename to statx() with the fd of interest in dfd.
Whether or not statx() synchronises the attributes with the backing store
can be controlled by OR'ing a value into the flags argument (this typically
only affects network filesystems):
(1) AT_STATX_SYNC_AS_STAT tells statx() to behave as stat() does in this
respect.
(2) AT_STATX_FORCE_SYNC will require a network filesystem to synchronise
its attributes with the server - which might require data writeback to
occur to get the timestamps correct.
(3) AT_STATX_DONT_SYNC will suppress synchronisation with the server in a
network filesystem. The resulting values should be considered
approximate.
mask is a bitmask indicating the fields in struct statx that are of
interest to the caller. The user should set this to STATX_BASIC_STATS to
get the basic set returned by stat(). It should be noted that asking for
more information may entail extra I/O operations.
buffer points to the destination for the data. This must be 256 bytes in
size.
======================
MAIN ATTRIBUTES RECORD
======================
The following structures are defined in which to return the main attribute
set:
struct statx_timestamp {
__s64 tv_sec;
__s32 tv_nsec;
__s32 __reserved;
};
struct statx {
__u32 stx_mask;
__u32 stx_blksize;
__u64 stx_attributes;
__u32 stx_nlink;
__u32 stx_uid;
__u32 stx_gid;
__u16 stx_mode;
__u16 __spare0[1];
__u64 stx_ino;
__u64 stx_size;
__u64 stx_blocks;
__u64 __spare1[1];
struct statx_timestamp stx_atime;
struct statx_timestamp stx_btime;
struct statx_timestamp stx_ctime;
struct statx_timestamp stx_mtime;
__u32 stx_rdev_major;
__u32 stx_rdev_minor;
__u32 stx_dev_major;
__u32 stx_dev_minor;
__u64 __spare2[14];
};
The defined bits in request_mask and stx_mask are:
STATX_TYPE Want/got stx_mode & S_IFMT
STATX_MODE Want/got stx_mode & ~S_IFMT
STATX_NLINK Want/got stx_nlink
STATX_UID Want/got stx_uid
STATX_GID Want/got stx_gid
STATX_ATIME Want/got stx_atime{,_ns}
STATX_MTIME Want/got stx_mtime{,_ns}
STATX_CTIME Want/got stx_ctime{,_ns}
STATX_INO Want/got stx_ino
STATX_SIZE Want/got stx_size
STATX_BLOCKS Want/got stx_blocks
STATX_BASIC_STATS [The stuff in the normal stat struct]
STATX_BTIME Want/got stx_btime{,_ns}
STATX_ALL [All currently available stuff]
stx_btime is the file creation time, stx_mask is a bitmask indicating the
data provided and __spares*[] are where as-yet undefined fields can be
placed.
Time fields are structures with separate seconds and nanoseconds fields
plus a reserved field in case we want to add even finer resolution. Note
that times will be negative if before 1970; in such a case, the nanosecond
fields will also be negative if not zero.
The bits defined in the stx_attributes field convey information about a
file, how it is accessed, where it is and what it does. The following
attributes map to FS_*_FL flags and are the same numerical value:
STATX_ATTR_COMPRESSED File is compressed by the fs
STATX_ATTR_IMMUTABLE File is marked immutable
STATX_ATTR_APPEND File is append-only
STATX_ATTR_NODUMP File is not to be dumped
STATX_ATTR_ENCRYPTED File requires key to decrypt in fs
Within the kernel, the supported flags are listed by:
KSTAT_ATTR_FS_IOC_FLAGS
[Are any other IOC flags of sufficient general interest to be exposed
through this interface?]
New flags include:
STATX_ATTR_AUTOMOUNT Object is an automount trigger
These are for the use of GUI tools that might want to mark files specially,
depending on what they are.
Fields in struct statx come in a number of classes:
(0) stx_dev_*, stx_blksize.
These are local system information and are always available.
(1) stx_mode, stx_nlinks, stx_uid, stx_gid, stx_[amc]time, stx_ino,
stx_size, stx_blocks.
These will be returned whether the caller asks for them or not. The
corresponding bits in stx_mask will be set to indicate whether they
actually have valid values.
If the caller didn't ask for them, then they may be approximated. For
example, NFS won't waste any time updating them from the server,
unless as a byproduct of updating something requested.
If the values don't actually exist for the underlying object (such as
UID or GID on a DOS file), then the bit won't be set in the stx_mask,
even if the caller asked for the value. In such a case, the returned
value will be a fabrication.
Note that there are instances where the type might not be valid, for
instance Windows reparse points.
(2) stx_rdev_*.
This will be set only if stx_mode indicates we're looking at a
blockdev or a chardev, otherwise will be 0.
(3) stx_btime.
Similar to (1), except this will be set to 0 if it doesn't exist.
=======
TESTING
=======
The following test program can be used to test the statx system call:
samples/statx/test-statx.c
Just compile and run, passing it paths to the files you want to examine.
The file is built automatically if CONFIG_SAMPLES is enabled.
Here's some example output. Firstly, an NFS directory that crosses to
another FSID. Note that the AUTOMOUNT attribute is set because transiting
this directory will cause d_automount to be invoked by the VFS.
[root@andromeda ~]# /tmp/test-statx -A /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:26 Inode: 1703937 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Attributes: 0000000000001000 (-------- -------- -------- -------- -------- -------- ---m---- --------)
Secondly, the result of automounting on that directory.
[root@andromeda ~]# /tmp/test-statx /warthog/data
statx(/warthog/data) = 0
results=7ff
Size: 4096 Blocks: 8 IO Block: 1048576 directory
Device: 00:27 Inode: 2 Links: 125
Access: (3777/drwxrwxrwx) Uid: 0 Gid: 4041
Access: 2016-11-24 09:02:12.219699527+0000
Modify: 2016-11-17 10:44:36.225653653+0000
Change: 2016-11-17 10:44:36.225653653+0000
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2017-01-31 16:46:22 +00:00
|
|
|
struct dentry *dentry = path->dentry;
|
2011-01-10 19:51:47 +00:00
|
|
|
struct v9fs_session_info *v9ses;
|
|
|
|
struct p9_fid *fid;
|
2022-12-08 02:40:37 +00:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2011-01-10 19:51:47 +00:00
|
|
|
struct p9_stat_dotl *st;
|
|
|
|
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
|
2011-03-08 11:09:50 +00:00
|
|
|
v9ses = v9fs_dentry2v9ses(dentry);
|
2023-03-27 01:53:10 +00:00
|
|
|
if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
|
2023-08-07 19:38:33 +00:00
|
|
|
generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
|
2011-02-28 11:34:01 +00:00
|
|
|
return 0;
|
2023-03-27 02:06:37 +00:00
|
|
|
} else if (v9ses->cache) {
|
2022-12-08 02:40:37 +00:00
|
|
|
if (S_ISREG(inode->i_mode)) {
|
|
|
|
int retval = filemap_fdatawrite(inode->i_mapping);
|
|
|
|
|
|
|
|
if (retval)
|
|
|
|
p9_debug(P9_DEBUG_ERROR,
|
|
|
|
"flushing writeback during getattr returned %d\n", retval);
|
|
|
|
}
|
2011-02-28 11:34:01 +00:00
|
|
|
}
|
2011-01-10 19:51:47 +00:00
|
|
|
fid = v9fs_fid_lookup(dentry);
|
|
|
|
if (IS_ERR(fid))
|
|
|
|
return PTR_ERR(fid);
|
|
|
|
|
|
|
|
/* Ask for all the fields in stat structure. Server will return
|
|
|
|
* whatever it supports
|
|
|
|
*/
|
|
|
|
|
|
|
|
st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(fid);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (IS_ERR(st))
|
|
|
|
return PTR_ERR(st);
|
|
|
|
|
2019-01-24 06:35:13 +00:00
|
|
|
v9fs_stat2inode_dotl(st, d_inode(dentry), 0);
|
2023-08-07 19:38:33 +00:00
|
|
|
generic_fillattr(&nop_mnt_idmap, request_mask, d_inode(dentry), stat);
|
2011-01-10 19:51:47 +00:00
|
|
|
/* Change block size to what the server returned */
|
|
|
|
stat->blksize = st->st_blksize;
|
|
|
|
|
|
|
|
kfree(st);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-18 17:33:13 +00:00
|
|
|
/*
|
|
|
|
* Attribute flags.
|
|
|
|
*/
|
|
|
|
#define P9_ATTR_MODE (1 << 0)
|
|
|
|
#define P9_ATTR_UID (1 << 1)
|
|
|
|
#define P9_ATTR_GID (1 << 2)
|
|
|
|
#define P9_ATTR_SIZE (1 << 3)
|
|
|
|
#define P9_ATTR_ATIME (1 << 4)
|
|
|
|
#define P9_ATTR_MTIME (1 << 5)
|
|
|
|
#define P9_ATTR_CTIME (1 << 6)
|
|
|
|
#define P9_ATTR_ATIME_SET (1 << 7)
|
|
|
|
#define P9_ATTR_MTIME_SET (1 << 8)
|
|
|
|
|
|
|
|
struct dotl_iattr_map {
|
|
|
|
int iattr_valid;
|
|
|
|
int p9_iattr_valid;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int v9fs_mapped_iattr_valid(int iattr_valid)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int p9_iattr_valid = 0;
|
|
|
|
struct dotl_iattr_map dotl_iattr_map[] = {
|
|
|
|
{ ATTR_MODE, P9_ATTR_MODE },
|
|
|
|
{ ATTR_UID, P9_ATTR_UID },
|
|
|
|
{ ATTR_GID, P9_ATTR_GID },
|
|
|
|
{ ATTR_SIZE, P9_ATTR_SIZE },
|
|
|
|
{ ATTR_ATIME, P9_ATTR_ATIME },
|
|
|
|
{ ATTR_MTIME, P9_ATTR_MTIME },
|
|
|
|
{ ATTR_CTIME, P9_ATTR_CTIME },
|
|
|
|
{ ATTR_ATIME_SET, P9_ATTR_ATIME_SET },
|
|
|
|
{ ATTR_MTIME_SET, P9_ATTR_MTIME_SET },
|
|
|
|
};
|
|
|
|
for (i = 0; i < ARRAY_SIZE(dotl_iattr_map); i++) {
|
|
|
|
if (iattr_valid & dotl_iattr_map[i].iattr_valid)
|
|
|
|
p9_iattr_valid |= dotl_iattr_map[i].p9_iattr_valid;
|
|
|
|
}
|
|
|
|
return p9_iattr_valid;
|
|
|
|
}
|
|
|
|
|
2011-01-10 19:51:47 +00:00
|
|
|
/**
|
|
|
|
* v9fs_vfs_setattr_dotl - set file metadata
|
2023-01-13 11:49:11 +00:00
|
|
|
* @idmap: idmap of the mount
|
2011-01-10 19:51:47 +00:00
|
|
|
* @dentry: file whose metadata to set
|
|
|
|
* @iattr: metadata assignment structure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-01-13 11:49:11 +00:00
|
|
|
int v9fs_vfs_setattr_dotl(struct mnt_idmap *idmap,
|
2021-01-21 13:19:43 +00:00
|
|
|
struct dentry *dentry, struct iattr *iattr)
|
2011-01-10 19:51:47 +00:00
|
|
|
{
|
2020-09-23 14:11:46 +00:00
|
|
|
int retval, use_dentry = 0;
|
2022-12-08 02:40:37 +00:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2023-03-27 01:53:10 +00:00
|
|
|
struct v9fs_session_info __maybe_unused *v9ses;
|
2020-07-10 10:15:48 +00:00
|
|
|
struct p9_fid *fid = NULL;
|
2021-11-29 11:44:34 +00:00
|
|
|
struct p9_iattr_dotl p9attr = {
|
|
|
|
.uid = INVALID_UID,
|
|
|
|
.gid = INVALID_GID,
|
|
|
|
};
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "\n");
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2023-01-13 11:49:11 +00:00
|
|
|
retval = setattr_prepare(&nop_mnt_idmap, dentry, iattr);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2022-12-08 02:40:37 +00:00
|
|
|
v9ses = v9fs_dentry2v9ses(dentry);
|
|
|
|
|
2011-12-18 17:33:13 +00:00
|
|
|
p9attr.valid = v9fs_mapped_iattr_valid(iattr->ia_valid);
|
2021-11-29 11:44:34 +00:00
|
|
|
if (iattr->ia_valid & ATTR_MODE)
|
|
|
|
p9attr.mode = iattr->ia_mode;
|
|
|
|
if (iattr->ia_valid & ATTR_UID)
|
|
|
|
p9attr.uid = iattr->ia_uid;
|
|
|
|
if (iattr->ia_valid & ATTR_GID)
|
|
|
|
p9attr.gid = iattr->ia_gid;
|
|
|
|
if (iattr->ia_valid & ATTR_SIZE)
|
|
|
|
p9attr.size = iattr->ia_size;
|
|
|
|
if (iattr->ia_valid & ATTR_ATIME_SET) {
|
|
|
|
p9attr.atime_sec = iattr->ia_atime.tv_sec;
|
|
|
|
p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
|
|
|
|
}
|
|
|
|
if (iattr->ia_valid & ATTR_MTIME_SET) {
|
|
|
|
p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
|
|
|
|
p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
|
|
|
|
}
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2020-07-10 10:15:48 +00:00
|
|
|
if (iattr->ia_valid & ATTR_FILE) {
|
|
|
|
fid = iattr->ia_file->private_data;
|
|
|
|
WARN_ON(!fid);
|
|
|
|
}
|
2020-09-23 14:11:46 +00:00
|
|
|
if (!fid) {
|
2020-07-10 10:15:48 +00:00
|
|
|
fid = v9fs_fid_lookup(dentry);
|
2020-09-23 14:11:46 +00:00
|
|
|
use_dentry = 1;
|
|
|
|
}
|
2011-01-10 19:51:47 +00:00
|
|
|
if (IS_ERR(fid))
|
|
|
|
return PTR_ERR(fid);
|
|
|
|
|
2011-02-28 11:34:11 +00:00
|
|
|
/* Write all dirty data */
|
2022-12-08 02:40:37 +00:00
|
|
|
if (S_ISREG(inode->i_mode)) {
|
|
|
|
retval = filemap_fdatawrite(inode->i_mapping);
|
|
|
|
if (retval < 0)
|
|
|
|
p9_debug(P9_DEBUG_ERROR,
|
|
|
|
"Flushing file prior to setattr failed: %d\n", retval);
|
|
|
|
}
|
2011-02-28 11:34:11 +00:00
|
|
|
|
2011-02-28 11:34:10 +00:00
|
|
|
retval = p9_client_setattr(fid, &p9attr);
|
2020-09-23 14:11:46 +00:00
|
|
|
if (retval < 0) {
|
|
|
|
if (use_dentry)
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(fid);
|
2011-02-28 11:34:10 +00:00
|
|
|
return retval;
|
2020-09-23 14:11:46 +00:00
|
|
|
}
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2022-12-08 02:40:37 +00:00
|
|
|
if ((iattr->ia_valid & ATTR_SIZE) && iattr->ia_size !=
|
|
|
|
i_size_read(inode)) {
|
2013-01-31 17:58:16 +00:00
|
|
|
truncate_setsize(inode, iattr->ia_size);
|
2023-12-06 12:48:56 +00:00
|
|
|
netfs_resize_file(netfs_inode(inode), iattr->ia_size, true);
|
2023-03-27 02:06:37 +00:00
|
|
|
|
2023-03-27 01:53:10 +00:00
|
|
|
#ifdef CONFIG_9P_FSCACHE
|
|
|
|
if (v9ses->cache & CACHE_FSCACHE)
|
|
|
|
fscache_resize_cookie(v9fs_inode_cookie(V9FS_I(inode)),
|
|
|
|
iattr->ia_size);
|
|
|
|
#endif
|
2022-12-08 02:40:37 +00:00
|
|
|
}
|
2011-03-08 11:09:48 +00:00
|
|
|
|
2013-01-31 17:58:16 +00:00
|
|
|
v9fs_invalidate_inode_attr(inode);
|
2023-01-13 11:49:11 +00:00
|
|
|
setattr_copy(&nop_mnt_idmap, inode, iattr);
|
2013-01-31 17:58:16 +00:00
|
|
|
mark_inode_dirty(inode);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (iattr->ia_valid & ATTR_MODE) {
|
|
|
|
/* We also want to update ACL when we update mode bits */
|
2013-01-31 17:58:16 +00:00
|
|
|
retval = v9fs_acl_chmod(inode, fid);
|
2020-09-23 14:11:46 +00:00
|
|
|
if (retval < 0) {
|
|
|
|
if (use_dentry)
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(fid);
|
2011-01-10 19:51:47 +00:00
|
|
|
return retval;
|
2020-09-23 14:11:46 +00:00
|
|
|
}
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
2020-09-23 14:11:46 +00:00
|
|
|
if (use_dentry)
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(fid);
|
2020-09-23 14:11:46 +00:00
|
|
|
|
2011-01-10 19:51:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_stat2inode_dotl - populate an inode structure with stat info
|
|
|
|
* @stat: stat structure
|
|
|
|
* @inode: inode to populate
|
2019-01-24 06:35:13 +00:00
|
|
|
* @flags: ctrl flags (e.g. V9FS_STAT2INODE_KEEP_ISIZE)
|
2011-01-10 19:51:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2019-01-24 06:35:13 +00:00
|
|
|
v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode,
|
|
|
|
unsigned int flags)
|
2011-01-10 19:51:47 +00:00
|
|
|
{
|
2011-07-26 06:53:22 +00:00
|
|
|
umode_t mode;
|
2011-02-28 11:34:06 +00:00
|
|
|
struct v9fs_inode *v9inode = V9FS_I(inode);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
|
|
|
if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
|
2023-10-04 18:52:00 +00:00
|
|
|
inode_set_atime(inode, stat->st_atime_sec,
|
|
|
|
stat->st_atime_nsec);
|
|
|
|
inode_set_mtime(inode, stat->st_mtime_sec,
|
|
|
|
stat->st_mtime_nsec);
|
2023-07-05 19:00:46 +00:00
|
|
|
inode_set_ctime(inode, stat->st_ctime_sec,
|
|
|
|
stat->st_ctime_nsec);
|
2011-01-10 19:51:47 +00:00
|
|
|
inode->i_uid = stat->st_uid;
|
|
|
|
inode->i_gid = stat->st_gid;
|
2011-10-28 12:13:29 +00:00
|
|
|
set_nlink(inode, stat->st_nlink);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2011-07-25 18:06:33 +00:00
|
|
|
mode = stat->st_mode & S_IALLUGO;
|
|
|
|
mode |= inode->i_mode & ~S_IALLUGO;
|
|
|
|
inode->i_mode = mode;
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2023-12-06 12:48:56 +00:00
|
|
|
v9inode->netfs.remote_i_size = stat->st_size;
|
2019-01-24 06:35:13 +00:00
|
|
|
if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE))
|
|
|
|
v9fs_i_size_write(inode, stat->st_size);
|
2011-01-10 19:51:47 +00:00
|
|
|
inode->i_blocks = stat->st_blocks;
|
|
|
|
} else {
|
|
|
|
if (stat->st_result_mask & P9_STATS_ATIME) {
|
2023-10-04 18:52:00 +00:00
|
|
|
inode_set_atime(inode, stat->st_atime_sec,
|
|
|
|
stat->st_atime_nsec);
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
|
|
|
if (stat->st_result_mask & P9_STATS_MTIME) {
|
2023-10-04 18:52:00 +00:00
|
|
|
inode_set_mtime(inode, stat->st_mtime_sec,
|
|
|
|
stat->st_mtime_nsec);
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
|
|
|
if (stat->st_result_mask & P9_STATS_CTIME) {
|
2023-07-05 19:00:46 +00:00
|
|
|
inode_set_ctime(inode, stat->st_ctime_sec,
|
|
|
|
stat->st_ctime_nsec);
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
|
|
|
if (stat->st_result_mask & P9_STATS_UID)
|
|
|
|
inode->i_uid = stat->st_uid;
|
|
|
|
if (stat->st_result_mask & P9_STATS_GID)
|
|
|
|
inode->i_gid = stat->st_gid;
|
|
|
|
if (stat->st_result_mask & P9_STATS_NLINK)
|
2011-10-28 12:13:29 +00:00
|
|
|
set_nlink(inode, stat->st_nlink);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (stat->st_result_mask & P9_STATS_MODE) {
|
2021-01-31 19:37:39 +00:00
|
|
|
mode = stat->st_mode & S_IALLUGO;
|
|
|
|
mode |= inode->i_mode & ~S_IALLUGO;
|
|
|
|
inode->i_mode = mode;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
2019-01-24 06:35:13 +00:00
|
|
|
if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE) &&
|
2023-12-06 12:48:56 +00:00
|
|
|
stat->st_result_mask & P9_STATS_SIZE) {
|
|
|
|
v9inode->netfs.remote_i_size = stat->st_size;
|
2019-01-24 06:35:13 +00:00
|
|
|
v9fs_i_size_write(inode, stat->st_size);
|
2023-12-06 12:48:56 +00:00
|
|
|
}
|
2011-01-10 19:51:47 +00:00
|
|
|
if (stat->st_result_mask & P9_STATS_BLOCKS)
|
|
|
|
inode->i_blocks = stat->st_blocks;
|
|
|
|
}
|
|
|
|
if (stat->st_result_mask & P9_STATS_GEN)
|
2011-07-11 16:40:59 +00:00
|
|
|
inode->i_generation = stat->st_gen;
|
2011-01-10 19:51:47 +00:00
|
|
|
|
|
|
|
/* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
|
|
|
|
* because the inode structure does not have fields for them.
|
|
|
|
*/
|
2011-02-28 11:34:06 +00:00
|
|
|
v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2023-01-13 11:49:14 +00:00
|
|
|
v9fs_vfs_symlink_dotl(struct mnt_idmap *idmap, struct inode *dir,
|
2021-01-21 13:19:43 +00:00
|
|
|
struct dentry *dentry, const char *symname)
|
2011-01-10 19:51:47 +00:00
|
|
|
{
|
|
|
|
int err;
|
2013-01-30 20:08:21 +00:00
|
|
|
kgid_t gid;
|
2017-01-12 09:01:17 +00:00
|
|
|
const unsigned char *name;
|
2011-02-28 11:34:08 +00:00
|
|
|
struct p9_qid qid;
|
|
|
|
struct p9_fid *dfid;
|
|
|
|
struct p9_fid *fid = NULL;
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2017-01-12 09:01:17 +00:00
|
|
|
name = dentry->d_name.name;
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "%lu,%s,%s\n", dir->i_ino, name, symname);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2016-05-29 19:29:26 +00:00
|
|
|
dfid = v9fs_parent_fid(dentry);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (IS_ERR(dfid)) {
|
|
|
|
err = PTR_ERR(dfid);
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
|
2011-01-10 19:51:47 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
gid = v9fs_get_fsgid_for_create(dir);
|
|
|
|
|
|
|
|
/* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
|
2017-01-12 09:01:17 +00:00
|
|
|
err = p9_client_symlink(dfid, name, symname, gid, &qid);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
|
|
|
if (err < 0) {
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
|
2011-01-10 19:51:47 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2011-02-28 11:34:08 +00:00
|
|
|
v9fs_invalidate_inode_attr(dir);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
|
|
|
error:
|
2022-06-12 07:05:39 +00:00
|
|
|
p9_fid_put(fid);
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(dfid);
|
2011-01-10 19:51:47 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_vfs_link_dotl - create a hardlink for dotl
|
|
|
|
* @old_dentry: dentry for file to link to
|
|
|
|
* @dir: inode destination for new link
|
|
|
|
* @dentry: dentry for link
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
|
|
|
|
struct dentry *dentry)
|
|
|
|
{
|
|
|
|
int err;
|
2011-02-28 11:34:08 +00:00
|
|
|
struct p9_fid *dfid, *oldfid;
|
|
|
|
struct v9fs_session_info *v9ses;
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2014-08-20 00:17:38 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "dir ino: %lu, old_name: %pd, new_name: %pd\n",
|
|
|
|
dir->i_ino, old_dentry, dentry);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
|
|
|
v9ses = v9fs_inode2v9ses(dir);
|
2016-05-29 19:29:26 +00:00
|
|
|
dfid = v9fs_parent_fid(dentry);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (IS_ERR(dfid))
|
|
|
|
return PTR_ERR(dfid);
|
|
|
|
|
|
|
|
oldfid = v9fs_fid_lookup(old_dentry);
|
2020-09-23 14:11:46 +00:00
|
|
|
if (IS_ERR(oldfid)) {
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(dfid);
|
2011-01-10 19:51:47 +00:00
|
|
|
return PTR_ERR(oldfid);
|
2020-09-23 14:11:46 +00:00
|
|
|
}
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2017-01-12 09:01:17 +00:00
|
|
|
err = p9_client_link(dfid, oldfid, dentry->d_name.name);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(dfid);
|
|
|
|
p9_fid_put(oldfid);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (err < 0) {
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
|
2011-01-10 19:51:47 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-02-28 11:34:08 +00:00
|
|
|
v9fs_invalidate_inode_attr(dir);
|
2023-03-27 01:53:10 +00:00
|
|
|
if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
|
2011-01-10 19:51:47 +00:00
|
|
|
/* Get the latest stat info from server. */
|
|
|
|
struct p9_fid *fid;
|
2021-11-02 13:16:43 +00:00
|
|
|
|
2011-01-10 19:51:47 +00:00
|
|
|
fid = v9fs_fid_lookup(old_dentry);
|
|
|
|
if (IS_ERR(fid))
|
|
|
|
return PTR_ERR(fid);
|
|
|
|
|
2015-03-17 22:25:59 +00:00
|
|
|
v9fs_refresh_inode_dotl(fid, d_inode(old_dentry));
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(fid);
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
2015-03-17 22:25:59 +00:00
|
|
|
ihold(d_inode(old_dentry));
|
|
|
|
d_instantiate(dentry, d_inode(old_dentry));
|
2011-01-10 19:51:47 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* v9fs_vfs_mknod_dotl - create a special file
|
2023-01-13 11:49:16 +00:00
|
|
|
* @idmap: The idmap of the mount
|
2011-01-10 19:51:47 +00:00
|
|
|
* @dir: inode destination for new link
|
|
|
|
* @dentry: dentry for file
|
2014-06-04 23:06:26 +00:00
|
|
|
* @omode: mode for creation
|
2011-01-10 19:51:47 +00:00
|
|
|
* @rdev: device associated with special file
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int
|
2023-01-13 11:49:16 +00:00
|
|
|
v9fs_vfs_mknod_dotl(struct mnt_idmap *idmap, struct inode *dir,
|
2021-01-21 13:19:43 +00:00
|
|
|
struct dentry *dentry, umode_t omode, dev_t rdev)
|
2011-01-10 19:51:47 +00:00
|
|
|
{
|
|
|
|
int err;
|
2013-01-30 20:08:21 +00:00
|
|
|
kgid_t gid;
|
2017-01-12 09:01:17 +00:00
|
|
|
const unsigned char *name;
|
2011-07-23 22:37:50 +00:00
|
|
|
umode_t mode;
|
2024-10-23 23:52:11 +00:00
|
|
|
struct v9fs_session_info *v9ses;
|
2011-01-10 19:51:47 +00:00
|
|
|
struct p9_fid *fid = NULL, *dfid = NULL;
|
|
|
|
struct inode *inode;
|
|
|
|
struct p9_qid qid;
|
|
|
|
struct posix_acl *dacl = NULL, *pacl = NULL;
|
|
|
|
|
2021-11-02 13:16:43 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %x MAJOR: %u MINOR: %u\n",
|
2014-10-22 00:11:25 +00:00
|
|
|
dir->i_ino, dentry, omode,
|
2011-11-28 18:40:46 +00:00
|
|
|
MAJOR(rdev), MINOR(rdev));
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2024-10-23 23:52:11 +00:00
|
|
|
v9ses = v9fs_inode2v9ses(dir);
|
2016-05-29 19:29:26 +00:00
|
|
|
dfid = v9fs_parent_fid(dentry);
|
2011-01-10 19:51:47 +00:00
|
|
|
if (IS_ERR(dfid)) {
|
|
|
|
err = PTR_ERR(dfid);
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
|
2011-01-10 19:51:47 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
gid = v9fs_get_fsgid_for_create(dir);
|
|
|
|
mode = omode;
|
|
|
|
/* Update mode based on ACL value */
|
|
|
|
err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
|
|
|
|
if (err) {
|
2011-11-28 18:40:46 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mknod %d\n",
|
|
|
|
err);
|
2011-01-10 19:51:47 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2017-01-12 09:01:17 +00:00
|
|
|
name = dentry->d_name.name;
|
2011-01-10 19:51:47 +00:00
|
|
|
|
|
|
|
err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
|
2011-02-28 11:34:08 +00:00
|
|
|
v9fs_invalidate_inode_attr(dir);
|
2013-01-31 18:45:39 +00:00
|
|
|
fid = p9_client_walk(dfid, 1, &name, 1);
|
|
|
|
if (IS_ERR(fid)) {
|
|
|
|
err = PTR_ERR(fid);
|
|
|
|
p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
|
|
|
|
err);
|
|
|
|
goto error;
|
|
|
|
}
|
Revert "fs/9p: simplify iget to remove unnecessary paths"
This reverts commit 724a08450f74b02bd89078a596fd24857827c012.
This code simplification introduced significant regressions on servers
that do not remap inode numbers when exporting multiple underlying
filesystems with colliding inodes, as can be illustrated with simple
tmpfs exports in qemu with remapping disabled:
```
# host side
cd /tmp/linux-test
mkdir m1 m2
mount -t tmpfs tmpfs m1
mount -t tmpfs tmpfs m2
mkdir m1/dir m2/dir
echo foo > m1/dir/foo
echo bar > m2/dir/bar
# guest side
# started with -virtfs local,path=/tmp/linux-test,mount_tag=tmp,security_model=mapped-file
mount -t 9p -o trans=virtio,debug=1 tmp /mnt/t
ls /mnt/t/m1/dir
# foo
ls /mnt/t/m2/dir
# bar (works ok if directry isn't open)
# cd to keep first dir's inode alive
cd /mnt/t/m1/dir
ls /mnt/t/m2/dir
# foo (should be bar)
```
Other examples can be crafted with regular files with fscache enabled,
in which case I/Os just happen to the wrong file leading to
corruptions, or guest failing to boot with:
| VFS: Lookup of 'com.android.runtime' in 9p 9p would have caused loop
In theory, we'd want the servers to be smart enough and ensure they
never send us two different files with the same 'qid.path', but while
qemu has an option to remap that is recommended (and qemu prints a
warning if this case happens), there are many other servers which do
not (kvmtool, nfs-ganesha, probably diod...), we should at least ensure
we don't cause regressions on this:
- assume servers can't be trusted and operations that should get a 'new'
inode properly do so. commit d05dcfdf5e16 (" fs/9p: mitigate inode
collisions") attempted to do this, but v9fs_fid_iget_dotl() was not
called so some higher level of caching got in the way; this needs to be
fixed properly before we can re-apply the patches.
- if we ever want to really simplify this code, we will need to add some
negotiation with the server at mount time where the server could claim
they handle this properly, at which point we could optimize this out.
(but that might not be needed at all if we properly handle the 'new'
check?)
Fixes: 724a08450f74 ("fs/9p: simplify iget to remove unnecessary paths")
Reported-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/all/20240408141436.GA17022@redhat.com/
Link: https://lkml.kernel.org/r/20240923100508.GA32066@willie-the-truck
Cc: stable@vger.kernel.org # v6.9+
Message-ID: <20241024-revert_iget-v1-4-4cac63d25f72@codewreck.org>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
2024-10-23 23:52:13 +00:00
|
|
|
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
|
2024-01-05 17:17:35 +00:00
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
|
|
|
p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
|
|
|
|
err);
|
|
|
|
goto error;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
2024-01-05 17:17:35 +00:00
|
|
|
v9fs_set_create_acl(inode, fid, dacl, pacl);
|
|
|
|
v9fs_fid_add(dentry, &fid);
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
err = 0;
|
2011-01-10 19:51:47 +00:00
|
|
|
error:
|
2022-06-12 07:05:39 +00:00
|
|
|
p9_fid_put(fid);
|
2013-01-31 18:31:23 +00:00
|
|
|
v9fs_put_acl(dacl, pacl);
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(dfid);
|
2020-09-23 14:11:46 +00:00
|
|
|
|
2011-01-10 19:51:47 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-17 15:20:54 +00:00
|
|
|
* v9fs_vfs_get_link_dotl - follow a symlink path
|
2011-01-10 19:51:47 +00:00
|
|
|
* @dentry: dentry for symlink
|
2015-11-17 15:20:54 +00:00
|
|
|
* @inode: inode for symlink
|
2015-12-29 20:58:39 +00:00
|
|
|
* @done: destructor for return value
|
2011-01-10 19:51:47 +00:00
|
|
|
*/
|
|
|
|
|
2015-05-02 17:32:22 +00:00
|
|
|
static const char *
|
2015-11-17 15:20:54 +00:00
|
|
|
v9fs_vfs_get_link_dotl(struct dentry *dentry,
|
2015-12-29 20:58:39 +00:00
|
|
|
struct inode *inode,
|
|
|
|
struct delayed_call *done)
|
2011-01-10 19:51:47 +00:00
|
|
|
{
|
2015-11-17 15:20:54 +00:00
|
|
|
struct p9_fid *fid;
|
2011-01-08 01:58:46 +00:00
|
|
|
char *target;
|
2015-04-14 21:42:49 +00:00
|
|
|
int retval;
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2015-11-17 15:20:54 +00:00
|
|
|
if (!dentry)
|
|
|
|
return ERR_PTR(-ECHILD);
|
|
|
|
|
2014-08-20 00:17:38 +00:00
|
|
|
p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
|
2011-01-10 19:51:47 +00:00
|
|
|
|
2015-11-17 15:20:54 +00:00
|
|
|
fid = v9fs_fid_lookup(dentry);
|
2015-04-14 21:42:49 +00:00
|
|
|
if (IS_ERR(fid))
|
|
|
|
return ERR_CAST(fid);
|
2011-01-08 01:58:46 +00:00
|
|
|
retval = p9_client_readlink(fid, &target);
|
2022-06-12 04:42:32 +00:00
|
|
|
p9_fid_put(fid);
|
2015-04-14 21:42:49 +00:00
|
|
|
if (retval)
|
|
|
|
return ERR_PTR(retval);
|
2015-12-29 20:58:39 +00:00
|
|
|
set_delayed_call(done, kfree_link, target);
|
|
|
|
return target;
|
2011-01-10 19:51:47 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 11:34:06 +00:00
|
|
|
int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
|
|
|
|
{
|
|
|
|
struct p9_stat_dotl *st;
|
|
|
|
struct v9fs_session_info *v9ses;
|
2019-01-24 06:35:13 +00:00
|
|
|
unsigned int flags;
|
2011-02-28 11:34:06 +00:00
|
|
|
|
|
|
|
v9ses = v9fs_inode2v9ses(inode);
|
|
|
|
st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
|
|
|
|
if (IS_ERR(st))
|
|
|
|
return PTR_ERR(st);
|
2011-07-25 18:06:33 +00:00
|
|
|
/*
|
|
|
|
* Don't update inode if the file type is different
|
|
|
|
*/
|
2021-03-02 01:37:10 +00:00
|
|
|
if (inode_wrong_type(inode, st->st_mode))
|
2011-07-25 18:06:33 +00:00
|
|
|
goto out;
|
2011-02-28 11:34:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't want to refresh inode->i_size,
|
|
|
|
* because we may have cached data
|
|
|
|
*/
|
2023-03-27 01:53:10 +00:00
|
|
|
flags = (v9ses->cache & CACHE_LOOSE) ?
|
2019-01-24 06:35:13 +00:00
|
|
|
V9FS_STAT2INODE_KEEP_ISIZE : 0;
|
|
|
|
v9fs_stat2inode_dotl(st, inode, flags);
|
2011-07-25 18:06:33 +00:00
|
|
|
out:
|
2011-02-28 11:34:06 +00:00
|
|
|
kfree(st);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-10 19:51:47 +00:00
|
|
|
const struct inode_operations v9fs_dir_inode_operations_dotl = {
|
|
|
|
.create = v9fs_vfs_create_dotl,
|
2012-06-05 13:10:26 +00:00
|
|
|
.atomic_open = v9fs_vfs_atomic_open_dotl,
|
2011-01-10 19:51:47 +00:00
|
|
|
.lookup = v9fs_vfs_lookup,
|
|
|
|
.link = v9fs_vfs_link_dotl,
|
|
|
|
.symlink = v9fs_vfs_symlink_dotl,
|
|
|
|
.unlink = v9fs_vfs_unlink,
|
|
|
|
.mkdir = v9fs_vfs_mkdir_dotl,
|
|
|
|
.rmdir = v9fs_vfs_rmdir,
|
|
|
|
.mknod = v9fs_vfs_mknod_dotl,
|
|
|
|
.rename = v9fs_vfs_rename,
|
|
|
|
.getattr = v9fs_vfs_getattr_dotl,
|
|
|
|
.setattr = v9fs_vfs_setattr_dotl,
|
|
|
|
.listxattr = v9fs_listxattr,
|
2022-09-22 15:17:04 +00:00
|
|
|
.get_inode_acl = v9fs_iop_get_inode_acl,
|
|
|
|
.get_acl = v9fs_iop_get_acl,
|
2022-09-22 15:17:05 +00:00
|
|
|
.set_acl = v9fs_iop_set_acl,
|
2011-01-10 19:51:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct inode_operations v9fs_file_inode_operations_dotl = {
|
|
|
|
.getattr = v9fs_vfs_getattr_dotl,
|
|
|
|
.setattr = v9fs_vfs_setattr_dotl,
|
|
|
|
.listxattr = v9fs_listxattr,
|
2022-09-22 15:17:04 +00:00
|
|
|
.get_inode_acl = v9fs_iop_get_inode_acl,
|
|
|
|
.get_acl = v9fs_iop_get_acl,
|
2022-09-22 15:17:05 +00:00
|
|
|
.set_acl = v9fs_iop_set_acl,
|
2011-01-10 19:51:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct inode_operations v9fs_symlink_inode_operations_dotl = {
|
2015-11-17 15:20:54 +00:00
|
|
|
.get_link = v9fs_vfs_get_link_dotl,
|
2011-01-10 19:51:47 +00:00
|
|
|
.getattr = v9fs_vfs_getattr_dotl,
|
|
|
|
.setattr = v9fs_vfs_setattr_dotl,
|
|
|
|
.listxattr = v9fs_listxattr,
|
|
|
|
};
|