Skip to contentSkip to conversation

SQUASHME pnfs-submit: replace layoutcommit_ctx with rpc_cred

PATCH In review [email protected] 4 participants 9 messages May 20, 2010 – May 24, 2010 5 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 SQUASHME pnfs-submit: replace layoutcommit_ctx with rpc_cred

From: Andy Adamson <[email protected]>

Taking a reference on the nfs_open_context to signal that a layoutcommit is needed is problematic because the last reference to the context triggers a close (nfs_release). But, if the layout holds a reference on the nfs_open_context, then close will not be triggered.

Since we only use the rpc credential from the layoutcommit_ctx, replace the layoutcommit_ctx with the rpc_cred.

Hold a reference on the rpc_cred until the layoutcommit rpc returns. Note that the rpc layer (rpcauth_bind) also references the rpc_cred.

If the layoutdriver fails to setup the layoutcommit, clear the layoutcommit properties and put the credential.

---
 fs/nfs/inode.c            |    4 ++--
 fs/nfs/nfs4state.c        |    2 +-
 fs/nfs/pnfs.c             |   42 +++++++++++++++++-------------------------
 fs/nfs/write.c            |    2 +-
 include/linux/nfs4_pnfs.h |    6 ++++++
 include/linux/nfs_fs.h    |    3 +--
 include/linux/pnfs_xdr.h  |    1 -
 7 files changed, 28 insertions(+), 32 deletions(-)
fs/nfs/inode.c +2 -2
index 7fd33d9..2b8e8e6 100644
@@ -1110,7 +1110,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 	/*
 	 * file needs layout commit, server attributes may be stale
 	 */
-	if (nfsi->layoutcommit_ctx && nfsi->change_attr >= fattr->change_attr) {
+	if (do_layoutcommit(nfsi) && nfsi->change_attr >= fattr->change_attr) {
 		dprintk("NFS: %s: layoutcommit is needed for file %s/%ld\n",
 			__func__, inode->i_sb->s_id, inode->i_ino);
 		return 0;
@@ -1331,7 +1331,7 @@ static void pnfs_alloc_init_inode(struct nfs_inode *nfsi)
 	nfsi->pnfs_layout_state = 0;
 	memset(&nfsi->layout.stateid, 0, NFS4_STATEID_SIZE);
 	nfsi->layout.roc_iomode = 0;
-	nfsi->layoutcommit_ctx = NULL;
+	nfsi->lo_cred = NULL;
 	nfsi->pnfs_write_begin_pos = 0;
 	nfsi->pnfs_write_end_pos = 0;
 #endif /* CONFIG_NFS_V4_1 */
fs/nfs/nfs4state.c +1 -1
index d145de1..bf03fde 100644
@@ -589,7 +589,7 @@ static void __nfs4_close(struct path *path, struct nfs4_state *state, fmode_t fm
 #ifdef CONFIG_NFS_V4_1
 		struct nfs_inode *nfsi = NFS_I(state->inode);
 
-		if (nfsi->layoutcommit_ctx)
+		if (do_layoutcommit(nfsi))
 			pnfs_layoutcommit_inode(state->inode, wait);
 		if (has_layout(nfsi) && nfsi->layout.roc_iomode) {
 			struct nfs4_pnfs_layout_segment range;
fs/nfs/pnfs.c +17 -25

100 lines not on this page · raw message

fs/nfs/write.c +1 -1
index a4c95a0..2c1918e 100644
@@ -1490,7 +1490,7 @@ static int nfs_commit_inode(struct inode *inode, int how)
 					nfs_wait_bit_killable,
 					TASK_KILLABLE);
 #ifdef CONFIG_NFS_V4_1
-		if (may_wait && NFS_I(inode)->layoutcommit_ctx) {
+		if (may_wait && do_layoutcommit(NFS_I(inode))) {
 			error = pnfs_layoutcommit_inode(inode, 1);
 			if (error < 0)
 				return error;
include/linux/nfs4_pnfs.h +6 -0
index 4d47b48..c9ef43e 100644
@@ -80,6 +80,12 @@ has_layout(struct nfs_inode *nfsi)
 	return nfsi->layout.ld_data != NULL;
 }
 
+static inline bool
+do_layoutcommit(struct nfs_inode *nfsi)
+{
+	return nfsi->lo_cred != NULL;
+}
+
 #endif /* CONFIG_NFS_V4_1 */
 
 struct pnfs_layout_segment {
include/linux/nfs_fs.h +1 -2
index 98a8dc0..478b00c 100644
@@ -203,11 +203,10 @@ struct nfs_inode {
 #define NFS_INO_RW_LAYOUT_FAILED 1 	/* get rw layout failed stop trying */
 #define NFS_INO_LAYOUT_ALLOC     2	/* bit lock for layout allocation */
 	time_t pnfs_layout_suspend;
+	struct rpc_cred		*lo_cred; /* layoutcommit credential */
 	wait_queue_head_t lo_waitq;
 	spinlock_t lo_lock;
 	struct pnfs_layout_type layout;
-	/* use rpc_creds in this open_context to send LAYOUTCOMMIT to MDS */
-	struct nfs_open_context *layoutcommit_ctx;
 	/* DH: These vars keep track of the maximum write range
 	 * so the values can be used for layoutcommit.
 	 */
include/linux/pnfs_xdr.h +0 -1
index a0bf341..154b04e 100644
@@ -86,7 +86,6 @@ struct pnfs_layoutcommit_data {
 	bool is_sync;
 	struct rpc_cred *cred;
 	struct nfs_fattr fattr;
-	struct nfs_open_context *ctx;
 	struct pnfs_layoutcommit_arg args;
 	struct pnfs_layoutcommit_res res;
 	int status;
Signature · 1 line
1.6.6
#1 lore raw
Quoted 3 lines · On Fri, May 21, 2010 at 12:04 AM, <[email protected]> wrote:

From: Andy Adamson <[email protected]>

Taking a reference on the nfs_open_context to signal that a layoutcom=

mit is

Quoted 1 line

needed is problematic because the last reference to the context trigg=

ers a

Quoted 1 line

close (nfs_release). =C2=A0But, if the layout holds a reference on th=

e

Quoted 3 lines

nfs_open_context, then close will not be triggered.

Since we only use the rpc credential from the layoutcommit_ctx, repla=

ce the

Quoted 3 lines

layoutcommit_ctx with the rpc_cred.

Hold a reference on the rpc_cred until the layoutcommit rpc returns. =

Note that

Quoted 3 lines

the rpc layer (rpcauth_bind) also references the rpc_cred.

If the layoutdriver fails to setup the layoutcommit, clear the layout=

commit

Quoted 5 lines

properties and put the credential.

---
=C2=A0fs/nfs/inode.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0=

=C2=A04 ++--

Quoted 1 line

=C2=A0fs/nfs/nfs4state.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A02 =

+-
> =C2=A0fs/nfs/pnfs.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0=

42 +++++++++++++++++-------------------------

Quoted 1 line

=C2=A0fs/nfs/write.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0=

=C2=A02 +-

fs/nfs/inode.c static int nfs_update_inode(struct inode *inode=

Quoted 10 lines

=C2=A0include/linux/nfs4_pnfs.h | =C2=A0 =C2=A06 ++++++ =C2=A0include/linux/nfs_fs.h =C2=A0 =C2=A0| =C2=A0 =C2=A03 +-- =C2=A0include/linux/pnfs_xdr.h =C2=A0| =C2=A0 =C2=A01 - =C2=A07 files changed, 28 insertions(+), 32 deletions(-)

fs/nfs/inode.c +0 -0
index 7fd33d9..2b8e8e6 100644
@@ -1110,7 +1110,7 @@ static int nfs_update_inode(struct inode *inode=

, struct nfs_fattr *fattr)

Quoted 2 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0/*
=C2=A0 =C2=A0 =C2=A0 =C2=A0 * file needs layout commit, server attrib=

utes may be stale

Quoted 2 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0 */
- =C2=A0 =C2=A0 =C2=A0 if (nfsi->layoutcommit_ctx && nfsi->change_att=

r >=3D fattr->change_attr) {

Quoted 3 lines

+ =C2=A0 =C2=A0 =C2=A0 if (do_layoutcommit(nfsi) && nfsi->change_attr= =3D fattr->change_attr) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dprintk("NFS: =

%s: layoutcommit is needed for file %s/%ld\n",

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0__func__, inode->i_sb->s_id, inode->i_ino);

fs/nfs/inode.c static void pnfs_alloc_init_inode(struct nfs_in=

Quoted 2 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;

fs/nfs/inode.c +0 -0
@@ -1331,7 +1331,7 @@ static void pnfs_alloc_init_inode(struct nfs_in=

ode *nfsi)

Quoted 2 lines
fs/nfs/inode.c +0 -0
 =C2=A0 =C2=A0 =C2=A0 =C2=A0nfsi->pnfs_layout_state =3D 0;

=C2=A0 =C2=A0 =C2=A0 =C2=A0memset(&nfsi->layout.stateid, 0, NFS4_STAT=

EID_SIZE);

fs/nfs/nfs4state.c static void __nfs4_close(struct path *path, struc=

Quoted 11 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0nfsi->layout.roc_iomode =3D 0;
- =C2=A0 =C2=A0 =C2=A0 nfsi->layoutcommit_ctx =3D NULL;
+ =C2=A0 =C2=A0 =C2=A0 nfsi->lo_cred =3D NULL; =C2=A0 =C2=A0 =C2=A0 =C2=A0nfsi->pnfs_write_begin_pos =3D 0; =C2=A0 =C2=A0 =C2=A0 =C2=A0nfsi->pnfs_write_end_pos =3D 0; =C2=A0#endif /* CONFIG_NFS_V4_1 */

fs/nfs/nfs4state.c +0 -0
index d145de1..bf03fde 100644
@@ -589,7 +589,7 @@ static void __nfs4_close(struct path *path, struc=

t nfs4_state *state, fmode_t fm

Quoted 2 lines

=C2=A0#ifdef CONFIG_NFS_V4_1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct nfs_ino=

de *nfsi =3D NFS_I(state->inode);

Quoted 2 lines

- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (nfsi->layoutco=

mmit_ctx)

Quoted 1 line

+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (do_layoutcommi=

t(nfsi))

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0pnfs_layoutcommit_inode(state->inode, wait);

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (has_layout=

(nfsi) && nfsi->layout.roc_iomode) {

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0struct nfs4_pnfs_layout_segment range;

fs/nfs/pnfs.c find_pnfs(u32 id, struct pnfs_module **module) =

Quoted 5 lines
fs/nfs/pnfs.c +0 -0
index 20285bc..cb8ff06 100644
@@ -145,21 +145,19 @@ find_pnfs(u32 id, struct pnfs_module **module) =

{

Quoted 9 lines
fs/nfs/pnfs.c +1 -1
 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
 =C2=A0}
 
-/* Set context to indicate we require a layoutcommit
+/* Set lo_cred to indicate we require a layoutcommit

=C2=A0* If we don't even have a layout, we don't need to commit it. =C2=A0*/
=C2=A0void
=C2=A0pnfs_need_layoutcommit(struct nfs_inode *nfsi, struct nfs_open_=

context *ctx)

Quoted 2 lines

=C2=A0{
- =C2=A0 =C2=A0 =C2=A0 dprintk("%s: has_layout=3D%d layoutcommit_ctx=3D=

%p ctx=3D%p\n", __func__,

Quoted 1 line

- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 has_layout(nfsi), =

nfsi->layoutcommit_ctx, ctx);

Quoted 1 line

+ =C2=A0 =C2=A0 =C2=A0 dprintk("%s: has_layout=3D%d ctx=3D%p\n", __fu=

nc__, has_layout(nfsi), ctx);

Quoted 2 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0spin_lock(&nfsi->lo_lock);
- =C2=A0 =C2=A0 =C2=A0 if (has_layout(nfsi) && !nfsi->layoutcommit_ct=

x) {

Quoted 1 line

- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 nfsi->layoutcommit=

_ctx =3D get_nfs_open_context(ctx);

Quoted 1 line

+ =C2=A0 =C2=A0 =C2=A0 if (has_layout(nfsi) && !do_layoutcommit(nfsi)=

) {

Quoted 1 line

+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 nfsi->lo_cred =3D =

get_rpccred(ctx->state->owner->so_cred);

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0nfsi->change_a=

ttr++;

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0spin_unlock(&n=

fsi->lo_lock);

Quoted 1 line

- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dprintk("%s: Set l=

ayoutcommit_ctx=3D%p\n", __func__,

Quoted 1 line

- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 nfsi->layoutcommit_ctx);

Quoted 1 line

+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dprintk("%s: Set l=

ayoutcommit\n", __func__);

fs/nfs/pnfs.c _pnfs_return_layout(struct inode *ino, struct nfs=

Quoted 4 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return; =C2=A0 =C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0 =C2=A0spin_unlock(&nfsi->lo_lock);

fs/nfs/pnfs.c +0 -0
@@ -755,7 +753,7 @@ _pnfs_return_layout(struct inode *ino, struct nfs=

4_pnfs_layout_segment *range,

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0!pnfs_return_layout_barrier(n=
fsi, &arg));

Quoted 3 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}

- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (nfsi->layoutco=

mmit_ctx) {

Quoted 1 line

+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (do_layoutcommi=

t(nfsi)) {

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0status =3D pnfs_layoutcommit_inode(ino, wait);

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0if (status) {

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dprintk("%s: layoutcommit fai=
led, status=3D%d. "

fs/nfs/pnfs.c pnfs_layoutcommit_done(struct pnfs_layoutcommi=

Quoted 1 line
fs/nfs/pnfs.c +0 -0
@@ -1910,16 +1908,9 @@ pnfs_layoutcommit_done(struct pnfs_layoutcommi=

t_data *data)

Quoted 2 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0dprintk("%s: (status %d)\n", __func__, dat=

a->status);

Quoted 2 lines

- =C2=A0 =C2=A0 =C2=A0 /* TODO: For now, set an error in the open con=

text (just like

Quoted 1 line

- =C2=A0 =C2=A0 =C2=A0 =C2=A0* if a commit failed) We may want to do =

more, much more, like

Quoted 6 lines

- =C2=A0 =C2=A0 =C2=A0 =C2=A0* replay all writes through the NFSv4
- =C2=A0 =C2=A0 =C2=A0 =C2=A0* server, or something.
- =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
- =C2=A0 =C2=A0 =C2=A0 if (data->status < 0) {
+ =C2=A0 =C2=A0 =C2=A0 if (data->status < 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printk(KERN_ER=

R "%s, Layoutcommit Failed! =3D %d\n",

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 __func__, data->status);

Quoted 1 line

- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 data->ctx->error =3D=

data->status;

Quoted 3 lines

- =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0 =C2=A0/* TODO: Maybe we should avoid this by all=

owing the layout driver

fs/nfs/pnfs.c pnfs_layoutcommit_done(struct pnfs_layoutcommit=

Quoted 2 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0 * to directly xdr its layout on the wire.

fs/nfs/pnfs.c +0 -0
@@ -1929,9 +1920,6 @@ pnfs_layoutcommit_done(struct pnfs_layoutcommit=

_data *data)

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&nfsi->layout,

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&data->args,

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0data->status);

Quoted 2 lines

-
- =C2=A0 =C2=A0 =C2=A0 /* release the open_context acquired in pnfs_w=

riteback_done */

fs/nfs/pnfs.c pnfs_layoutcommit_inode(struct inode *inode, =

Quoted 5 lines

- =C2=A0 =C2=A0 =C2=A0 put_nfs_open_context(data->ctx); =C2=A0}

=C2=A0/*

fs/nfs/pnfs.c +0 -0
@@ -1995,30 +1983,34 @@ pnfs_layoutcommit_inode(struct inode *inode, =

int sync)

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -ENOMEM=

;

Quoted 5 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0spin_lock(&nfsi->lo_lock);
- =C2=A0 =C2=A0 =C2=A0 if (!nfsi->layoutcommit_ctx)
+ =C2=A0 =C2=A0 =C2=A0 if (!do_layoutcommit(nfsi))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0goto out_unloc=

k;

Quoted 3 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0data->args.inode =3D inode;
- =C2=A0 =C2=A0 =C2=A0 data->cred =C2=A0=3D nfsi->layoutcommit_ctx->c=

red;

Quoted 5 lines

- =C2=A0 =C2=A0 =C2=A0 data->ctx =3D nfsi->layoutcommit_ctx;
+ =C2=A0 =C2=A0 =C2=A0 data->cred =3D nfsi->lo_cred;

=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Set up layout commit args*/ =C2=A0 =C2=A0 =C2=A0 =C2=A0status =3D pnfs_layoutcommit_setup(data, s=

ync);

Quoted 4 lines

- =C2=A0 =C2=A0 =C2=A0 if (status)
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto out_unlock;

=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Clear layoutcommit properties in the in=

ode so

Quoted 9 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0 * new lc info can be generated =C2=A0 =C2=A0 =C2=A0 =C2=A0 */
=C2=A0 =C2=A0 =C2=A0 =C2=A0nfsi->pnfs_write_begin_pos =3D 0; =C2=A0 =C2=A0 =C2=A0 =C2=A0nfsi->pnfs_write_end_pos =3D 0;
- =C2=A0 =C2=A0 =C2=A0 nfsi->layoutcommit_ctx =3D NULL;
+ =C2=A0 =C2=A0 =C2=A0 nfsi->lo_cred =3D NULL;
+
+ =C2=A0 =C2=A0 =C2=A0 if (status) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* The layout driv=

er failed to setup the layoutcommit */

Quoted 1 line

+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 put_rpccred(data->=

cred);

Quoted 4 lines

+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto out_unlock;
+ =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0 =C2=A0/* release lock on pnfs layoutcommit attrs=

*/

Quoted 5 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0spin_unlock(&nfsi->lo_lock);

=C2=A0 =C2=A0 =C2=A0 =C2=A0data->is_sync =3D sync;
=C2=A0 =C2=A0 =C2=A0 =C2=A0status =3D pnfs4_proc_layoutcommit(data);
+ =C2=A0 =C2=A0 =C2=A0 put_rpccred(data->cred);

Is this OK to put_rpccred here if sync =3D=3D 0? why not move it into pnfs_layoutcommit_done just as the code did?
--tao

Quoted 2 lines

=C2=A0out:
=C2=A0 =C2=A0 =C2=A0 =C2=A0dprintk("%s end (err:%d)\n", __func__, sta=

tus);

fs/nfs/write.c static int nfs_commit_inode(struct inode *inode=

Quoted 6 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0return status;

fs/nfs/write.c +0 -0
index a4c95a0..2c1918e 100644
@@ -1490,7 +1490,7 @@ static int nfs_commit_inode(struct inode *inode=

, int how)

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0n=
fs_wait_bit_killable,

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0T=
ASK_KILLABLE);

Quoted 2 lines

=C2=A0#ifdef CONFIG_NFS_V4_1
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (may_wait && NF=

S_I(inode)->layoutcommit_ctx) {

Quoted 1 line

+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (may_wait && do=

_layoutcommit(NFS_I(inode))) {

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0error =3D pnfs_layoutcommit_inode(inode, 1);

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0if (error < 0)

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return error;

Quoted 22 lines
include/linux/nfs4_pnfs.h +6 -0
index 4d47b48..c9ef43e 100644
@@ -80,6 +80,12 @@ has_layout(struct nfs_inode *nfsi)
 =C2=A0 =C2=A0 =C2=A0 =C2=A0return nfsi->layout.ld_data !=3D NULL;
 =C2=A0}
 
+static inline bool
+do_layoutcommit(struct nfs_inode *nfsi)
+{
+ =C2=A0 =C2=A0 =C2=A0 return nfsi->lo_cred !=3D NULL;
+}
+

=C2=A0#endif /* CONFIG_NFS_V4_1 */

=C2=A0struct pnfs_layout_segment {

include/linux/nfs_fs.h +0 -0
index 98a8dc0..478b00c 100644
@@ -203,11 +203,10 @@ struct nfs_inode {
Quoted 1 line

=C2=A0#define NFS_INO_RW_LAYOUT_FAILED 1 =C2=A0 =C2=A0 /* get rw layo=

ut failed stop trying */

Quoted 1 line

=C2=A0#define NFS_INO_LAYOUT_ALLOC =C2=A0 =C2=A0 2 =C2=A0 =C2=A0 /* b=

it lock for layout allocation */

Quoted 2 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0time_t pnfs_layout_suspend;
+ =C2=A0 =C2=A0 =C2=A0 struct rpc_cred =C2=A0 =C2=A0 =C2=A0 =C2=A0 *l=

o_cred; /* layoutcommit credential */

Quoted 4 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0wait_queue_head_t lo_waitq; =C2=A0 =C2=A0 =C2=A0 =C2=A0spinlock_t lo_lock;
=C2=A0 =C2=A0 =C2=A0 =C2=A0struct pnfs_layout_type layout;
- =C2=A0 =C2=A0 =C2=A0 /* use rpc_creds in this open_context to send =

LAYOUTCOMMIT to MDS */

Quoted 2 lines

- =C2=A0 =C2=A0 =C2=A0 struct nfs_open_context *layoutcommit_ctx; =C2=A0 =C2=A0 =C2=A0 =C2=A0/* DH: These vars keep track of the maximu=

m write range

Quoted 1 line

=C2=A0 =C2=A0 =C2=A0 =C2=A0 * so the values can be used for layoutcom=

mit.

Quoted 16 lines

=C2=A0 =C2=A0 =C2=A0 =C2=A0 */

include/linux/pnfs_xdr.h +0 -2
index a0bf341..154b04e 100644
@@ -86,7 +86,6 @@ struct pnfs_layoutcommit_data {
 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool is_sync;
 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct rpc_cred *cred;
 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct nfs_fattr fattr;
- =C2=A0 =C2=A0 =C2=A0 struct nfs_open_context *ctx;
 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct pnfs_layoutcommit_arg args;
 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct pnfs_layoutcommit_res res;
 =C2=A0 =C2=A0 =C2=A0 =C2=A0int status;
--

1.6.6

Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" =

in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at =C2=A0http://vger.kernel.org/majordomo-info.ht=

ml

Quoted 1 line

--=20
tao.

A message that is not in the archive (sent off-list or not yet received): AANLkTinRG_AhVwFZ6a3GllIHSLa3zBDl0zmVDp3btJhn-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#3 lore raw

On Thu, May 20, 2010 at 10:50 PM, Tao Guo <[email protected]> wrote= :

Quoted 4 lines · On Fri, May 21, 2010 at 12:04 AM, =A0<[email protected]> wrote:
Quoted 3 lines

From: Andy Adamson <[email protected]>

Taking a reference on the nfs_open_context to signal that a layoutco=

mmit is

Quoted 1 line
Quoted 1 line

needed is problematic because the last reference to the context trig=

gers a

Quoted 4 lines
Quoted 4 lines

close (nfs_release). =A0But, if the layout holds a reference on the nfs_open_context, then close will not be triggered.

Since we only use the rpc credential from the layoutcommit_ctx, repl=

ace the

Quoted 3 lines
Quoted 3 lines

layoutcommit_ctx with the rpc_cred.

Hold a reference on the rpc_cred until the layoutcommit rpc returns.=

Note that

Quoted 3 lines
Quoted 3 lines

the rpc layer (rpcauth_bind) also references the rpc_cred.

If the layoutdriver fails to setup the layoutcommit, clear the layou=

tcommit

Quoted 7 lines
Quoted 7 lines

properties and put the credential.

---
=A0fs/nfs/inode.c =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A04 ++-- =A0fs/nfs/nfs4state.c =A0 =A0 =A0 =A0| =A0 =A02 +- =A0fs/nfs/pnfs.c =A0 =A0 =A0 =A0 =A0 =A0 | =A0 42 +++++++++++++++++-=

------------------------

Quoted 11 lines

fs/nfs/inode.c static int nfs_update_inode(struct inode *inod=

Quoted 11 lines

=A0fs/nfs/write.c =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A02 +- =A0include/linux/nfs4_pnfs.h | =A0 =A06 ++++++ =A0include/linux/nfs_fs.h =A0 =A0| =A0 =A03 +-- =A0include/linux/pnfs_xdr.h =A0| =A0 =A01 - =A07 files changed, 28 insertions(+), 32 deletions(-)

fs/nfs/inode.c +0 -0
index 7fd33d9..2b8e8e6 100644
@@ -1110,7 +1110,7 @@ static int nfs_update_inode(struct inode *inod=

e, struct nfs_fattr *fattr)

Quoted 2 lines
Quoted 2 lines

=A0 =A0 =A0 =A0/*
=A0 =A0 =A0 =A0 * file needs layout commit, server attributes may be=

stale

Quoted 2 lines
Quoted 2 lines

=A0 =A0 =A0 =A0 */
- =A0 =A0 =A0 if (nfsi->layoutcommit_ctx && nfsi->change_attr >=3D f=

attr->change_attr) {

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 if (do_layoutcommit(nfsi) && nfsi->change_attr >=3D fa=

ttr->change_attr) {

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dprintk("NFS: %s: layoutcommit is nee=

ded for file %s/%ld\n",

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0__func__, inode->i_sb=

->s_id, inode->i_ino);

Quoted 2 lines

fs/nfs/inode.c static void pnfs_alloc_init_inode(struct nfs_i=

Quoted 2 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return 0;

fs/nfs/inode.c +0 -0
@@ -1331,7 +1331,7 @@ static void pnfs_alloc_init_inode(struct nfs_i=

node *nfsi)

Quoted 5 lines
Quoted 5 lines
fs/nfs/inode.c +1 -1
 =A0 =A0 =A0 =A0nfsi->pnfs_layout_state =3D 0;
 =A0 =A0 =A0 =A0memset(&nfsi->layout.stateid, 0, NFS4_STATEID_SIZE);
 =A0 =A0 =A0 =A0nfsi->layout.roc_iomode =3D 0;
- =A0 =A0 =A0 nfsi->layoutcommit_ctx =3D NULL;
+ =A0 =A0 =A0 nfsi->lo_cred =3D NULL;
Quoted 8 lines

fs/nfs/nfs4state.c static void __nfs4_close(struct path *path, stru=

Quoted 8 lines
fs/nfs/inode.c +0 -0
 =A0 =A0 =A0 =A0nfsi->pnfs_write_begin_pos =3D 0;
 =A0 =A0 =A0 =A0nfsi->pnfs_write_end_pos =3D 0;

=A0#endif /* CONFIG_NFS_V4_1 */

fs/nfs/nfs4state.c +0 -0
index d145de1..bf03fde 100644
@@ -589,7 +589,7 @@ static void __nfs4_close(struct path *path, stru=

ct nfs4_state *state, fmode_t fm

Quoted 2 lines
Quoted 2 lines

=A0#ifdef CONFIG_NFS_V4_1
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct nfs_inode *nfsi =3D NFS_I(stat=

e->inode);

Quoted 4 lines
Quoted 4 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (nfsi->layoutcommit_ctx)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (do_layoutcommit(nfsi)) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pnfs_layoutcommit_ino=

de(state->inode, wait);

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (has_layout(nfsi) && nfsi->layout.=

roc_iomode) {

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct nfs4_pnfs_layo=

ut_segment range;

Quoted 5 lines

fs/nfs/pnfs.c find_pnfs(u32 id, struct pnfs_module **module)=

Quoted 5 lines
fs/nfs/pnfs.c +0 -0
index 20285bc..cb8ff06 100644
@@ -145,21 +145,19 @@ find_pnfs(u32 id, struct pnfs_module **module)=

{

Quoted 9 lines
Quoted 9 lines
fs/nfs/pnfs.c +1 -1
 =A0 =A0 =A0 =A0return 0;
 =A0}
 
-/* Set context to indicate we require a layoutcommit
+/* Set lo_cred to indicate we require a layoutcommit

=A0* If we don't even have a layout, we don't need to commit it. =A0*/
=A0void
=A0pnfs_need_layoutcommit(struct nfs_inode *nfsi, struct nfs_open_co=

ntext *ctx)

Quoted 2 lines
Quoted 2 lines

=A0{
- =A0 =A0 =A0 dprintk("%s: has_layout=3D%d layoutcommit_ctx=3D%p ctx=

=3D%p\n", __func__,

Quoted 1 line
Quoted 1 line

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 has_layout(nfsi), nfsi->layoutcommit_c=

tx, ctx);

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 dprintk("%s: has_layout=3D%d ctx=3D%p\n", __func__, ha=

s_layout(nfsi), ctx);

Quoted 3 lines
Quoted 3 lines

=A0 =A0 =A0 =A0spin_lock(&nfsi->lo_lock);
- =A0 =A0 =A0 if (has_layout(nfsi) && !nfsi->layoutcommit_ctx) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 nfsi->layoutcommit_ctx =3D get_nfs_ope=

n_context(ctx);

Quoted 2 lines
Quoted 2 lines

+ =A0 =A0 =A0 if (has_layout(nfsi) && !do_layoutcommit(nfsi)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 nfsi->lo_cred =3D get_rpccred(ctx->sta=

te->owner->so_cred);

Quoted 3 lines
Quoted 3 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0nfsi->change_attr++;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0spin_unlock(&nfsi->lo_lock);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 dprintk("%s: Set layoutcommit_ctx=3D%p=

\n", __func__,

Quoted 1 line
Quoted 1 line

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 nfsi->layoutcommit_ctx=

);

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dprintk("%s: Set layoutcommit\n", __fu=

nc__);

Quoted 4 lines

fs/nfs/pnfs.c _pnfs_return_layout(struct inode *ino, struct nf=

Quoted 4 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return;
=A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0spin_unlock(&nfsi->lo_lock);

fs/nfs/pnfs.c +0 -0
@@ -755,7 +753,7 @@ _pnfs_return_layout(struct inode *ino, struct nf=

s4_pnfs_layout_segment *range,

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0!pnfs=

_return_layout_barrier(nfsi, &arg));

Quoted 5 lines
Quoted 5 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (nfsi->layoutcommit_ctx) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (do_layoutcommit(nfsi)) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0status =3D pnfs_layou=

tcommit_inode(ino, wait);

Quoted 2 lines
Quoted 2 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (status) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dprin=

tk("%s: layoutcommit failed, status=3D%d. "

Quoted 1 line

fs/nfs/pnfs.c pnfs_layoutcommit_done(struct pnfs_layoutcomm=

Quoted 1 line
fs/nfs/pnfs.c +0 -0
@@ -1910,16 +1908,9 @@ pnfs_layoutcommit_done(struct pnfs_layoutcomm=

it_data *data)

Quoted 4 lines

fs/nfs/pnfs.c pnfs_layoutcommit_done(struct pnfs_layoutcomm= · line 1912

Quoted 4 lines
fs/nfs/pnfs.c +0 -1
 =A0 =A0 =A0 =A0dprintk("%s: (status %d)\n", __func__, data->status);
 
- =A0 =A0 =A0 /* TODO: For now, set an error in the open context (ju=

st like

Quoted 1 line

fs/nfs/pnfs.c pnfs_layoutcommit_done(struct pnfs_layoutcomm= · line 1913

Quoted 1 line
fs/nfs/pnfs.c +0 -1
- =A0 =A0 =A0 =A0* if a commit failed) We may want to do more, much =

more, like

Quoted 6 lines
Quoted 6 lines
fs/nfs/pnfs.c +1 -4
- =A0 =A0 =A0 =A0* replay all writes through the NFSv4
- =A0 =A0 =A0 =A0* server, or something.
- =A0 =A0 =A0 =A0*/
- =A0 =A0 =A0 if (data->status < 0) {
+ =A0 =A0 =A0 if (data->status < 0)

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk(KERN_ERR "%s, Layoutcommit Fai=

led! =3D %d\n",

Quoted 5 lines
Quoted 5 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 __func__, data->status);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 data->ctx->error =3D data->status;
- =A0 =A0 =A0 }

=A0 =A0 =A0 =A0/* TODO: Maybe we should avoid this by allowing the l=

ayout driver

Quoted 2 lines

fs/nfs/pnfs.c pnfs_layoutcommit_done(struct pnfs_layoutcommi=

Quoted 2 lines

=A0 =A0 =A0 =A0 * to directly xdr its layout on the wire.

fs/nfs/pnfs.c +0 -0
@@ -1929,9 +1920,6 @@ pnfs_layoutcommit_done(struct pnfs_layoutcommi=

t_data *data)

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&nfsi->layout,

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&data->args,

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0data->status);

Quoted 2 lines
Quoted 2 lines

-
- =A0 =A0 =A0 /* release the open_context acquired in pnfs_writeback=

_done */

Quoted 5 lines

fs/nfs/pnfs.c pnfs_layoutcommit_inode(struct inode *inode,=

Quoted 5 lines

- =A0 =A0 =A0 put_nfs_open_context(data->ctx);
=A0}

=A0/*

fs/nfs/pnfs.c +0 -0
@@ -1995,30 +1983,34 @@ pnfs_layoutcommit_inode(struct inode *inode,=

int sync)

Quoted 17 lines
Quoted 17 lines
fs/nfs/pnfs.c +2 -3
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -ENOMEM;
 
 =A0 =A0 =A0 =A0spin_lock(&nfsi->lo_lock);
- =A0 =A0 =A0 if (!nfsi->layoutcommit_ctx)
+ =A0 =A0 =A0 if (!do_layoutcommit(nfsi))
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto out_unlock;
 
 =A0 =A0 =A0 =A0data->args.inode =3D inode;
- =A0 =A0 =A0 data->cred =A0=3D nfsi->layoutcommit_ctx->cred;
- =A0 =A0 =A0 data->ctx =3D nfsi->layoutcommit_ctx;
+ =A0 =A0 =A0 data->cred =3D nfsi->lo_cred;
 

=A0 =A0 =A0 =A0/* Set up layout commit args*/
=A0 =A0 =A0 =A0status =3D pnfs_layoutcommit_setup(data, sync);
- =A0 =A0 =A0 if (status)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_unlock;

Quoted 10 lines
Quoted 10 lines

=A0 =A0 =A0 =A0/* Clear layoutcommit properties in the inode so =A0 =A0 =A0 =A0 * new lc info can be generated
=A0 =A0 =A0 =A0 */
=A0 =A0 =A0 =A0nfsi->pnfs_write_begin_pos =3D 0;
=A0 =A0 =A0 =A0nfsi->pnfs_write_end_pos =3D 0;
- =A0 =A0 =A0 nfsi->layoutcommit_ctx =3D NULL;
+ =A0 =A0 =A0 nfsi->lo_cred =3D NULL;
+
+ =A0 =A0 =A0 if (status) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* The layout driver failed to setup t=

he layoutcommit */

Quoted 4 lines
Quoted 4 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 put_rpccred(data->cred);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_unlock;
+ =A0 =A0 =A0 }

Quoted 8 lines
Quoted 6 lines

=A0 =A0 =A0 =A0/* release lock on pnfs layoutcommit attrs */ =A0 =A0 =A0 =A0spin_unlock(&nfsi->lo_lock);

=A0 =A0 =A0 =A0data->is_sync =3D sync;
=A0 =A0 =A0 =A0status =3D pnfs4_proc_layoutcommit(data);
+ =A0 =A0 =A0 put_rpccred(data->cred);

Is this OK to put_rpccred here if sync =3D=3D 0? why not move it into pnfs_layoutcommit_done just as the code did?

As I said in the patch comments, the RPC layer takes a reference on the=
cred,

-->Andy

Quoted 10 lines

--tao

fs/nfs/write.c static int nfs_commit_inode(struct inode *inod=

Quoted 8 lines

=A0out:
=A0 =A0 =A0 =A0dprintk("%s end (err:%d)\n", __func__, status); =A0 =A0 =A0 =A0return status;

fs/nfs/write.c +0 -0
index a4c95a0..2c1918e 100644
@@ -1490,7 +1490,7 @@ static int nfs_commit_inode(struct inode *inod=

e, int how)

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0 =A0nfs_wait_bit_killable,

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0 =A0TASK_KILLABLE);

Quoted 2 lines
Quoted 2 lines

=A0#ifdef CONFIG_NFS_V4_1
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (may_wait && NFS_I(inode)->layoutco=

mmit_ctx) {

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (may_wait && do_layoutcommit(NFS_I(=

inode))) {

Quoted 1 line
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0error =3D pnfs_layout=

commit_inode(inode, 1);

Quoted 2 lines
Quoted 2 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (error < 0) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0retur=

n error;

Quoted 16 lines
Quoted 16 lines
include/linux/nfs4_pnfs.h +6 -0
index 4d47b48..c9ef43e 100644
@@ -80,6 +80,12 @@ has_layout(struct nfs_inode *nfsi)
 =A0 =A0 =A0 =A0return nfsi->layout.ld_data !=3D NULL;
 =A0}
 
+static inline bool
+do_layoutcommit(struct nfs_inode *nfsi)
+{
+ =A0 =A0 =A0 return nfsi->lo_cred !=3D NULL;
+}
+

=A0#endif /* CONFIG_NFS_V4_1 */

Quoted 7 lines
Quoted 7 lines

=A0struct pnfs_layout_segment {

include/linux/nfs_fs.h +0 -0
index 98a8dc0..478b00c 100644
@@ -203,11 +203,10 @@ struct nfs_inode {

=A0#define NFS_INO_RW_LAYOUT_FAILED 1 =A0 =A0 /* get rw layout faile=

d stop trying */

Quoted 1 line
Quoted 1 line

=A0#define NFS_INO_LAYOUT_ALLOC =A0 =A0 2 =A0 =A0 /* bit lock for la=

yout allocation */

Quoted 2 lines
Quoted 2 lines

=A0 =A0 =A0 =A0time_t pnfs_layout_suspend;
+ =A0 =A0 =A0 struct rpc_cred =A0 =A0 =A0 =A0 *lo_cred; /* layoutcom=

mit credential */

Quoted 4 lines
Quoted 4 lines

=A0 =A0 =A0 =A0wait_queue_head_t lo_waitq;
=A0 =A0 =A0 =A0spinlock_t lo_lock;
=A0 =A0 =A0 =A0struct pnfs_layout_type layout;
- =A0 =A0 =A0 /* use rpc_creds in this open_context to send LAYOUTCO=

MMIT to MDS */

Quoted 2 lines
Quoted 2 lines

- =A0 =A0 =A0 struct nfs_open_context *layoutcommit_ctx; =A0 =A0 =A0 =A0/* DH: These vars keep track of the maximum write ran=

ge

Quoted 17 lines
Quoted 17 lines

=A0 =A0 =A0 =A0 * so the values can be used for layoutcommit. =A0 =A0 =A0 =A0 */

include/linux/pnfs_xdr.h +0 -2
index a0bf341..154b04e 100644
@@ -86,7 +86,6 @@ struct pnfs_layoutcommit_data {
 =A0 =A0 =A0 =A0bool is_sync;
 =A0 =A0 =A0 =A0struct rpc_cred *cred;
 =A0 =A0 =A0 =A0struct nfs_fattr fattr;
- =A0 =A0 =A0 struct nfs_open_context *ctx;
 =A0 =A0 =A0 =A0struct pnfs_layoutcommit_arg args;
 =A0 =A0 =A0 =A0struct pnfs_layoutcommit_res res;
 =A0 =A0 =A0 =A0int status;
--

1.6.6

Quoted 2 lines
Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs"=

in

Quoted 10 lines
Quoted 3 lines

the body of a message to [email protected]
More majordomo info at =A0http://vger.kernel.org/majordomo-info.html

--
tao.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" =

in

Quoted 3 lines

the body of a message to [email protected]
More majordomo info at =A0http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): AANLkTikCPFKKMWFVCT3AlIz792q12x3QrH3vDVVePPXN-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#5 lore raw

I see... But what if sync == 1? At that time, data must have already been freed, so you should not use data->cred anymore.

Signature · 1 line
tao.
#6 lore raw
Quoted 2 lines · Tao Guo

I see... But what if sync == 1? At that time, data must have already been freed, so you should not use data->cred anymore.

Agreed.

Since LAYOUTCOMMIT is not called after close, we can get rid of taking the reference all together since a reference is taken on OPEN and dropped on CLOSE.

-->Andy

Quoted 4 lines

--
tao.

A message that is not in the archive (sent off-list or not yet received): AANLkTikvP2aetI4bF-3ebus1Y91qFV4ahCXfxR_5ZNBN-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#8 lore raw
Quoted 11 lines · William A. (Andy) Adamson
Quoted 2 lines · Tao Guo

I see... But what if sync == 1? At that time, data must have already been freed, so you should not use data->cred anymore.

Agreed.

Since LAYOUTCOMMIT is not called after close, we can get rid of taking the reference all together since a reference is taken on OPEN and dropped on CLOSE.

-->Andy

I agree. However that will change several functions' interface I guess.

I still have a question: why some procedures need to set rpc_cred whereas some needn't ? what is the connection between ctx's rpc_cred and nfs4_state_owner's so_cred? Any guidance will be appreciated...

Quoted 5 lines
Quoted 4 lines

--
tao.

Signature · 1 line
tao.

A message that is not in the archive (sent off-list or not yet received): AANLkTik-l_9nhBGWv-C8FKz9Aq99uP7-AWSi_uB4YDBG-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#10 lore raw
Quoted 11 lines · Tao Guo
Quoted 9 lines · William A. (Andy) Adamson
Quoted 2 lines · Tao Guo

I see... But what if sync == 1? At that time, data must have already been freed, so you should not use data->cred anymore.

Agreed.

Since LAYOUTCOMMIT is not called after close, we can get rid of taking the reference all together since a reference is taken on OPEN and dropped on CLOSE.

I forgot memory mapped files where writes can occur after the close, and so layoutcommit can also occur after the close. So, I will keep the get_rpccred in pnfs_need_layout commit and resend this patch with the put_rpccred in the layoutcommit done routine.

Quoted 7 lines
Quoted 2 lines

-->Andy

I agree. However that will change several functions' interface I guess.

I still have a question: why some procedures need to set rpc_cred whereas some needn't ? what is the connection between ctx's rpc_cred and nfs4_state_owner's so_cred? Any guidance will be appreciated...

Here's my take on an answer...

If an rpc_cred is not specified in the rpc_msg then the fsuid, fsgid, and group info toe the current_cred is used to lookup an rpc_cred. RPC's can be sent from several tasks - rpciod vrs the application task for example. OPEN, CLOSE, LOCK, UNLOCK, READ, WRITE (and memmapped I/O) should all be sent with the credential that opened the file. So, in order to ensure this the nfs4_state_owner->so_cred is used for these compounds even if the task is rpciod with root fsuid/fsgid. The nfs_open_context rpc_cred is the nfs4_state_owner so_cred. The nfs_open_context can exist longer than the nfs4_state_owner.

I think LAYOUTCOMMIT also wants to use the credential that did the I/O
- not for the file layout driver which doesn't care, but for the object and block layout drivers that use the layout as a lock and where a permissions check (?) is done on LAYOUTCOMMIT.

Currently, LAYOUTGET and LAYOUTRETURN don't set the rpc_cred. This is because the layout can last past opens and closes. If we ever want to support EXCHGID4_FLAG_BIND_PRINC_STATEID we will need to remember the cred and set it for these calls.

-->Andy

Quoted 12 lines
Quoted 6 lines
Quoted 5 lines

--
tao.

--
tao.

A message that is not in the archive (sent off-list or not yet received): AANLkTikCKm-ogV0byN2LSxAoYVFWPujpF3iKe7qlOTIY-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#12 lore raw
Quoted 9 lines · William A. (Andy) Adamson
Quoted 8 lines · Tao Guo
Quoted 6 lines · William A. (Andy) Adamson
Quoted 2 lines · Tao Guo

I see... But what if sync == 1? At that time, data must have already been freed, so you should not use data->cred anymore.

Agreed.

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

Since LAYOUTCOMMIT is not called after close, we can get rid of taking the reference all together since a reference is taken on OPEN and dropped on CLOSE.

I forgot memory mapped files where writes can occur after the close, and so layoutcommit can also occur after the close. So, I will keep the get_rpccred in pnfs_need_layout commit and resend this patch with the put_rpccred in the layoutcommit done routine.

Andy I get hangs on:

       data->is_sync = sync;
        status = pnfs4_proc_layoutcommit(data);

+ put_rpccred(data->cred);

with sync==1 like Tao Guo said

could you send the updated patch?

Boaz

Quoted 51 lines
Quoted 7 lines
Quoted 2 lines

-->Andy

I agree. However that will change several functions' interface I guess.

I still have a question: why some procedures need to set rpc_cred whereas some needn't ? what is the connection between ctx's rpc_cred and nfs4_state_owner's so_cred? Any guidance will be appreciated...

Here's my take on an answer...

If an rpc_cred is not specified in the rpc_msg then the fsuid, fsgid, and group info toe the current_cred is used to lookup an rpc_cred. RPC's can be sent from several tasks - rpciod vrs the application task for example. OPEN, CLOSE, LOCK, UNLOCK, READ, WRITE (and memmapped I/O) should all be sent with the credential that opened the file. So, in order to ensure this the nfs4_state_owner->so_cred is used for these compounds even if the task is rpciod with root fsuid/fsgid. The nfs_open_context rpc_cred is the nfs4_state_owner so_cred. The nfs_open_context can exist longer than the nfs4_state_owner.

I think LAYOUTCOMMIT also wants to use the credential that did the I/O
- not for the file layout driver which doesn't care, but for the object and block layout drivers that use the layout as a lock and where a permissions check (?) is done on LAYOUTCOMMIT.

Currently, LAYOUTGET and LAYOUTRETURN don't set the rpc_cred. This is because the layout can last past opens and closes. If we ever want to support EXCHGID4_FLAG_BIND_PRINC_STATEID we will need to remember the cred and set it for these calls.

-->Andy

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

--
tao.

Quoted 3 lines

--
tao.

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw
Quoted 20 lines · Boaz Harrosh
Quoted 9 lines · William A. (Andy) Adamson
Quoted 8 lines · Tao Guo
Quoted 6 lines · William A. (Andy) Adamson
Quoted 2 lines · Tao Guo

I see... But what if sync == 1? At that time, data must have already been freed, so you should not use data->cred anymore.

Agreed.

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

Since LAYOUTCOMMIT is not called after close, we can get rid of taking the reference all together since a reference is taken on OPEN and dropped on CLOSE.

I forgot memory mapped files where writes can occur after the close, and so layoutcommit can also occur after the close. So, I will keep the get_rpccred in pnfs_need_layout commit and resend this patch with the put_rpccred in the layoutcommit done routine.

Quoted 8 lines

Andy I get hangs on:

      data->is_sync = sync;
       status = pnfs4_proc_layoutcommit(data);

+ put_rpccred(data->cred);

with sync==1 like Tao Guo said

could you send the updated patch?

On it's way

Quoted 59 lines

Boaz

Quoted 43 lines
Quoted 7 lines
Quoted 2 lines

-->Andy

I agree. However that will change several functions' interface I guess.

I still have a question: why some procedures need to set rpc_cred whereas some needn't ? what is the connection between ctx's rpc_cred and nfs4_state_owner's so_cred? Any guidance will be appreciated...

Here's my take on an answer...

If an rpc_cred is not specified in the rpc_msg then the fsuid, fsgid, and group info toe the current_cred is used to lookup an rpc_cred. RPC's can be sent from several tasks - rpciod vrs the application task for example. OPEN, CLOSE, LOCK, UNLOCK, READ, WRITE (and memmapped I/O) should all be sent with the credential that opened the file. So, in order to ensure this the nfs4_state_owner->so_cred is used for these compounds even if the task is rpciod with root fsuid/fsgid. The nfs_open_context rpc_cred is the nfs4_state_owner so_cred. The nfs_open_context can exist longer than the nfs4_state_owner.

I think LAYOUTCOMMIT also wants to use the credential that did the I/O
- not for the file layout driver which doesn't care, but for the object and block layout drivers that use the layout as a lock and where a permissions check (?) is done on LAYOUTCOMMIT.

Currently, LAYOUTGET and LAYOUTRETURN don't set the rpc_cred. This is because the layout can last past opens and closes. If we ever want to support EXCHGID4_FLAG_BIND_PRINC_STATEID we will need to remember the cred and set it for these calls.

-->Andy

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

--
tao.

Quoted 8 lines
Quoted 3 lines

--
tao.

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html