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