Bala.FA has posted comments on this change.
Change subject: gluster: Get size information of a gluster volume ......................................................................
Patch Set 14: Code-Review-1
Please use below code. This code uses libgfapi and working fine. I tested through vdsClient->vdsm->supervdsm->glfspy.so. Only thing is that glfspy_statvfs return value needs to be changed according to statvfs structure.
#include <Python.h>
#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <time.h> #include <sys/types.h> #include <sys/statvfs.h>
#include "api/glfs.h" #include "api/glfs-handles.h"
#define USAGE_ERROR -1 #define GLFS_NEW_FAILURE -2 #define GLFS_INIT_FAILURE -3 #define GLFS_STATVFS_FAILURE -4 #define GLFS_FINI_FAILURE -5 #define DEFAULT_TRANSPORT "tcp" #define DEFAULT_SERVER "127.0.0.1" #define DEFAULT_SERVER_PORT 24007
int get_volume_statvfs (const char *volume_name, const char *server_name, struct statvfs *buf) { glfs_t *fs = NULL; int ret = 0; struct statvfs statvfsinfo = {0, }; int rv = 0;
if (!(volume_name && buf)) { return USAGE_ERROR; }
fs = glfs_new (volume_name); if (!fs) { fprintf (stderr, "glfs_new: returned NULL\n"); return GLFS_NEW_FAILURE; }
if (server_name) { ret = glfs_set_volfile_server (fs, DEFAULT_TRANSPORT, server_name, DEFAULT_SERVER_PORT); } else { ret = glfs_set_volfile_server (fs, DEFAULT_TRANSPORT, DEFAULT_SERVER, DEFAULT_SERVER_PORT); }
ret = glfs_set_logging (fs, "/dev/null", 7);
ret = glfs_init (fs); if (ret != 0) { fprintf (stderr, "glfs_init() failed with code %d\n", ret); rv = GLFS_INIT_FAILURE; goto out; }
fprintf (stdout, "waiting for 3 seconds to initialize\n"); sleep (3);
ret = glfs_statvfs (fs, "/", &statvfsinfo); if (ret == 0) { *buf = statvfsinfo; } else { fprintf (stderr, "glfs_statvfs() failed with [%d:%s] for "/"\n", ret, strerror (errno)); rv = GLFS_STATVFS_FAILURE; }
out: ret = glfs_fini (fs); if (ret != 0) { fprintf (stderr, "glfs_fini() failed with code %d\n", ret); }
return rv; }
static PyObject *glfspy_statvfs (PyObject *self, PyObject *args) { char *volume_name = NULL; char *server_name = NULL; int port = 0; char *transport = NULL; struct statvfs buf = {0, }; int rv = 0;
if (!PyArg_ParseTuple (args, "s|ziz", &volume_name, &server_name, &port, &transport)) { return NULL; }
rv = get_volume_statvfs (volume_name, server_name, &buf);
return Py_BuildValue("i", rv); }
static PyMethodDef glfspy_methods[] = { { "statvfs", (PyCFunction)glfspy_statvfs, METH_VARARGS, NULL }, { NULL, NULL, 0, NULL } };
PyMODINIT_FUNC initglfspy () { Py_InitModule3 ("glfspy", glfspy_methods, "gluster gfapi top level extension module."); }