diff options
| -rw-r--r-- | libglusterfs/src/strfd.c | 107 | ||||
| -rw-r--r-- | libglusterfs/src/strfd.h | 10 | ||||
| -rwxr-xr-x | tests/basic/meta.t | 9 | ||||
| -rw-r--r-- | xlators/meta/src/cmdline-file.c | 15 | ||||
| -rw-r--r-- | xlators/meta/src/frames-file.c | 142 | ||||
| -rw-r--r-- | xlators/meta/src/version-file.c | 13 | 
6 files changed, 162 insertions, 134 deletions
diff --git a/libglusterfs/src/strfd.c b/libglusterfs/src/strfd.c index f5b7b94bfa1..3eda05c2dbc 100644 --- a/libglusterfs/src/strfd.c +++ b/libglusterfs/src/strfd.c @@ -20,83 +20,78 @@  #include "strfd.h"  #include "common-utils.h" -  strfd_t *  strfd_open ()  { -	strfd_t *strfd = NULL; +        strfd_t *strfd = NULL; -	strfd = GF_CALLOC(1, sizeof(*strfd), gf_common_mt_strfd_t); +        strfd = GF_CALLOC(1, sizeof(*strfd), gf_common_mt_strfd_t); -	return strfd; +        return strfd;  } -  int  strvprintf (strfd_t *strfd, const char *fmt, va_list ap)  { -	char *str = NULL; -	int size = 0; - -	size = vasprintf (&str, fmt, ap); - -	if (size < 0) -		return size; - -	if (!strfd->alloc_size) { -		strfd->data = GF_CALLOC (max(size + 1, 4096), 1, -					 gf_common_mt_strfd_data_t); -		if (!strfd->data) { -			free (str); /* NOT GF_FREE */ -			return -1; -		} -		strfd->alloc_size = max(size + 1, 4096); -	} - -	if (strfd->alloc_size <= (strfd->size + size)) { -		char *tmp_ptr = NULL; -		int new_size = max ((strfd->alloc_size * 2), -				    gf_roundup_next_power_of_two (strfd->size + size + 1)); -		tmp_ptr = GF_REALLOC (strfd->data, new_size); -		if (!tmp_ptr) { -			free (str); /* NOT GF_FREE */ -			return -1; -		} -		strfd->alloc_size = new_size; -		strfd->data = tmp_ptr; -	} - -	// Copy the trailing '\0', but do not account for it in ->size. -	// This allows safe use of strfd->data as a string. -	memcpy (strfd->data + strfd->size, str, size + 1); -	strfd->size += size; - -	free (str); /* NOT GF_FREE */ - -	return size; +        char *str = NULL; +        int size = 0; + +        size = vasprintf (&str, fmt, ap); + +        if (size < 0) +                return size; + +        if (!strfd->alloc_size) { +                strfd->data = GF_CALLOC (max(size + 1, 4096), 1, +                                         gf_common_mt_strfd_data_t); +                if (!strfd->data) { +                        free (str); /* NOT GF_FREE */ +                        return -1; +                } +                strfd->alloc_size = max(size + 1, 4096); +        } + +        if (strfd->alloc_size <= (strfd->size + size)) { +                char *tmp_ptr = NULL; +                int new_size = max ((strfd->alloc_size * 2), +                                    gf_roundup_next_power_of_two (strfd->size + size + 1)); +                tmp_ptr = GF_REALLOC (strfd->data, new_size); +                if (!tmp_ptr) { +                        free (str); /* NOT GF_FREE */ +                        return -1; +                } +                strfd->alloc_size = new_size; +                strfd->data = tmp_ptr; +        } + +        /* Copy the trailing '\0', but do not account for it in ->size. +           This allows safe use of strfd->data as a string. */ +        memcpy (strfd->data + strfd->size, str, size + 1); +        strfd->size += size; + +        free (str); /* NOT GF_FREE */ + +        return size;  } -  int  strprintf (strfd_t *strfd, const char *fmt, ...)  { -	int ret = 0; -	va_list ap; +        int ret = 0; +        va_list ap; -	va_start (ap, fmt); -	ret = strvprintf (strfd, fmt, ap); -	va_end (ap); +        va_start (ap, fmt); +        ret = strvprintf (strfd, fmt, ap); +        va_end (ap); -	return ret; +        return ret;  } -  int  strfd_close (strfd_t *strfd)  { -	GF_FREE (strfd->data); -	GF_FREE (strfd); +        GF_FREE (strfd->data); +        GF_FREE (strfd); -	return 0; +        return 0;  } - diff --git a/libglusterfs/src/strfd.h b/libglusterfs/src/strfd.h index a9e6eaa87bc..9084e235eef 100644 --- a/libglusterfs/src/strfd.h +++ b/libglusterfs/src/strfd.h @@ -12,16 +12,16 @@  #define _STRFD_H  typedef struct { -	void *data; -	size_t alloc_size; -	size_t size; -	off_t pos; +        void *data; +        size_t alloc_size; +        size_t size; +        off_t pos;  } strfd_t;  strfd_t *strfd_open();  int strprintf(strfd_t *strfd, const char *fmt, ...) -	__attribute__ ((__format__ (__printf__, 2, 3))); +        __attribute__ ((__format__ (__printf__, 2, 3)));  int strvprintf(strfd_t *strfd, const char *fmt, va_list ap); diff --git a/tests/basic/meta.t b/tests/basic/meta.t index baea27d3dff..7a810bcbc35 100755 --- a/tests/basic/meta.t +++ b/tests/basic/meta.t @@ -19,8 +19,13 @@ EXPECT 'Started' volinfo_field $V0 'Status';  TEST glusterfs -s $H0 --volfile-id $V0 $M0; -# the read() on frames file itself should be visible as a frame -TEST grep -q READ $M0/.meta/frames; +# verify json validity + +TEST /usr/bin/json_verify < $M0/.meta/frames; + +TEST /usr/bin/json_verify < $M0/.meta/cmdline; + +TEST /usr/bin/json_verify < $M0/.meta/version;  # default log level (INFO) is 7  TEST grep -q 7 $M0/.meta/logging/loglevel; diff --git a/xlators/meta/src/cmdline-file.c b/xlators/meta/src/cmdline-file.c index 1eded6d19b8..88411f2629b 100644 --- a/xlators/meta/src/cmdline-file.c +++ b/xlators/meta/src/cmdline-file.c @@ -26,22 +26,23 @@  static int  cmdline_file_fill (xlator_t *this, inode_t *file, strfd_t *strfd)  { -	if (this->ctx->cmdlinestr) -		strprintf (strfd, "%s\n", this->ctx->cmdlinestr); -	return strfd->size; +        if (this->ctx->cmdlinestr) +                strprintf (strfd, "{ \n  \"Cmdlinestr\": \"%s\"\n}", +                           this->ctx->cmdlinestr); +        return strfd->size;  }  static struct meta_ops cmdline_file_ops = { -	.file_fill = cmdline_file_fill, +        .file_fill = cmdline_file_fill,  };  int  meta_cmdline_file_hook (call_frame_t *frame, xlator_t *this, loc_t *loc, -			dict_t *xdata) +                        dict_t *xdata)  { -	meta_ops_set (loc->inode, this, &cmdline_file_ops); +        meta_ops_set (loc->inode, this, &cmdline_file_ops); -	return 0; +        return 0;  } diff --git a/xlators/meta/src/frames-file.c b/xlators/meta/src/frames-file.c index 0c3b9a2eb71..0e9777c9da2 100644 --- a/xlators/meta/src/frames-file.c +++ b/xlators/meta/src/frames-file.c @@ -22,75 +22,101 @@  #include "globals.h"  #include "lkowner.h" -  static int  frames_file_fill (xlator_t *this, inode_t *file, strfd_t *strfd)  { -	struct call_pool *pool = NULL; -	call_stack_t *stack = NULL; -	call_frame_t *frame = NULL; -	int i = 0; -	int j = 0; - -	pool = this->ctx->pool; - -	LOCK (&pool->lock); -	{ -		strprintf (strfd, "Call_Count: %d\n", (int)pool->cnt); - -		list_for_each_entry (stack, &pool->all_frames, all_frames) { -			strprintf (strfd, "== Stack %d ==\n", i++); -			strprintf (strfd, "Unique: %"PRId64"\n", stack->unique); -			strprintf (strfd, "Type: %s\n", gf_fop_list[stack->op]); -			strprintf (strfd, "UID: %d\n", stack->uid); -			strprintf (strfd, "GID: %d\n", stack->gid); -			strprintf (strfd, "LK_owner: %s\n", -				   lkowner_utoa (&stack->lk_owner)); - -			j = 0; -			for (frame = &stack->frames; frame; frame = frame->next) { -				strprintf (strfd, "\t-- Frame %d --\n", j++); -				strprintf (strfd, "\tXlator: %s\n", frame->this->name); -				if (frame->begin.tv_sec) -					strprintf (strfd, "\tCreation_time: %d.%d\n", -						   (int)frame->begin.tv_sec, -						   (int)frame->begin.tv_usec); -				strprintf (strfd, "\tRefcount: %d\n", frame->ref_count); -				strprintf (strfd, "\tComplete: %d\n", frame->complete); -				if (frame->parent) -					strprintf (strfd, "\tParent: %s\n", -						   frame->parent->this->name); -				if (frame->wind_from) -					strprintf (strfd, "\tWind_from: %s\n", -						   frame->wind_from); -				if (frame->wind_to) -					strprintf (strfd, "\tWind_to: %s\n", -						   frame->wind_to); -				if (frame->unwind_from) -					strprintf (strfd, "\tUnwind_from: %s\n", -						   frame->unwind_from); -				if (frame->unwind_to) -					strprintf (strfd, "\tUnwind_to: %s\n", -						   frame->unwind_to); -			} -		} -	} -	UNLOCK (&pool->lock); - -	return strfd->size; +        struct call_pool *pool = NULL; +        call_stack_t *stack = NULL; +        call_frame_t *frame = NULL; +        int i = 0; +        int j = 1; + +        if (!this || !file || !strfd) +                return -1; + +        pool = this->ctx->pool; + +        LOCK (&pool->lock); +        { +                strprintf (strfd, "{ \n\t\"Stack\": [\n"); +                list_for_each_entry (stack, &pool->all_frames, all_frames) { +                        strprintf (strfd, "\t   {\n"); +                        strprintf (strfd, "\t\t\"Number\": %d,\n", ++i); +                        strprintf (strfd, "\t\t\"Frame\": [\n"); +                        j = 1; +                        for (frame = &stack->frames; frame; +                             frame = frame->next) { +                                strprintf (strfd, "\t\t   {\n"); +                                strprintf (strfd, "\t\t\t\"Number\": %d,\n", +                                                j++); +                                strprintf (strfd, +                                                "\t\t\t\"Xlator\": \"%s\",\n", +                                                frame->this->name); +                                if (frame->begin.tv_sec) +                                        strprintf (strfd, +                                                        "\t\t\t\"Creation_time\": %d.%d,\n", +                                                        (int)frame->begin.tv_sec, +                                                        (int)frame->begin.tv_usec); +                                strprintf (strfd, " \t\t\t\"Refcount\": %d,\n", +                                                frame->ref_count); +                                if (frame->parent) +                                        strprintf (strfd, "\t\t\t\"Parent\": \"%s\",\n", +                                                        frame->parent->this->name); +                                if (frame->wind_from) +                                        strprintf (strfd, "\t\t\t\"Wind_from\": \"%s\",\n", +                                                        frame->wind_from); +                                if (frame->wind_to) +                                        strprintf (strfd, "\t\t\t\"Wind_to\": \"%s\",\n", +                                                        frame->wind_to); +                                if (frame->unwind_from) +                                        strprintf (strfd, "\t\t\t\"Unwind_from\": \"%s\",\n", +                                                        frame->unwind_from); +                                if (frame->unwind_to) +                                        strprintf (strfd, "\t\t\t\"Unwind_to\": \"%s\",\n", +                                                        frame->unwind_to); +                                strprintf (strfd, "\t\t\t\"Complete\": %d\n", +                                                frame->complete); +                                if (frame->next == NULL) +                                        strprintf (strfd, "\t\t   }\n"); +                                else +                                        strprintf (strfd, "\t\t   },\n"); +                        } +                        strprintf (strfd, "\t\t],\n"); +                        strprintf (strfd, "\t\t\"Unique\": %"PRId64",\n", +                                        stack->unique); +                        strprintf (strfd, "\t\t\"Type\": \"%s\",\n", +                                        gf_fop_list[stack->op]); +                        strprintf (strfd, "\t\t\"UID\": %d,\n", +                                        stack->uid); +                        strprintf (strfd, "\t\t\"GID\": %d,\n", +                                        stack->gid); +                        strprintf (strfd, "\t\t\"LK_owner\": \"%s\"\n", +                                        lkowner_utoa (&stack->lk_owner)); +                        if (i == (int)pool->cnt) +                                strprintf (strfd, "\t   }\n"); +                        else +                                strprintf (strfd, "\t   },\n"); +                } +                strprintf (strfd, "\t],\n"); +                strprintf (strfd, "\t\"Call_Count\": %d\n", +                                (int)pool->cnt); +                strprintf (strfd, "}"); +        } +        UNLOCK (&pool->lock); + +        return strfd->size;  }  static struct meta_ops frames_file_ops = { -	.file_fill = frames_file_fill, +        .file_fill = frames_file_fill,  };  int  meta_frames_file_hook (call_frame_t *frame, xlator_t *this, loc_t *loc, -		       dict_t *xdata) +                       dict_t *xdata)  { -	meta_ops_set (loc->inode, this, &frames_file_ops); - -	return 0; +        meta_ops_set (loc->inode, this, &frames_file_ops); +        return 0;  } diff --git a/xlators/meta/src/version-file.c b/xlators/meta/src/version-file.c index 77f2dea3d66..c402453ee96 100644 --- a/xlators/meta/src/version-file.c +++ b/xlators/meta/src/version-file.c @@ -26,21 +26,22 @@  static int  version_file_fill (xlator_t *this, inode_t *file, strfd_t *strfd)  { -	strprintf (strfd, "%s\n", PACKAGE_VERSION); -	return strfd->size; +        strprintf (strfd, "{ \n  \"Package Version\": \"%s\"\n}", +                   PACKAGE_VERSION); +        return strfd->size;  }  static struct meta_ops version_file_ops = { -	.file_fill = version_file_fill, +        .file_fill = version_file_fill,  };  int  meta_version_file_hook (call_frame_t *frame, xlator_t *this, loc_t *loc, -			dict_t *xdata) +                        dict_t *xdata)  { -	meta_ops_set (loc->inode, this, &version_file_ops); +        meta_ops_set (loc->inode, this, &version_file_ops); -	return 0; +        return 0;  }  | 
