Skip to content

Commit

Permalink
client-cbk: remove multiple calls to 'THIS' (#3464)
Browse files Browse the repository at this point in the history
Pass it along instead.

Updates: #1000
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
  • Loading branch information
Yaniv Kaul authored Apr 25, 2022
1 parent 57f3707 commit aa3f126
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
21 changes: 9 additions & 12 deletions rpc/xdr/src/glusterfs3.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,23 @@ gf_proto_lease_from_lease(struct gf_proto_lease *gf_proto_lease,
}

static inline int
gf_proto_recall_lease_to_upcall(struct gfs3_recall_lease_req *recall_lease,
gf_proto_recall_lease_to_upcall(xlator_t *this,
struct gfs3_recall_lease_req *recall_lease,
struct gf_upcall *gf_up_data)
{
struct gf_upcall_recall_lease *tmp = NULL;
int ret = 0;

GF_VALIDATE_OR_GOTO(THIS->name, recall_lease, out);
GF_VALIDATE_OR_GOTO(THIS->name, gf_up_data, out);
GF_VALIDATE_OR_GOTO(this->name, recall_lease, out);
GF_VALIDATE_OR_GOTO(this->name, gf_up_data, out);

tmp = (struct gf_upcall_recall_lease *)gf_up_data->data;
tmp->lease_type = recall_lease->lease_type;
memcpy(gf_up_data->gfid, recall_lease->gfid, 16);
memcpy(tmp->tid, recall_lease->tid, 16);

GF_PROTOCOL_DICT_UNSERIALIZE(
THIS, tmp->dict, (recall_lease->xdata).xdata_val,
this, tmp->dict, (recall_lease->xdata).xdata_val,
(recall_lease->xdata).xdata_len, ret, errno, out);
out:
return ret;
Expand Down Expand Up @@ -438,16 +439,14 @@ gf_proto_cache_invalidation_to_upcall(xlator_t *this,
}

static inline int
gf_proto_inodelk_contention_to_upcall(struct gfs4_inodelk_contention_req *lc,
gf_proto_inodelk_contention_to_upcall(xlator_t *this,
struct gfs4_inodelk_contention_req *lc,
struct gf_upcall *gf_up_data)
{
struct gf_upcall_inodelk_contention *tmp = NULL;
xlator_t *this = NULL;
int ret = -1;
int op_errno = EINVAL;

this = THIS;

GF_VALIDATE_OR_GOTO(this->name, lc, out);
GF_VALIDATE_OR_GOTO(this->name, gf_up_data, out);

Expand Down Expand Up @@ -512,16 +511,14 @@ gf_proto_inodelk_contention_from_upcall(xlator_t *this,
}

static inline int
gf_proto_entrylk_contention_to_upcall(struct gfs4_entrylk_contention_req *lc,
gf_proto_entrylk_contention_to_upcall(xlator_t *this,
struct gfs4_entrylk_contention_req *lc,
struct gf_upcall *gf_up_data)
{
struct gf_upcall_entrylk_contention *tmp = NULL;
xlator_t *this = NULL;
int ret = -1;
int op_errno = EINVAL;

this = THIS;

GF_VALIDATE_OR_GOTO(this->name, lc, out);
GF_VALIDATE_OR_GOTO(this->name, gf_up_data, out);

Expand Down
37 changes: 22 additions & 15 deletions xlators/protocol/client/src/client-callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,32 @@ client_cbk_recall_lease(struct rpc_clnt *rpc, void *mydata, void *data)
0,
},
};
xlator_t *this;

GF_VALIDATE_OR_GOTO("client-callback", data, out);

this = THIS;
iov = (struct iovec *)data;
ret = xdr_to_generic(*iov, &recall_lease,
(xdrproc_t)xdr_gfs3_recall_lease_req);

if (ret < 0) {
gf_smsg(THIS->name, GF_LOG_WARNING, -ret, PC_MSG_RECALL_LEASE_FAIL,
gf_smsg(this->name, GF_LOG_WARNING, -ret, PC_MSG_RECALL_LEASE_FAIL,
NULL);
goto out;
}

upcall_data.data = &rl_data;
ret = gf_proto_recall_lease_to_upcall(&recall_lease, &upcall_data);
ret = gf_proto_recall_lease_to_upcall(this, &recall_lease, &upcall_data);
if (ret < 0)
goto out;

upcall_data.event_type = GF_UPCALL_RECALL_LEASE;

gf_msg_trace(THIS->name, 0, "Upcall gfid = %s, ret = %d", recall_lease.gfid,
gf_msg_trace(this->name, 0, "Upcall gfid = %s, ret = %d", recall_lease.gfid,
ret);

default_notify(THIS, GF_EVENT_UPCALL, &upcall_data);
default_notify(this, GF_EVENT_UPCALL, &upcall_data);

out:
if (recall_lease.xdata.xdata_val)
Expand All @@ -98,8 +100,9 @@ client_cbk_cache_invalidation(struct rpc_clnt *rpc, void *mydata, void *data)
gfs3_cbk_cache_invalidation_req ca_req = {
0,
};
xlator_t *this = THIS;

gf_msg_trace(THIS->name, 0, "Upcall callback is called");
gf_msg_trace(this->name, 0, "Upcall callback is called");

if (!data)
goto out;
Expand All @@ -109,22 +112,22 @@ client_cbk_cache_invalidation(struct rpc_clnt *rpc, void *mydata, void *data)
(xdrproc_t)xdr_gfs3_cbk_cache_invalidation_req);

if (ret < 0) {
gf_smsg(THIS->name, GF_LOG_WARNING, -ret,
gf_smsg(this->name, GF_LOG_WARNING, -ret,
PC_MSG_CACHE_INVALIDATION_FAIL, NULL);
goto out;
}

upcall_data.data = &ca_data;
ret = gf_proto_cache_invalidation_to_upcall(THIS, &ca_req, &upcall_data);
ret = gf_proto_cache_invalidation_to_upcall(this, &ca_req, &upcall_data);
if (ret < 0)
goto out;

gf_msg_trace(THIS->name, 0,
gf_msg_trace(this->name, 0,
"Cache invalidation cbk received for gfid:"
" %s, ret = %d",
ca_req.gfid, ret);

default_notify(THIS, GF_EVENT_UPCALL, &upcall_data);
default_notify(this, GF_EVENT_UPCALL, &upcall_data);

out:
if (ca_req.gfid)
Expand Down Expand Up @@ -193,27 +196,29 @@ client_cbk_inodelk_contention(struct rpc_clnt *rpc, void *mydata, void *data)
0,
},
};
xlator_t *this;

GF_VALIDATE_OR_GOTO("client-callback", data, out);

this = THIS;
iov = (struct iovec *)data;
ret = xdr_to_generic(*iov, &proto_lc,
(xdrproc_t)xdr_gfs4_inodelk_contention_req);

if (ret < 0) {
gf_smsg(THIS->name, GF_LOG_WARNING, -ret,
gf_smsg(this->name, GF_LOG_WARNING, -ret,
PC_MSG_INODELK_CONTENTION_FAIL, NULL);
goto out;
}

upcall_data.data = &lc;
ret = gf_proto_inodelk_contention_to_upcall(&proto_lc, &upcall_data);
ret = gf_proto_inodelk_contention_to_upcall(this, &proto_lc, &upcall_data);
if (ret < 0)
goto out;

upcall_data.event_type = GF_UPCALL_INODELK_CONTENTION;

default_notify(THIS, GF_EVENT_UPCALL, &upcall_data);
default_notify(this, GF_EVENT_UPCALL, &upcall_data);

out:
if (proto_lc.domain)
Expand Down Expand Up @@ -244,27 +249,29 @@ client_cbk_entrylk_contention(struct rpc_clnt *rpc, void *mydata, void *data)
0,
},
};
xlator_t *this;

GF_VALIDATE_OR_GOTO("client-callback", data, out);

this = THIS;
iov = (struct iovec *)data;
ret = xdr_to_generic(*iov, &proto_lc,
(xdrproc_t)xdr_gfs4_entrylk_contention_req);

if (ret < 0) {
gf_smsg(THIS->name, GF_LOG_WARNING, -ret,
gf_smsg(this->name, GF_LOG_WARNING, -ret,
PC_MSG_ENTRYLK_CONTENTION_FAIL, NULL);
goto out;
}

upcall_data.data = &lc;
ret = gf_proto_entrylk_contention_to_upcall(&proto_lc, &upcall_data);
ret = gf_proto_entrylk_contention_to_upcall(this, &proto_lc, &upcall_data);
if (ret < 0)
goto out;

upcall_data.event_type = GF_UPCALL_ENTRYLK_CONTENTION;

default_notify(THIS, GF_EVENT_UPCALL, &upcall_data);
default_notify(this, GF_EVENT_UPCALL, &upcall_data);

out:
if (proto_lc.name)
Expand Down

0 comments on commit aa3f126

Please sign in to comment.