|
|
d1681e |
From 37132b4ea02a57056a426e04e77defb28e447ff9 Mon Sep 17 00:00:00 2001
|
|
|
d1681e |
From: Amar Tumballi <amarts@redhat.com>
|
|
|
d1681e |
Date: Tue, 24 Jul 2018 15:42:28 +0530
|
|
|
d1681e |
Subject: [PATCH 345/351] io-stats: allow only relative path for dumping
|
|
|
d1681e |
io-stats info
|
|
|
d1681e |
|
|
|
d1681e |
It wouldn't make sense to allow iostats file to be written in
|
|
|
d1681e |
*any* directory. While the formating makes sure we try to append
|
|
|
d1681e |
io-stats-name for the file, so overwriting existing file is slim,
|
|
|
d1681e |
it makes sense to restrict dumping to one directory.
|
|
|
d1681e |
|
|
|
d1681e |
BUG: 1605086
|
|
|
d1681e |
Change-Id: Ie28b6a355de574d8d3855c8654d6756ef0389055
|
|
|
d1681e |
Signed-off-by: Amar Tumballi <amarts@redhat.com>
|
|
|
d1681e |
Reviewed-on: https://code.engineering.redhat.com/gerrit/145898
|
|
|
d1681e |
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
|
|
|
d1681e |
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
|
|
|
d1681e |
---
|
|
|
d1681e |
tests/bugs/core/io-stats-1322825.t | 12 ++++++------
|
|
|
d1681e |
xlators/debug/io-stats/src/io-stats.c | 29 ++++++++++++++++++++++-------
|
|
|
d1681e |
2 files changed, 28 insertions(+), 13 deletions(-)
|
|
|
d1681e |
|
|
|
d1681e |
diff --git a/tests/bugs/core/io-stats-1322825.t b/tests/bugs/core/io-stats-1322825.t
|
|
|
d1681e |
index d232ecb..53f2d04 100755
|
|
|
d1681e |
--- a/tests/bugs/core/io-stats-1322825.t
|
|
|
d1681e |
+++ b/tests/bugs/core/io-stats-1322825.t
|
|
|
d1681e |
@@ -23,7 +23,7 @@ TEST $CLI volume profile $V0 start
|
|
|
d1681e |
TEST mkdir $M0/dir1
|
|
|
d1681e |
|
|
|
d1681e |
# Generate the stat dump across the io-stat instances
|
|
|
d1681e |
-TEST setfattr -n trusted.io-stats-dump -v /tmp/io-stats-1322825 $M0
|
|
|
d1681e |
+TEST setfattr -n trusted.io-stats-dump -v io-stats-1322825 $M0
|
|
|
d1681e |
|
|
|
d1681e |
# Check if $M0 is clean w.r.t xattr information
|
|
|
d1681e |
# TODO: if there are better ways to check we really get no attr error, please
|
|
|
d1681e |
@@ -42,12 +42,12 @@ ret=$(echo $?)
|
|
|
d1681e |
EXPECT 0 echo $ret
|
|
|
d1681e |
|
|
|
d1681e |
# Check if we have 5 io-stat files in /tmp
|
|
|
d1681e |
-EXPECT 5 ls -1 /tmp/io-stats-1322825*
|
|
|
d1681e |
+EXPECT 5 ls -1 /var/run/gluster/io-stats-1322825*
|
|
|
d1681e |
# Cleanup the 5 generated files
|
|
|
d1681e |
-rm -f /tmp/io-stats-1322825*
|
|
|
d1681e |
+rm -f /var/run/gluster/io-stats-1322825*
|
|
|
d1681e |
|
|
|
d1681e |
# Rinse and repeat above for a directory
|
|
|
d1681e |
-TEST setfattr -n trusted.io-stats-dump -v /tmp/io-stats-1322825 $M0/dir1
|
|
|
d1681e |
+TEST setfattr -n trusted.io-stats-dump -v io-stats-1322825 $M0/dir1
|
|
|
d1681e |
getfattr -n trusted.io-stats-dump $B0/${V0}1/dir1 2>&1 | grep -qi "no such attribute"
|
|
|
d1681e |
ret=$(echo $?)
|
|
|
d1681e |
EXPECT 0 echo $ret
|
|
|
d1681e |
@@ -61,7 +61,7 @@ getfattr -n trusted.io-stats-dump $B0/${V0}4/dir1 2>&1 | grep -qi "no such attri
|
|
|
d1681e |
ret=$(echo $?)
|
|
|
d1681e |
EXPECT 0 echo $ret
|
|
|
d1681e |
|
|
|
d1681e |
-EXPECT 5 ls -1 /tmp/io-stats-1322825*
|
|
|
d1681e |
-rm -f /tmp/io-stats-1322825*
|
|
|
d1681e |
+EXPECT 5 ls -1 /var/run/gluster/io-stats-1322825*
|
|
|
d1681e |
+rm -f /var/run/gluster/io-stats-1322825*
|
|
|
d1681e |
|
|
|
d1681e |
cleanup;
|
|
|
d1681e |
diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c
|
|
|
d1681e |
index f46474b..868890f 100644
|
|
|
d1681e |
--- a/xlators/debug/io-stats/src/io-stats.c
|
|
|
d1681e |
+++ b/xlators/debug/io-stats/src/io-stats.c
|
|
|
d1681e |
@@ -45,6 +45,8 @@
|
|
|
d1681e |
#define DEFAULT_GRP_BUF_SZ 16384
|
|
|
d1681e |
#define IOS_BLOCK_COUNT_SIZE 32
|
|
|
d1681e |
|
|
|
d1681e |
+#define IOS_STATS_DUMP_DIR DEFAULT_VAR_RUN_DIRECTORY
|
|
|
d1681e |
+
|
|
|
d1681e |
typedef enum {
|
|
|
d1681e |
IOS_STATS_TYPE_NONE,
|
|
|
d1681e |
IOS_STATS_TYPE_OPEN,
|
|
|
d1681e |
@@ -3000,7 +3002,6 @@ io_stats_fsync (call_frame_t *frame, xlator_t *this,
|
|
|
d1681e |
return 0;
|
|
|
d1681e |
}
|
|
|
d1681e |
|
|
|
d1681e |
-
|
|
|
d1681e |
int
|
|
|
d1681e |
conditional_dump (dict_t *dict, char *key, data_t *value, void *data)
|
|
|
d1681e |
{
|
|
|
d1681e |
@@ -3016,6 +3017,7 @@ conditional_dump (dict_t *dict, char *key, data_t *value, void *data)
|
|
|
d1681e |
int pid, namelen;
|
|
|
d1681e |
char dump_key[100];
|
|
|
d1681e |
char *slash_ptr = NULL;
|
|
|
d1681e |
+ char *path_in_value = NULL;
|
|
|
d1681e |
|
|
|
d1681e |
stub = data;
|
|
|
d1681e |
this = stub->this;
|
|
|
d1681e |
@@ -3024,13 +3026,26 @@ conditional_dump (dict_t *dict, char *key, data_t *value, void *data)
|
|
|
d1681e |
name as well. This helps when there is more than a single io-stats
|
|
|
d1681e |
instance in the graph, or the client and server processes are running
|
|
|
d1681e |
on the same node */
|
|
|
d1681e |
- /* hmmm... no check for this */
|
|
|
d1681e |
- /* name format: <passed in path/filename>.<xlator name slashes to -> */
|
|
|
d1681e |
- namelen = value->len + strlen (this->name) + 2; /* '.' and '\0' */
|
|
|
d1681e |
+ /* For the sanity of where the file should be located, we should make
|
|
|
d1681e |
+ sure file is written only inside RUNDIR (ie, /var/run/gluster) */
|
|
|
d1681e |
+ /* TODO: provide an option to dump it to different directory of
|
|
|
d1681e |
+ choice, based on options */
|
|
|
d1681e |
+ /* name format: /var/run/gluster/<passed in path/filename>.<xlator name slashes to -> */
|
|
|
d1681e |
+
|
|
|
d1681e |
+ path_in_value = data_to_str (value);
|
|
|
d1681e |
+
|
|
|
d1681e |
+ if (strstr (path_in_value, "../")) {
|
|
|
d1681e |
+ gf_log (this->name, GF_LOG_ERROR,
|
|
|
d1681e |
+ "%s: no \"../\" allowed in path", path_in_value);
|
|
|
d1681e |
+ return -1;
|
|
|
d1681e |
+ }
|
|
|
d1681e |
+ namelen = (strlen (IOS_STATS_DUMP_DIR) + value->len +
|
|
|
d1681e |
+ strlen (this->name) + 2); /* '.' and '\0' */
|
|
|
d1681e |
+
|
|
|
d1681e |
filename = alloca0 (namelen);
|
|
|
d1681e |
- memcpy (filename, data_to_str (value), value->len);
|
|
|
d1681e |
- memcpy (filename + value->len, ".", 1);
|
|
|
d1681e |
- memcpy (filename + value->len + 1, this->name, strlen(this->name));
|
|
|
d1681e |
+
|
|
|
d1681e |
+ snprintf (filename, namelen, "%s%s.%s", IOS_STATS_DUMP_DIR,
|
|
|
d1681e |
+ path_in_value, this->name);
|
|
|
d1681e |
|
|
|
d1681e |
/* convert any slashes to '-' so that fopen works correctly */
|
|
|
d1681e |
slash_ptr = strchr (filename + value->len + 1, '/');
|
|
|
d1681e |
--
|
|
|
d1681e |
1.8.3.1
|
|
|
d1681e |
|