[PATCH 2/5] afs: Add fsinfo support

From: David Howells
Date: Wed Aug 01 2018 - 12:14:13 EST


Add fsinfo support to the AFS filesystem.

Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
---

fs/afs/super.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 128 insertions(+)

diff --git a/fs/afs/super.c b/fs/afs/super.c
index 56eab3433aba..10b5616a7843 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -26,6 +26,7 @@
#include <linux/sched.h>
#include <linux/nsproxy.h>
#include <linux/magic.h>
+#include <linux/fsinfo.h>
#include <net/net_namespace.h>
#include "internal.h"

@@ -34,6 +35,7 @@ static void afs_kill_super(struct super_block *sb);
static struct inode *afs_alloc_inode(struct super_block *sb);
static void afs_destroy_inode(struct inode *inode);
static int afs_statfs(struct dentry *dentry, struct kstatfs *buf);
+static int afs_get_fsinfo(struct dentry *dentry, struct fsinfo_kparams *params);
static int afs_show_devname(struct seq_file *m, struct dentry *root);
static int afs_show_options(struct seq_file *m, struct dentry *root);
static int afs_init_fs_context(struct fs_context *fc, struct dentry *reference);
@@ -53,6 +55,7 @@ int afs_net_id;

static const struct super_operations afs_super_ops = {
.statfs = afs_statfs,
+ .get_fsinfo = afs_get_fsinfo,
.alloc_inode = afs_alloc_inode,
.drop_inode = afs_drop_inode,
.destroy_inode = afs_destroy_inode,
@@ -769,3 +772,128 @@ static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)

return ret;
}
+
+/*
+ * Get filesystem information.
+ */
+static int afs_get_fsinfo(struct dentry *dentry, struct fsinfo_kparams *params)
+{
+ struct fsinfo_timestamp_info *tsinfo;
+ struct fsinfo_server_address *addr;
+ struct fsinfo_capabilities *caps;
+ struct fsinfo_supports *sup;
+ struct afs_server_list *slist;
+ struct afs_super_info *as = AFS_FS_S(dentry->d_sb);
+ struct afs_addr_list *alist;
+ struct afs_server *server;
+ struct afs_volume *volume = as->volume;
+ struct afs_cell *cell = as->cell;
+ struct afs_net *net = afs_d2net(dentry);
+ bool dyn_root = as->dyn_root;
+ int ret;
+
+ switch (params->request) {
+ case FSINFO_ATTR_TIMESTAMP_INFO:
+ tsinfo = params->buffer;
+ tsinfo->minimum_timestamp = 0;
+ tsinfo->maximum_timestamp = UINT_MAX;
+ tsinfo->mtime_gran_mantissa = 1;
+ tsinfo->mtime_gran_exponent = 0;
+ return sizeof(*tsinfo);
+
+ case FSINFO_ATTR_SUPPORTS:
+ sup = params->buffer;
+ sup->stx_mask = (STATX_TYPE | STATX_MODE |
+ STATX_NLINK |
+ STATX_UID | STATX_GID |
+ STATX_MTIME | STATX_INO |
+ STATX_SIZE);
+ sup->stx_attributes = STATX_ATTR_AUTOMOUNT;
+ return sizeof(*sup);
+
+ case FSINFO_ATTR_CAPABILITIES:
+ caps = params->buffer;
+ if (dyn_root) {
+ fsinfo_set_cap(caps, FSINFO_CAP_IS_AUTOMOUNTER_FS);
+ fsinfo_set_cap(caps, FSINFO_CAP_AUTOMOUNTS);
+ } else {
+ fsinfo_set_cap(caps, FSINFO_CAP_IS_NETWORK_FS);
+ fsinfo_set_cap(caps, FSINFO_CAP_AUTOMOUNTS);
+ fsinfo_set_cap(caps, FSINFO_CAP_ADV_LOCKS);
+ fsinfo_set_cap(caps, FSINFO_CAP_UIDS);
+ fsinfo_set_cap(caps, FSINFO_CAP_GIDS);
+ fsinfo_set_cap(caps, FSINFO_CAP_VOLUME_ID);
+ fsinfo_set_cap(caps, FSINFO_CAP_VOLUME_NAME);
+ fsinfo_set_cap(caps, FSINFO_CAP_CELL_NAME);
+ fsinfo_set_cap(caps, FSINFO_CAP_IVER_MONO_INCR);
+ fsinfo_set_cap(caps, FSINFO_CAP_SYMLINKS);
+ fsinfo_set_cap(caps, FSINFO_CAP_HARD_LINKS_1DIR);
+ fsinfo_set_cap(caps, FSINFO_CAP_HAS_MTIME);
+ }
+ return sizeof(*caps);
+
+ case FSINFO_ATTR_VOLUME_NAME:
+ if (dyn_root)
+ return -EOPNOTSUPP;
+ memcpy(params->buffer, volume->name, volume->name_len);
+ return volume->name_len;
+
+ case FSINFO_ATTR_CELL_NAME:
+ if (dyn_root)
+ return -EOPNOTSUPP;
+ memcpy(params->buffer, cell->name, cell->name_len);
+ return cell->name_len;
+
+ case FSINFO_ATTR_SERVER_NAME:
+ if (dyn_root)
+ return -EOPNOTSUPP;
+ read_lock(&volume->servers_lock);
+ slist = afs_get_serverlist(volume->servers);
+ read_unlock(&volume->servers_lock);
+
+ if (params->Nth < slist->nr_servers) {
+ server = slist->servers[params->Nth].server;
+ ret = sprintf(params->buffer, "%pU", &server->uuid);
+ } else {
+ ret = -ENODATA;
+ }
+
+ afs_put_serverlist(net, slist);
+ return ret;
+
+ case FSINFO_ATTR_SERVER_ADDRESS:
+ addr = params->buffer;
+ if (dyn_root)
+ return -EOPNOTSUPP;
+ read_lock(&volume->servers_lock);
+ slist = afs_get_serverlist(volume->servers);
+ read_unlock(&volume->servers_lock);
+
+ ret = -ENODATA;
+ if (params->Nth >= slist->nr_servers)
+ goto put_slist;
+ server = slist->servers[params->Nth].server;
+
+ read_lock(&server->fs_lock);
+ alist = afs_get_addrlist(rcu_access_pointer(server->addresses));
+ read_unlock(&server->fs_lock);
+ if (!alist)
+ goto put_slist;
+
+ if (params->Mth >= alist->nr_addrs)
+ goto put_alist;
+
+ memcpy(addr, &alist->addrs[params->Mth],
+ sizeof(struct sockaddr_rxrpc));
+ ret = sizeof(*addr);
+
+ put_alist:
+ afs_put_addrlist(alist);
+ put_slist:
+ afs_put_serverlist(net, slist);
+ return ret;
+
+ default:
+ return generic_fsinfo(dentry, params);
+ }
+}