exposing knfsd client state to userspace
Subsystems (5)
cover exposing knfsd client state to userspace
From: "J. Bruce Fields" <[email protected]>
Changes since last time:
- added display of client implementation ID
- changed display of binary data to escape anything nonprintable or nonascii
- some minor cleanup and patch reshuffling
I'm happy enough with at this point and hoping to merge it for 5.3.
Recapping discussion from last time:
The following patches expose information about NFSv4 state held by knfsd on behalf of NFSv4 clients. This is especially important for opens, which are currently invisible to userspace on the server, unlike locks (/proc/locks) and local processes' opens (under /proc/<pid>/).
The approach is to add a new directory /proc/fs/nfsd/clients/ with subdirectories for each active NFSv4 client. Each subdirectory has an "info" file with some basic information to help identify the client and a "states" directory that lists the open state held by that client.
Currently these pseudofiles look like:
# find /proc/fs/nfsd/clients -type f|xargs tail ==> /proc/fs/nfsd/clients/3/ctl <== tail: error reading '/proc/fs/nfsd/clients/3/ctl': Invalid argument
==> /proc/fs/nfsd/clients/3/states <==
- 0x01000000f58f0b5d2898a19801000000: { type: open, access: r-, deny: --, superblock: "fd:10:13649", owner: "open id:\x00\x00\x00&\x00\x00\x00\x00\x00\x00\x02x\xac\xd0 \x09" }
- 0x01000000f58f0b5d2898a19802000000: { type: deleg, access: r, superblock: "fd:10:13649" }
- 0x01000000f58f0b5d2898a19803000000: { type: open, access: r-, deny: --, superblock: "fd:10:13650", owner: "open id:\x00\x00\x00&\x00\x00\x00\x00\x00\x00\x02x\xac\xd0 \x09" }
- 0x01000000f58f0b5d2898a19804000000: { type: deleg, access: r, superblock: "fd:10:13650" }
==> /proc/fs/nfsd/clients/3/info <==
clientid: 0x98a198285d0b8ff5
address: "192.168.122.36:935"
name: "Linux NFSv4.2 test2.fieldses.org"
minor version: 2
Implementation domain: "kernel.org"
Implementation name: "Linux 5.2.0-rc1-00017-ge73cab140ec0 #2263 SMP PREEMPT Tue Jun 18 16:54:41 EDT 2019 x86_64" Implementation time: [0, 0]
The "ctl" file is not readable; all you can do is write "expire\n" to it to force the server to revoke all that client's state.
The "info" and "states" files are meant to be valid YAML.
Possibly also todo, though I think none have to be done before merging:
- add some information about krb5 principals to the clients file.
- add information about the stateids used to represent asynchronous copies. They're a little different from the other stateids and might end up in a separate "copies" file,
- this duplicates some functionality of the little-used fault injection code; could we replace it entirely?
- some of the bits of filesystem code could probably be shared with rpc_pipefs and libfs.
--b.
J. Bruce Fields (16):
nfsd: persist nfsd filesystem across mounts
nfsd: rename cl_refcount
nfsd4: use reference count to free client
nfsd: add nfsd/clients directory
nfsd: make client/ directory names small ints
nfsd4: add a client info file
nfsd: copy client's address including port number to cl_addr
nfsd: escape high characters in binary data
nfsd: add more information to client info file
nfsd4: add file to display list of client's opens
nfsd: show lock and deleg stateids
nfsd4: show layout stateids
nfsd: create get_nfsdfs_clp helper
nfsd: allow forced expiration of NFSv4 clients
nfsd: create xdr_netobj_dup helper
nfsd: decode implementation id
fs/nfsd/netns.h | 6 + fs/nfsd/nfs4state.c | 453 ++++++++++++++++++++++++++++++--- fs/nfsd/nfs4xdr.c | 21 +- fs/nfsd/nfsctl.c | 221 +++++++++++++++- fs/nfsd/nfsd.h | 11 + fs/nfsd/state.h | 11 +- fs/nfsd/xdr4.h | 3 + fs/seq_file.c | 11 + include/linux/seq_file.h | 1 + include/linux/string_helpers.h | 3 + include/linux/sunrpc/xdr.h | 7 + lib/string_helpers.c | 19 ++ 12 files changed, 723 insertions(+), 44 deletions(-)
Signature · 1 line
2.21.0
PATCH 1/16 nfsd: persist nfsd filesystem across mounts
From: "J. Bruce Fields" <[email protected]>
Keep around one internal mount of the nfsd filesystem so that we can add stuff to it when clients come and go, regardless of whether anyone has it mounted.
--- fs/nfsd/netns.h | 3 +++ fs/nfsd/nfsctl.c | 13 +++++++++++++ 2 files changed, 16 insertions(+)
fs/nfsd/netns.h +3 -0
@@ -55,6 +55,9 @@ struct nfsd_net {bool grace_ended;time_t boot_time; +/* internal mount of the "nfsd" pseudofilesystem: */ +struct vfsmount *nfsd_mnt; +/* * reclaim_str_hashtbl[] holds known client info from previous reset/reboot * used in reboot/reset lease grace period processing
fs/nfsd/nfsctl.c +13 -0
@@ -1231,6 +1231,7 @@ unsigned int nfsd_net_id;static __net_init int nfsd_init_net (struct net *net) {int retval; +struct vfsmount *mnt;struct nfsd_net *nn =net_generic (net, nfsd_net_id); retval =nfsd_export_init (net);
@@ -1251,8 +1252,17 @@ static __net_init int nfsd_init_net(struct net *net)atomic_set (&nn->ntf_refcnt,0 );init_waitqueue_head (&nn->ntf_wq); + + mnt =vfs_kern_mount (&nfsd_fs_type,SB_KERNMOUNT ,"nfsd" ,NULL ); +if (IS_ERR (mnt)) { + retval =PTR_ERR (mnt); + goto out_mount_err; + } + nn->nfsd_mnt = mnt;return 0 ; +out_mount_err: +nfsd_idmap_shutdown (net); out_idmap_error:nfsd_export_shutdown (net); out_export_error:
@@ -1261,6 +1271,9 @@ static __net_init int nfsd_init_net(struct net *net) static __net_exit void nfsd_exit_net(struct net *net) { +struct nfsd_net *nn =net_generic (net, nfsd_net_id); + +mntput (nn->nfsd_mnt);nfsd_idmap_shutdown (net);nfsd_export_shutdown (net);nfsd_netns_free_versions (net_generic (net, nfsd_net_id));
Signature · 1 line
2.21.0
PATCH 2/16 nfsd: rename cl_refcount
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Rename this to a more descriptive name: it counts the number of in-progress rpc's referencing this client.
Next I'm going to add a second refcount with a slightly different use.
--- fs/nfsd/nfs4state.c | 26 +++++++++++++------------- fs/nfsd/state.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-)
fs/nfsd/nfs4state.c +13 -13
@@ -138,7 +138,7 @@ static __be32 get_client_locked(struct nfs4_client *clp)if (is_client_expired (clp))return nfserr_expired; -atomic_inc (&clp->cl_refcount); +atomic_inc (&clp->cl_rpc_users);return nfs_ok; }
@@ -170,7 +170,7 @@ static void put_client_renew_locked(struct nfs4_client *clp)lockdep_assert_held (&nn->client_lock); -if (!atomic_dec_and_test (&clp->cl_refcount)) +if (!atomic_dec_and_test (&clp->cl_rpc_users))return ;if (!is_client_expired (clp))renew_client_locked (clp);
@@ -180,7 +180,7 @@ static void put_client_renew(struct nfs4_client *clp) {struct nfsd_net *nn =net_generic (clp->net, nfsd_net_id); -if (!atomic_dec_and_lock (&clp->cl_refcount, &nn->client_lock)) +if (!atomic_dec_and_lock (&clp->cl_rpc_users, &nn->client_lock))return ;if (!is_client_expired (clp))renew_client_locked (clp);
@@ -1857,7 +1857,7 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name) clp->cl_name.len = name.len;INIT_LIST_HEAD (&clp->cl_sessions);idr_init (&clp->cl_stateids); -atomic_set (&clp->cl_refcount,0 ); +atomic_set (&clp->cl_rpc_users,0 ); clp->cl_cb_state =NFSD4_CB_UNKNOWN ;INIT_LIST_HEAD (&clp->cl_idhash);INIT_LIST_HEAD (&clp->cl_openowners);
@@ -1936,7 +1936,7 @@ unhash_client(struct nfs4_client *clp)static __be32 mark_client_expired_locked (struct nfs4_client *clp) { -if (atomic_read (&clp->cl_refcount)) +if (atomic_read (&clp->cl_rpc_users))return nfserr_jukebox;unhash_client_locked (clp);return nfs_ok;
@@ -4092,7 +4092,7 @@ static __be32 lookup_clientid(clientid_t *clid,spin_unlock (&nn->client_lock);return nfserr_expired; } -atomic_inc (&found->cl_refcount); +atomic_inc (&found->cl_rpc_users);spin_unlock (&nn->client_lock);/* Cache the nfs4_client in cstate! */
@@ -6584,7 +6584,7 @@ nfs4_check_open_reclaim(clientid_t *clid,static inline void put_client (struct nfs4_client *clp) { -atomic_dec (&clp->cl_refcount); +atomic_dec (&clp->cl_rpc_users); } static struct nfs4_client *
@@ -6702,7 +6702,7 @@ nfsd_inject_add_lock_to_list(struct nfs4_ol_stateid *lst,return ;lockdep_assert_held (&nn->client_lock); -atomic_inc (&clp->cl_refcount); +atomic_inc (&clp->cl_rpc_users);list_add (&lst->st_locks, collect); }
@@ -6731,7 +6731,7 @@ static u64 nfsd_foreach_client_lock(struct nfs4_client *clp, u64 max,* Despite the fact that these functions deal * with 64-bit integers for "count", we must * ensure that it doesn't blow up the -* clp->cl_refcount. Throw a warning if we +* clp->cl_rpc_users. Throw a warning if we * start to approach INT_MAX here. */ WARN_ON_ONCE (count == (INT_MAX /2 ));
@@ -6855,7 +6855,7 @@ nfsd_foreach_client_openowner(struct nfs4_client *clp, u64 max,if (func) {func (oop);if (collect) { -atomic_inc (&clp->cl_refcount); +atomic_inc (&clp->cl_rpc_users);list_add (&oop->oo_perclient, collect); } }
@@ -6863,7 +6863,7 @@ nfsd_foreach_client_openowner(struct nfs4_client *clp, u64 max,/* * Despite the fact that these functions deal with * 64-bit integers for "count", we must ensure that -* it doesn't blow up the clp->cl_refcount. Throw a +* it doesn't blow up the clp->cl_rpc_users. Throw a * warning if we start to approach INT_MAX here. */ WARN_ON_ONCE (count == (INT_MAX /2 ));
@@ -6993,7 +6993,7 @@ static u64 nfsd_find_all_delegations(struct nfs4_client *clp, u64 max,if (dp->dl_time !=0 )continue ; -atomic_inc (&clp->cl_refcount); +atomic_inc (&clp->cl_rpc_users);WARN_ON (!unhash_delegation_locked (dp));list_add (&dp->dl_recall_lru, victims); }
@@ -7001,7 +7001,7 @@ static u64 nfsd_find_all_delegations(struct nfs4_client *clp, u64 max,/* * Despite the fact that these functions deal with * 64-bit integers for "count", we must ensure that -* it doesn't blow up the clp->cl_refcount. Throw a +* it doesn't blow up the clp->cl_rpc_users. Throw a * warning if we start to approach INT_MAX here. */ WARN_ON_ONCE (count == (INT_MAX /2 ));
fs/nfsd/state.h +1 -1
@@ -347,7 +347,7 @@ struct nfs4_client {struct nfsd4_clid_slot cl_cs_slot;/* create_session slot */ u32 cl_exchange_flags;/* number of rpc's in progress over an associated session: */ -atomic_t cl_refcount; +atomic_t cl_rpc_users;struct nfs4_op_map cl_spo_must_allow;/* for nfs41 callbacks */
Signature · 1 line
2.21.0
PATCH 3/16 nfsd4: use reference count to free client
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Keep a second reference count which is what is really used to decide when to free the client's memory.
Next I'm going to add an nfsd/clients/ directory with a subdirectory for each NFSv4 client. File objects under nfsd/clients/ will hold these references.
--- fs/nfsd/nfs4state.c | 26 +++++++++++++++++++++----- fs/nfsd/state.h | 1 + 2 files changed, 22 insertions(+), 5 deletions(-)
fs/nfsd/nfs4state.c +21 -5
@@ -1879,6 +1879,24 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)return NULL ; } +static void __free_client (struct kref *k) +{ + struct nfs4_client *clp = container_of(k, struct nfs4_client, cl_ref); + +free_svc_cred (&clp->cl_cred); +kfree (clp->cl_ownerstr_hashtbl); +kfree (clp->cl_name.data); +idr_destroy (&clp->cl_stateids); +if (clp->cl_nfsd_dentry) +nfsd_client_rmdir (clp->cl_nfsd_dentry); +kmem_cache_free (client_slab, clp); +} + +void drop_client (struct nfs4_client *clp) +{ +kref_put (&clp->cl_ref, __free_client); +} +static void free_client (struct nfs4_client *clp) {
@@ -1891,11 +1909,7 @@ free_client(struct nfs4_client *clp)free_session (ses); }rpc_destroy_wait_queue (&clp->cl_cb_waitq); -free_svc_cred (&clp->cl_cred); -kfree (clp->cl_ownerstr_hashtbl); -kfree (clp->cl_name.data); -idr_destroy (&clp->cl_stateids); -kmem_cache_free (client_slab, clp); +drop_client (clp); }/* must be called under the client_lock */
@@ -2216,6 +2230,8 @@ static struct nfs4_client *create_client(struct xdr_netobj name,free_client (clp);return NULL ; } + +kref_init (&clp->cl_ref);nfsd4_init_cb (&clp->cl_cb_null, clp,NULL ,NFSPROC4_CLNT_CB_NULL ); clp->cl_time =get_seconds ();clear_bit (0 , &clp->cl_cb_slot_busy);
fs/nfsd/state.h +1 -0
@@ -348,6 +348,7 @@ struct nfs4_client {u32 cl_exchange_flags;/* number of rpc's in progress over an associated session: */ atomic_t cl_rpc_users; +struct kref cl_ref;struct nfs4_op_map cl_spo_must_allow;/* for nfs41 callbacks */
Signature · 1 line
2.21.0
PATCH 4/16 nfsd: add nfsd/clients directory
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
I plan to expose some information about nfsv4 clients here.
--- fs/nfsd/netns.h | 2 + fs/nfsd/nfs4state.c | 23 ++++++---- fs/nfsd/nfsctl.c | 103 +++++++++++++++++++++++++++++++++++++++++++- fs/nfsd/nfsd.h | 9 ++++ fs/nfsd/state.h | 6 ++- 5 files changed, 133 insertions(+), 10 deletions(-)
fs/nfsd/netns.h +2 -0
@@ -58,6 +58,8 @@ struct nfsd_net {/* internal mount of the "nfsd" pseudofilesystem: */ struct vfsmount *nfsd_mnt; +struct dentry *nfsd_client_dir; +/* * reclaim_str_hashtbl[] holds known client info from previous reset/reboot * used in reboot/reset lease grace period processing
fs/nfsd/nfs4state.c +15 -8
@@ -1881,20 +1881,19 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)static void __free_client (struct kref *k) { - struct nfs4_client *clp = container_of(k, struct nfs4_client, cl_ref); + struct nfsdfs_client *c = container_of(k, struct nfsdfs_client, cl_ref); + struct nfs4_client *clp = container_of(c, struct nfs4_client, cl_nfsdfs);free_svc_cred (&clp->cl_cred);kfree (clp->cl_ownerstr_hashtbl);kfree (clp->cl_name.data);idr_destroy (&clp->cl_stateids); -if (clp->cl_nfsd_dentry) -nfsd_client_rmdir (clp->cl_nfsd_dentry);kmem_cache_free (client_slab, clp); }void drop_client (struct nfs4_client *clp) { -kref_put (&clp->cl_ref, __free_client); +kref_put (&clp->cl_nfsdfs.cl_ref, __free_client); } static void
@@ -1909,6 +1908,8 @@ free_client(struct nfs4_client *clp)free_session (ses); }rpc_destroy_wait_queue (&clp->cl_cb_waitq); +if (clp->cl_nfsd_dentry) +nfsd_client_rmdir (clp->cl_nfsd_dentry);drop_client (clp); }
@@ -2220,6 +2221,7 @@ static struct nfs4_client *create_client(struct xdr_netobj name,struct sockaddr *sa =svc_addr (rqstp);int ret;struct net *net =SVC_NET (rqstp); +struct nfsd_net *nn =net_generic (net, nfsd_net_id); clp =alloc_client (name);if (clp ==NULL )
@@ -2230,8 +2232,8 @@ static struct nfs4_client *create_client(struct xdr_netobj name,free_client (clp);return NULL ; } - -kref_init (&clp->cl_ref); +gen_clid (clp, nn); +kref_init (&clp->cl_nfsdfs.cl_ref);nfsd4_init_cb (&clp->cl_cb_null, clp,NULL ,NFSPROC4_CLNT_CB_NULL ); clp->cl_time =get_seconds ();clear_bit (0 , &clp->cl_cb_slot_busy);
@@ -2239,6 +2241,12 @@ static struct nfs4_client *create_client(struct xdr_netobj name,rpc_copy_addr ((struct sockaddr *) &clp->cl_addr, sa); clp->cl_cb_session =NULL ; clp->net = net; + clp->cl_nfsd_dentry =nfsd_client_mkdir (nn, &clp->cl_nfsdfs, + clp->cl_clientid.cl_id); +if (!clp->cl_nfsd_dentry) { +free_client (clp); +return NULL ; + }return clp; }
@@ -2683,7 +2691,6 @@ nfsd4_exchange_id(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, new->cl_spo_must_allow.u.words[0 ] = exid->spo_must_allow[0 ]; new->cl_spo_must_allow.u.words[1 ] = exid->spo_must_allow[1 ]; -gen_clid (new, nn);add_to_unconfirmed (new);swap (new, conf); out_copy:
@@ -3427,7 +3434,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,copy_clid (new, conf);gen_confirm (new, nn); }else /* case 4 (new client) or cases 2, 3 (client reboot): */ -gen_clid (new, nn); + ; new->cl_minorversion =0 ;gen_callback (new, setclid, rqstp);add_to_unconfirmed (new);
fs/nfsd/nfsctl.c +102 -1
129 lines not on this page · raw message
fs/nfsd/nfsd.h +9 -0
@@ -22,6 +22,7 @@#include <uapi/linux/nfsd/debug.h> +#include "netns.h" #include "stats.h" #include "export.h"
@@ -86,6 +87,14 @@ int nfsd_pool_stats_release(struct inode *, struct file *);void nfsd_destroy (struct net *net); +struct nfsdfs_client { +struct kref cl_ref; +void (*cl_release)(struct kref *kref); +}; + +struct dentry *nfsd_client_mkdir (struct nfsd_net *nn,struct nfsdfs_client *ncl,u32 id); +void nfsd_client_rmdir (struct dentry *dentry); +#if defined(CONFIG_NFSD_V2_ACL ) || defined(CONFIG_NFSD_V3_ACL )#ifdef CONFIG_NFSD_V2_ACL extern const struct svc_version nfsd_acl_version2;
fs/nfsd/state.h +5 -1
@@ -39,6 +39,7 @@#include <linux/refcount.h> #include <linux/sunrpc/svc_xprt.h> #include "nfsfh.h" +#include "nfsd.h" typedef struct { u32 cl_boot;
@@ -348,9 +349,12 @@ struct nfs4_client {u32 cl_exchange_flags;/* number of rpc's in progress over an associated session: */ atomic_t cl_rpc_users; -struct kref cl_ref; +struct nfsdfs_client cl_nfsdfs;struct nfs4_op_map cl_spo_must_allow; +/* debugging info directory under nfsd/clients/ : */ +struct dentry *cl_nfsd_dentry; +/* for nfs41 callbacks */ /* We currently support a single back channel with a single slot */ unsigned long cl_cb_slot_busy;
Signature · 1 line
2.21.0
PATCH 5/16 nfsd: make client/ directory names small ints
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
We want clientid's on the wire to be randomized for reasons explained in ebd7c72c63ac "nfsd: randomize SETCLIENTID reply to help distinguish servers". But I'd rather have mostly small integers for the clients/ directory.
--- fs/nfsd/netns.h | 1 + fs/nfsd/nfs4state.c | 2 +- fs/nfsd/nfsctl.c | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-)
fs/nfsd/netns.h +1 -0
@@ -124,6 +124,7 @@ struct nfsd_net {*/ unsigned int max_connections; +u32 clientid_base;u32 clientid_counter;u32 clverifier_counter;
fs/nfsd/nfs4state.c +1 -1
@@ -2242,7 +2242,7 @@ static struct nfs4_client *create_client(struct xdr_netobj name, clp->cl_cb_session =NULL ; clp->net = net; clp->cl_nfsd_dentry =nfsd_client_mkdir (nn, &clp->cl_nfsdfs, - clp->cl_clientid.cl_id); + clp->cl_clientid.cl_id - nn->clientid_base);if (!clp->cl_nfsd_dentry) {free_client (clp);return NULL ;
fs/nfsd/nfsctl.c +3 -2
@@ -1212,7 +1212,7 @@ struct dentry *nfsd_client_mkdir(struct nfsd_net *nn, struct nfsdfs_client *ncl, {char name[11 ]; -sprintf (name,"%d" , id++); +sprintf (name,"%u" , id);return nfsd_mkdir (nn->nfsd_client_dir, ncl, name); }
@@ -1348,7 +1348,8 @@ static __net_init int nfsd_init_net(struct net *net) nn->somebody_reclaimed = false; nn->track_reclaim_completes = false; nn->clverifier_counter =prandom_u32 (); - nn->clientid_counter =prandom_u32 (); + nn->clientid_base =prandom_u32 (); + nn->clientid_counter = nn->clientid_base +1 ; nn->s2s_cp_cl_id = nn->clientid_counter++;atomic_set (&nn->ntf_refcnt,0 );
Signature · 1 line
2.21.0
PATCH 6/16 nfsd4: add a client info file
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Add a new nfsd/clients/#/info file with some basic information about each NFSv4 client.
--- fs/nfsd/nfs4state.c | 38 ++++++++++++++- fs/nfsd/nfsctl.c | 114 +++++++++++++++++++++++++++++++++++++++++--- fs/nfsd/nfsd.h | 4 +- 3 files changed, 148 insertions(+), 8 deletions(-)
fs/nfsd/nfs4state.c +37 -1
@@ -2214,6 +2214,41 @@ find_stateid_by_type(struct nfs4_client *cl, stateid_t *t, char typemask)return s; } +static int client_info_show (struct seq_file *m,void *v) +{ +struct inode *inode = m->private; +struct nfsdfs_client *nc; +struct nfs4_client *clp; +u64 clid; + + nc =get_nfsdfs_client (inode); +if (!nc) +return -ENXIO ; + clp = container_of(nc, struct nfs4_client, cl_nfsdfs); +memcpy (&clid, &clp->cl_clientid,sizeof (clid)); +seq_printf (m,"clientid: 0x%llx\n" , clid); +drop_client (clp); + +return 0 ; +} + +static int client_info_open (struct inode *inode,struct file *file) +{ +return single_open (file, client_info_show, inode); +} + +static const struct file_operations client_info_fops = { + .open = client_info_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static const struct tree_descr client_files[] = { + [0 ] = {"info" , &client_info_fops,S_IRUSR }, + [1 ] = {"" }, +}; +static struct nfs4_client *create_client (struct xdr_netobj name,struct svc_rqst *rqstp,nfs4_verifier *verf) {
@@ -2242,7 +2277,8 @@ static struct nfs4_client *create_client(struct xdr_netobj name, clp->cl_cb_session =NULL ; clp->net = net; clp->cl_nfsd_dentry =nfsd_client_mkdir (nn, &clp->cl_nfsdfs, - clp->cl_clientid.cl_id - nn->clientid_base); + clp->cl_clientid.cl_id - nn->clientid_base, + client_files);if (!clp->cl_nfsd_dentry) {free_client (clp);return NULL ;
fs/nfsd/nfsctl.c +108 -6
138 lines not on this page · raw message
fs/nfsd/nfsd.h +3 -1
@@ -92,7 +92,9 @@ struct nfsdfs_client {void (*cl_release)(struct kref *kref); }; -struct dentry *nfsd_client_mkdir (struct nfsd_net *nn,struct nfsdfs_client *ncl,u32 id); +struct nfsdfs_client *get_nfsdfs_client (struct inode *); +struct dentry *nfsd_client_mkdir (struct nfsd_net *nn, +struct nfsdfs_client *ncl,u32 id,const struct tree_descr *);void nfsd_client_rmdir (struct dentry *dentry);#if defined(CONFIG_NFSD_V2_ACL ) || defined(CONFIG_NFSD_V3_ACL )
Signature · 1 line
2.21.0
PATCH 7/16 nfsd: copy client's address including port number to cl_addr
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
rpc_copy_addr() copies only the IP address and misses any port numbers. It seems potentially useful to keep the port number around too.
--- fs/nfsd/nfs4state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4state.c +1 -1
@@ -2273,7 +2273,7 @@ static struct nfs4_client *create_client(struct xdr_netobj name, clp->cl_time =get_seconds ();clear_bit (0 , &clp->cl_cb_slot_busy);copy_verf (clp, verf); -rpc_copy_addr ((struct sockaddr *) &clp->cl_addr, sa); +memcpy (&clp->cl_addr, sa,sizeof (struct sockaddr_storage )); clp->cl_cb_session =NULL ; clp->net = net; clp->cl_nfsd_dentry = nfsd_client_mkdir(nn, &clp->cl_nfsdfs,
Signature · 1 line
2.21.0
PATCH 8/16 nfsd: escape high characters in binary data
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
I'm exposing some information about NFS clients in pseudofiles. I expect to eventually have simple tools to help read those pseudofiles.
But it's also helpful if the raw files are human-readable to the extent possible. It aids debugging and makes them usable on systems that don't have the latest nfs-utils.
A minor challenge there is opaque client-generated protocol objects like state owners and client identifiers. Some clients generate those to include handy information in plain ascii. But they may also include arbitrary byte sequences.
I think the simplest approach is to limit to isprint(c) && isascii(c) and escape everything else.
That means you can just cat the file and get something that looks OK. Also, I'm trying to keep these files legal YAML, which requires them to UTF-8, and this is a simple way to guarantee that.
--- fs/seq_file.c | 11 +++++++++++ include/linux/seq_file.h | 1 + include/linux/string_helpers.h | 3 +++ lib/string_helpers.c | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+)
fs/seq_file.c +11 -0
@@ -384,6 +384,17 @@ void seq_escape(struct seq_file *m, const char *s, const char *esc) }EXPORT_SYMBOL (seq_escape); +void seq_escape_mem_ascii (struct seq_file *m,const char *src,size_t isz) +{ +char *buf; +size_t size =seq_get_buf (m, &buf); +int ret; + + ret =string_escape_mem_ascii (src, isz, buf, size); +seq_commit (m, ret < size ? ret :-1 ); +} +EXPORT_SYMBOL (seq_escape_mem_ascii); +void seq_vprintf (struct seq_file *m,const char *f,va_list args) {int len;
include/linux/seq_file.h +1 -0
@@ -127,6 +127,7 @@ void seq_put_hex_ll(struct seq_file *m, const char *delimiter, unsigned long long v, unsigned int width);void seq_escape (struct seq_file *m,const char *s,const char *esc); +void seq_escape_mem_ascii (struct seq_file *m,const char *src,size_t isz); void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len,
include/linux/string_helpers.h +3 -0
@@ -54,6 +54,9 @@ static inline int string_unescape_any_inplace(char *buf)int string_escape_mem (const char *src,size_t isz,char *dst,size_t osz,unsigned int flags,const char *only); +int string_escape_mem_ascii (const char *src,size_t isz,char *dst, +size_t osz); +static inline int string_escape_mem_any_np (const char *src,size_t isz,char *dst,size_t osz,const char *only) {
lib/string_helpers.c +19 -0
@@ -539,6 +539,25 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, }EXPORT_SYMBOL (string_escape_mem); +int string_escape_mem_ascii (const char *src,size_t isz,char *dst, +size_t osz) +{ +char *p = dst; +char *end = p + osz; + +while (isz--) { +unsigned char c = *src++; + +if (!isprint (c) || !isascii (c) || c =='"' || c =='\\' ) +escape_hex (c, &p, end); +else +escape_passthrough (c, &p, end); + } + +return p - dst; +} +EXPORT_SYMBOL (string_escape_mem_ascii); +/* * Return an allocated string that has been escaped of special characters * and double quotes, making it safe to log in quotes.
Signature · 1 line
2.21.0
Re: [PATCH 08/16] nfsd: escape high characters in binary data
I'm not sure who to get review from for this kind of thing.
Kees, you seem to be one of the only people to touch string_helpers.c at all recently, any ideas?
--b.
Quoted 109 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
I'm exposing some information about NFS clients in pseudofiles. I expect to eventually have simple tools to help read those pseudofiles.
But it's also helpful if the raw files are human-readable to the extent possible. It aids debugging and makes them usable on systems that don't have the latest nfs-utils.
A minor challenge there is opaque client-generated protocol objects like state owners and client identifiers. Some clients generate those to include handy information in plain ascii. But they may also include arbitrary byte sequences.
I think the simplest approach is to limit to isprint(c) && isascii(c) and escape everything else.
That means you can just cat the file and get something that looks OK. Also, I'm trying to keep these files legal YAML, which requires them to UTF-8, and this is a simple way to guarantee that.
Signed-off-by J. Bruce Fields <[email protected]>--- fs/seq_file.c | 11 +++++++++++ include/linux/seq_file.h | 1 + include/linux/string_helpers.h | 3 +++ lib/string_helpers.c | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+)fs/seq_file.c +11
-0@@ -384,6 +384,17 @@ void seq_escape(struct seq_file *m, const char *s, const char *esc) }EXPORT_SYMBOL (seq_escape); +void seq_escape_mem_ascii (struct seq_file *m,const char *src,size_t isz) +{ +char *buf; +size_t size =seq_get_buf (m, &buf); +int ret; + + ret =string_escape_mem_ascii (src, isz, buf, size); +seq_commit (m, ret < size ? ret :-1 ); +} +EXPORT_SYMBOL (seq_escape_mem_ascii); +void seq_vprintf (struct seq_file *m,const char *f,va_list args) {int len;include/linux/seq_file.h +1
-0@@ -127,6 +127,7 @@ void seq_put_hex_ll(struct seq_file *m, const char *delimiter, unsigned long long v, unsigned int width);void seq_escape (struct seq_file *m,const char *s,const char *esc); +void seq_escape_mem_ascii (struct seq_file *m,const char *src,size_t isz); void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len,include/linux/string_helpers.h +3
-0@@ -54,6 +54,9 @@ static inline int string_unescape_any_inplace(char *buf)int string_escape_mem (const char *src,size_t isz,char *dst,size_t osz,unsigned int flags,const char *only); +int string_escape_mem_ascii (const char *src,size_t isz,char *dst, +size_t osz); +static inline int string_escape_mem_any_np (const char *src,size_t isz,char *dst,size_t osz,const char *only) {lib/string_helpers.c +19
-0@@ -539,6 +539,25 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, }EXPORT_SYMBOL (string_escape_mem); +int string_escape_mem_ascii (const char *src,size_t isz,char *dst, +size_t osz) +{ +char *p = dst; +char *end = p + osz; + +while (isz--) { +unsigned char c = *src++; + +if (!isprint (c) || !isascii (c) || c =='"' || c =='\\' ) +escape_hex (c, &p, end); +else +escape_passthrough (c, &p, end); + } + +return p - dst; +} +EXPORT_SYMBOL (string_escape_mem_ascii); +/* * Return an allocated string that has been escaped of special characters * and double quotes, making it safe to log in quotes. Signature · 1 line
2.21.0
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 4 lines · J. Bruce Fields
I'm not sure who to get review from for this kind of thing.
Kees, you seem to be one of the only people to touch
string_helpers.cat all recently, any ideas?
Hi! Yeah, I'm happy to take a look. Notes below...
Quoted 20 lines
--b.
Quoted 16 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
I'm exposing some information about NFS clients in pseudofiles. I expect to eventually have simple tools to help read those pseudofiles.
But it's also helpful if the raw files are human-readable to the extent possible. It aids debugging and makes them usable on systems that don't have the latest nfs-utils.
A minor challenge there is opaque client-generated protocol objects like state owners and client identifiers. Some clients generate those to include handy information in plain ascii. But they may also include arbitrary byte sequences.
I think the simplest approach is to limit to isprint(c) && isascii(c) and escape everything else.
Can you get the same functionality out of sprintf's %pE (escaped string)? If not, maybe we should expand the flags available?
* - 'E[achnops]' For an escaped buffer, where rules are defined by
* combination
* of the following flags (see string_escape_mem() for * the * details): * a - ESCAPE_ANY * c - ESCAPE_SPECIAL * h - ESCAPE_HEX * n - ESCAPE_NULL * o - ESCAPE_OCTAL * p - ESCAPE_NP * s - ESCAPE_SPACE
* By default ESCAPE_ANY_NP is used.
This doesn't cover escaping >0x7f and " and \
And perhaps I should rework kstrdup_quotable() to have that flag? It's not currently escaping non-ascii and it probably should. Maybe "ESCAPE_QUOTABLE" as "q"?
Signature · 1 line
Kees Cook
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 7 lines · Kees Cook
Quoted 4 lines · J. Bruce Fields
I'm not sure who to get review from for this kind of thing.
Kees, you seem to be one of the only people to touch
string_helpers.cat all recently, any ideas?Hi! Yeah, I'm happy to take a look. Notes below...
Thanks!
Quoted 15 lines
Quoted 15 lines · J. Bruce Fields
Quoted 14 lines
From: "J. Bruce Fields" <[email protected]>
I'm exposing some information about NFS clients in pseudofiles. I expect to eventually have simple tools to help read those pseudofiles.
But it's also helpful if the raw files are human-readable to the extent possible. It aids debugging and makes them usable on systems that don't have the latest nfs-utils.
A minor challenge there is opaque client-generated protocol objects like state owners and client identifiers. Some clients generate those to include handy information in plain ascii. But they may also include arbitrary byte sequences.
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
I think the simplest approach is to limit to isprint(c) && isascii(c) and escape everything else.
Can you get the same functionality out of sprintf's %pE (escaped string)? If not, maybe we should expand the flags available?
Nothing against it, I just didn't want it to do that for one user, but...
Quoted 13 lines
* - 'E[achnops]' For an escaped buffer, where rules are defined by
* combination* of the following flags (see string_escape_mem() for * the * details): * a - ESCAPE_ANY * c - ESCAPE_SPECIAL * h - ESCAPE_HEX * n - ESCAPE_NULL * o - ESCAPE_OCTAL * p - ESCAPE_NP * s - ESCAPE_SPACE
Quoted 7 lines
* By default
ESCAPE_ANY_NPis used.This doesn't cover escaping >0x7f and " and \
And perhaps I should rework
kstrdup_quotable()to have that flag? It's not currently escaping non-ascii and it probably should. Maybe "ESCAPE_QUOTABLE" as "q"?
... but if you think there's a lot of existing users that really want this behavior, then great.
I'll look into that.
The logic around ESCAPE_NP and the "only" string is really confusing. I started assuming I could just add an ESCAPE_NONASCII flag and stick " and \ into the "only" string, but it doesn't work that way.
---b.
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 3 lines · J. Bruce Fields
The logic around
ESCAPE_NPand the "only" string is really confusing. I started assuming I could just add anESCAPE_NONASCIIflag and stick " and \ into the "only" string, but it doesn't work that way.
Yeah, if ESCAPE_NP isn't specified, the "only" characters are passed through. It'd be nice to have an "add" or a clearer way to do actual ctype subsets, etc. If there isn't an obviously clear way to refactor it, just skip it for now and I'm happy to ack your original patch. :)
Signature · 1 line
Kees Cook
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 9 lines · Kees Cook
Quoted 3 lines · J. Bruce Fields
The logic around
ESCAPE_NPand the "only" string is really confusing. I started assuming I could just add anESCAPE_NONASCIIflag and stick " and \ into the "only" string, but it doesn't work that way.Yeah, if
ESCAPE_NPisn't specified, the "only" characters are passed through. It'd be nice to have an "add" or a clearer way to do actual ctype subsets, etc. If there isn't an obviously clear way to refactor it, just skip it for now and I'm happy to ack your original patch. :)
There may well be some simplification possible here.... There aren't really many users of "only", for example. I'll look into it some more.
--b.
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 6 lines · J. Bruce Fields
Quoted 5 lines · Kees Cook
Quoted 3 lines · J. Bruce Fields
The logic around
ESCAPE_NPand the "only" string is really confusing. I started assuming I could just add anESCAPE_NONASCIIflag and stick " and \ into the "only" string, but it doesn't work that way.
Quoted 7 lines
Quoted 4 lines
Yeah, if
ESCAPE_NPisn't specified, the "only" characters are passed through. It'd be nice to have an "add" or a clearer way to do actual ctype subsets, etc. If there isn't an obviously clear way to refactor it, just skip it for now and I'm happy to ack your original patch. :)There may well be some simplification possible here.... There aren't really many users of "only", for example. I'll look into it some more.
The printk users are kind of mysterious to me. I did a grep for
git grep '%[0-9.*]pE'
which got 75 hits. All of them for pE. I couldn't find any of the other pE[achnops] variants. pE is equivalent to ESCAPE_ANY|ESCAPE_NP. Confusingly, ESCAPE_NP doesn't mean "escape non-printable", it means "don't escape printable". So things like carriage returns aren't escaped.
Of those 57 were in drivers/net/wireless, and from a quick check seemed mostly to be for SSIDs in debug messages. I *think* SSIDs can be arbitrary bytes? If they really want them escaped then I suspect they want more than just nonprintable characters escaped.
One of the hits outside wireless code was in drm_dp_cec_adap_status, which was printing some device ID into a debugfs file with "ID: %*pE\n". If the ID actually needs escaping, then I suspect the meant to escape \n too to prevent misparsing that output.
--b.
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 15 lines · J. Bruce Fields
Quoted 6 lines · J. Bruce Fields
Quoted 5 lines · Kees Cook
Quoted 3 lines · J. Bruce Fields
The logic around
ESCAPE_NPand the "only" string is really confusing. I started assuming I could just add anESCAPE_NONASCIIflag and stick " and \ into the "only" string, but it doesn't work that way.Quoted 7 lines
Quoted 4 lines
Yeah, if
ESCAPE_NPisn't specified, the "only" characters are passed through. It'd be nice to have an "add" or a clearer way to do actual ctype subsets, etc. If there isn't an obviously clear way to refactor it, just skip it for now and I'm happy to ack your original patch. :)There may well be some simplification possible here.... There aren't really many users of "only", for example. I'll look into it some more.
Quoted 6 lines
The printk users are kind of mysterious to me. I did a grep for
git grep '%[0-9.*]pE'which got 75 hits. All of them for pE. I couldn't find any of the other pE[achnops] variants. pE is equivalent to ESCAPE_ANY|ESCAPE_NP.
I saw pEn and pEhp and pEp:
drivers/staging/rtl8192e/rtllib.h: snprintf(escaped, sizeof(escaped), "%*pEn", essid_len, essid);drivers/staging/rtl8192u/ieee80211/ieee80211.h: snprintf(escaped, sizeof(escaped), "%*pEn", essid_len, essid); drivers/staging/wlan-ng/prism2sta.c: netdev_info(wlandev->netdev, "Prism2 card SN: %*pEhp\n", drivers/thunderbolt/xdomain.c: return sprintf(buf, "%*pEp\n", (int)strlen(svc->key), svc->key);
However, every use was insufficient, AFAICT.
This:
git grep -2 '\bescape_essid\b'
Shows that all the staging uses end up getting logged as: '%s' so their escaping is insufficient.
Quoted 3 lines
Confusingly,
ESCAPE_NPdoesn't mean "escape non-printable", it means "don't escape printable". So things like carriage returns aren't escaped.
Right -- any they're almost all logged surrounded by ' or " which means those would need to be escaped as well. The prism2 is leaking newlines too, as well as the thunderbolt sysfs printing.
So... seems like we should fix this. :P
Quoted 9 lines
Of those 57 were in
drivers/net/wireless, and from a quick check seemed mostly to be for SSIDs in debug messages. I *think* SSIDs can be arbitrary bytes? If they really want them escaped then I suspect they want more than just nonprintable characters escaped.One of the hits outside wireless code was in
drm_dp_cec_adap_status, which was printing some device ID into a debugfs file with "ID: %*pE\n". If the ID actually needs escaping, then I suspect the meant to escape \n too to prevent misparsing that output.
I think we need to make the default produce "loggable" output. non-ascii, non-printables, \, ', and " need to be escaped. Maybe " " too?
Signature · 1 line
Kees Cook
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 5 lines · Kees Cook
Right -- any they're almost all logged surrounded by ' or " which means those would need to be escaped as well. The prism2 is leaking newlines too, as well as the thunderbolt sysfs printing.
So... seems like we should fix this. :P
...
Quoted 3 lines
I think we need to make the default produce "loggable" output. non-ascii, non-printables, \, ', and " need to be escaped. Maybe " " too?
OK, so I think the first step is to take a closer look at the users of the default %*pE. If there are any that look like they'd be broken by a change, we should make patches moving to something else, then we can change the default.
Then we can also replace ESCAPE_ANY and ESCAPE_NP--that "don't escape printable" logic is confusing and makes it hard to add more types of escaping. And it appears to only be used by %*pE.
--b
Re: [PATCH 08/16] nfsd: escape high characters in binary data
In reply to J. Bruce FieldsQuoted 17 lines · J. Bruce Fields
Quoted 6 lines · J. Bruce Fields
Quoted 5 lines · Kees Cook
Quoted 3 lines · J. Bruce Fields
The logic around
ESCAPE_NPand the "only" string is really confusing. I started assuming I could just add anESCAPE_NONASCIIflag and stick " and \ into the "only" string, but it doesn't work that way.Quoted 7 lines
Quoted 4 lines
Yeah, if
ESCAPE_NPisn't specified, the "only" characters are passed through. It'd be nice to have an "add" or a clearer way to do actual ctype subsets, etc. If there isn't an obviously clear way to refactor it, just skip it for now and I'm happy to ack your original patch. :)There may well be some simplification possible here.... There aren't really many users of "only", for example. I'll look into it some more.
The printk users are kind of mysterious to me. I did a grep for
Quoted 7 lines
git grep '%[0-9.*]pE'which got 75 hits. All of them for pE. I couldn't find any of the other pE[achnops] variants. pE is equivalent to ESCAPE_ANY|ESCAPE_NP. Confusingly,
ESCAPE_NPdoesn't mean "escape non-printable", it means "don't escape printable". So things like carriage returns aren't escaped.
No, I was confused: "\n" is non-printable according to isprint(), so ESCAPE_ANY_NP *will* escape it. So this isn't quite so bad. SSIDs are usually printed as '%*pE', so arguably we should be escaping the single quote character too, but at least we're not allowing line breaks through. I don't know about non-ascii.
Quoted 4 lines
One of the hits outside wireless code was in
drm_dp_cec_adap_status, which was printing some device ID into a debugfs file with "ID: %*pE\n". If the ID actually needs escaping, then I suspect the meant to escape \n too to prevent misparsing that output.
And same here, this is OK.
--b.
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 5 lines · J. Bruce Fields
No, I was confused: "\n" is non-printable according to
isprint(), soESCAPE_ANY_NP*will* escape it. So this isn't quite so bad. SSIDs are usually printed as '%*pE', so arguably we should be escaping the single quote character too, but at least we're not allowing line breaks through. I don't know about non-ascii.
Okay, cool. Given that most things are just trying to log, it seems like it should be safe to have %pE escape non-ascii, non-printable, \, ', and "?
And if we changing that, we're likely changing string_escape_mem(). Looking at callers of string_escape_mem() makes my head spin...
Anyway, I don't want to block you needlessly. What would like to have be next steps here?
Signature · 1 line
Kees Cook
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 7 lines · Kees Cook
Quoted 5 lines · J. Bruce Fields
No, I was confused: "\n" is non-printable according to
isprint(), soESCAPE_ANY_NP*will* escape it. So this isn't quite so bad. SSIDs are usually printed as '%*pE', so arguably we should be escaping the single quote character too, but at least we're not allowing line breaks through. I don't know about non-ascii.
Quoted 6 lines
Okay, cool. Given that most things are just trying to log, it seems like it should be safe to have %pE escape non-ascii, non-printable, \, ', and "?
And if we changing that, we're likely changing
string_escape_mem(). Looking at callers ofstring_escape_mem()makes my head spin...
kstrdup_quotable:
- only a few callers, mostly just logging, but msm_gpu_crashstate_capture uses it to generate some data that looks like it goes in a crashdump. Dunno if there might be some utility depending on the current escaping. On the other hand, kstrdup_quotable uses ESCAPE_HEX, "\f\n\r\t\v\a\e\\\"" so those characters are all escaped as \xNN, so I'd hope any parser would be prepared to unescape any hex character, they'd have to go out of their way to do anything else.string_escape_str:
- proc_task_name: ESCAPE_SPACE|ESCAPE_SPECIAL, "\n\\", used for command name in /proc/<pid>/stat{us}. No way do I want to change the format of those files at all.
- seq_escape: ESCAPE_OCTAL, esc: haven't surveyed callers carefully, but this probably shouldn't be changed.
- qword_add: ESCAPE_OCTAL, "\\ \n\t", some nfsd upcalls. Fine as they are, but the other side will happily accept any octal or hex escaping.string_escape_mem_any_np, string_escape_str_any_np:
- totally unused.escaped_string: this is the vsnprintf logic. Tons of users, haven't had
a chance to look at them all. Almost all %*pE, the exceptions don't look important.
So the only flag values we care about are ESCAPE_HEX, ESCAPE_OCTAL, ESCAPE_SPACE|ESCAPE_SPECIAL, and ESCAPE_ANY_NP.
So this could be cleaned up some if we wanted.
Quoted 2 lines
Anyway, I don't want to block you needlessly. What would like to have be next steps here?
I might still be interested in some cleanup, I find the current logic unnecessarily confusing.
But I may just give up and go with my existing patch and put off that project indefinitely, especially if there's no real need to fix the existing callers.
I don't know....
--b.
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 3 lines · J. Bruce Fields
But I may just give up and go with my existing patch and put off that project indefinitely, especially if there's no real need to fix the existing callers.
I went with the existing patch, but gave a little more thought to string_escape_mem. Stuff that bugs me:
- ESCAPE_NP sounds like it means "escape nonprinting characters", but actually means "do not escape printing characters"
- the use of the "only" string to limit the list of escaped characters rather than supplement them is confusing and kind of unhelpful.
- most of the flags are actually totally unused
So what I'd like to do is:
- eliminate unused flags
- use the "only" string to add to, rather than replace, the list of characters to escape
- separate flags into those that select which characters to escape, and those that choose the format of the escaping ("\ " vs "\x20" vs "\040".)
I've got some patches that do all that and I think it works. I need to clean them up a bit and fix up the tests.
--b.
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 25 lines · J. Bruce Fields
Quoted 3 lines · J. Bruce Fields
But I may just give up and go with my existing patch and put off that project indefinitely, especially if there's no real need to fix the existing callers.
I went with the existing patch, but gave a little more thought to
string_escape_mem. Stuff that bugs me:-
ESCAPE_NPsounds like it means "escape nonprinting characters", but actually means "do not escape printing characters"
- the use of the "only" string to limit the list of escaped characters rather than supplement them is confusing and kind of unhelpful.
- most of the flags are actually totally unusedSo what I'd like to do is:
- eliminate unused flags
- use the "only" string to add to, rather than replace, the list of characters to escape
- separate flags into those that select which characters to escape, and those that choose the format of the escaping ("\ " vs "\x20" vs "\040".)
Quoted 2 lines
I've got some patches that do all that and I think it works. I need to clean them up a bit and fix up the tests.
This sounds amazing; thanks! Luckily there are self-tests for this code, so anything really surprising should stand out. I'm looking forward to it -- I want to see if I can refactor a few of the callers (if you haven't already do so) too.
Yay!
Signature · 1 line
Kees Cook
Re: [PATCH 08/16] nfsd: escape high characters in binary data
In reply to J. Bruce FieldsQuoted 14 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
I'm exposing some information about NFS clients in pseudofiles. I expect to eventually have simple tools to help read those pseudofiles.
But it's also helpful if the raw files are human-readable to the extent possible. It aids debugging and makes them usable on systems that don't have the latest nfs-utils.
A minor challenge there is opaque client-generated protocol objects like state owners and client identifiers. Some clients generate those to include handy information in plain ascii. But they may also include arbitrary byte sequences.
Quoted 6 lines
I think the simplest approach is to limit to isprint(c) && isascii(c) and escape everything else.
That means you can just cat the file and get something that looks OK. Also, I'm trying to keep these files legal YAML, which requires them to UTF-8, and this is a simple way to guarantee that.
Two questions:
- why can't be original function extended to cover this case (using additional flags, maybe)?
- where are the test cases?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 18 lines · Andy Shevchenko
Quoted 17 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
I'm exposing some information about NFS clients in pseudofiles. I expect to eventually have simple tools to help read those pseudofiles.
But it's also helpful if the raw files are human-readable to the extent possible. It aids debugging and makes them usable on systems that don't have the latest nfs-utils.
A minor challenge there is opaque client-generated protocol objects like state owners and client identifiers. Some clients generate those to include handy information in plain ascii. But they may also include arbitrary byte sequences.
I think the simplest approach is to limit to isprint(c) && isascii(c) and escape everything else.
Quoted 7 lines
Quoted 3 lines
That means you can just cat the file and get something that looks OK. Also, I'm trying to keep these files legal YAML, which requires them to UTF-8, and this is a simple way to guarantee that.
Two questions:
- why can't be original function extended to cover this case (using additional flags, maybe)?
I found the ESCAPE_NP/"only" logic made it a little difficult to extend string_escape_mem().
So, I wrote a patch series that removes the string_escape_mem flags that aren't used, simplifies it a bit, then separates the flags into two different types: those that select which characters to escape (non-printable, non-ascii, whitespace, etc.) and those that choose a style of escaping to use (octal, hex, or \\). That seems to make the code a little easier to extend while still covering the cases people actually use. I'll try to get those out this week and you can tell me what you think.
Quoted 1 line
- where are the test cases?
I didn't write a test case. I agree that it would be a good idea--I'll work on it.
--b.
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 23 lines · J. Bruce Fields
Quoted 22 lines · Andy Shevchenko
Quoted 20 lines · J. Bruce Fields
From: "J. Bruce Fields" <[email protected]>
I'm exposing some information about NFS clients in pseudofiles. I expect to eventually have simple tools to help read those pseudofiles.
But it's also helpful if the raw files are human-readable to the extent possible. It aids debugging and makes them usable on systems that don't have the latest nfs-utils.
A minor challenge there is opaque client-generated protocol objects like state owners and client identifiers. Some clients generate those to include handy information in plain ascii. But they may also include arbitrary byte sequences.
I think the simplest approach is to limit to isprint(c) && isascii(c) and escape everything else.
That means you can just cat the file and get something that looks OK. Also, I'm trying to keep these files legal YAML, which requires them to UTF-8, and this is a simple way to guarantee that.
Quoted 6 lines
Quoted 3 lines
Two questions:
- why can't be original function extended to cover this case (using additional flags, maybe)?I found the ESCAPE_NP/"only" logic made it a little difficult to extend
string_escape_mem().
Maybe it requires more thinking about?
I think it is still possible to extend existing, rather to take workarounds like this one.
Quoted 2 lines
So, I wrote a patch series that removes the
string_escape_memflags that aren't used
Have you considered the potential users that can be converted to use string_escape_mem()?
I know about at least one (needs to be reworked a bit, but it is in slow progress).
There are potentially others that would be converted using "unused" flags.
Quoted 7 lines
, simplifies it a bit, then separates the flags into two different types: those that select which characters to escape (non-printable, non-ascii, whitespace, etc.) and those that choose a style of escaping to use (octal, hex, or \\). That seems to make the code a little easier to extend while still covering the cases people actually use. I'll try to get those out this week and you can tell me what you think.
Will be glad to help!
In any case regarding to this one, I would like rather to see it's never appeared, or now will be gone in favour of string_escape_mem() extension.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 3 lines · Andy Shevchenko
Maybe it requires more thinking about?
I think it is still possible to extend existing, rather to take workarounds like this one.
Yeah, agreed.
Quoted 10 lines
Quoted 2 lines
So, I wrote a patch series that removes the
string_escape_memflags that aren't usedHave you considered the potential users that can be converted to use
string_escape_mem()?I know about at least one (needs to be reworked a bit, but it is in slow progress).
There are potentially others that would be converted using "unused" flags.
OK, that'd be interesting to know about.
Quoted 9 lines
Quoted 8 lines
, simplifies it a bit, then separates the flags into two different types: those that select which characters to escape (non-printable, non-ascii, whitespace, etc.) and those that choose a style of escaping to use (octal, hex, or \\). That seems to make the code a little easier to extend while still covering the cases people actually use. I'll try to get those out this week and you can tell me what you think.
Quoted 4 lines
Will be glad to help!
In any case regarding to this one, I would like rather to see it's never appeared, or now will be gone in favour of
string_escape_mem()extension.
To be clear, it's already merged. Apologies, I actually saw your name when looking for people to cc, but the last commit was 5 years ago and I assumed you'd moved on. The project to extend string_escape_mem() looked more complicated than I first expected so I decided to merge this first and then follow up with my attempt at that.
--b.
Re: [PATCH 08/16] nfsd: escape high characters in binary data
Quoted 10 lines · J. Bruce Fields
Quoted 2 lines · Andy Shevchenko
In any case regarding to this one, I would like rather to see it's never appeared, or now will be gone in favour of
string_escape_mem()extension.To be clear, it's already merged. Apologies, I actually saw your name when looking for people to cc, but the last commit was 5 years ago and I assumed you'd moved on. The project to extend
string_escape_mem()looked more complicated than I first expected so I decided to merge this first and then follow up with my attempt at that.
The (main) problem with the new helper is that is missed from %pE point of view. That's why I really prefer to see new flags rather than new helpers like that.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 9/16 nfsd: add more information to client info file
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Add ip address, full client-provided identifier, and minor version. There's much more that could possibly be useful but this is a start.
--- fs/nfsd/nfs4state.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/nfsd/nfs4state.c +12 -0
@@ -42,6 +42,7 @@#include <linux/sunrpc/svcauth_gss.h> #include <linux/sunrpc/addr.h> #include <linux/jhash.h> +#include <linux/string_helpers.h> #include "xdr4.h" #include "xdr4cb.h" #include "vfs.h"
@@ -2214,6 +2215,13 @@ find_stateid_by_type(struct nfs4_client *cl, stateid_t *t, char typemask)return s; } +static void seq_quote_mem (struct seq_file *m,char *data,int len) +{ +seq_printf (m,"\"" ); +seq_escape_mem_ascii (m, data, len); +seq_printf (m,"\"" ); +} +static int client_info_show (struct seq_file *m,void *v) {struct inode *inode = m->private;
@@ -2227,6 +2235,10 @@ static int client_info_show(struct seq_file *m, void *v) clp = container_of(nc, struct nfs4_client, cl_nfsdfs);memcpy (&clid, &clp->cl_clientid,sizeof (clid));seq_printf (m,"clientid: 0x%llx\n" , clid); +seq_printf (m,"address: \"%pISpc\"\n" , (struct sockaddr *)&clp->cl_addr); +seq_printf (m,"name: " ); +seq_quote_mem (m, clp->cl_name.data, clp->cl_name.len); +seq_printf (m,"\nminor version: %d\n" , clp->cl_minorversion);drop_client (clp);return 0 ;
Signature · 1 line
2.21.0
PATCH 10/16 nfsd4: add file to display list of client's opens
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Add a nfsd/clients/#/opens file to list some information about all the opens held by the given client, including open modes, device numbers, inode numbers, and open owners.
Open owners are totally opaque but seem to sometimes have some useful ascii strings included, so passing through printable ascii characters and escaping the rest seems useful while still being machine-readable.
--- fs/nfsd/nfs4state.c | 149 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +147 -2
@@ -695,7 +695,8 @@ struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *slaidr_preload (GFP_KERNEL );spin_lock (&cl->cl_lock); - new_id =idr_alloc_cyclic (&cl->cl_stateids, stid,0 ,0 ,GFP_NOWAIT ); +/* Reserving 0 for start of file in nfsdfs "states" file: */ + new_id =idr_alloc_cyclic (&cl->cl_stateids, stid,1 ,0 ,GFP_NOWAIT );spin_unlock (&cl->cl_lock);idr_preload_end ();if (new_id <0 )
@@ -2256,9 +2257,153 @@ static const struct file_operations client_info_fops = { .release = single_release, }; +static void *states_start (struct seq_file *s,loff_t *pos) + __acquires(&clp->cl_lock) +{ +struct nfs4_client *clp = s->private; +unsigned long id = *pos; +void *ret; + +spin_lock (&clp->cl_lock); + ret =idr_get_next_ul (&clp->cl_stateids, &id); + *pos = id; +return ret; +} + +static void *states_next (struct seq_file *s,void *v,loff_t *pos) +{ +struct nfs4_client *clp = s->private; +unsigned long id = *pos; +void *ret; + + id = *pos; + id++; + ret =idr_get_next_ul (&clp->cl_stateids, &id); + *pos = id; +return ret; +} + +static void states_stop (struct seq_file *s,void *v) + __releases(&clp->cl_lock) +{ +struct nfs4_client *clp = s->private; + +spin_unlock (&clp->cl_lock); +} + +static void nfs4_show_superblock (struct seq_file *s,struct file *f) +{ +struct inode *inode =file_inode (f); + +seq_printf (s,"superblock: \"%02x:%02x:%ld\"" , +MAJOR (inode->i_sb->s_dev), +MINOR (inode->i_sb->s_dev), + inode->i_ino); +} + +static void nfs4_show_owner (struct seq_file *s,struct nfs4_stateowner *oo) +{ +seq_printf (s,"owner: " ); +seq_quote_mem (s, oo->so_owner.data, oo->so_owner.len); +} + +static int nfs4_show_open (struct seq_file *s,struct nfs4_stid *st) +{ +struct nfs4_ol_stateid *ols; +struct nfs4_file *nf; +struct file *file; +struct nfs4_stateowner *oo; +unsigned int access, deny; + +if (st->sc_type !=NFS4_OPEN_STID && st->sc_type !=NFS4_LOCK_STID ) +return 0 ;/* XXX: or SEQ_SKIP? */ + ols =openlockstateid (st); + oo = ols->st_stateowner; + nf = st->sc_file; + file =find_any_file (nf); + +seq_printf (s,"- 0x%16phN: { type: open, " , &st->sc_stateid); + + access =bmap_to_share_mode (ols->st_access_bmap); + deny =bmap_to_share_mode (ols->st_deny_bmap); + +seq_printf (s,"access: \%s\%s, " , + access &NFS4_SHARE_ACCESS_READ ?"r" :"-" , + access &NFS4_SHARE_ACCESS_WRITE ?"w" :"-" ); +seq_printf (s,"deny: \%s\%s, " , + deny &NFS4_SHARE_ACCESS_READ ?"r" :"-" , + deny &NFS4_SHARE_ACCESS_WRITE ?"w" :"-" ); + +nfs4_show_superblock (s, file); +seq_printf (s,", " ); +nfs4_show_owner (s, oo); +seq_printf (s," }\n" ); + +fput (file); + +return 0 ; +} + +static int states_show (struct seq_file *s,void *v) +{ +struct nfs4_stid *st = v; + +switch (st->sc_type) { +case NFS4_OPEN_STID : +return nfs4_show_open (s, st); +default : +return 0 ;/* XXX: or SEQ_SKIP? */ + } +} + +static struct seq_operations states_seq_ops = { + .start = states_start, + .next = states_next, + .stop = states_stop, + .show = states_show +}; + +static int client_states_open (struct inode *inode,struct file *file) +{ +struct nfsdfs_client *nc; +struct seq_file *s; +struct nfs4_client *clp; +int ret; + + nc =get_nfsdfs_client (inode); +if (!nc) +return -ENXIO ; + clp = container_of(nc, struct nfs4_client, cl_nfsdfs); + + ret =seq_open (file, &states_seq_ops); +if (ret) +return ret; + s = file->private_data; + s->private = clp; +return 0 ; +} + +static int client_opens_release (struct inode *inode,struct file *file) +{ +struct seq_file *m = file->private_data; +struct nfs4_client *clp = m->private; + +/* XXX: alternatively, we could get/drop in seq start/stop */ +drop_client (clp); +return 0 ; +} + +static const struct file_operations client_states_fops = { + .open = client_states_open, + .read = seq_read, + .llseek = seq_lseek, + .release = client_opens_release, +}; +static const struct tree_descr client_files[] = { [0 ] = {"info" , &client_info_fops,S_IRUSR }, - [1 ] = {"" }, + [1 ] = {"states" , &client_states_fops,S_IRUSR }, + [3 ] = {"" }, }; static struct nfs4_client *create_client(struct xdr_netobj name,
Signature · 1 line
2.21.0
PATCH 11/16 nfsd: show lock and deleg stateids
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
These entries are pretty minimal for now.
--- fs/nfsd/nfs4state.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)
fs/nfsd/nfs4state.c +59 -0
@@ -2338,12 +2338,66 @@ static int nfs4_show_open(struct seq_file *s, struct nfs4_stid *st)seq_printf (s,", " );nfs4_show_owner (s, oo);seq_printf (s," }\n" ); +fput (file); + +return 0 ; +} + +static int nfs4_show_lock (struct seq_file *s,struct nfs4_stid *st) +{ +struct nfs4_ol_stateid *ols; +struct nfs4_file *nf; +struct file *file; +struct nfs4_stateowner *oo; + ols =openlockstateid (st); + oo = ols->st_stateowner; + nf = st->sc_file; + file =find_any_file (nf); + +seq_printf (s,"- 0x%16phN: { type: lock, " , &st->sc_stateid); + +/* +* Note: a lock stateid isn't really the same thing as a lock, +* it's the locking state held by one owner on a file, and there +* may be multiple (or no) lock ranges associated with it. +* (Same for the matter is true of open stateids.) +*/ + +nfs4_show_superblock (s, file); +/* XXX: open stateid? */ +seq_printf (s,", " ); +nfs4_show_owner (s, oo); +seq_printf (s," }\n" );fput (file);return 0 ; } +static int nfs4_show_deleg (struct seq_file *s,struct nfs4_stid *st) +{ +struct nfs4_delegation *ds; +struct nfs4_file *nf; +struct file *file; + + ds =delegstateid (st); + nf = st->sc_file; + file = nf->fi_deleg_file; + +seq_printf (s,"- 0x%16phN: { type: deleg, " , &st->sc_stateid); + +/* Kinda dead code as long as we only support read delegs: */ +seq_printf (s,"access: %s, " , + ds->dl_type ==NFS4_OPEN_DELEGATE_READ ?"r" :"w" ); + +/* XXX: lease time, whether it's being recalled. */ + +nfs4_show_superblock (s, file); +seq_printf (s," }\n" ); + +return 0 ; +} +static int states_show (struct seq_file *s,void *v) {struct nfs4_stid *st = v;
@@ -2351,9 +2405,14 @@ static int states_show(struct seq_file *s, void *v)switch (st->sc_type) {case NFS4_OPEN_STID :return nfs4_show_open (s, st); +case NFS4_LOCK_STID : +return nfs4_show_lock (s, st); +case NFS4_DELEG_STID : +return nfs4_show_deleg (s, st);default :return 0 ;/* XXX: or SEQ_SKIP? */ } +/* XXX: copy stateids? */ }static struct seq_operations states_seq_ops = {
Signature · 1 line
2.21.0
PATCH 12/16 nfsd4: show layout stateids
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
These are also minimal for now, I'm not sure what information would be useful.
--- fs/nfsd/nfs4state.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
fs/nfsd/nfs4state.c +20 -0
@@ -2398,6 +2398,24 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)return 0 ; } +static int nfs4_show_layout (struct seq_file *s,struct nfs4_stid *st) +{ +struct nfs4_layout_stateid *ls; +struct file *file; + + ls = container_of(st, struct nfs4_layout_stateid, ls_stid); + file = ls->ls_file; + +seq_printf (s,"- 0x%16phN: { type: layout, " , &st->sc_stateid); + +/* XXX: What else would be useful? */ + +nfs4_show_superblock (s, file); +seq_printf (s," }\n" ); + +return 0 ; +} +static int states_show (struct seq_file *s,void *v) {struct nfs4_stid *st = v;
@@ -2409,6 +2427,8 @@ static int states_show(struct seq_file *s, void *v)return nfs4_show_lock (s, st);case NFS4_DELEG_STID :return nfs4_show_deleg (s, st); +case NFS4_LAYOUT_STID : +return nfs4_show_layout (s, st);default :return 0 ;/* XXX: or SEQ_SKIP? */ }
Signature · 1 line
2.21.0
PATCH 13/16 nfsd: create get_nfsdfs_clp helper
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Factor our some common code. No change in behavior.
--- fs/nfsd/nfs4state.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
fs/nfsd/nfs4state.c +13 -8
@@ -2216,6 +2216,15 @@ find_stateid_by_type(struct nfs4_client *cl, stateid_t *t, char typemask)return s; } +static struct nfs4_client *get_nfsdfs_clp (struct inode *inode) +{ +struct nfsdfs_client *nc; + nc =get_nfsdfs_client (inode); +if (!nc) +return NULL ; + return container_of(nc, struct nfs4_client, cl_nfsdfs); +} +static void seq_quote_mem (struct seq_file *m,char *data,int len) {seq_printf (m,"\"" );
@@ -2226,14 +2235,12 @@ static void seq_quote_mem(struct seq_file *m, char *data, int len)static int client_info_show (struct seq_file *m,void *v) {struct inode *inode = m->private; -struct nfsdfs_client *nc;struct nfs4_client *clp;u64 clid; - nc =get_nfsdfs_client (inode); -if (!nc) + clp =get_nfsdfs_clp (inode); +if (!clp)return -ENXIO ; - clp = container_of(nc, struct nfs4_client, cl_nfsdfs);memcpy (&clid, &clp->cl_clientid,sizeof (clid));seq_printf (m,"clientid: 0x%llx\n" , clid);seq_printf (m,"address: \"%pISpc\"\n" , (struct sockaddr *)&clp->cl_addr);
@@ -2444,15 +2451,13 @@ static struct seq_operations states_seq_ops = {static int client_states_open (struct inode *inode,struct file *file) { -struct nfsdfs_client *nc;struct seq_file *s;struct nfs4_client *clp;int ret; - nc =get_nfsdfs_client (inode); -if (!nc) + clp =get_nfsdfs_clp (inode); +if (!clp)return -ENXIO ; - clp = container_of(nc, struct nfs4_client, cl_nfsdfs); ret =seq_open (file, &states_seq_ops);if (ret)
Signature · 1 line
2.21.0
PATCH 14/16 nfsd: allow forced expiration of NFSv4 clients
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
NFSv4 clients are automatically expired and all their locks removed if they don't contact the server for a certain amount of time (the lease period, 90 seconds by default).
There can still be situations where that's not enough, so allow userspace to force expiry by writing "expire\n" to the new nfsd/client/#/ctl file.
(The generic "ctl" name is because I expect we may want to allow other operations on clients in the future.)
The write will not return until the client is expired and all of its locks and other state removed.
The fault injection code also provides a way of expiring clients, but it fails if there are any in-progress RPC's referencing the client. Also, its method of selecting a client to expire is a little more primitive--it uses an IP address, which can't always uniquely specify an NFSv4 client.
--- fs/nfsd/nfs4state.c | 70 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-)
fs/nfsd/nfs4state.c +69 -1
@@ -100,6 +100,13 @@ enum nfsd4_st_mutex_lock_subclass {*/ static DECLARE_WAIT_QUEUE_HEAD (close_wq); +/* +* A waitqueue where a writer to clients/#/ctl destroying a client can +* wait for cl_rpc_users to drop to 0 and then for the client to be +* unhashed. +*/ +static DECLARE_WAIT_QUEUE_HEAD (expiry_wq); +static struct kmem_cache *client_slab;static struct kmem_cache *openowner_slab;static struct kmem_cache *lockowner_slab;
@@ -175,6 +182,8 @@ static void put_client_renew_locked(struct nfs4_client *clp)return ;if (!is_client_expired (clp))renew_client_locked (clp); +else +wake_up_all (&expiry_wq); }static void put_client_renew (struct nfs4_client *clp)
@@ -185,6 +194,8 @@ static void put_client_renew(struct nfs4_client *clp)return ;if (!is_client_expired (clp))renew_client_locked (clp); +else +wake_up_all (&expiry_wq);spin_unlock (&nn->client_lock); }
@@ -1910,8 +1921,11 @@ free_client(struct nfs4_client *clp)free_session (ses); }rpc_destroy_wait_queue (&clp->cl_cb_waitq); -if (clp->cl_nfsd_dentry) +if (clp->cl_nfsd_dentry) {nfsd_client_rmdir (clp->cl_nfsd_dentry); + clp->cl_nfsd_dentry =NULL ; +wake_up_all (&expiry_wq); + }drop_client (clp); }
@@ -2006,6 +2020,7 @@ __destroy_client(struct nfs4_client *clp)if (clp->cl_cb_conn.cb_xprt)svc_xprt_put (clp->cl_cb_conn.cb_xprt);free_client (clp); +wake_up_all (&expiry_wq); } static void
@@ -2484,9 +2499,62 @@ static const struct file_operations client_states_fops = { .release = client_opens_release, }; +/* +* Normally we refuse to destroy clients that are in use, but here the +* administrator is telling us to just do it. We also want to wait +* so the caller has a guarantee that the client's locks are gone by +* the time the write returns: +*/ +void force_expire_client (struct nfs4_client *clp) +{ +struct nfsd_net *nn =net_generic (clp->net, nfsd_net_id); +bool already_expired; + +spin_lock (&clp->cl_lock); + clp->cl_time =0 ; +spin_unlock (&clp->cl_lock); + +wait_event (expiry_wq,atomic_read (&clp->cl_rpc_users) ==0 ); +spin_lock (&nn->client_lock); + already_expired =list_empty (&clp->cl_lru); +if (!already_expired) +unhash_client_locked (clp); +spin_unlock (&nn->client_lock); + +if (!already_expired) +expire_client (clp); +else +wait_event (expiry_wq, clp->cl_nfsd_dentry ==NULL ); +} + +static ssize_t client_ctl_write (struct file *file,const char __user *buf, +size_t size,loff_t *pos) +{ +char *data; +struct nfs4_client *clp; + + data =simple_transaction_get (file, buf, size); +if (IS_ERR (data)) +return PTR_ERR (data); +if (size !=7 ||0 !=memcmp (data,"expire\n" ,7 )) +return -EINVAL ; + clp =get_nfsdfs_clp (file_inode (file)); +if (!clp) +return -ENXIO ; +force_expire_client (clp); +drop_client (clp); +return 7 ; +} + +static const struct file_operations client_ctl_fops = { + .write = client_ctl_write, + .release = simple_transaction_release, +}; +static const struct tree_descr client_files[] = { [0 ] = {"info" , &client_info_fops,S_IRUSR }, [1 ] = {"states" , &client_states_fops,S_IRUSR }, + [2 ] = {"ctl" , &client_ctl_fops,S_IRUSR |S_IWUSR }, [3 ] = {"" }, };
Signature · 1 line
2.21.0
PATCH 15/16 nfsd: create xdr_netobj_dup helper
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Move some repeated code to a common helper. No change in behavior.
--- fs/nfsd/nfs4state.c | 11 ++++------- include/linux/sunrpc/xdr.h | 7 +++++++ 2 files changed, 11 insertions(+), 7 deletions(-)
fs/nfsd/nfs4state.c +4 -7
@@ -1857,7 +1857,7 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name) clp =kmem_cache_zalloc (client_slab,GFP_KERNEL );if (clp ==NULL )return NULL ; - clp->cl_name.data =kmemdup (name.data, name.len,GFP_KERNEL ); +xdr_netobj_dup (&clp->cl_name, &name,GFP_KERNEL );if (clp->cl_name.data ==NULL ) goto err_no_name; clp->cl_ownerstr_hashtbl = kmalloc_array(OWNER_HASH_SIZE,
@@ -1867,7 +1867,6 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name) goto err_no_hashtbl;for (i =0 ; i <OWNER_HASH_SIZE ; i++)INIT_LIST_HEAD (&clp->cl_ownerstr_hashtbl[i]); - clp->cl_name.len = name.len;INIT_LIST_HEAD (&clp->cl_sessions);idr_init (&clp->cl_stateids);atomic_set (&clp->cl_rpc_users,0 );
@@ -4000,12 +3999,11 @@ static inline void *alloc_stateowner(struct kmem_cache *slab, struct xdr_netobjif (!sop)return NULL ; - sop->so_owner.data =kmemdup (owner->data, owner->len,GFP_KERNEL ); +xdr_netobj_dup (&sop->so_owner, owner,GFP_KERNEL );if (!sop->so_owner.data) {kmem_cache_free (slab, sop);return NULL ; } - sop->so_owner.len = owner->len;INIT_LIST_HEAD (&sop->so_stateids); sop->so_client = clp;
@@ -6093,12 +6091,11 @@ nfs4_set_lock_denied(struct file_lock *fl, struct nfsd4_lock_denied *deny)if (fl->fl_lmops == &nfsd_posix_mng_ops) { lo = (struct nfs4_lockowner *) fl->fl_owner; - deny->ld_owner.data =kmemdup (lo->lo_owner.so_owner.data, - lo->lo_owner.so_owner.len,GFP_KERNEL ); +xdr_netobj_dup (&deny->ld_owner, &lo->lo_owner.so_owner, +GFP_KERNEL );if (!deny->ld_owner.data)/* We just don't care that much */ goto nevermind; - deny->ld_owner.len = lo->lo_owner.so_owner.len; deny->ld_clientid = lo->lo_owner.so_client->cl_clientid; }else { nevermind:
include/linux/sunrpc/xdr.h +7 -0
@@ -164,6 +164,13 @@ xdr_decode_opaque_fixed(__be32 *p, void *ptr, unsigned int len)return p +XDR_QUADLEN (len); } +static inline void xdr_netobj_dup (struct xdr_netobj *dst, +struct xdr_netobj *src,gfp_t gfp_mask) +{ + dst->data =kmemdup (src->data, src->len, gfp_mask); + dst->len = src->len; +} +/* * Adjust kvec to reflect end of xdr'ed data (RPC client XDR) */
Signature · 1 line
2.21.0
PATCH 16/16 nfsd: decode implementation id
In reply to J. Bruce FieldsFrom: "J. Bruce Fields" <[email protected]>
Decode the implementation ID and display in nfsd/clients/#/info. It may be help identify the client. It won't be used otherwise.
(When this went into the protocol, I thought the implementation ID would be a slippery slope towards implementation-specific workarounds as with the http user-agent. But I guess I was wrong, the risk seems pretty low now.)
--- fs/nfsd/nfs4state.c | 30 ++++++++++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 21 +++++++++------------ fs/nfsd/state.h | 4 ++++ fs/nfsd/xdr4.h | 3 +++ 4 files changed, 46 insertions(+), 12 deletions(-)
fs/nfsd/nfs4state.c +30 -0
@@ -1899,6 +1899,8 @@ static void __free_client(struct kref *k)free_svc_cred (&clp->cl_cred);kfree (clp->cl_ownerstr_hashtbl);kfree (clp->cl_name.data); +kfree (clp->cl_nii_domain.data); +kfree (clp->cl_nii_name.data);idr_destroy (&clp->cl_stateids);kmem_cache_free (client_slab, clp); }
@@ -2261,6 +2263,15 @@ static int client_info_show(struct seq_file *m, void *v)seq_printf (m,"name: " );seq_quote_mem (m, clp->cl_name.data, clp->cl_name.len);seq_printf (m,"\nminor version: %d\n" , clp->cl_minorversion); +if (clp->cl_nii_domain.data) { +seq_printf (m,"Implementation domain: " ); +seq_quote_mem (m, clp->cl_nii_domain.data, + clp->cl_nii_domain.len); +seq_printf (m,"\nImplementation name: " ); +seq_quote_mem (m, clp->cl_nii_name.data, clp->cl_nii_name.len); +seq_printf (m,"\nImplementation time: [%ld, %ld]\n" , + clp->cl_nii_time.tv_sec, clp->cl_nii_time.tv_nsec); + }drop_client (clp);return 0 ;
@@ -2901,6 +2912,22 @@ static bool client_has_state(struct nfs4_client *clp) || !list_empty(&clp->async_copies); } +static __be32 copy_impl_id (struct nfs4_client *clp, +struct nfsd4_exchange_id *exid) +{ +if (!exid->nii_domain.data) +return 0 ; +xdr_netobj_dup (&clp->cl_nii_domain, &exid->nii_domain,GFP_KERNEL ); +if (!clp->cl_nii_domain.data) +return nfserr_jukebox; +xdr_netobj_dup (&clp->cl_nii_name, &exid->nii_name,GFP_KERNEL ); +if (!clp->cl_nii_name.data) +return nfserr_jukebox; + clp->cl_nii_time.tv_sec = exid->nii_time.tv_sec; + clp->cl_nii_time.tv_nsec = exid->nii_time.tv_nsec; +return 0 ; +} +__be32 nfsd4_exchange_id (struct svc_rqst *rqstp,struct nfsd4_compound_state *cstate,union nfsd4_op_u *u)
@@ -2927,6 +2954,9 @@ nfsd4_exchange_id(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, new =create_client (exid->clname, rqstp, &verf);if (new ==NULL )return nfserr_jukebox; + status =copy_impl_id (new, exid); +if (status) + goto out_nolock;switch (exid->spa_how) {case SP4_MACH_CRED :
fs/nfsd/nfs4xdr.c +9 -12
@@ -1398,7 +1398,6 @@ nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, goto xdr_error; } -/* Ignore Implementation ID */ READ_BUF (4 );/* nfs_impl_id4 array length */ dummy =be32_to_cpup (p++);
@@ -1406,21 +1405,19 @@ nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, goto xdr_error;if (dummy ==1 ) { -/* nii_domain */ -READ_BUF (4 ); - dummy =be32_to_cpup (p++); -READ_BUF (dummy); - p +=XDR_QUADLEN (dummy); + status =nfsd4_decode_opaque (argp, &exid->nii_domain); +if (status) + goto xdr_error;/* nii_name */ -READ_BUF (4 ); - dummy =be32_to_cpup (p++); -READ_BUF (dummy); - p +=XDR_QUADLEN (dummy); + status =nfsd4_decode_opaque (argp, &exid->nii_name); +if (status) + goto xdr_error;/* nii_date */ -READ_BUF (12 ); - p +=3 ; + status =nfsd4_decode_time (argp, &exid->nii_time); +if (status) + goto xdr_error; }DECODE_TAIL ; }
fs/nfsd/state.h +4 -0
@@ -317,6 +317,10 @@ struct nfs4_client {clientid_t cl_clientid;/* generated by server */ nfs4_verifier cl_confirm;/* generated by server */ u32 cl_minorversion; +/* NFSv4.1 client implementation id: */ +struct xdr_netobj cl_nii_domain; +struct xdr_netobj cl_nii_name; +struct timespec cl_nii_time;/* for v4.0 and v4.1 callbacks: */ struct nfs4_cb_conn cl_cb_conn;
fs/nfsd/xdr4.h +3 -0
@@ -410,6 +410,9 @@ struct nfsd4_exchange_id {int spa_how;u32 spo_must_enforce[3 ];u32 spo_must_allow[3 ]; +struct xdr_netobj nii_domain; +struct xdr_netobj nii_name; +struct timespec nii_time; };struct nfsd4_sequence {
Signature · 1 line
2.21.0
Quoted 2 lines · J. Bruce Fields
- this duplicates some functionality of the little-used fault injection code; could we replace it entirely?
I'd be really curious to hear from any users of that code, by the way. Anna, any ideas?
The idea was that it could be used to test client handling of exceptional conditions like recalled delegations and partially lost state. Is anyone regularly running such tests?
I don't hate the code, and I'm not on a crusade to tear it all out Right Now, but it does create a few odd corner cases, so I'm wondering whether I could get away with replacing it eventually or whether that risks breaking someone's scripts.
--b.
Quoted 7 lines · J. Bruce Fields
Quoted 2 lines · J. Bruce Fields
- this duplicates some functionality of the little-used fault injection code; could we replace it entirely?
I'd be really curious to hear from any users of that code, by the way.
Anna, any ideas?
I'm not sure who else has used it besides me, and it's been a while since I have too.
Quoted 11 lines
The idea was that it could be used to test client handling of exceptional conditions like recalled delegations and partially lost state. Is anyone regularly running such tests?
I don't hate the code, and I'm not on a crusade to tear it all out Right
Now, but it does create a few odd corner cases, so I'm wondering whether
I could get away with replacing it eventually or whether that risks breaking someone's scripts.
I'm cool with replacing it if there is a better way to do things.
Anna
Quoted 2 lines
--b.
Quoted 11 lines · Anna Schumaker
Quoted 7 lines · J. Bruce Fields
Quoted 2 lines · J. Bruce Fields
- this duplicates some functionality of the little-used fault injection code; could we replace it entirely?
I'd be really curious to hear from any users of that code, by the way.
Anna, any ideas?I'm not sure who else has used it besides me, and it's been a while since I have too.
Do you remember which ones were most useful? They are:
- forget_clients
- forget_locks
- forget_openowners
- forget_delegations
- recall_delegations
We've got a functional replacement for forget_clients, but I haven't looked into the others yet.
--b.
Quoted 19 lines
Quoted 6 lines
The idea was that it could be used to test client handling of exceptional conditions like recalled delegations and partially lost state. Is anyone regularly running such tests?
Quoted 6 lines
I don't hate the code, and I'm not on a crusade to tear it all out Right
Now, but it does create a few odd corner cases, so I'm wondering whether
I could get away with replacing it eventually or whether that risks breaking someone's scripts.I'm cool with replacing it if there is a better way to do things.
Anna
Quoted 2 lines
--b.