Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

NFS: add superblock sysfs entries

Create a sysfs directory for each mount that corresponds to the mount's
nfs_server struct. As the mount is being constructed, use the name
"server-n", but rename it to the "MAJOR:MINOR" of the mount after assigning
a device_id. The rename approach allows us to populate the mount's directory
with links to the various rpc_client objects during the mount's
construction. The naming convention (MAJOR:MINOR) can be used to reference
a particular NFS mount's sysfs tree.

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>

authored by

Benjamin Coddington and committed by
Trond Myklebust
1c725118 e96f9268

+90 -1
+16
fs/nfs/client.c
··· 698 698 return PTR_ERR(clp); 699 699 700 700 server->nfs_client = clp; 701 + nfs_sysfs_add_server(server); 701 702 702 703 /* Initialise the client representation from the mount data */ 703 704 server->flags = ctx->flags; ··· 953 952 } 954 953 EXPORT_SYMBOL_GPL(nfs_server_remove_lists); 955 954 955 + static DEFINE_IDA(s_sysfs_ids); 956 + 956 957 /* 957 958 * Allocate and initialise a server record 958 959 */ ··· 965 962 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); 966 963 if (!server) 967 964 return NULL; 965 + 966 + server->s_sysfs_id = ida_alloc(&s_sysfs_ids, GFP_KERNEL); 967 + if (server->s_sysfs_id < 0) { 968 + kfree(server); 969 + return NULL; 970 + } 968 971 969 972 server->client = server->client_acl = ERR_PTR(-EINVAL); 970 973 ··· 1017 1008 rpc_shutdown_client(server->client); 1018 1009 1019 1010 nfs_put_client(server->nfs_client); 1011 + 1012 + nfs_sysfs_remove_server(server); 1013 + kobject_put(&server->kobj); 1014 + ida_free(&s_sysfs_ids, server->s_sysfs_id); 1020 1015 1021 1016 ida_destroy(&server->lockowner_id); 1022 1017 ida_destroy(&server->openowner_id); ··· 1122 1109 nfs_server_copy_userdata(server, source); 1123 1110 1124 1111 server->fsid = fattr->fsid; 1112 + 1113 + nfs_sysfs_add_server(server); 1125 1114 1126 1115 error = nfs_init_server_rpcclient(server, 1127 1116 source->client->cl_timeout, ··· 1408 1393 void nfs_fs_proc_exit(void) 1409 1394 { 1410 1395 remove_proc_subtree("fs/nfsfs", NULL); 1396 + ida_destroy(&s_sysfs_ids); 1411 1397 } 1412 1398 1413 1399 #endif /* CONFIG_PROC_FS */
+3
fs/nfs/nfs4client.c
··· 18 18 #include "nfs4idmap.h" 19 19 #include "pnfs.h" 20 20 #include "netns.h" 21 + #include "sysfs.h" 21 22 22 23 #define NFSDBG_FACILITY NFSDBG_CLIENT 23 24 ··· 953 952 set_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state); 954 953 955 954 server->nfs_client = clp; 955 + nfs_sysfs_add_server(server); 956 + 956 957 return 0; 957 958 } 958 959
+5 -1
fs/nfs/super.c
··· 70 70 #include "nfs4session.h" 71 71 #include "pnfs.h" 72 72 #include "nfs.h" 73 + #include "netns.h" 74 + #include "sysfs.h" 73 75 74 76 #define NFSDBG_FACILITY NFSDBG_VFS 75 77 ··· 1091 1089 &sb->s_blocksize_bits); 1092 1090 1093 1091 nfs_super_set_maxbytes(sb, server->maxfilesize); 1092 + nfs_sysfs_move_server_to_sb(sb); 1094 1093 server->has_sec_mnt_opts = ctx->has_sec_mnt_opts; 1095 1094 } 1096 1095 ··· 1334 1331 } 1335 1332 1336 1333 /* 1337 - * Destroy an NFS2/3 superblock 1334 + * Destroy an NFS superblock 1338 1335 */ 1339 1336 void nfs_kill_super(struct super_block *s) 1340 1337 { 1341 1338 struct nfs_server *server = NFS_SB(s); 1342 1339 dev_t dev = s->s_dev; 1343 1340 1341 + nfs_sysfs_move_sb_to_server(server); 1344 1342 generic_shutdown_super(s); 1345 1343 1346 1344 nfs_fscache_release_super_cookie(s);
+59
fs/nfs/sysfs.c
··· 215 215 netns->nfs_client = NULL; 216 216 } 217 217 } 218 + 219 + static void nfs_sysfs_sb_release(struct kobject *kobj) 220 + { 221 + /* no-op: why? see lib/kobject.c kobject_cleanup() */ 222 + } 223 + 224 + static const void *nfs_netns_server_namespace(const struct kobject *kobj) 225 + { 226 + return container_of(kobj, struct nfs_server, kobj)->nfs_client->cl_net; 227 + } 228 + 229 + static struct kobj_type nfs_sb_ktype = { 230 + .release = nfs_sysfs_sb_release, 231 + .sysfs_ops = &kobj_sysfs_ops, 232 + .namespace = nfs_netns_server_namespace, 233 + .child_ns_type = nfs_netns_object_child_ns_type, 234 + }; 235 + 236 + void nfs_sysfs_add_server(struct nfs_server *server) 237 + { 238 + int ret; 239 + 240 + ret = kobject_init_and_add(&server->kobj, &nfs_sb_ktype, 241 + &nfs_kset->kobj, "server-%d", server->s_sysfs_id); 242 + if (ret < 0) 243 + pr_warn("NFS: nfs sysfs add server-%d failed (%d)\n", 244 + server->s_sysfs_id, ret); 245 + } 246 + EXPORT_SYMBOL_GPL(nfs_sysfs_add_server); 247 + 248 + void nfs_sysfs_move_server_to_sb(struct super_block *s) 249 + { 250 + struct nfs_server *server = s->s_fs_info; 251 + int ret; 252 + 253 + ret = kobject_rename(&server->kobj, s->s_id); 254 + if (ret < 0) 255 + pr_warn("NFS: rename sysfs %s failed (%d)\n", 256 + server->kobj.name, ret); 257 + } 258 + 259 + void nfs_sysfs_move_sb_to_server(struct nfs_server *server) 260 + { 261 + const char *s; 262 + int ret = -ENOMEM; 263 + 264 + s = kasprintf(GFP_KERNEL, "server-%d", server->s_sysfs_id); 265 + if (s) 266 + ret = kobject_rename(&server->kobj, s); 267 + if (ret < 0) 268 + pr_warn("NFS: rename sysfs %s failed (%d)\n", 269 + server->kobj.name, ret); 270 + } 271 + 272 + /* unlink, not dec-ref */ 273 + void nfs_sysfs_remove_server(struct nfs_server *server) 274 + { 275 + kobject_del(&server->kobj); 276 + }
+5
fs/nfs/sysfs.h
··· 23 23 void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net); 24 24 void nfs_netns_sysfs_destroy(struct nfs_net *netns); 25 25 26 + void nfs_sysfs_add_server(struct nfs_server *s); 27 + void nfs_sysfs_move_server_to_sb(struct super_block *s); 28 + void nfs_sysfs_move_sb_to_server(struct nfs_server *s); 29 + void nfs_sysfs_remove_server(struct nfs_server *s); 30 + 26 31 #endif
+2
include/linux/nfs_fs_sb.h
··· 184 184 change_attr_type;/* Description of change attribute */ 185 185 186 186 struct nfs_fsid fsid; 187 + int s_sysfs_id; /* sysfs dentry index */ 187 188 __u64 maxfilesize; /* maximum file size */ 188 189 struct timespec64 time_delta; /* smallest time granularity */ 189 190 unsigned long mount_time; /* when this fs was mounted */ ··· 261 260 /* User namespace info */ 262 261 const struct cred *cred; 263 262 bool has_sec_mnt_opts; 263 + struct kobject kobj; 264 264 }; 265 265 266 266 /* Server capabilities */