From 35e911abef34f923eaa948b022687241c221c988 Mon Sep 17 00:00:00 2001
From: Pranith Kumar K <pkarampu@redhat.com>
Date: Mon, 14 Mar 2016 10:59:38 +0530
Subject: [PATCH 126/139] dht/afr/client/posix: Fail mkdir without gfid-req
Do not allow directory creations without gfids as
after the directories are created, operations
on them fail anyway. So it is better to fail mkdir.
>BUG: 1317361
>Change-Id: I8f8e3b38bbded1960b7215bac0432500f7e78038
>Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
>Reviewed-on: http://review.gluster.org/13690
>Smoke: Gluster Build System <jenkins@build.gluster.com>
>Reviewed-by: Krutika Dhananjay <kdhananj@redhat.com>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
BUG: 1321550
Change-Id: I566741c2e94be2cf7a198cfc1473231ad37f8a1a
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/73689
---
libglusterfs/src/common-utils.h | 3 ++-
xlators/cluster/afr/src/afr-dir-write.c | 18 ++++++++++++------
xlators/cluster/dht/src/dht-common.c | 8 ++++++++
xlators/protocol/client/src/client-messages.h | 12 +++++++++++-
xlators/protocol/client/src/client-rpc-fops.c | 9 +++++++++
xlators/protocol/server/src/server-rpc-fops.c | 7 +++++--
xlators/storage/posix/src/posix.c | 10 +++++++++-
7 files changed, 56 insertions(+), 11 deletions(-)
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 388b695..bc1825e 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -133,7 +133,8 @@ enum _gf_client_pid
GF_CLIENT_PID_GLFS_HEAL = -7,
GF_CLIENT_PID_BITD = -8,
GF_CLIENT_PID_SCRUB = -9,
- GF_CLIENT_PID_TIER_DEFRAG = -10
+ GF_CLIENT_PID_TIER_DEFRAG = -10,
+ GF_SERVER_PID_TRASH = -11
};
enum _gf_xlator_ipc_targets {
diff --git a/xlators/cluster/afr/src/afr-dir-write.c b/xlators/cluster/afr/src/afr-dir-write.c
index 6d4a352..b1ff557 100644
--- a/xlators/cluster/afr/src/afr-dir-write.c
+++ b/xlators/cluster/afr/src/afr-dir-write.c
@@ -744,13 +744,19 @@ afr_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
local->cont.mkdir.mode = mode;
local->umask = umask;
- if (xdata)
- local->xdata_req = dict_copy_with_ref (xdata, NULL);
- else
- local->xdata_req = dict_new ();
+ if (!xdata || !dict_get (xdata, "gfid-req")) {
+ op_errno = EPERM;
+ gf_msg_callingfn (this->name, GF_LOG_WARNING, op_errno,
+ AFR_MSG_GFID_NULL, "mkdir: %s is received "
+ "without gfid-req %p", loc->path, xdata);
+ goto out;
+ }
- if (!local->xdata_req)
- goto out;
+ local->xdata_req = dict_copy_with_ref (xdata, NULL);
+ if (!local->xdata_req) {
+ op_errno = ENOMEM;
+ goto out;
+ }
local->op = GF_FOP_MKDIR;
local->transaction.wind = afr_mkdir_wind;
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index c5bb9b7..594eca0 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -7348,6 +7348,14 @@ dht_mkdir (call_frame_t *frame, xlator_t *this,
conf = this->private;
+ if (!params || !dict_get (params, "gfid-req")) {
+ op_errno = EPERM;
+ gf_msg_callingfn (this->name, GF_LOG_WARNING, op_errno,
+ DHT_MSG_GFID_NULL, "mkdir: %s is received "
+ "without gfid-req %p", loc->path, params);
+ goto err;
+ }
+
dht_get_du_info (frame, this, loc);
local = dht_local_init (frame, loc, NULL, GF_FOP_MKDIR);
diff --git a/xlators/protocol/client/src/client-messages.h b/xlators/protocol/client/src/client-messages.h
index 9239176..ea0d880 100644
--- a/xlators/protocol/client/src/client-messages.h
+++ b/xlators/protocol/client/src/client-messages.h
@@ -45,7 +45,7 @@
*/
#define GLFS_PC_BASE GLFS_MSGID_COMP_PC
-#define GLFS_PC_NUM_MESSAGES 63
+#define GLFS_PC_NUM_MESSAGES 65
#define GLFS_PC_MSGID_END (GLFS_PC_BASE + GLFS_NUM_MESSAGES + 1)
/* Messages with message IDs */
#define glfs_msg_start_x GLFS_PC_BASE, "Invalid: Start of messages"
@@ -618,6 +618,16 @@
*
*/
+#define PC_MSG_CHILD_STATUS (GLFS_PC_BASE + 64)
+
+/*!
+ * @messageid
+ * @diagnosis
+ * @recommendedaction
+ *
+ */
+
+#define PC_MSG_GFID_NULL (GLFS_PC_BASE + 65)
/*------------*/
#define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
diff --git a/xlators/protocol/client/src/client-rpc-fops.c b/xlators/protocol/client/src/client-rpc-fops.c
index 2e28516..90be4bc 100644
--- a/xlators/protocol/client/src/client-rpc-fops.c
+++ b/xlators/protocol/client/src/client-rpc-fops.c
@@ -4133,6 +4133,15 @@ client3_3_create (call_frame_t *frame, xlator_t *this,
args = data;
+ if (!args->xdata || !dict_get (args->xdata, "gfid-req")) {
+ op_errno = EPERM;
+ gf_msg_callingfn (this->name, GF_LOG_WARNING, op_errno,
+ PC_MSG_GFID_NULL, "mkdir: %s is received "
+ "without gfid-req %p", args->loc->path,
+ args->xdata);
+ goto unwind;
+ }
+
local = mem_get0 (this->local_pool);
if (!local) {
op_errno = ENOMEM;
diff --git a/xlators/protocol/server/src/server-rpc-fops.c b/xlators/protocol/server/src/server-rpc-fops.c
index 25ffc0d..954374b 100644
--- a/xlators/protocol/server/src/server-rpc-fops.c
+++ b/xlators/protocol/server/src/server-rpc-fops.c
@@ -496,20 +496,23 @@ server_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
server_state_t *state = NULL;
inode_t *link_inode = NULL;
rpcsvc_request_t *req = NULL;
+ client_t *client = NULL;
GF_PROTOCOL_DICT_SERIALIZE (this, xdata, &rsp.xdata.xdata_val,
rsp.xdata.xdata_len, op_errno, out);
state = CALL_STATE (frame);
+ client = frame->root->client;
if (op_ret < 0) {
gf_msg (this->name, fop_log_level (GF_FOP_MKDIR, op_errno),
op_errno, PS_MSG_DIR_INFO,
- "%"PRId64": MKDIR %s (%s/%s) ==> (%s)",
+ "%"PRId64": MKDIR %s (%s/%s) client: %s",
frame->root->unique,
(state->loc.path) ? state->loc.path : "",
uuid_utoa (state->resolve.pargfid),
- state->resolve.bname, strerror (op_errno));
+ state->resolve.bname,
+ (!client || !client->client_uid) ? "-":client->client_uid);
goto out;
}
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 28835cb..94e3c45 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -1392,7 +1392,8 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
SET_FS_ID (frame->root->uid, gid);
- op_ret = dict_get_ptr (xdata, "gfid-req", &uuid_req);
+ if (xdata)
+ op_ret = dict_get_ptr (xdata, "gfid-req", &uuid_req);
if (uuid_req && !gf_uuid_is_null (uuid_req)) {
op_ret = posix_istat (this, uuid_req, NULL, &stbuf);
if ((op_ret == 0) && IA_ISDIR (stbuf.ia_type)) {
@@ -1413,6 +1414,13 @@ posix_mkdir (call_frame_t *frame, xlator_t *this,
uuid_utoa (uuid_req), gfid_path ? gfid_path
: "<NULL>");
}
+ } else if (!uuid_req && frame->root->pid != GF_SERVER_PID_TRASH) {
+ op_ret = -1;
+ op_errno = EPERM;
+ gf_msg_callingfn (this->name, GF_LOG_WARNING, op_errno,
+ P_MSG_NULL_GFID, "mkdir (%s): is issued without "
+ "gfid-req %p", loc->path, xdata);
+ goto out;
}
op_ret = posix_pstat (this, loc->pargfid, par_path, &preparent);
--
1.7.1