diff options
author | Raghavendra G <rgowdapp@redhat.com> | 2019-05-13 12:54:52 +0530 |
---|---|---|
committer | Raghavendra G <rgowdapp@redhat.com> | 2019-09-12 20:25:30 +0530 |
commit | 59f3c790048c9036adb81d56329a66fc3ffb255a (patch) | |
tree | f25e39fa8243b979b64118d7f712007dbcc96a7e /xlators/protocol/client/src/client-rpc-fops.c | |
parent | 61d438e73857776a1f96a7334f56b132275a587b (diff) |
protocol/client: don't reopen fds on which POSIX locks are held after a reconnect
Bricks cleanup any granted locks after a client disconnects and
currently these locks are not healed after a reconnect. This means
post reconnect a competing process could be granted a lock even though
the first process which was granted locks has not unlocked. By not
re-opening fds, subsequent operations on such fds will fail forcing
the application to close the current fd and reopen a new one. This way
we prevent any silent corruption.
A new option "client.strict-locks" is introduced to control this
behaviour. This option is set to "off" by default.
Change-Id: Ieed545efea466cb5e8f5a36199aa26380c301b9e
Signed-off-by: Raghavendra G <rgowdapp@redhat.com>
updates: bz#1694920
Diffstat (limited to 'xlators/protocol/client/src/client-rpc-fops.c')
-rw-r--r-- | xlators/protocol/client/src/client-rpc-fops.c | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/xlators/protocol/client/src/client-rpc-fops.c b/xlators/protocol/client/src/client-rpc-fops.c index 8ca6cbedc85..247d49728a3 100644 --- a/xlators/protocol/client/src/client-rpc-fops.c +++ b/xlators/protocol/client/src/client-rpc-fops.c @@ -21,8 +21,18 @@ int32_t client3_getspec(call_frame_t *frame, xlator_t *this, void *data); rpc_clnt_prog_t clnt3_3_fop_prog; -/* CBK */ +int +client_is_setlk(int32_t cmd) +{ + if ((cmd == F_SETLK) || (cmd == F_SETLK64) || (cmd == F_SETLKW) || + (cmd == F_SETLKW64)) { + return 1; + } + return 0; +} + +/* CBK */ int client3_3_symlink_cbk(struct rpc_req *req, struct iovec *iov, int count, void *myframe) @@ -815,7 +825,8 @@ client3_3_flush_cbk(struct rpc_req *req, struct iovec *iov, int count, goto out; } - if (rsp.op_ret >= 0 && !fd_is_anonymous(local->fd)) { + if ((rsp.op_ret >= 0 || (rsp.op_errno == ENOTCONN)) && + !fd_is_anonymous(local->fd)) { /* Delete all saved locks of the owner issuing flush */ ret = delete_granted_locks_owner(local->fd, &local->owner); gf_msg_trace(this->name, 0, "deleting locks of owner (%s) returned %d", @@ -2387,10 +2398,12 @@ client3_3_lk_cbk(struct rpc_req *req, struct iovec *iov, int count, int ret = 0; xlator_t *this = NULL; dict_t *xdata = NULL; + clnt_local_t *local = NULL; this = THIS; frame = myframe; + local = frame->local; if (-1 == req->rpc_status) { rsp.op_ret = -1; @@ -2411,6 +2424,18 @@ client3_3_lk_cbk(struct rpc_req *req, struct iovec *iov, int count, ret = client_post_lk(this, &rsp, &lock, &xdata); if (ret < 0) goto out; + + /* Save the lock to the client lock cache to be able + to recover in the case of server reboot.*/ + + if (client_is_setlk(local->cmd)) { + ret = client_add_lock_for_recovery(local->fd, &lock, &local->owner, + local->cmd); + if (ret < 0) { + rsp.op_ret = -1; + rsp.op_errno = -ret; + } + } } out: @@ -4184,8 +4209,16 @@ client3_3_flush(call_frame_t *frame, xlator_t *this, void *data) ret = client_pre_flush(this, &req, args->fd, args->xdata); if (ret) { op_errno = -ret; + if (op_errno == EBADF) { + ret = delete_granted_locks_owner(local->fd, &local->owner); + gf_msg_trace(this->name, 0, + "deleting locks of owner (%s) returned %d", + lkowner_utoa(&local->owner), ret); + } + goto unwind; } + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_FLUSH, client3_3_flush_cbk, NULL, (xdrproc_t)xdr_gfs3_flush_req); @@ -5120,8 +5153,16 @@ client3_3_lk(call_frame_t *frame, xlator_t *this, void *data) args->xdata); if (ret) { op_errno = -ret; + + if ((op_errno == EBADF) && (args->flock->l_type == F_UNLCK) && + client_is_setlk(local->cmd)) { + client_add_lock_for_recovery(local->fd, args->flock, &local->owner, + local->cmd); + } + goto unwind; } + ret = client_submit_request(this, &req, frame, conf->fops, GFS3_OP_LK, client3_3_lk_cbk, NULL, (xdrproc_t)xdr_gfs3_lk_req); |