nlm: use appropriate open flags while locking

In case of a shared/read lock, open the file in O_RDONLY
mode, and in the case of an exclusive lock, open the file
in O_WRONLY mode to emulate the behaviour posix fcntl
implementation as given in the man pages.

Change-Id: Ib9eab6570c3bc65f8bd48a14a9d801616213b295
BUG: 916930
Signed-off-by: Rajesh Amaravathi <rajesh@redhat.com>
Reviewed-on: http://review.gluster.org/4603
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
This commit is contained in:
Rajesh Amaravathi 2013-03-01 14:49:57 +05:30 committed by Anand Avati
parent 2398e1e0da
commit 16ce96c299

View File

@ -594,9 +594,15 @@ nlm4_file_open_and_resume(nfs3_call_state_t *cs, nlm4_resume_fn_t resume)
{
fd_t *fd = NULL;
int ret = -1;
int flags = 0;
nlm_client_t *nlmclnt = NULL;
call_frame_t *frame = NULL;
if (cs->args.nlm4_lockargs.exclusive == _gf_false)
flags = O_RDONLY;
else
flags = O_WRONLY;
nlmclnt = nlm_get_uniq (cs->args.nlm4_lockargs.alock.caller_name);
if (nlmclnt == NULL) {
gf_log (GF_NLM, GF_LOG_ERROR, "nlm_get_uniq() returned NULL");
@ -636,7 +642,7 @@ nlm4_file_open_and_resume(nfs3_call_state_t *cs, nlm4_resume_fn_t resume)
nfs_fix_groups (cs->nfsx, frame->root);
STACK_WIND_COOKIE (frame, nlm4_file_open_cbk, cs->vol, cs->vol,
cs->vol->fops->open, &cs->resolvedloc, O_RDWR,
cs->vol->fops->open, &cs->resolvedloc, flags,
cs->fd, NULL);
ret = 0;
err: