|
|
233933 |
From 52dc121c412de9c1cc3058d782b949dc7b25dc3e Mon Sep 17 00:00:00 2001
|
|
|
233933 |
From: Soumya Koduri <skoduri@redhat.com>
|
|
|
233933 |
Date: Thu, 25 Jul 2019 12:56:12 +0530
|
|
|
233933 |
Subject: [PATCH 264/265] gfapi: Fix deadlock while processing upcall
|
|
|
233933 |
|
|
|
233933 |
As mentioned in bug1733166, there could be potential deadlock
|
|
|
233933 |
while processing upcalls depending on how each xlator choose
|
|
|
233933 |
to act on it. The right way of fixing such issues
|
|
|
233933 |
is to change rpc callback communication process.
|
|
|
233933 |
- https://github.com/gluster/glusterfs/issues/697
|
|
|
233933 |
|
|
|
233933 |
Till then, making changes in gfapi layer to avoid any I/O
|
|
|
233933 |
processing.
|
|
|
233933 |
|
|
|
233933 |
This is backport of below mainline patch
|
|
|
233933 |
> https://review.gluster.org/#/c/glusterfs/+/23108/
|
|
|
233933 |
> bz#1733166
|
|
|
233933 |
> https://review.gluster.org/#/c/glusterfs/+/23107/ (release-6)
|
|
|
233933 |
|
|
|
233933 |
Change-Id: I2079e95339e5d761d5060707f4555cfacab95c83
|
|
|
233933 |
fixes: bz#1733520
|
|
|
233933 |
Signed-off-by: Soumya Koduri <skoduri@redhat.com>
|
|
|
233933 |
Reviewed-on: https://code.engineering.redhat.com/gerrit/177675
|
|
|
233933 |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
233933 |
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
|
|
|
233933 |
---
|
|
|
233933 |
api/src/glfs-fops.c | 164 +++++++++++++++++++++++++++++++++++++++++-----------
|
|
|
233933 |
1 file changed, 131 insertions(+), 33 deletions(-)
|
|
|
233933 |
|
|
|
233933 |
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c
|
|
|
233933 |
index 396f18c..e6adea5 100644
|
|
|
233933 |
--- a/api/src/glfs-fops.c
|
|
|
233933 |
+++ b/api/src/glfs-fops.c
|
|
|
233933 |
@@ -34,7 +34,7 @@
|
|
|
233933 |
|
|
|
233933 |
struct upcall_syncop_args {
|
|
|
233933 |
struct glfs *fs;
|
|
|
233933 |
- struct glfs_upcall *up_arg;
|
|
|
233933 |
+ struct gf_upcall upcall_data;
|
|
|
233933 |
};
|
|
|
233933 |
|
|
|
233933 |
#define READDIRBUF_SIZE (sizeof(struct dirent) + GF_NAME_MAX + 1)
|
|
|
233933 |
@@ -5716,8 +5716,28 @@ out:
|
|
|
233933 |
static int
|
|
|
233933 |
upcall_syncop_args_free(struct upcall_syncop_args *args)
|
|
|
233933 |
{
|
|
|
233933 |
- if (args && args->up_arg)
|
|
|
233933 |
- GLFS_FREE(args->up_arg);
|
|
|
233933 |
+ dict_t *dict = NULL;
|
|
|
233933 |
+ struct gf_upcall *upcall_data = NULL;
|
|
|
233933 |
+
|
|
|
233933 |
+ if (args) {
|
|
|
233933 |
+ upcall_data = &args->upcall_data;
|
|
|
233933 |
+ switch (upcall_data->event_type) {
|
|
|
233933 |
+ case GF_UPCALL_CACHE_INVALIDATION:
|
|
|
233933 |
+ dict = ((struct gf_upcall_cache_invalidation *)(upcall_data
|
|
|
233933 |
+ ->data))
|
|
|
233933 |
+ ->dict;
|
|
|
233933 |
+ break;
|
|
|
233933 |
+ case GF_UPCALL_RECALL_LEASE:
|
|
|
233933 |
+ dict = ((struct gf_upcall_recall_lease *)(upcall_data->data))
|
|
|
233933 |
+ ->dict;
|
|
|
233933 |
+ break;
|
|
|
233933 |
+ }
|
|
|
233933 |
+ if (dict)
|
|
|
233933 |
+ dict_unref(dict);
|
|
|
233933 |
+
|
|
|
233933 |
+ GF_FREE(upcall_data->client_uid);
|
|
|
233933 |
+ GF_FREE(upcall_data->data);
|
|
|
233933 |
+ }
|
|
|
233933 |
GF_FREE(args);
|
|
|
233933 |
return 0;
|
|
|
233933 |
}
|
|
|
233933 |
@@ -5727,14 +5747,7 @@ glfs_upcall_syncop_cbk(int ret, call_frame_t *frame, void *opaque)
|
|
|
233933 |
{
|
|
|
233933 |
struct upcall_syncop_args *args = opaque;
|
|
|
233933 |
|
|
|
233933 |
- /* Here we not using upcall_syncop_args_free as application
|
|
|
233933 |
- * will be cleaning up the args->up_arg using glfs_free
|
|
|
233933 |
- * post processing upcall.
|
|
|
233933 |
- */
|
|
|
233933 |
- if (ret) {
|
|
|
233933 |
- upcall_syncop_args_free(args);
|
|
|
233933 |
- } else
|
|
|
233933 |
- GF_FREE(args);
|
|
|
233933 |
+ (void)upcall_syncop_args_free(args);
|
|
|
233933 |
|
|
|
233933 |
return 0;
|
|
|
233933 |
}
|
|
|
233933 |
@@ -5743,29 +5756,17 @@ static int
|
|
|
233933 |
glfs_cbk_upcall_syncop(void *opaque)
|
|
|
233933 |
{
|
|
|
233933 |
struct upcall_syncop_args *args = opaque;
|
|
|
233933 |
+ struct gf_upcall *upcall_data = NULL;
|
|
|
233933 |
struct glfs_upcall *up_arg = NULL;
|
|
|
233933 |
struct glfs *fs;
|
|
|
233933 |
+ int ret = -1;
|
|
|
233933 |
|
|
|
233933 |
fs = args->fs;
|
|
|
233933 |
- up_arg = args->up_arg;
|
|
|
233933 |
-
|
|
|
233933 |
- if (fs->up_cbk && up_arg) {
|
|
|
233933 |
- (fs->up_cbk)(up_arg, fs->up_data);
|
|
|
233933 |
- return 0;
|
|
|
233933 |
- }
|
|
|
233933 |
-
|
|
|
233933 |
- return -1;
|
|
|
233933 |
-}
|
|
|
233933 |
+ upcall_data = &args->upcall_data;
|
|
|
233933 |
|
|
|
233933 |
-static struct upcall_syncop_args *
|
|
|
233933 |
-upcall_syncop_args_init(struct glfs *fs, struct gf_upcall *upcall_data)
|
|
|
233933 |
-{
|
|
|
233933 |
- struct upcall_syncop_args *args = NULL;
|
|
|
233933 |
- int ret = -1;
|
|
|
233933 |
- struct glfs_upcall *up_arg = NULL;
|
|
|
233933 |
-
|
|
|
233933 |
- if (!fs || !upcall_data)
|
|
|
233933 |
+ if (!upcall_data) {
|
|
|
233933 |
goto out;
|
|
|
233933 |
+ }
|
|
|
233933 |
|
|
|
233933 |
up_arg = GLFS_CALLOC(1, sizeof(struct gf_upcall), glfs_release_upcall,
|
|
|
233933 |
glfs_mt_upcall_entry_t);
|
|
|
233933 |
@@ -5795,6 +5796,8 @@ upcall_syncop_args_init(struct glfs *fs, struct gf_upcall *upcall_data)
|
|
|
233933 |
if (up_arg->reason == GLFS_UPCALL_EVENT_NULL) {
|
|
|
233933 |
gf_msg(THIS->name, GF_LOG_DEBUG, errno, API_MSG_INVALID_ENTRY,
|
|
|
233933 |
"Upcall_EVENT_NULL received. Skipping it.");
|
|
|
233933 |
+ ret = 0;
|
|
|
233933 |
+ GLFS_FREE(up_arg);
|
|
|
233933 |
goto out;
|
|
|
233933 |
} else if (ret) {
|
|
|
233933 |
gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INVALID_ENTRY,
|
|
|
233933 |
@@ -5802,6 +5805,85 @@ upcall_syncop_args_init(struct glfs *fs, struct gf_upcall *upcall_data)
|
|
|
233933 |
goto out;
|
|
|
233933 |
}
|
|
|
233933 |
|
|
|
233933 |
+ if (fs->up_cbk && up_arg)
|
|
|
233933 |
+ (fs->up_cbk)(up_arg, fs->up_data);
|
|
|
233933 |
+
|
|
|
233933 |
+ /* application takes care of calling glfs_free on up_arg post
|
|
|
233933 |
+ * their processing */
|
|
|
233933 |
+
|
|
|
233933 |
+out:
|
|
|
233933 |
+ return ret;
|
|
|
233933 |
+}
|
|
|
233933 |
+
|
|
|
233933 |
+static struct gf_upcall_cache_invalidation *
|
|
|
233933 |
+gf_copy_cache_invalidation(struct gf_upcall_cache_invalidation *src)
|
|
|
233933 |
+{
|
|
|
233933 |
+ struct gf_upcall_cache_invalidation *dst = NULL;
|
|
|
233933 |
+
|
|
|
233933 |
+ if (!src)
|
|
|
233933 |
+ goto out;
|
|
|
233933 |
+
|
|
|
233933 |
+ dst = GF_CALLOC(1, sizeof(struct gf_upcall_cache_invalidation),
|
|
|
233933 |
+ glfs_mt_upcall_entry_t);
|
|
|
233933 |
+
|
|
|
233933 |
+ if (!dst) {
|
|
|
233933 |
+ gf_msg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED,
|
|
|
233933 |
+ "Upcall entry allocation failed.");
|
|
|
233933 |
+ goto out;
|
|
|
233933 |
+ }
|
|
|
233933 |
+
|
|
|
233933 |
+ dst->flags = src->flags;
|
|
|
233933 |
+ dst->expire_time_attr = src->expire_time_attr;
|
|
|
233933 |
+ dst->stat = src->stat;
|
|
|
233933 |
+ dst->p_stat = src->p_stat;
|
|
|
233933 |
+ dst->oldp_stat = src->oldp_stat;
|
|
|
233933 |
+
|
|
|
233933 |
+ if (src->dict)
|
|
|
233933 |
+ dst->dict = dict_copy_with_ref(src->dict, NULL);
|
|
|
233933 |
+
|
|
|
233933 |
+ return dst;
|
|
|
233933 |
+out:
|
|
|
233933 |
+ return NULL;
|
|
|
233933 |
+}
|
|
|
233933 |
+
|
|
|
233933 |
+static struct gf_upcall_recall_lease *
|
|
|
233933 |
+gf_copy_recall_lease(struct gf_upcall_recall_lease *src)
|
|
|
233933 |
+{
|
|
|
233933 |
+ struct gf_upcall_recall_lease *dst = NULL;
|
|
|
233933 |
+
|
|
|
233933 |
+ if (!src)
|
|
|
233933 |
+ goto out;
|
|
|
233933 |
+
|
|
|
233933 |
+ dst = GF_CALLOC(1, sizeof(struct gf_upcall_recall_lease),
|
|
|
233933 |
+ glfs_mt_upcall_entry_t);
|
|
|
233933 |
+
|
|
|
233933 |
+ if (!dst) {
|
|
|
233933 |
+ gf_msg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED,
|
|
|
233933 |
+ "Upcall entry allocation failed.");
|
|
|
233933 |
+ goto out;
|
|
|
233933 |
+ }
|
|
|
233933 |
+
|
|
|
233933 |
+ dst->lease_type = src->lease_type;
|
|
|
233933 |
+ memcpy(dst->tid, src->tid, 16);
|
|
|
233933 |
+
|
|
|
233933 |
+ if (src->dict)
|
|
|
233933 |
+ dst->dict = dict_copy_with_ref(src->dict, NULL);
|
|
|
233933 |
+
|
|
|
233933 |
+ return dst;
|
|
|
233933 |
+out:
|
|
|
233933 |
+ return NULL;
|
|
|
233933 |
+}
|
|
|
233933 |
+
|
|
|
233933 |
+static struct upcall_syncop_args *
|
|
|
233933 |
+upcall_syncop_args_init(struct glfs *fs, struct gf_upcall *upcall_data)
|
|
|
233933 |
+{
|
|
|
233933 |
+ struct upcall_syncop_args *args = NULL;
|
|
|
233933 |
+ int ret = -1;
|
|
|
233933 |
+ struct gf_upcall *t_data = NULL;
|
|
|
233933 |
+
|
|
|
233933 |
+ if (!fs || !upcall_data)
|
|
|
233933 |
+ goto out;
|
|
|
233933 |
+
|
|
|
233933 |
args = GF_CALLOC(1, sizeof(struct upcall_syncop_args),
|
|
|
233933 |
glfs_mt_upcall_entry_t);
|
|
|
233933 |
if (!args) {
|
|
|
233933 |
@@ -5819,15 +5901,31 @@ upcall_syncop_args_init(struct glfs *fs, struct gf_upcall *upcall_data)
|
|
|
233933 |
* notification without taking any lock/ref.
|
|
|
233933 |
*/
|
|
|
233933 |
args->fs = fs;
|
|
|
233933 |
- args->up_arg = up_arg;
|
|
|
233933 |
+ t_data = &(args->upcall_data);
|
|
|
233933 |
+ t_data->client_uid = gf_strdup(upcall_data->client_uid);
|
|
|
233933 |
|
|
|
233933 |
- /* application takes care of calling glfs_free on up_arg post
|
|
|
233933 |
- * their processing */
|
|
|
233933 |
+ gf_uuid_copy(t_data->gfid, upcall_data->gfid);
|
|
|
233933 |
+ t_data->event_type = upcall_data->event_type;
|
|
|
233933 |
+
|
|
|
233933 |
+ switch (t_data->event_type) {
|
|
|
233933 |
+ case GF_UPCALL_CACHE_INVALIDATION:
|
|
|
233933 |
+ t_data->data = gf_copy_cache_invalidation(
|
|
|
233933 |
+ (struct gf_upcall_cache_invalidation *)upcall_data->data);
|
|
|
233933 |
+ break;
|
|
|
233933 |
+ case GF_UPCALL_RECALL_LEASE:
|
|
|
233933 |
+ t_data->data = gf_copy_recall_lease(
|
|
|
233933 |
+ (struct gf_upcall_recall_lease *)upcall_data->data);
|
|
|
233933 |
+ break;
|
|
|
233933 |
+ }
|
|
|
233933 |
+
|
|
|
233933 |
+ if (!t_data->data)
|
|
|
233933 |
+ goto out;
|
|
|
233933 |
|
|
|
233933 |
return args;
|
|
|
233933 |
out:
|
|
|
233933 |
- if (up_arg) {
|
|
|
233933 |
- GLFS_FREE(up_arg);
|
|
|
233933 |
+ if (ret) {
|
|
|
233933 |
+ GF_FREE(args->upcall_data.client_uid);
|
|
|
233933 |
+ GF_FREE(args);
|
|
|
233933 |
}
|
|
|
233933 |
|
|
|
233933 |
return NULL;
|
|
|
233933 |
--
|
|
|
233933 |
1.8.3.1
|
|
|
233933 |
|