From 1fbffa0aa45560889e29a74c4c6ff16d526de700 Mon Sep 17 00:00:00 2001 From: Jeff Darcy Date: Tue, 4 Mar 2014 16:53:33 +0000 Subject: api: add glfs_get_volfile From the API-header description: > Sometimes it's useful e.g. for scripts to see the volfile, so that > they can parse it and find subvolumes to do things like split-brain > resolution or custom layouts. The API here was specifically intended > to make access e.g. from Python as simple as possible. > > Note that the volume must be started (not necessarily mounted) for > this to work. Change-Id: If3f55ee9611cdf4b77aa53659f0af0d21957817d Signed-off-by: Jeff Darcy Reviewed-on: http://review.gluster.org/7183 Reviewed-by: Anand Avati Tested-by: Gluster Build System --- api/src/glfs-mgmt.c | 4 ++++ api/src/glfs.c | 20 ++++++++++++++++++++ api/src/glfs.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) (limited to 'api/src') diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c index afb351da03a..7f62fa259af 100644 --- a/api/src/glfs-mgmt.c +++ b/api/src/glfs-mgmt.c @@ -207,6 +207,8 @@ glusterfs_oldvolfile_update (struct glfs *fs, char *volfile, ssize_t size) { int ret = -1; + pthread_mutex_lock (&fs->mutex); + fs->oldvollen = size; if (!fs->oldvolfile) { fs->oldvolfile = GF_CALLOC (1, size+1, glfs_mt_volfile_t); @@ -222,6 +224,8 @@ glusterfs_oldvolfile_update (struct glfs *fs, char *volfile, ssize_t size) ret = 0; } + pthread_mutex_unlock (&fs->mutex); + return ret; } diff --git a/api/src/glfs.c b/api/src/glfs.c index ea10fb55c65..9e9a55ccb65 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -680,3 +680,23 @@ glfs_fini (struct glfs *fs) return ret; } + +ssize_t +glfs_get_volfile (struct glfs *fs, void *buf, size_t len) +{ + ssize_t res; + + glfs_lock(fs); + if (len >= fs->oldvollen) { + gf_log ("glfs", GF_LOG_TRACE, "copying %lu to %p", len, buf); + memcpy(buf,fs->oldvolfile,len); + res = len; + } + else { + res = len - fs->oldvollen; + gf_log ("glfs", GF_LOG_TRACE, "buffer is %ld too short", -res); + } + glfs_unlock(fs); + + return res; +} diff --git a/api/src/glfs.h b/api/src/glfs.h index 20fb18c9ecf..af6b4899037 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -252,6 +252,36 @@ int glfs_init (glfs_t *fs) __THROW; int glfs_fini (glfs_t *fs) __THROW; +/* + SYNOPSIS + + glfs_getvol: Get the volfile associated with a 'virtual mount' + + DESCRIPTION + + Sometimes it's useful e.g. for scripts to see the volfile, so that they + can parse it and find subvolumes to do things like split-brain resolution + or custom layouts. The API here was specifically intended to make access + e.g. from Python as simple as possible. + + Note that the volume must be started (not necessarily mounted) for this + to work. + + PARAMETERS + + @fs: The 'virtual mount' object for which a volfile is desired + @buf: Pointer to a place for the volfile length to be stored + @len: Length of @buf + + RETURN VALUES + + >0: filled N bytes of buffer + 0: no volfile available + <0: volfile length exceeds @len by N bytes (@buf unchanged) +*/ + +ssize_t glfs_get_volfile (glfs_t *fs, void *buf, size_t len) __THROW; + /* * FILE OPERATION * -- cgit