diff options
author | Jeff Darcy <jdarcy@redhat.com> | 2014-03-24 20:44:07 +0000 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2014-03-24 20:44:07 +0000 |
commit | efbb23837761bda6c526baca1b5ea72d227e2ae3 (patch) | |
tree | 728199c73595103d7561dd9d441bdbe1845c6331 /api | |
parent | a58b023443b7a2ec089c45bf35bde2b0108aa19b (diff) | |
parent | 17454dfea9f3c4d47fcf0b5370a6155f639c8aeb (diff) |
Merge branch 'upstream'
Diffstat (limited to 'api')
-rwxr-xr-x | api/examples/getvolfile.py | 43 | ||||
-rw-r--r-- | api/examples/glfsxmp.c | 8 | ||||
-rw-r--r-- | api/src/glfs-handleops.c | 2 | ||||
-rw-r--r-- | api/src/glfs-mgmt.c | 4 | ||||
-rw-r--r-- | api/src/glfs.c | 20 | ||||
-rw-r--r-- | api/src/glfs.h | 30 |
6 files changed, 102 insertions, 5 deletions
diff --git a/api/examples/getvolfile.py b/api/examples/getvolfile.py new file mode 100755 index 000000000..82d9db055 --- /dev/null +++ b/api/examples/getvolfile.py @@ -0,0 +1,43 @@ +#!/usr/bin/python + +import ctypes +import ctypes.util + +api = ctypes.CDLL(ctypes.util.find_library("gfapi")) +api.glfs_get_volfile.argtypes = [ctypes.c_void_p, + ctypes.c_void_p, + ctypes.c_ulong] +api.glfs_get_volfile.restype = ctypes.c_long; + +def get_volfile (host, volume): + # This is set to a large value to exercise the "buffer not big enough" + # path. More realistically, you'd just start with a huge buffer. + BUF_LEN = 0 + fs = api.glfs_new(volume) + #api.glfs_set_logging(fs,"/dev/stderr",7) + api.glfs_set_volfile_server(fs,"tcp",host,24007) + api.glfs_init(fs) + vbuf = ctypes.create_string_buffer(BUF_LEN) + vlen = api.glfs_get_volfile(fs,vbuf,BUF_LEN) + if vlen < 0: + vlen = BUF_LEN - vlen + vbuf = ctypes.create_string_buffer(vlen) + vlen = api.glfs_get_volfile(fs,vbuf,vlen) + api.glfs_fini(fs) + if vlen <= 0: + return vlen + return vbuf.value[:vlen] + +if __name__ == "__main__": + import sys + + try: + res = apply(get_volfile,sys.argv[1:3]) + except: + print "fetching volfile failed (volume not started?)" + + try: + for line in res.split('\n'): + print line + except: + print "bad return value %s" % res diff --git a/api/examples/glfsxmp.c b/api/examples/glfsxmp.c index 600d72fb5..7180a997f 100644 --- a/api/examples/glfsxmp.c +++ b/api/examples/glfsxmp.c @@ -293,19 +293,19 @@ test_h_unlink (void) goto out; } - /* unlink non-existant regular file */ + /* unlink non-existent regular file */ ret = glfs_h_unlink (fs, dir, my_file); if ((ret && errno != ENOENT) || (ret == 0)) { - fprintf (stderr, "glfs_h_unlink: error unlinking non-existant %s: invalid errno ,%d, %s\n", + fprintf (stderr, "glfs_h_unlink: error unlinking non-existent %s: invalid errno ,%d, %s\n", my_file, ret, strerror (errno)); printf ("glfs_h_unlink tests: FAILED\n"); goto out; } - /* unlink non-existant directory */ + /* unlink non-existent directory */ ret = glfs_h_unlink (fs, dir, my_subdir); if ((ret && errno != ENOENT) || (ret == 0)) { - fprintf (stderr, "glfs_h_unlink: error unlinking non-existant %s: invalid errno ,%d, %s\n", + fprintf (stderr, "glfs_h_unlink: error unlinking non-existent %s: invalid errno ,%d, %s\n", my_subdir, ret, strerror (errno)); printf ("glfs_h_unlink tests: FAILED\n"); goto out; diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c index 14d6c1b2c..65642697e 100644 --- a/api/src/glfs-handleops.c +++ b/api/src/glfs-handleops.c @@ -1316,7 +1316,7 @@ glfs_h_rename_with_xdata (struct glfs *fs, struct glfs_object *olddir, const cha * or both must be non-dirs. Else, fail. */ ret = -1; - errno = EISDIR; + errno = EEXIST; goto out; } } diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c index afb351da0..7f62fa259 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 ea10fb55c..9e9a55ccb 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 9feaa8015..7fef3a873 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -253,6 +253,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 * * What follows are filesystem operations performed on the |