Skip to content

Commit bf95f82

Browse files
chenhanxiaoTrond Myklebust
authored andcommitted
NFS: make sure lock/nolock overriding local_lock mount option
Currently, mount option lock/nolock and local_lock option may override NFS_MOUNT_LOCAL_FLOCK NFS_MOUNT_LOCAL_FCNTL flags when passing in different order: mount -o vers=3,local_lock=all,lock: local_lock=none mount -o vers=3,lock,local_lock=all: local_lock=all This patch will let lock/nolock override local_lock option as nfs(5) suggested. Signed-off-by: Chen Hanxiao <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 7c6c524 commit bf95f82

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

fs/nfs/fs_context.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,11 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
600600
break;
601601
case Opt_lock:
602602
if (result.negated) {
603+
ctx->lock_status = NFS_LOCK_NOLOCK;
603604
ctx->flags |= NFS_MOUNT_NONLM;
604605
ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK | NFS_MOUNT_LOCAL_FCNTL);
605606
} else {
607+
ctx->lock_status = NFS_LOCK_LOCK;
606608
ctx->flags &= ~NFS_MOUNT_NONLM;
607609
ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | NFS_MOUNT_LOCAL_FCNTL);
608610
}

fs/nfs/internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct nfs_fs_context {
112112
unsigned short protofamily;
113113
unsigned short mountfamily;
114114
bool has_sec_mnt_opts;
115+
int lock_status;
115116

116117
struct {
117118
union {
@@ -153,6 +154,12 @@ struct nfs_fs_context {
153154
} clone_data;
154155
};
155156

157+
enum nfs_lock_status {
158+
NFS_LOCK_NOT_SET = 0,
159+
NFS_LOCK_LOCK = 1,
160+
NFS_LOCK_NOLOCK = 2,
161+
};
162+
156163
#define nfs_errorf(fc, fmt, ...) ((fc)->log.log ? \
157164
errorf(fc, fmt, ## __VA_ARGS__) : \
158165
({ dprintk(fmt "\n", ## __VA_ARGS__); }))

fs/nfs/super.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,16 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
901901
rpc_authflavor_t authlist[NFS_MAX_SECFLAVORS];
902902
unsigned int authlist_len = ARRAY_SIZE(authlist);
903903

904+
/* make sure 'nolock'/'lock' override the 'local_lock' mount option */
905+
if (ctx->lock_status) {
906+
if (ctx->lock_status == NFS_LOCK_NOLOCK) {
907+
ctx->flags |= NFS_MOUNT_NONLM;
908+
ctx->flags |= (NFS_MOUNT_LOCAL_FLOCK | NFS_MOUNT_LOCAL_FCNTL);
909+
} else {
910+
ctx->flags &= ~NFS_MOUNT_NONLM;
911+
ctx->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | NFS_MOUNT_LOCAL_FCNTL);
912+
}
913+
}
904914
status = nfs_request_mount(fc, ctx->mntfh, authlist, &authlist_len);
905915
if (status)
906916
return ERR_PTR(status);

0 commit comments

Comments
 (0)