From eb37bd1269b0c4ac182398ea7017a758cc60e30f Mon Sep 17 00:00:00 2001 From: Li Dongyang Date: Mon, 1 Feb 2016 15:31:03 +1100 Subject: [PATCH] LU-7727 mdt: fail FMODE_WRITE open if the client is read only O_WRONLY/O_RDWR open on a file will get EROFS on a read only client, but the rpc gets sent to the mdt anyway. mdt will increase the mot_write_count of the mdt object, blocking subsequent FMODE_EXEC open to the same file. This patch makes sure we fail the FMODE_WRITE open with EROFS on mdt if the open request is from a read only client. We also do a similar check on the client so we can fail with EROFS straight away without sending the rpc to mdt. Signed-off-by: Li Dongyang Change-Id: I8b08e9d100a1ab8edf2fa47d4e2ebc5170f36df5 Reviewed-on: http://review.whamcloud.com/18242 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Ian Costello Reviewed-by: Nathaniel Clark Reviewed-by: Yang Sheng Reviewed-by: Oleg Drokin --- lustre/llite/namei.c | 4 ++++ lustre/mdt/mdt_open.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 1359d25..021fc0f 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -578,6 +578,10 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, RETURN(dentry == save ? NULL : dentry); } + if (it->it_op & IT_OPEN && it->it_flags & FMODE_WRITE && + dentry->d_sb->s_flags & MS_RDONLY) + RETURN(ERR_PTR(-EROFS)); + if (it->it_op & IT_CREAT) opc = LUSTRE_OPC_CREATE; else diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index ce9be37..f716949 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -1219,6 +1219,10 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) info->mti_spec.u.sp_ea.eadata == NULL) GOTO(out, result = err_serious(-EINVAL)); + if (create_flags & FMODE_WRITE && + exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY) + GOTO(out, result = -EROFS); + CDEBUG(D_INODE, "I am going to open "DFID"/("DNAME"->"DFID") " "cr_flag="LPO64" mode=0%06o msg_flag=0x%x\n", PFID(rr->rr_fid1), PNAME(&rr->rr_name), -- 1.8.3.1