]> www.infradead.org Git - users/willy/linux.git/commitdiff
vfs: Allow fsinfo() to query what's in an fs_context
authorDavid Howells <dhowells@redhat.com>
Mon, 29 Oct 2018 12:53:12 +0000 (12:53 +0000)
committerDavid Howells <dhowells@redhat.com>
Mon, 29 Oct 2018 12:53:12 +0000 (12:53 +0000)
Allow fsinfo() to be used to query the filesystem attached to an fs_context
once a superblock has been created or if it comes from fspick().

This is done with something like:

fd = fsopen("ext4", 0);
...
fsconfig(fd, fsconfig_cmd_create, ...);
fsinfo(fd, NULL, ...);

Signed-off-by: David Howells <dhowells@redhat.com>
fs/statfs.c

index f3cf8aa42a3dadbb3539a942978d4bb14e34c7b5..790e21367d7037ebaa46eac7acb194434102d47e 100644 (file)
@@ -636,7 +636,8 @@ int vfs_fsinfo(struct path *path, struct fsinfo_kparams *params)
                return ret;
 
        if (params->request == FSINFO_ATTR_IDS &&
-           params->buffer) {
+           params->buffer &&
+           path->mnt) {
                struct fsinfo_ids *p = params->buffer;
 
                p->f_flags |= flags_by_mnt(path->mnt->mnt_flags);
@@ -677,13 +678,40 @@ out:
        return ret;
 }
 
+static int vfs_fsinfo_fscontext(struct fs_context *fc,
+                               struct fsinfo_kparams *params)
+{
+       int ret;
+
+       if (fc->ops == &legacy_fs_context_ops)
+               return -EOPNOTSUPP;
+
+       ret = mutex_lock_interruptible(&fc->uapi_mutex);
+       if (ret < 0)
+               return ret;
+
+       ret = -EIO;
+       if (fc->root) {
+               struct path path = { .dentry = fc->root };
+
+               ret = vfs_fsinfo(&path, params);
+       }
+
+       mutex_unlock(&fc->uapi_mutex);
+       return ret;
+}
+
 static int vfs_fsinfo_fd(unsigned int fd, struct fsinfo_kparams *params)
 {
        struct fd f = fdget_raw(fd);
        int ret = -EBADF;
 
        if (f.file) {
-               ret = vfs_fsinfo(&f.file->f_path, params);
+               if (f.file->f_op == &fscontext_fops)
+                       ret = vfs_fsinfo_fscontext(f.file->private_data,
+                                                  params);
+               else
+                       ret = vfs_fsinfo(&f.file->f_path, params);
                fdput(f);
        }
        return ret;