|
|
887953 |
From 3c0f27fd697a8c977873d44fbdf3aa63c1065645 Mon Sep 17 00:00:00 2001
|
|
|
887953 |
From: Csaba Henk <csaba@redhat.com>
|
|
|
887953 |
Date: Thu, 6 Dec 2018 16:13:46 +0100
|
|
|
887953 |
Subject: [PATCH 528/529] locks: handle "clear locks" xattr in fgetxattr too
|
|
|
887953 |
|
|
|
887953 |
The lock clearing procedure was kicked in only in
|
|
|
887953 |
getxattr context. We need it to work the same way
|
|
|
887953 |
if it's triggered via fgetxattr (as is the case
|
|
|
887953 |
with interrupt handling).
|
|
|
887953 |
|
|
|
887953 |
Also cleaned up the instrumentation a bit (more logs,
|
|
|
887953 |
proper management of allocated data).
|
|
|
887953 |
|
|
|
887953 |
Upstream: https://review.gluster.org/21820
|
|
|
887953 |
> updates: #465
|
|
|
887953 |
> Change-Id: Icfca26ee181da3b8e15ca3fcf61cd5702e2730c8
|
|
|
887953 |
> Signed-off-by: Csaba Henk <csaba@redhat.com>
|
|
|
887953 |
|
|
|
887953 |
Change-Id: Ia15108fd6d92ea2bdb73cea5fb04126785b19663
|
|
|
887953 |
BUG: 1595246
|
|
|
887953 |
Signed-off-by: Csaba Henk <csaba@redhat.com>
|
|
|
887953 |
Reviewed-on: https://code.engineering.redhat.com/gerrit/162551
|
|
|
887953 |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
887953 |
Reviewed-by: Amar Tumballi Suryanarayan <amarts@redhat.com>
|
|
|
887953 |
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
|
|
|
887953 |
---
|
|
|
887953 |
xlators/features/locks/src/clear.c | 6 +++
|
|
|
887953 |
xlators/features/locks/src/clear.h | 2 +
|
|
|
887953 |
xlators/features/locks/src/posix.c | 107 ++++++++++++++++++++++++-------------
|
|
|
887953 |
3 files changed, 77 insertions(+), 38 deletions(-)
|
|
|
887953 |
|
|
|
887953 |
diff --git a/xlators/features/locks/src/clear.c b/xlators/features/locks/src/clear.c
|
|
|
887953 |
index 22c03b5..c3d5dd2 100644
|
|
|
887953 |
--- a/xlators/features/locks/src/clear.c
|
|
|
887953 |
+++ b/xlators/features/locks/src/clear.c
|
|
|
887953 |
@@ -24,6 +24,12 @@
|
|
|
887953 |
#include "statedump.h"
|
|
|
887953 |
#include "clear.h"
|
|
|
887953 |
|
|
|
887953 |
+const char *clrlk_type_names[CLRLK_TYPE_MAX] = {
|
|
|
887953 |
+ [CLRLK_INODE] = "inode",
|
|
|
887953 |
+ [CLRLK_ENTRY] = "entry",
|
|
|
887953 |
+ [CLRLK_POSIX] = "posix",
|
|
|
887953 |
+};
|
|
|
887953 |
+
|
|
|
887953 |
int
|
|
|
887953 |
clrlk_get_kind (char *kind)
|
|
|
887953 |
{
|
|
|
887953 |
diff --git a/xlators/features/locks/src/clear.h b/xlators/features/locks/src/clear.h
|
|
|
887953 |
index 78fc5ae..1542953 100644
|
|
|
887953 |
--- a/xlators/features/locks/src/clear.h
|
|
|
887953 |
+++ b/xlators/features/locks/src/clear.h
|
|
|
887953 |
@@ -22,6 +22,8 @@ typedef enum {
|
|
|
887953 |
CLRLK_TYPE_MAX
|
|
|
887953 |
} clrlk_type;
|
|
|
887953 |
|
|
|
887953 |
+extern const char *clrlk_type_names[];
|
|
|
887953 |
+
|
|
|
887953 |
typedef enum {
|
|
|
887953 |
CLRLK_BLOCKED = 1,
|
|
|
887953 |
CLRLK_GRANTED,
|
|
|
887953 |
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
|
|
|
887953 |
index 2cc2837..142a5cc 100644
|
|
|
887953 |
--- a/xlators/features/locks/src/posix.c
|
|
|
887953 |
+++ b/xlators/features/locks/src/posix.c
|
|
|
887953 |
@@ -1028,41 +1028,35 @@ pl_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
|
|
887953 |
|
|
|
887953 |
}
|
|
|
887953 |
|
|
|
887953 |
-int32_t
|
|
|
887953 |
-pl_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
|
|
|
887953 |
- const char *name, dict_t *xdata)
|
|
|
887953 |
+static int32_t
|
|
|
887953 |
+pl_getxattr_clrlk (xlator_t *this, const char *name, inode_t *inode,
|
|
|
887953 |
+ dict_t **dict, int32_t *op_errno)
|
|
|
887953 |
{
|
|
|
887953 |
- int32_t op_errno = EINVAL;
|
|
|
887953 |
- int op_ret = -1;
|
|
|
887953 |
int32_t bcount = 0;
|
|
|
887953 |
int32_t gcount = 0;
|
|
|
887953 |
- char key[PATH_MAX] = {0, };
|
|
|
887953 |
+ char *key = NULL;
|
|
|
887953 |
char *lk_summary = NULL;
|
|
|
887953 |
pl_inode_t *pl_inode = NULL;
|
|
|
887953 |
- dict_t *dict = NULL;
|
|
|
887953 |
clrlk_args args = {0,};
|
|
|
887953 |
char *brickname = NULL;
|
|
|
887953 |
+ int32_t op_ret = -1;
|
|
|
887953 |
|
|
|
887953 |
- if (!name)
|
|
|
887953 |
- goto usual;
|
|
|
887953 |
-
|
|
|
887953 |
- if (strncmp (name, GF_XATTR_CLRLK_CMD, strlen (GF_XATTR_CLRLK_CMD)))
|
|
|
887953 |
- goto usual;
|
|
|
887953 |
+ *op_errno = EINVAL;
|
|
|
887953 |
|
|
|
887953 |
if (clrlk_parse_args (name, &args)) {
|
|
|
887953 |
- op_errno = EINVAL;
|
|
|
887953 |
+ *op_errno = EINVAL;
|
|
|
887953 |
goto out;
|
|
|
887953 |
}
|
|
|
887953 |
|
|
|
887953 |
- dict = dict_new ();
|
|
|
887953 |
- if (!dict) {
|
|
|
887953 |
- op_errno = ENOMEM;
|
|
|
887953 |
+ *dict = dict_new ();
|
|
|
887953 |
+ if (!*dict) {
|
|
|
887953 |
+ *op_errno = ENOMEM;
|
|
|
887953 |
goto out;
|
|
|
887953 |
}
|
|
|
887953 |
|
|
|
887953 |
- pl_inode = pl_inode_get (this, loc->inode);
|
|
|
887953 |
+ pl_inode = pl_inode_get (this, inode);
|
|
|
887953 |
if (!pl_inode) {
|
|
|
887953 |
- op_errno = ENOMEM;
|
|
|
887953 |
+ *op_errno = ENOMEM;
|
|
|
887953 |
goto out;
|
|
|
887953 |
}
|
|
|
887953 |
|
|
|
887953 |
@@ -1072,23 +1066,31 @@ pl_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
|
|
|
887953 |
op_ret = clrlk_clear_lks_in_all_domains (this, pl_inode,
|
|
|
887953 |
&args, &bcount,
|
|
|
887953 |
&gcount,
|
|
|
887953 |
- &op_errno);
|
|
|
887953 |
- if (op_ret)
|
|
|
887953 |
- goto out;
|
|
|
887953 |
+ op_errno);
|
|
|
887953 |
break;
|
|
|
887953 |
case CLRLK_POSIX:
|
|
|
887953 |
op_ret = clrlk_clear_posixlk (this, pl_inode, &args,
|
|
|
887953 |
&bcount, &gcount,
|
|
|
887953 |
- &op_errno);
|
|
|
887953 |
- if (op_ret)
|
|
|
887953 |
- goto out;
|
|
|
887953 |
+ op_errno);
|
|
|
887953 |
break;
|
|
|
887953 |
- case CLRLK_TYPE_MAX:
|
|
|
887953 |
- op_errno = EINVAL;
|
|
|
887953 |
- goto out;
|
|
|
887953 |
+ default:
|
|
|
887953 |
+ op_ret = -1;
|
|
|
887953 |
+ *op_errno = EINVAL;
|
|
|
887953 |
+ }
|
|
|
887953 |
+ if (op_ret) {
|
|
|
887953 |
+ if (args.type >= CLRLK_TYPE_MAX) {
|
|
|
887953 |
+ gf_log (this->name, GF_LOG_ERROR,
|
|
|
887953 |
+ "clear locks: invalid lock type %d", args.type);
|
|
|
887953 |
+ } else {
|
|
|
887953 |
+ gf_log (this->name, GF_LOG_ERROR,
|
|
|
887953 |
+ "clear locks of type %s failed: %s",
|
|
|
887953 |
+ clrlk_type_names[args.type], strerror (*op_errno));
|
|
|
887953 |
+ }
|
|
|
887953 |
+
|
|
|
887953 |
+ goto out;
|
|
|
887953 |
}
|
|
|
887953 |
|
|
|
887953 |
- op_ret = fetch_pathinfo (this, loc->inode, &op_errno, &brickname);
|
|
|
887953 |
+ op_ret = fetch_pathinfo (this, inode, op_errno, &brickname);
|
|
|
887953 |
if (op_ret) {
|
|
|
887953 |
gf_log (this->name, GF_LOG_WARNING,
|
|
|
887953 |
"Couldn't get brickname");
|
|
|
887953 |
@@ -1105,39 +1107,62 @@ pl_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
|
|
|
887953 |
if (!gcount && !bcount) {
|
|
|
887953 |
if (gf_asprintf (&lk_summary, "No locks cleared.") == -1) {
|
|
|
887953 |
op_ret = -1;
|
|
|
887953 |
- op_errno = ENOMEM;
|
|
|
887953 |
+ *op_errno = ENOMEM;
|
|
|
887953 |
goto out;
|
|
|
887953 |
}
|
|
|
887953 |
} else if (gf_asprintf (&lk_summary, "%s: %s blocked locks=%d "
|
|
|
887953 |
"granted locks=%d",
|
|
|
887953 |
(brickname == NULL)? this->name : brickname,
|
|
|
887953 |
- (args.type == CLRLK_INODE)? "inode":
|
|
|
887953 |
- (args.type == CLRLK_ENTRY)? "entry":
|
|
|
887953 |
- (args.type == CLRLK_POSIX)? "posix": " ",
|
|
|
887953 |
+ clrlk_type_names[args.type],
|
|
|
887953 |
bcount, gcount) == -1) {
|
|
|
887953 |
op_ret = -1;
|
|
|
887953 |
- op_errno = ENOMEM;
|
|
|
887953 |
+ *op_errno = ENOMEM;
|
|
|
887953 |
goto out;
|
|
|
887953 |
}
|
|
|
887953 |
+ gf_log (this->name, GF_LOG_DEBUG, "%s", lk_summary);
|
|
|
887953 |
|
|
|
887953 |
- if (snprintf(key, sizeof(key), "%s", name) >= sizeof(key)) {
|
|
|
887953 |
+ key = gf_strdup (name);
|
|
|
887953 |
+ if (!key) {
|
|
|
887953 |
op_ret = -1;
|
|
|
887953 |
goto out;
|
|
|
887953 |
}
|
|
|
887953 |
- if (dict_set_dynstr (dict, key, lk_summary)) {
|
|
|
887953 |
+ if (dict_set_dynstr (*dict, key, lk_summary)) {
|
|
|
887953 |
op_ret = -1;
|
|
|
887953 |
- op_errno = ENOMEM;
|
|
|
887953 |
+ *op_errno = ENOMEM;
|
|
|
887953 |
goto out;
|
|
|
887953 |
}
|
|
|
887953 |
|
|
|
887953 |
op_ret = 0;
|
|
|
887953 |
out:
|
|
|
887953 |
GF_FREE(brickname);
|
|
|
887953 |
- STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict, xdata);
|
|
|
887953 |
|
|
|
887953 |
GF_FREE (args.opts);
|
|
|
887953 |
- if (op_ret && lk_summary)
|
|
|
887953 |
+ if (op_ret) {
|
|
|
887953 |
GF_FREE (lk_summary);
|
|
|
887953 |
+ GF_FREE (key);
|
|
|
887953 |
+ }
|
|
|
887953 |
+
|
|
|
887953 |
+ return op_ret;
|
|
|
887953 |
+}
|
|
|
887953 |
+
|
|
|
887953 |
+int32_t
|
|
|
887953 |
+pl_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name,
|
|
|
887953 |
+ dict_t *xdata)
|
|
|
887953 |
+{
|
|
|
887953 |
+ int32_t op_errno = EINVAL;
|
|
|
887953 |
+ int32_t op_ret = -1;
|
|
|
887953 |
+ dict_t *dict = NULL;
|
|
|
887953 |
+
|
|
|
887953 |
+ if (!name)
|
|
|
887953 |
+ goto usual;
|
|
|
887953 |
+
|
|
|
887953 |
+ if (strncmp (name, GF_XATTR_CLRLK_CMD, strlen (GF_XATTR_CLRLK_CMD)))
|
|
|
887953 |
+ goto usual;
|
|
|
887953 |
+
|
|
|
887953 |
+ op_ret = pl_getxattr_clrlk (this, name, loc->inode, &dict, &op_errno);
|
|
|
887953 |
+
|
|
|
887953 |
+ STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict, xdata);
|
|
|
887953 |
+
|
|
|
887953 |
if (dict)
|
|
|
887953 |
dict_unref (dict);
|
|
|
887953 |
return 0;
|
|
|
887953 |
@@ -1415,6 +1440,12 @@ pl_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
|
|
|
887953 |
}
|
|
|
887953 |
|
|
|
887953 |
goto unwind;
|
|
|
887953 |
+ } else if (strncmp (name, GF_XATTR_CLRLK_CMD,
|
|
|
887953 |
+ strlen (GF_XATTR_CLRLK_CMD)) == 0) {
|
|
|
887953 |
+ op_ret = pl_getxattr_clrlk (this, name, fd->inode, &dict,
|
|
|
887953 |
+ &op_errno);
|
|
|
887953 |
+
|
|
|
887953 |
+ goto unwind;
|
|
|
887953 |
} else {
|
|
|
887953 |
goto usual;
|
|
|
887953 |
}
|
|
|
887953 |
--
|
|
|
887953 |
1.8.3.1
|
|
|
887953 |
|