dynamic volume changes for graph replacement
Signed-off-by: Anand V. Avati <avati@blackhole.gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 971 (dynamic volume management) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=971
This commit is contained in:
parent
c4ebd25a17
commit
79241696fb
@ -34,6 +34,8 @@
|
|||||||
#include "defaults.h"
|
#include "defaults.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
int glusterfs_graph_parent_up (xlator_t *graph);
|
int glusterfs_graph_parent_up (xlator_t *graph);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -297,3 +299,5 @@ fetch_spec (glusterfs_ctx_t *ctx)
|
|||||||
|
|
||||||
return spec_fp;
|
return spec_fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -25,8 +25,8 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEFAULT_CLIENT_VOLUME_FILE CONFDIR "/glusterfs.vol"
|
#define DEFAULT_CLIENT_VOLFILE CONFDIR "/glusterfs.vol"
|
||||||
#define DEFAULT_SERVER_VOLUME_FILE CONFDIR "/glusterfsd.vol"
|
#define DEFAULT_SERVER_VOLFILE CONFDIR "/glusterfsd.vol"
|
||||||
#define DEFAULT_LOG_FILE_DIRECTORY DATADIR "/log/glusterfs"
|
#define DEFAULT_LOG_FILE_DIRECTORY DATADIR "/log/glusterfs"
|
||||||
#define DEFAULT_LOG_LEVEL GF_LOG_NORMAL
|
#define DEFAULT_LOG_LEVEL GF_LOG_NORMAL
|
||||||
|
|
||||||
@ -54,26 +54,26 @@
|
|||||||
#define ZR_DUMP_FUSE "dump-fuse"
|
#define ZR_DUMP_FUSE "dump-fuse"
|
||||||
|
|
||||||
enum argp_option_keys {
|
enum argp_option_keys {
|
||||||
ARGP_VOLFILE_SERVER_KEY = 's',
|
ARGP_VOLFILE_SERVER_KEY = 's',
|
||||||
ARGP_VOLUME_FILE_KEY = 'f',
|
ARGP_VOLUME_FILE_KEY = 'f',
|
||||||
ARGP_LOG_LEVEL_KEY = 'L',
|
ARGP_LOG_LEVEL_KEY = 'L',
|
||||||
ARGP_LOG_FILE_KEY = 'l',
|
ARGP_LOG_FILE_KEY = 'l',
|
||||||
ARGP_VOLFILE_SERVER_PORT_KEY = 131,
|
ARGP_VOLFILE_SERVER_PORT_KEY = 131,
|
||||||
ARGP_VOLFILE_SERVER_TRANSPORT_KEY = 132,
|
ARGP_VOLFILE_SERVER_TRANSPORT_KEY = 132,
|
||||||
ARGP_PID_FILE_KEY = 'p',
|
ARGP_PID_FILE_KEY = 'p',
|
||||||
ARGP_NO_DAEMON_KEY = 'N',
|
ARGP_NO_DAEMON_KEY = 'N',
|
||||||
ARGP_RUN_ID_KEY = 'r',
|
ARGP_RUN_ID_KEY = 'r',
|
||||||
ARGP_DEBUG_KEY = 133,
|
ARGP_DEBUG_KEY = 133,
|
||||||
ARGP_DISABLE_DIRECT_IO_MODE_KEY = 134,
|
ARGP_DISABLE_DIRECT_IO_MODE_KEY = 134,
|
||||||
ARGP_ENTRY_TIMEOUT_KEY = 135,
|
ARGP_ENTRY_TIMEOUT_KEY = 135,
|
||||||
ARGP_ATTRIBUTE_TIMEOUT_KEY = 136,
|
ARGP_ATTRIBUTE_TIMEOUT_KEY = 136,
|
||||||
ARGP_VOLUME_NAME_KEY = 137,
|
ARGP_VOLUME_NAME_KEY = 137,
|
||||||
ARGP_XLATOR_OPTION_KEY = 138,
|
ARGP_XLATOR_OPTION_KEY = 138,
|
||||||
ARGP_ENABLE_DIRECT_IO_MODE_KEY = 139,
|
ARGP_ENABLE_DIRECT_IO_MODE_KEY = 139,
|
||||||
#ifdef GF_DARWIN_HOST_OS
|
#ifdef GF_DARWIN_HOST_OS
|
||||||
ARGP_NON_LOCAL_KEY = 140,
|
ARGP_NON_LOCAL_KEY = 140,
|
||||||
#endif /* DARWIN */
|
#endif /* DARWIN */
|
||||||
ARGP_VOLFILE_ID_KEY = 143,
|
ARGP_VOLFILE_ID_KEY = 143,
|
||||||
ARGP_VOLFILE_CHECK_KEY = 144,
|
ARGP_VOLFILE_CHECK_KEY = 144,
|
||||||
ARGP_VOLFILE_MAX_FETCH_ATTEMPTS = 145,
|
ARGP_VOLFILE_MAX_FETCH_ATTEMPTS = 145,
|
||||||
ARGP_LOG_SERVER_KEY = 146,
|
ARGP_LOG_SERVER_KEY = 146,
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
libglusterfs_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS)
|
libglusterfs_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS)
|
||||||
|
|
||||||
libglusterfs_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" -D$(GF_HOST_OS) -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\" -I$(CONTRIBDIR)/rbtree -DSCHEDULERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/scheduler\"
|
libglusterfs_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" -D$(GF_HOST_OS) -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\" -I$(CONTRIBDIR)/rbtree -DSCHEDULERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/scheduler\" -I$(CONTRIBDIR)/md5
|
||||||
|
|
||||||
libglusterfs_la_LIBADD = @LEXLIB@
|
libglusterfs_la_LIBADD = @LEXLIB@
|
||||||
|
|
||||||
lib_LTLIBRARIES = libglusterfs.la
|
lib_LTLIBRARIES = libglusterfs.la
|
||||||
|
|
||||||
libglusterfs_la_SOURCES = dict.c spec.lex.c y.tab.c xlator.c logging.c hashfn.c defaults.c common-utils.c timer.c inode.c call-stub.c compat.c fd.c compat-errno.c event.c mem-pool.c gf-dirent.c syscall.c iobuf.c globals.c statedump.c stack.c checksum.c md5.c $(CONTRIBDIR)/rbtree/rb.c rbthash.c latency.c
|
libglusterfs_la_SOURCES = dict.c graph.lex.c y.tab.c xlator.c logging.c hashfn.c defaults.c common-utils.c timer.c inode.c call-stub.c compat.c fd.c compat-errno.c event.c mem-pool.c gf-dirent.c syscall.c iobuf.c globals.c statedump.c stack.c checksum.c $(CONTRIBDIR)/md5/md5.c $(CONTRIBDIR)/rbtree/rb.c rbthash.c latency.c graph.c
|
||||||
|
|
||||||
noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h logging.h xlator.h stack.h timer.h list.h inode.h call-stub.h compat.h fd.h revision.h compat-errno.h event.h mem-pool.h byte-order.h gf-dirent.h locking.h syscall.h iobuf.h globals.h statedump.h checksum.h md5.h $(CONTRIBDIR)/rbtree/rb.h rbthash.h iatt.h latency.h
|
noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h logging.h xlator.h stack.h timer.h list.h inode.h call-stub.h compat.h fd.h revision.h compat-errno.h event.h mem-pool.h byte-order.h gf-dirent.h locking.h syscall.h iobuf.h globals.h statedump.h checksum.h $(CONTRIBDIR)/md5/md5.h $(CONTRIBDIR)/rbtree/rb.h rbthash.h iatt.h latency.h
|
||||||
|
|
||||||
EXTRA_DIST = spec.l spec.y
|
EXTRA_DIST = graph.l graph.y
|
||||||
|
|
||||||
spec.lex.c: spec.l y.tab.h
|
graph.lex.c: graph.l y.tab.h
|
||||||
$(LEX) -t $(srcdir)/spec.l > $@
|
$(LEX) -t $(srcdir)/graph.l > $@
|
||||||
|
|
||||||
y.tab.c y.tab.h: spec.y
|
y.tab.c y.tab.h: graph.y
|
||||||
$(YACC) -d $(srcdir)/spec.y
|
$(YACC) -d $(srcdir)/graph.y
|
||||||
|
|
||||||
CLEANFILES = spec.lex.c y.tab.c y.tab.h
|
CLEANFILES = graph.lex.c y.tab.c y.tab.h
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
|
|
||||||
typedef int32_t (*rw_op_t)(int32_t fd, char *buf, int32_t size);
|
typedef int32_t (*rw_op_t)(int32_t fd, char *buf, int32_t size);
|
||||||
typedef int32_t (*rwv_op_t)(int32_t fd, const struct iovec *buf, int32_t size);
|
typedef int32_t (*rwv_op_t)(int32_t fd, const struct iovec *buf, int32_t size);
|
||||||
static glusterfs_ctx_t *gf_global_ctx;
|
|
||||||
|
|
||||||
|
|
||||||
struct dnscache6 {
|
struct dnscache6 {
|
||||||
@ -179,85 +178,6 @@ err:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *gf_fop_list[GF_FOP_MAXVALUE];
|
|
||||||
char *gf_mgmt_list[GF_MGMT_MAXVALUE];
|
|
||||||
|
|
||||||
void
|
|
||||||
gf_global_variable_init()
|
|
||||||
{
|
|
||||||
gf_fop_list[GF_FOP_NULL] = "NULL";
|
|
||||||
gf_fop_list[GF_FOP_STAT] = "STAT";
|
|
||||||
gf_fop_list[GF_FOP_READLINK] = "READLINK";
|
|
||||||
gf_fop_list[GF_FOP_MKNOD] = "MKNOD";
|
|
||||||
gf_fop_list[GF_FOP_MKDIR] = "MKDIR";
|
|
||||||
gf_fop_list[GF_FOP_UNLINK] = "UNLINK";
|
|
||||||
gf_fop_list[GF_FOP_RMDIR] = "RMDIR";
|
|
||||||
gf_fop_list[GF_FOP_SYMLINK] = "SYMLINK";
|
|
||||||
gf_fop_list[GF_FOP_RENAME] = "RENAME";
|
|
||||||
gf_fop_list[GF_FOP_LINK] = "LINK";
|
|
||||||
gf_fop_list[GF_FOP_TRUNCATE] = "TRUNCATE";
|
|
||||||
gf_fop_list[GF_FOP_OPEN] = "OPEN";
|
|
||||||
gf_fop_list[GF_FOP_READ] = "READ";
|
|
||||||
gf_fop_list[GF_FOP_WRITE] = "WRITE";
|
|
||||||
gf_fop_list[GF_FOP_STATFS] = "STATFS";
|
|
||||||
gf_fop_list[GF_FOP_FLUSH] = "FLUSH";
|
|
||||||
gf_fop_list[GF_FOP_FSYNC] = "FSYNC";
|
|
||||||
gf_fop_list[GF_FOP_SETXATTR] = "SETXATTR";
|
|
||||||
gf_fop_list[GF_FOP_GETXATTR] = "GETXATTR";
|
|
||||||
gf_fop_list[GF_FOP_REMOVEXATTR] = "REMOVEXATTR";
|
|
||||||
gf_fop_list[GF_FOP_OPENDIR] = "OPENDIR";
|
|
||||||
gf_fop_list[GF_FOP_FSYNCDIR] = "FSYNCDIR";
|
|
||||||
gf_fop_list[GF_FOP_ACCESS] = "ACCESS";
|
|
||||||
gf_fop_list[GF_FOP_CREATE] = "CREATE";
|
|
||||||
gf_fop_list[GF_FOP_FTRUNCATE] = "FTRUNCATE";
|
|
||||||
gf_fop_list[GF_FOP_FSTAT] = "FSTAT";
|
|
||||||
gf_fop_list[GF_FOP_LK] = "LK";
|
|
||||||
gf_fop_list[GF_FOP_LOOKUP] = "LOOKUP";
|
|
||||||
gf_fop_list[GF_FOP_READDIR] = "READDIR";
|
|
||||||
gf_fop_list[GF_FOP_INODELK] = "INODELK";
|
|
||||||
gf_fop_list[GF_FOP_FINODELK] = "FINODELK";
|
|
||||||
gf_fop_list[GF_FOP_ENTRYLK] = "ENTRYLK";
|
|
||||||
gf_fop_list[GF_FOP_FENTRYLK] = "FENTRYLK";
|
|
||||||
gf_fop_list[GF_FOP_CHECKSUM] = "CHECKSUM";
|
|
||||||
gf_fop_list[GF_FOP_XATTROP] = "XATTROP";
|
|
||||||
gf_fop_list[GF_FOP_FXATTROP] = "FXATTROP";
|
|
||||||
gf_fop_list[GF_FOP_FSETXATTR] = "FSETXATTR";
|
|
||||||
gf_fop_list[GF_FOP_FGETXATTR] = "FGETXATTR";
|
|
||||||
gf_fop_list[GF_FOP_RCHECKSUM] = "RCHECKSUM";
|
|
||||||
gf_fop_list[GF_FOP_SETATTR] = "SETATTR";
|
|
||||||
gf_fop_list[GF_FOP_FSETATTR] = "FSETATTR";
|
|
||||||
gf_fop_list[GF_FOP_READDIRP] = "READDIRP";
|
|
||||||
gf_fop_list[GF_FOP_GETSPEC] = "GETSPEC";
|
|
||||||
gf_fop_list[GF_FOP_FORGET] = "FORGET";
|
|
||||||
gf_fop_list[GF_FOP_RELEASE] = "RELEASE";
|
|
||||||
gf_fop_list[GF_FOP_RELEASEDIR] = "RELEASEDIR";
|
|
||||||
|
|
||||||
gf_fop_list[GF_MGMT_NULL] = "NULL";
|
|
||||||
|
|
||||||
/* Are there any more variables to be included? All global
|
|
||||||
variables initialization should go here */
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
set_global_ctx_ptr (glusterfs_ctx_t *ctx)
|
|
||||||
{
|
|
||||||
gf_global_ctx = ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Don't use this function other than in glusterfsd.c. libglusterfsclient does
|
|
||||||
* not set gf_global_ctx since there can be multiple glusterfs-contexts
|
|
||||||
* initialized in a single process. Instead access the context from ctx member
|
|
||||||
* of the xlator object.
|
|
||||||
*/
|
|
||||||
|
|
||||||
glusterfs_ctx_t *
|
|
||||||
get_global_ctx_ptr (void)
|
|
||||||
{
|
|
||||||
return gf_global_ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gf_log_volume_file (FILE *specfp)
|
gf_log_volume_file (FILE *specfp)
|
||||||
@ -397,8 +317,7 @@ gf_print_trace (int32_t signum)
|
|||||||
/* Pending frames, (if any), list them in order */
|
/* Pending frames, (if any), list them in order */
|
||||||
ret = write (fd, "pending frames:\n", 16);
|
ret = write (fd, "pending frames:\n", 16);
|
||||||
{
|
{
|
||||||
extern glusterfs_ctx_t *gf_global_ctx;
|
glusterfs_ctx_t *ctx = glusterfs_ctx_get ();
|
||||||
glusterfs_ctx_t *ctx = gf_global_ctx;
|
|
||||||
struct list_head *trav = ((call_pool_t *)ctx->pool)->all_frames.next;
|
struct list_head *trav = ((call_pool_t *)ctx->pool)->all_frames.next;
|
||||||
while (trav != (&((call_pool_t *)ctx->pool)->all_frames)) {
|
while (trav != (&((call_pool_t *)ctx->pool)->all_frames)) {
|
||||||
call_frame_t *tmp = (call_frame_t *)(&((call_stack_t *)trav)->frames);
|
call_frame_t *tmp = (call_frame_t *)(&((call_stack_t *)trav)->frames);
|
||||||
|
@ -82,8 +82,6 @@ enum _gf_boolean
|
|||||||
typedef enum _gf_boolean gf_boolean_t;
|
typedef enum _gf_boolean gf_boolean_t;
|
||||||
|
|
||||||
void gf_global_variable_init(void);
|
void gf_global_variable_init(void);
|
||||||
void set_global_ctx_ptr (glusterfs_ctx_t *ctx);
|
|
||||||
glusterfs_ctx_t *get_global_ctx_ptr (void);
|
|
||||||
|
|
||||||
in_addr_t gf_resolve_ip (const char *hostname, void **dnscache);
|
in_addr_t gf_resolve_ip (const char *hostname, void **dnscache);
|
||||||
|
|
||||||
|
@ -30,17 +30,18 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static uint32_t
|
static int
|
||||||
gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr);
|
gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr);
|
||||||
|
|
||||||
|
|
||||||
static fd_t *
|
static fd_t *
|
||||||
_fd_ref (fd_t *fd);
|
_fd_ref (fd_t *fd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Allocate in memory chunks of power of 2 starting from 1024B
|
Allocate in memory chunks of power of 2 starting from 1024B
|
||||||
Assumes fdtable->lock is held
|
Assumes fdtable->lock is held
|
||||||
*/
|
*/
|
||||||
static inline uint32_t
|
static inline int
|
||||||
gf_roundup_power_of_two (uint32_t nr)
|
gf_roundup_power_of_two (uint32_t nr)
|
||||||
{
|
{
|
||||||
uint32_t result = 1;
|
uint32_t result = 1;
|
||||||
@ -58,6 +59,7 @@ gf_roundup_power_of_two (uint32_t nr)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
gf_fd_chain_fd_entries (fdentry_t *entries, uint32_t startidx,
|
gf_fd_chain_fd_entries (fdentry_t *entries, uint32_t startidx,
|
||||||
uint32_t endcount)
|
uint32_t endcount)
|
||||||
@ -80,18 +82,17 @@ gf_fd_chain_fd_entries (fdentry_t *entries, uint32_t startidx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint32_t
|
static int
|
||||||
gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr)
|
gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr)
|
||||||
{
|
{
|
||||||
fdentry_t *oldfds = NULL;
|
fdentry_t *oldfds = NULL;
|
||||||
uint32_t oldmax_fds = -1;
|
uint32_t oldmax_fds = -1;
|
||||||
|
|
||||||
if (fdtable == NULL || nr < 0)
|
if (fdtable == NULL || nr < 0) {
|
||||||
{
|
|
||||||
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
nr /= (1024 / sizeof (fdentry_t));
|
nr /= (1024 / sizeof (fdentry_t));
|
||||||
nr = gf_roundup_power_of_two (nr + 1);
|
nr = gf_roundup_power_of_two (nr + 1);
|
||||||
nr *= (1024 / sizeof (fdentry_t));
|
nr *= (1024 / sizeof (fdentry_t));
|
||||||
@ -102,7 +103,7 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr)
|
|||||||
fdtable->fdentries = GF_CALLOC (nr, sizeof (fdentry_t),
|
fdtable->fdentries = GF_CALLOC (nr, sizeof (fdentry_t),
|
||||||
gf_common_mt_fdentry_t);
|
gf_common_mt_fdentry_t);
|
||||||
ERR_ABORT (fdtable->fdentries);
|
ERR_ABORT (fdtable->fdentries);
|
||||||
fdtable->max_fds = nr;
|
fdtable->max_fds = nr;
|
||||||
|
|
||||||
if (oldfds) {
|
if (oldfds) {
|
||||||
uint32_t cpy = oldmax_fds * sizeof (fdentry_t);
|
uint32_t cpy = oldmax_fds * sizeof (fdentry_t);
|
||||||
@ -121,8 +122,9 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fdtable_t *
|
fdtable_t *
|
||||||
gf_fd_fdtable_alloc (void)
|
gf_fd_fdtable_alloc (void)
|
||||||
{
|
{
|
||||||
fdtable_t *fdtable = NULL;
|
fdtable_t *fdtable = NULL;
|
||||||
|
|
||||||
@ -141,6 +143,7 @@ gf_fd_fdtable_alloc (void)
|
|||||||
return fdtable;
|
return fdtable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fdentry_t *
|
fdentry_t *
|
||||||
__gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count)
|
__gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count)
|
||||||
{
|
{
|
||||||
@ -160,10 +163,12 @@ out:
|
|||||||
return fdentries;
|
return fdentries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fdentry_t *
|
fdentry_t *
|
||||||
gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count)
|
gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count)
|
||||||
{
|
{
|
||||||
fdentry_t *entries = NULL;
|
fdentry_t *entries = NULL;
|
||||||
|
|
||||||
if (fdtable) {
|
if (fdtable) {
|
||||||
pthread_mutex_lock (&fdtable->lock);
|
pthread_mutex_lock (&fdtable->lock);
|
||||||
{
|
{
|
||||||
@ -175,14 +180,15 @@ gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count)
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
|
void
|
||||||
gf_fd_fdtable_destroy (fdtable_t *fdtable)
|
gf_fd_fdtable_destroy (fdtable_t *fdtable)
|
||||||
{
|
{
|
||||||
struct list_head list = {0, };
|
struct list_head list = {0, };
|
||||||
fd_t *fd = NULL;
|
fd_t *fd = NULL;
|
||||||
fdentry_t *fdentries = NULL;
|
fdentry_t *fdentries = NULL;
|
||||||
uint32_t fd_count = 0;
|
uint32_t fd_count = 0;
|
||||||
int32_t i = 0;
|
int32_t i = 0;
|
||||||
|
|
||||||
INIT_LIST_HEAD (&list);
|
INIT_LIST_HEAD (&list);
|
||||||
|
|
||||||
@ -210,20 +216,21 @@ gf_fd_fdtable_destroy (fdtable_t *fdtable)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t
|
|
||||||
|
int
|
||||||
gf_fd_unused_get (fdtable_t *fdtable, fd_t *fdptr)
|
gf_fd_unused_get (fdtable_t *fdtable, fd_t *fdptr)
|
||||||
{
|
{
|
||||||
int32_t fd = -1;
|
int32_t fd = -1;
|
||||||
fdentry_t *fde = NULL;
|
fdentry_t *fde = NULL;
|
||||||
int error;
|
int error;
|
||||||
int alloc_attempts = 0;
|
int alloc_attempts = 0;
|
||||||
|
|
||||||
if (fdtable == NULL || fdptr == NULL)
|
if (fdtable == NULL || fdptr == NULL)
|
||||||
{
|
{
|
||||||
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock (&fdtable->lock);
|
pthread_mutex_lock (&fdtable->lock);
|
||||||
{
|
{
|
||||||
fd_alloc_try_again:
|
fd_alloc_try_again:
|
||||||
@ -268,20 +275,18 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
gf_fd_put (fdtable_t *fdtable, int32_t fd)
|
gf_fd_put (fdtable_t *fdtable, int32_t fd)
|
||||||
{
|
{
|
||||||
fd_t *fdptr = NULL;
|
fd_t *fdptr = NULL;
|
||||||
fdentry_t *fde = NULL;
|
fdentry_t *fde = NULL;
|
||||||
|
|
||||||
if (fdtable == NULL || fd < 0)
|
if (fdtable == NULL || fd < 0) {
|
||||||
{
|
|
||||||
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(fd < fdtable->max_fds))
|
if (!(fd < fdtable->max_fds)) {
|
||||||
{
|
|
||||||
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -316,16 +321,14 @@ fd_t *
|
|||||||
gf_fd_fdptr_get (fdtable_t *fdtable, int64_t fd)
|
gf_fd_fdptr_get (fdtable_t *fdtable, int64_t fd)
|
||||||
{
|
{
|
||||||
fd_t *fdptr = NULL;
|
fd_t *fdptr = NULL;
|
||||||
|
|
||||||
if (fdtable == NULL || fd < 0)
|
if (fdtable == NULL || fd < 0) {
|
||||||
{
|
|
||||||
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(fd < fdtable->max_fds))
|
if (!(fd < fdtable->max_fds)) {
|
||||||
{
|
|
||||||
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -343,14 +346,16 @@ gf_fd_fdptr_get (fdtable_t *fdtable, int64_t fd)
|
|||||||
return fdptr;
|
return fdptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fd_t *
|
fd_t *
|
||||||
_fd_ref (fd_t *fd)
|
_fd_ref (fd_t *fd)
|
||||||
{
|
{
|
||||||
++fd->refcount;
|
++fd->refcount;
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fd_t *
|
fd_t *
|
||||||
fd_ref (fd_t *fd)
|
fd_ref (fd_t *fd)
|
||||||
{
|
{
|
||||||
@ -364,10 +369,11 @@ fd_ref (fd_t *fd)
|
|||||||
LOCK (&fd->inode->lock);
|
LOCK (&fd->inode->lock);
|
||||||
refed_fd = _fd_ref (fd);
|
refed_fd = _fd_ref (fd);
|
||||||
UNLOCK (&fd->inode->lock);
|
UNLOCK (&fd->inode->lock);
|
||||||
|
|
||||||
return refed_fd;
|
return refed_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fd_t *
|
fd_t *
|
||||||
_fd_unref (fd_t *fd)
|
_fd_unref (fd_t *fd)
|
||||||
{
|
{
|
||||||
@ -375,25 +381,26 @@ _fd_unref (fd_t *fd)
|
|||||||
|
|
||||||
--fd->refcount;
|
--fd->refcount;
|
||||||
|
|
||||||
if (fd->refcount == 0){
|
if (fd->refcount == 0) {
|
||||||
list_del_init (&fd->inode_list);
|
list_del_init (&fd->inode_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fd_destroy (fd_t *fd)
|
fd_destroy (fd_t *fd)
|
||||||
{
|
{
|
||||||
xlator_t *xl = NULL;
|
xlator_t *xl = NULL;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
xlator_t *old_THIS = NULL;
|
xlator_t *old_THIS = NULL;
|
||||||
|
|
||||||
if (fd == NULL){
|
if (fd == NULL){
|
||||||
gf_log ("xlator", GF_LOG_ERROR, "invalid arugument");
|
gf_log ("xlator", GF_LOG_ERROR, "invalid arugument");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd->inode == NULL){
|
if (fd->inode == NULL){
|
||||||
gf_log ("xlator", GF_LOG_ERROR, "fd->inode is NULL");
|
gf_log ("xlator", GF_LOG_ERROR, "fd->inode is NULL");
|
||||||
goto out;
|
goto out;
|
||||||
@ -402,7 +409,7 @@ fd_destroy (fd_t *fd)
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (IA_ISDIR (fd->inode->ia_type)) {
|
if (IA_ISDIR (fd->inode->ia_type)) {
|
||||||
for (i = 0; i < fd->inode->table->xl->ctx->xl_count; i++) {
|
for (i = 0; i < fd->inode->table->xl->graph->xl_count; i++) {
|
||||||
if (fd->_ctx[i].key) {
|
if (fd->_ctx[i].key) {
|
||||||
xl = (xlator_t *)(long)fd->_ctx[i].key;
|
xl = (xlator_t *)(long)fd->_ctx[i].key;
|
||||||
old_THIS = THIS;
|
old_THIS = THIS;
|
||||||
@ -413,7 +420,7 @@ fd_destroy (fd_t *fd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < fd->inode->table->xl->ctx->xl_count; i++) {
|
for (i = 0; i < fd->inode->table->xl->graph->xl_count; i++) {
|
||||||
if (fd->_ctx[i].key) {
|
if (fd->_ctx[i].key) {
|
||||||
xl = (xlator_t *)(long)fd->_ctx[i].key;
|
xl = (xlator_t *)(long)fd->_ctx[i].key;
|
||||||
old_THIS = THIS;
|
old_THIS = THIS;
|
||||||
@ -424,18 +431,18 @@ fd_destroy (fd_t *fd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCK_DESTROY (&fd->lock);
|
LOCK_DESTROY (&fd->lock);
|
||||||
|
|
||||||
GF_FREE (fd->_ctx);
|
GF_FREE (fd->_ctx);
|
||||||
inode_unref (fd->inode);
|
inode_unref (fd->inode);
|
||||||
fd->inode = (inode_t *)0xaaaaaaaa;
|
fd->inode = (inode_t *)0xaaaaaaaa;
|
||||||
GF_FREE (fd);
|
GF_FREE (fd);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
fd_unref (fd_t *fd)
|
fd_unref (fd_t *fd)
|
||||||
{
|
{
|
||||||
@ -445,14 +452,14 @@ fd_unref (fd_t *fd)
|
|||||||
gf_log ("fd.c", GF_LOG_ERROR, "fd is NULL");
|
gf_log ("fd.c", GF_LOG_ERROR, "fd is NULL");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCK (&fd->inode->lock);
|
LOCK (&fd->inode->lock);
|
||||||
{
|
{
|
||||||
_fd_unref (fd);
|
_fd_unref (fd);
|
||||||
refcount = fd->refcount;
|
refcount = fd->refcount;
|
||||||
}
|
}
|
||||||
UNLOCK (&fd->inode->lock);
|
UNLOCK (&fd->inode->lock);
|
||||||
|
|
||||||
if (refcount == 0) {
|
if (refcount == 0) {
|
||||||
fd_destroy (fd);
|
fd_destroy (fd);
|
||||||
}
|
}
|
||||||
@ -460,6 +467,7 @@ fd_unref (fd_t *fd)
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fd_t *
|
fd_t *
|
||||||
fd_bind (fd_t *fd)
|
fd_bind (fd_t *fd)
|
||||||
{
|
{
|
||||||
@ -476,7 +484,7 @@ fd_bind (fd_t *fd)
|
|||||||
list_add (&fd->inode_list, &inode->fd_list);
|
list_add (&fd->inode_list, &inode->fd_list);
|
||||||
}
|
}
|
||||||
UNLOCK (&inode->lock);
|
UNLOCK (&inode->lock);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,22 +492,23 @@ fd_t *
|
|||||||
fd_create (inode_t *inode, pid_t pid)
|
fd_create (inode_t *inode, pid_t pid)
|
||||||
{
|
{
|
||||||
fd_t *fd = NULL;
|
fd_t *fd = NULL;
|
||||||
|
|
||||||
if (inode == NULL) {
|
if (inode == NULL) {
|
||||||
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
gf_log ("fd", GF_LOG_ERROR, "invalid argument");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = GF_CALLOC (1, sizeof (fd_t), gf_common_mt_fd_t);
|
fd = GF_CALLOC (1, sizeof (fd_t), gf_common_mt_fd_t);
|
||||||
ERR_ABORT (fd);
|
ERR_ABORT (fd);
|
||||||
|
|
||||||
fd->_ctx = GF_CALLOC (1, (sizeof (struct _fd_ctx) *
|
fd->_ctx = GF_CALLOC (1, (sizeof (struct _fd_ctx) *
|
||||||
inode->table->xl->ctx->xl_count),
|
inode->table->xl->graph->xl_count),
|
||||||
gf_common_mt_fd_ctx);
|
gf_common_mt_fd_ctx);
|
||||||
|
|
||||||
fd->inode = inode_ref (inode);
|
fd->inode = inode_ref (inode);
|
||||||
fd->pid = pid;
|
fd->pid = pid;
|
||||||
INIT_LIST_HEAD (&fd->inode_list);
|
INIT_LIST_HEAD (&fd->inode_list);
|
||||||
|
|
||||||
LOCK_INIT (&fd->lock);
|
LOCK_INIT (&fd->lock);
|
||||||
|
|
||||||
LOCK (&inode->lock);
|
LOCK (&inode->lock);
|
||||||
@ -509,6 +518,7 @@ fd_create (inode_t *inode, pid_t pid)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fd_t *
|
fd_t *
|
||||||
fd_lookup (inode_t *inode, pid_t pid)
|
fd_lookup (inode_t *inode, pid_t pid)
|
||||||
{
|
{
|
||||||
@ -537,24 +547,26 @@ fd_lookup (inode_t *inode, pid_t pid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
UNLOCK (&inode->lock);
|
UNLOCK (&inode->lock);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t
|
uint8_t
|
||||||
fd_list_empty (inode_t *inode)
|
fd_list_empty (inode_t *inode)
|
||||||
{
|
{
|
||||||
uint8_t empty = 0;
|
uint8_t empty = 0;
|
||||||
|
|
||||||
LOCK (&inode->lock);
|
LOCK (&inode->lock);
|
||||||
{
|
{
|
||||||
empty = list_empty (&inode->fd_list);
|
empty = list_empty (&inode->fd_list);
|
||||||
}
|
}
|
||||||
UNLOCK (&inode->lock);
|
UNLOCK (&inode->lock);
|
||||||
|
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
__fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value)
|
__fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value)
|
||||||
{
|
{
|
||||||
@ -564,8 +576,8 @@ __fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value)
|
|||||||
|
|
||||||
if (!fd || !xlator)
|
if (!fd || !xlator)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (index = 0; index < xlator->ctx->xl_count; index++) {
|
for (index = 0; index < xlator->graph->xl_count; index++) {
|
||||||
if (!fd->_ctx[index].key) {
|
if (!fd->_ctx[index].key) {
|
||||||
if (set_idx == -1)
|
if (set_idx == -1)
|
||||||
set_idx = index;
|
set_idx = index;
|
||||||
@ -577,12 +589,12 @@ __fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set_idx == -1) {
|
if (set_idx == -1) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd->_ctx[set_idx].key = (uint64_t)(long) xlator;
|
fd->_ctx[set_idx].key = (uint64_t)(long) xlator;
|
||||||
fd->_ctx[set_idx].value = value;
|
fd->_ctx[set_idx].value = value;
|
||||||
|
|
||||||
@ -598,7 +610,7 @@ fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value)
|
|||||||
|
|
||||||
if (!fd || !xlator)
|
if (!fd || !xlator)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
LOCK (&fd->lock);
|
LOCK (&fd->lock);
|
||||||
{
|
{
|
||||||
ret = __fd_ctx_set (fd, xlator, value);
|
ret = __fd_ctx_set (fd, xlator, value);
|
||||||
@ -609,7 +621,7 @@ fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
__fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
__fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@ -617,26 +629,26 @@ __fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
|||||||
|
|
||||||
if (!fd || !xlator)
|
if (!fd || !xlator)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (index = 0; index < xlator->ctx->xl_count; index++) {
|
for (index = 0; index < xlator->graph->xl_count; index++) {
|
||||||
if (fd->_ctx[index].key == (uint64_t)(long)xlator)
|
if (fd->_ctx[index].key == (uint64_t)(long)xlator)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == xlator->ctx->xl_count) {
|
if (index == xlator->graph->xl_count) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
*value = fd->_ctx[index].value;
|
*value = fd->_ctx[index].value;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -654,7 +666,7 @@ fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
__fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
__fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@ -662,20 +674,20 @@ __fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
|||||||
|
|
||||||
if (!fd || !xlator)
|
if (!fd || !xlator)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (index = 0; index < xlator->ctx->xl_count; index++) {
|
for (index = 0; index < xlator->graph->xl_count; index++) {
|
||||||
if (fd->_ctx[index].key == (uint64_t)(long)xlator)
|
if (fd->_ctx[index].key == (uint64_t)(long)xlator)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == xlator->ctx->xl_count) {
|
if (index == xlator->graph->xl_count) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
*value = fd->_ctx[index].value;
|
*value = fd->_ctx[index].value;
|
||||||
|
|
||||||
fd->_ctx[index].key = 0;
|
fd->_ctx[index].key = 0;
|
||||||
fd->_ctx[index].value = 0;
|
fd->_ctx[index].value = 0;
|
||||||
|
|
||||||
@ -684,14 +696,14 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (!fd || !xlator)
|
if (!fd || !xlator)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
LOCK (&fd->lock);
|
LOCK (&fd->lock);
|
||||||
{
|
{
|
||||||
ret = __fd_ctx_del (fd, xlator, value);
|
ret = __fd_ctx_del (fd, xlator, value);
|
||||||
@ -709,7 +721,7 @@ fd_dump (fd_t *fd, char *prefix)
|
|||||||
|
|
||||||
if (!fd)
|
if (!fd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memset(key, 0, sizeof(key));
|
memset(key, 0, sizeof(key));
|
||||||
gf_proc_dump_build_key(key, prefix, "pid");
|
gf_proc_dump_build_key(key, prefix, "pid");
|
||||||
gf_proc_dump_write(key, "%d", fd->pid);
|
gf_proc_dump_write(key, "%d", fd->pid);
|
||||||
@ -733,10 +745,11 @@ fdentry_dump (fdentry_t *fdentry, char *prefix)
|
|||||||
if (GF_FDENTRY_ALLOCATED != fdentry->next_free)
|
if (GF_FDENTRY_ALLOCATED != fdentry->next_free)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fdentry->fd)
|
if (fdentry->fd)
|
||||||
fd_dump(fdentry->fd, prefix);
|
fd_dump(fdentry->fd, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
fdtable_dump (fdtable_t *fdtable, char *prefix)
|
fdtable_dump (fdtable_t *fdtable, char *prefix)
|
||||||
{
|
{
|
||||||
@ -746,7 +759,7 @@ fdtable_dump (fdtable_t *fdtable, char *prefix)
|
|||||||
|
|
||||||
if (!fdtable)
|
if (!fdtable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ret = pthread_mutex_trylock (&fdtable->lock);
|
ret = pthread_mutex_trylock (&fdtable->lock);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -763,7 +776,7 @@ fdtable_dump (fdtable_t *fdtable, char *prefix)
|
|||||||
gf_proc_dump_write(key, "%d", fdtable->first_free);
|
gf_proc_dump_write(key, "%d", fdtable->first_free);
|
||||||
|
|
||||||
for ( i = 0 ; i < fdtable->max_fds; i++) {
|
for ( i = 0 ; i < fdtable->max_fds; i++) {
|
||||||
if (GF_FDENTRY_ALLOCATED ==
|
if (GF_FDENTRY_ALLOCATED ==
|
||||||
fdtable->fdentries[i].next_free) {
|
fdtable->fdentries[i].next_free) {
|
||||||
gf_proc_dump_build_key(key, prefix, "fdentry[%d]", i);
|
gf_proc_dump_build_key(key, prefix, "fdentry[%d]", i);
|
||||||
gf_proc_dump_add_section(key);
|
gf_proc_dump_add_section(key);
|
||||||
@ -773,4 +786,3 @@ fdtable_dump (fdtable_t *fdtable, char *prefix)
|
|||||||
|
|
||||||
pthread_mutex_unlock(&fdtable->lock);
|
pthread_mutex_unlock(&fdtable->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +33,10 @@
|
|||||||
|
|
||||||
struct _inode;
|
struct _inode;
|
||||||
struct _dict;
|
struct _dict;
|
||||||
|
|
||||||
struct _fd_ctx {
|
struct _fd_ctx {
|
||||||
uint64_t key;
|
uint64_t key;
|
||||||
uint64_t value;
|
uint64_t value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* If this structure changes, please have mercy on the booster maintainer
|
/* If this structure changes, please have mercy on the booster maintainer
|
||||||
@ -55,12 +56,14 @@ struct _fd {
|
|||||||
};
|
};
|
||||||
typedef struct _fd fd_t;
|
typedef struct _fd fd_t;
|
||||||
|
|
||||||
|
|
||||||
struct fd_table_entry {
|
struct fd_table_entry {
|
||||||
fd_t *fd;
|
fd_t *fd;
|
||||||
int next_free;
|
int next_free;
|
||||||
};
|
};
|
||||||
typedef struct fd_table_entry fdentry_t;
|
typedef struct fd_table_entry fdentry_t;
|
||||||
|
|
||||||
|
|
||||||
struct _fdtable {
|
struct _fdtable {
|
||||||
int refcount;
|
int refcount;
|
||||||
uint32_t max_fds;
|
uint32_t max_fds;
|
||||||
@ -70,6 +73,7 @@ struct _fdtable {
|
|||||||
};
|
};
|
||||||
typedef struct _fdtable fdtable_t;
|
typedef struct _fdtable fdtable_t;
|
||||||
|
|
||||||
|
|
||||||
/* Signifies no more entries in the fd table. */
|
/* Signifies no more entries in the fd table. */
|
||||||
#define GF_FDTABLE_END -1
|
#define GF_FDTABLE_END -1
|
||||||
|
|
||||||
@ -81,58 +85,77 @@ typedef struct _fdtable fdtable_t;
|
|||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "xlator.h"
|
#include "xlator.h"
|
||||||
|
|
||||||
inline void
|
|
||||||
|
inline void
|
||||||
gf_fd_put (fdtable_t *fdtable, int32_t fd);
|
gf_fd_put (fdtable_t *fdtable, int32_t fd);
|
||||||
|
|
||||||
|
|
||||||
fd_t *
|
fd_t *
|
||||||
gf_fd_fdptr_get (fdtable_t *fdtable, int64_t fd);
|
gf_fd_fdptr_get (fdtable_t *fdtable, int64_t fd);
|
||||||
|
|
||||||
|
|
||||||
fdtable_t *
|
fdtable_t *
|
||||||
gf_fd_fdtable_alloc (void);
|
gf_fd_fdtable_alloc (void);
|
||||||
|
|
||||||
int32_t
|
|
||||||
|
int
|
||||||
gf_fd_unused_get (fdtable_t *fdtable, fd_t *fdptr);
|
gf_fd_unused_get (fdtable_t *fdtable, fd_t *fdptr);
|
||||||
|
|
||||||
|
|
||||||
fdentry_t *
|
fdentry_t *
|
||||||
gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count);
|
gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count);
|
||||||
|
|
||||||
void
|
|
||||||
|
void
|
||||||
gf_fd_fdtable_destroy (fdtable_t *fdtable);
|
gf_fd_fdtable_destroy (fdtable_t *fdtable);
|
||||||
|
|
||||||
|
|
||||||
fd_t *
|
fd_t *
|
||||||
fd_ref (fd_t *fd);
|
fd_ref (fd_t *fd);
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
fd_unref (fd_t *fd);
|
fd_unref (fd_t *fd);
|
||||||
|
|
||||||
|
|
||||||
fd_t *
|
fd_t *
|
||||||
fd_create (struct _inode *inode, pid_t pid);
|
fd_create (struct _inode *inode, pid_t pid);
|
||||||
|
|
||||||
|
|
||||||
fd_t *
|
fd_t *
|
||||||
fd_lookup (struct _inode *inode, pid_t pid);
|
fd_lookup (struct _inode *inode, pid_t pid);
|
||||||
|
|
||||||
|
|
||||||
uint8_t
|
uint8_t
|
||||||
fd_list_empty (struct _inode *inode);
|
fd_list_empty (struct _inode *inode);
|
||||||
|
|
||||||
|
|
||||||
fd_t *
|
fd_t *
|
||||||
fd_bind (fd_t *fd);
|
fd_bind (fd_t *fd);
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value);
|
fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value);
|
||||||
|
|
||||||
int
|
|
||||||
|
int
|
||||||
fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value);
|
fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value);
|
||||||
|
|
||||||
int
|
|
||||||
|
int
|
||||||
fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value);
|
fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value);
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
__fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value);
|
__fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value);
|
||||||
|
|
||||||
int
|
|
||||||
|
int
|
||||||
__fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value);
|
__fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value);
|
||||||
|
|
||||||
int
|
|
||||||
|
int
|
||||||
__fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value);
|
__fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value);
|
||||||
|
|
||||||
|
|
||||||
#endif /* _FD_H */
|
#endif /* _FD_H */
|
||||||
|
@ -24,12 +24,73 @@
|
|||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include "globals.h"
|
|
||||||
#include "glusterfs.h"
|
#include "glusterfs.h"
|
||||||
|
#include "globals.h"
|
||||||
#include "xlator.h"
|
#include "xlator.h"
|
||||||
#include "mem-pool.h"
|
#include "mem-pool.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* gf_*_list[] */
|
||||||
|
|
||||||
|
char *gf_fop_list[GF_FOP_MAXVALUE];
|
||||||
|
char *gf_mgmt_list[GF_MGMT_MAXVALUE];
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
gf_op_list_init()
|
||||||
|
{
|
||||||
|
gf_fop_list[GF_FOP_NULL] = "NULL";
|
||||||
|
gf_fop_list[GF_FOP_STAT] = "STAT";
|
||||||
|
gf_fop_list[GF_FOP_READLINK] = "READLINK";
|
||||||
|
gf_fop_list[GF_FOP_MKNOD] = "MKNOD";
|
||||||
|
gf_fop_list[GF_FOP_MKDIR] = "MKDIR";
|
||||||
|
gf_fop_list[GF_FOP_UNLINK] = "UNLINK";
|
||||||
|
gf_fop_list[GF_FOP_RMDIR] = "RMDIR";
|
||||||
|
gf_fop_list[GF_FOP_SYMLINK] = "SYMLINK";
|
||||||
|
gf_fop_list[GF_FOP_RENAME] = "RENAME";
|
||||||
|
gf_fop_list[GF_FOP_LINK] = "LINK";
|
||||||
|
gf_fop_list[GF_FOP_TRUNCATE] = "TRUNCATE";
|
||||||
|
gf_fop_list[GF_FOP_OPEN] = "OPEN";
|
||||||
|
gf_fop_list[GF_FOP_READ] = "READ";
|
||||||
|
gf_fop_list[GF_FOP_WRITE] = "WRITE";
|
||||||
|
gf_fop_list[GF_FOP_STATFS] = "STATFS";
|
||||||
|
gf_fop_list[GF_FOP_FLUSH] = "FLUSH";
|
||||||
|
gf_fop_list[GF_FOP_FSYNC] = "FSYNC";
|
||||||
|
gf_fop_list[GF_FOP_SETXATTR] = "SETXATTR";
|
||||||
|
gf_fop_list[GF_FOP_GETXATTR] = "GETXATTR";
|
||||||
|
gf_fop_list[GF_FOP_REMOVEXATTR] = "REMOVEXATTR";
|
||||||
|
gf_fop_list[GF_FOP_OPENDIR] = "OPENDIR";
|
||||||
|
gf_fop_list[GF_FOP_FSYNCDIR] = "FSYNCDIR";
|
||||||
|
gf_fop_list[GF_FOP_ACCESS] = "ACCESS";
|
||||||
|
gf_fop_list[GF_FOP_CREATE] = "CREATE";
|
||||||
|
gf_fop_list[GF_FOP_FTRUNCATE] = "FTRUNCATE";
|
||||||
|
gf_fop_list[GF_FOP_FSTAT] = "FSTAT";
|
||||||
|
gf_fop_list[GF_FOP_LK] = "LK";
|
||||||
|
gf_fop_list[GF_FOP_LOOKUP] = "LOOKUP";
|
||||||
|
gf_fop_list[GF_FOP_READDIR] = "READDIR";
|
||||||
|
gf_fop_list[GF_FOP_INODELK] = "INODELK";
|
||||||
|
gf_fop_list[GF_FOP_FINODELK] = "FINODELK";
|
||||||
|
gf_fop_list[GF_FOP_ENTRYLK] = "ENTRYLK";
|
||||||
|
gf_fop_list[GF_FOP_FENTRYLK] = "FENTRYLK";
|
||||||
|
gf_fop_list[GF_FOP_CHECKSUM] = "CHECKSUM";
|
||||||
|
gf_fop_list[GF_FOP_XATTROP] = "XATTROP";
|
||||||
|
gf_fop_list[GF_FOP_FXATTROP] = "FXATTROP";
|
||||||
|
gf_fop_list[GF_FOP_FSETXATTR] = "FSETXATTR";
|
||||||
|
gf_fop_list[GF_FOP_FGETXATTR] = "FGETXATTR";
|
||||||
|
gf_fop_list[GF_FOP_RCHECKSUM] = "RCHECKSUM";
|
||||||
|
gf_fop_list[GF_FOP_SETATTR] = "SETATTR";
|
||||||
|
gf_fop_list[GF_FOP_FSETATTR] = "FSETATTR";
|
||||||
|
gf_fop_list[GF_FOP_READDIRP] = "READDIRP";
|
||||||
|
gf_fop_list[GF_FOP_GETSPEC] = "GETSPEC";
|
||||||
|
gf_fop_list[GF_FOP_FORGET] = "FORGET";
|
||||||
|
gf_fop_list[GF_FOP_RELEASE] = "RELEASE";
|
||||||
|
gf_fop_list[GF_FOP_RELEASEDIR] = "RELEASEDIR";
|
||||||
|
|
||||||
|
gf_fop_list[GF_MGMT_NULL] = "NULL";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* CTX */
|
/* CTX */
|
||||||
static glusterfs_ctx_t *glusterfs_ctx;
|
static glusterfs_ctx_t *glusterfs_ctx;
|
||||||
|
|
||||||
@ -48,6 +109,7 @@ glusterfs_ctx_init ()
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INIT_LIST_HEAD (&glusterfs_ctx->graphs);
|
||||||
ret = pthread_mutex_init (&glusterfs_ctx->lock, NULL);
|
ret = pthread_mutex_init (&glusterfs_ctx->lock, NULL);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
@ -168,7 +230,7 @@ glusterfs_central_log_flag_init ()
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
ret = pthread_key_create (¢ral_log_flag_key,
|
ret = pthread_key_create (¢ral_log_flag_key,
|
||||||
glusterfs_central_log_flag_destroy);
|
glusterfs_central_log_flag_destroy);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@ -194,7 +256,7 @@ glusterfs_central_log_flag_get ()
|
|||||||
long flag = 0;
|
long flag = 0;
|
||||||
|
|
||||||
flag = (long) pthread_getspecific (central_log_flag_key);
|
flag = (long) pthread_getspecific (central_log_flag_key);
|
||||||
|
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,6 +273,8 @@ glusterfs_globals_init ()
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
gf_op_list_init ();
|
||||||
|
|
||||||
ret = glusterfs_ctx_init ();
|
ret = glusterfs_ctx_init ();
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -27,13 +27,14 @@
|
|||||||
#define GF_REQUEST_MAXGROUPS 16
|
#define GF_REQUEST_MAXGROUPS 16
|
||||||
|
|
||||||
#include "glusterfs.h"
|
#include "glusterfs.h"
|
||||||
#include "xlator.h"
|
|
||||||
|
|
||||||
/* CTX */
|
/* CTX */
|
||||||
#define CTX (glusterfs_ctx_get())
|
#define CTX (glusterfs_ctx_get())
|
||||||
|
|
||||||
glusterfs_ctx_t *glusterfs_ctx_get ();
|
glusterfs_ctx_t *glusterfs_ctx_get ();
|
||||||
|
|
||||||
|
#include "xlator.h"
|
||||||
|
|
||||||
/* THIS */
|
/* THIS */
|
||||||
#define THIS (*__glusterfs_this_location())
|
#define THIS (*__glusterfs_this_location())
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
|
||||||
#define GF_YES 1
|
#define GF_YES 1
|
||||||
#define GF_NO 0
|
#define GF_NO 0
|
||||||
|
|
||||||
@ -95,7 +96,7 @@ typedef enum {
|
|||||||
GF_FOP_WRITE,
|
GF_FOP_WRITE,
|
||||||
GF_FOP_STATFS,
|
GF_FOP_STATFS,
|
||||||
GF_FOP_FLUSH,
|
GF_FOP_FLUSH,
|
||||||
GF_FOP_FSYNC,
|
GF_FOP_FSYNC, /* 15 */
|
||||||
GF_FOP_SETXATTR,
|
GF_FOP_SETXATTR,
|
||||||
GF_FOP_GETXATTR,
|
GF_FOP_GETXATTR,
|
||||||
GF_FOP_REMOVEXATTR,
|
GF_FOP_REMOVEXATTR,
|
||||||
@ -104,7 +105,7 @@ typedef enum {
|
|||||||
GF_FOP_ACCESS,
|
GF_FOP_ACCESS,
|
||||||
GF_FOP_CREATE,
|
GF_FOP_CREATE,
|
||||||
GF_FOP_FTRUNCATE,
|
GF_FOP_FTRUNCATE,
|
||||||
GF_FOP_FSTAT,
|
GF_FOP_FSTAT, /* 25 */
|
||||||
GF_FOP_LK,
|
GF_FOP_LK,
|
||||||
GF_FOP_LOOKUP,
|
GF_FOP_LOOKUP,
|
||||||
GF_FOP_READDIR,
|
GF_FOP_READDIR,
|
||||||
@ -141,6 +142,7 @@ typedef enum {
|
|||||||
GF_OP_TYPE_MAX,
|
GF_OP_TYPE_MAX,
|
||||||
} gf_op_type_t;
|
} gf_op_type_t;
|
||||||
|
|
||||||
|
|
||||||
/* NOTE: all the miscellaneous flags used by GlusterFS should be listed here */
|
/* NOTE: all the miscellaneous flags used by GlusterFS should be listed here */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GF_LK_GETLK = 0,
|
GF_LK_GETLK = 0,
|
||||||
@ -148,32 +150,38 @@ typedef enum {
|
|||||||
GF_LK_SETLKW,
|
GF_LK_SETLKW,
|
||||||
} glusterfs_lk_cmds_t;
|
} glusterfs_lk_cmds_t;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GF_LK_F_RDLCK = 0,
|
GF_LK_F_RDLCK = 0,
|
||||||
GF_LK_F_WRLCK,
|
GF_LK_F_WRLCK,
|
||||||
GF_LK_F_UNLCK
|
GF_LK_F_UNLCK
|
||||||
} glusterfs_lk_types_t;
|
} glusterfs_lk_types_t;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GF_LOCK_POSIX,
|
GF_LOCK_POSIX,
|
||||||
GF_LOCK_INTERNAL
|
GF_LOCK_INTERNAL
|
||||||
} gf_lk_domain_t;
|
} gf_lk_domain_t;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ENTRYLK_LOCK,
|
ENTRYLK_LOCK,
|
||||||
ENTRYLK_UNLOCK,
|
ENTRYLK_UNLOCK,
|
||||||
ENTRYLK_LOCK_NB
|
ENTRYLK_LOCK_NB
|
||||||
} entrylk_cmd;
|
} entrylk_cmd;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ENTRYLK_RDLCK,
|
ENTRYLK_RDLCK,
|
||||||
ENTRYLK_WRLCK
|
ENTRYLK_WRLCK
|
||||||
} entrylk_type;
|
} entrylk_type;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GF_XATTROP_ADD_ARRAY,
|
GF_XATTROP_ADD_ARRAY,
|
||||||
} gf_xattrop_flags_t;
|
} gf_xattrop_flags_t;
|
||||||
|
|
||||||
|
|
||||||
#define GF_SET_IF_NOT_PRESENT 0x1 /* default behaviour */
|
#define GF_SET_IF_NOT_PRESENT 0x1 /* default behaviour */
|
||||||
#define GF_SET_OVERWRITE 0x2 /* Overwrite with the buf given */
|
#define GF_SET_OVERWRITE 0x2 /* Overwrite with the buf given */
|
||||||
#define GF_SET_DIR_ONLY 0x4
|
#define GF_SET_DIR_ONLY 0x4
|
||||||
@ -186,17 +194,18 @@ typedef enum {
|
|||||||
#define GF_REPLICATE_TRASH_DIR ".landfill"
|
#define GF_REPLICATE_TRASH_DIR ".landfill"
|
||||||
|
|
||||||
struct _xlator_cmdline_option {
|
struct _xlator_cmdline_option {
|
||||||
struct list_head cmd_args;
|
struct list_head cmd_args;
|
||||||
char *volume;
|
char *volume;
|
||||||
char *key;
|
char *key;
|
||||||
char *value;
|
char *value;
|
||||||
};
|
};
|
||||||
typedef struct _xlator_cmdline_option xlator_cmdline_option_t;
|
typedef struct _xlator_cmdline_option xlator_cmdline_option_t;
|
||||||
|
|
||||||
|
|
||||||
struct _cmd_args {
|
struct _cmd_args {
|
||||||
/* basic options */
|
/* basic options */
|
||||||
char *volfile_server;
|
char *volfile_server;
|
||||||
char *volume_file;
|
char *volfile;
|
||||||
char *log_server;
|
char *log_server;
|
||||||
gf_loglevel_t log_level;
|
gf_loglevel_t log_level;
|
||||||
char *log_file;
|
char *log_file;
|
||||||
@ -229,41 +238,61 @@ struct _cmd_args {
|
|||||||
};
|
};
|
||||||
typedef struct _cmd_args cmd_args_t;
|
typedef struct _cmd_args cmd_args_t;
|
||||||
|
|
||||||
struct _glusterfs_ctx {
|
|
||||||
cmd_args_t cmd_args;
|
|
||||||
char *process_uuid;
|
|
||||||
FILE *specfp;
|
|
||||||
FILE *pidfp;
|
|
||||||
char fin;
|
|
||||||
void *timer;
|
|
||||||
void *ib;
|
|
||||||
void *pool;
|
|
||||||
void *graph;
|
|
||||||
void *top; /* either fuse or server protocol */
|
|
||||||
void *event_pool;
|
|
||||||
void *iobuf_pool;
|
|
||||||
pthread_mutex_t lock;
|
|
||||||
int xl_count;
|
|
||||||
uint32_t volfile_checksum;
|
|
||||||
size_t page_size;
|
|
||||||
unsigned char measure_latency; /* toggle switch for latency measurement */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
struct _glusterfs_graph {
|
||||||
|
struct list_head list;
|
||||||
|
char graph_uuid[128];
|
||||||
|
struct timeval dob;
|
||||||
|
void *first;
|
||||||
|
void *top; /* selected by -n */
|
||||||
|
int xl_count;
|
||||||
|
uint32_t volfile_checksum;
|
||||||
|
};
|
||||||
|
typedef struct _glusterfs_graph glusterfs_graph_t;
|
||||||
|
|
||||||
|
|
||||||
|
struct _glusterfs_ctx {
|
||||||
|
cmd_args_t cmd_args;
|
||||||
|
char *process_uuid;
|
||||||
|
FILE *pidfp;
|
||||||
|
char fin;
|
||||||
|
void *timer;
|
||||||
|
void *ib;
|
||||||
|
void *pool;
|
||||||
|
void *event_pool;
|
||||||
|
void *iobuf_pool;
|
||||||
|
pthread_mutex_t lock;
|
||||||
|
size_t page_size;
|
||||||
|
struct list_head graphs; /* double linked list of graphs - one per volfile parse */
|
||||||
|
glusterfs_graph_t *active; /* the latest graph in use */
|
||||||
|
void *master; /* fuse, or libglusterfsclient (however, not protocol/server) */
|
||||||
|
void *mgmt; /* xlator implementing MOPs for centralized logging, volfile server */
|
||||||
|
unsigned char measure_latency; /* toggle switch for latency measurement */
|
||||||
|
pthread_t sigwaiter;
|
||||||
|
};
|
||||||
typedef struct _glusterfs_ctx glusterfs_ctx_t;
|
typedef struct _glusterfs_ctx glusterfs_ctx_t;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GF_EVENT_PARENT_UP = 1,
|
GF_EVENT_PARENT_UP = 1,
|
||||||
GF_EVENT_POLLIN,
|
GF_EVENT_POLLIN,
|
||||||
GF_EVENT_POLLOUT,
|
GF_EVENT_POLLOUT,
|
||||||
GF_EVENT_POLLERR,
|
GF_EVENT_POLLERR,
|
||||||
GF_EVENT_CHILD_UP,
|
GF_EVENT_CHILD_UP,
|
||||||
GF_EVENT_CHILD_DOWN,
|
GF_EVENT_CHILD_DOWN,
|
||||||
GF_EVENT_CHILD_CONNECTING,
|
GF_EVENT_CHILD_CONNECTING,
|
||||||
GF_EVENT_TRANSPORT_CLEANUP,
|
GF_EVENT_TRANSPORT_CLEANUP,
|
||||||
GF_EVENT_TRANSPORT_CONNECTED,
|
GF_EVENT_TRANSPORT_CONNECTED,
|
||||||
GF_EVENT_VOLFILE_MODIFIED,
|
GF_EVENT_VOLFILE_MODIFIED,
|
||||||
|
GF_EVENT_GRAPH_NEW,
|
||||||
} glusterfs_event_t;
|
} glusterfs_event_t;
|
||||||
|
|
||||||
|
|
||||||
#define GF_MUST_CHECK __attribute__((warn_unused_result))
|
#define GF_MUST_CHECK __attribute__((warn_unused_result))
|
||||||
|
|
||||||
|
int glusterfs_graph_prepare (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx);
|
||||||
|
int glusterfs_graph_destroy (glusterfs_graph_t *graph);
|
||||||
|
int glusterfs_graph_activate (glusterfs_ctx_t *ctx, glusterfs_graph_t *graph);
|
||||||
|
glusterfs_graph_t *glusterfs_graph_construct (FILE *fp);
|
||||||
|
glusterfs_graph_t *glusterfs_graph_new ();
|
||||||
#endif /* _GLUSTERFS_H */
|
#endif /* _GLUSTERFS_H */
|
||||||
|
499
libglusterfs/src/graph.c
Normal file
499
libglusterfs/src/graph.c
Normal file
@ -0,0 +1,499 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
|
||||||
|
This file is part of GlusterFS.
|
||||||
|
|
||||||
|
GlusterFS is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published
|
||||||
|
by the Free Software Foundation; either version 3 of the License,
|
||||||
|
or (at your option) any later version.
|
||||||
|
|
||||||
|
GlusterFS is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CONFIG_H
|
||||||
|
#define _CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "xlator.h"
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <fnmatch.h>
|
||||||
|
#include "defaults.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static void
|
||||||
|
_gf_dump_details (int argc, char **argv)
|
||||||
|
{
|
||||||
|
extern FILE *gf_log_logfile;
|
||||||
|
int i = 0;
|
||||||
|
char timestr[256];
|
||||||
|
time_t utime = 0;
|
||||||
|
struct tm *tm = NULL;
|
||||||
|
pid_t mypid = 0;
|
||||||
|
struct utsname uname_buf = {{0, }, };
|
||||||
|
int uname_ret = -1;
|
||||||
|
|
||||||
|
utime = time (NULL);
|
||||||
|
tm = localtime (&utime);
|
||||||
|
mypid = getpid ();
|
||||||
|
uname_ret = uname (&uname_buf);
|
||||||
|
|
||||||
|
/* Which git? What time? */
|
||||||
|
strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm);
|
||||||
|
fprintf (gf_log_logfile,
|
||||||
|
"========================================"
|
||||||
|
"========================================\n");
|
||||||
|
fprintf (gf_log_logfile, "Version : %s %s built on %s %s\n",
|
||||||
|
PACKAGE_NAME, PACKAGE_VERSION, __DATE__, __TIME__);
|
||||||
|
fprintf (gf_log_logfile, "git: %s\n",
|
||||||
|
GLUSTERFS_REPOSITORY_REVISION);
|
||||||
|
fprintf (gf_log_logfile, "Starting Time: %s\n", timestr);
|
||||||
|
fprintf (gf_log_logfile, "Command line : ");
|
||||||
|
for (i = 0; i < argc; i++) {
|
||||||
|
fprintf (gf_log_logfile, "%s ", argv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (gf_log_logfile, "\nPID : %d\n", mypid);
|
||||||
|
|
||||||
|
if (uname_ret == 0) {
|
||||||
|
fprintf (gf_log_logfile, "System name : %s\n",
|
||||||
|
uname_buf.sysname);
|
||||||
|
fprintf (gf_log_logfile, "Nodename : %s\n",
|
||||||
|
uname_buf.nodename);
|
||||||
|
fprintf (gf_log_logfile, "Kernel Release : %s\n",
|
||||||
|
uname_buf.release);
|
||||||
|
fprintf (gf_log_logfile, "Hardware Identifier: %s\n",
|
||||||
|
uname_buf.machine);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fprintf (gf_log_logfile, "\n");
|
||||||
|
fflush (gf_log_logfile);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
_log_if_option_is_invalid (xlator_t *xl, data_pair_t *pair)
|
||||||
|
{
|
||||||
|
volume_opt_list_t *vol_opt = NULL;
|
||||||
|
volume_option_t *opt = NULL;
|
||||||
|
int i = 0;
|
||||||
|
int index = 0;
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
|
/* Get the first volume_option */
|
||||||
|
list_for_each_entry (vol_opt, &xl->volume_options, list) {
|
||||||
|
/* Warn for extra option */
|
||||||
|
if (!vol_opt->given_opt)
|
||||||
|
break;
|
||||||
|
|
||||||
|
opt = vol_opt->given_opt;
|
||||||
|
for (index = 0;
|
||||||
|
((index < ZR_OPTION_MAX_ARRAY_SIZE) &&
|
||||||
|
(opt[index].key && opt[index].key[0])); index++)
|
||||||
|
for (i = 0; (i < ZR_VOLUME_MAX_NUM_KEY) &&
|
||||||
|
opt[index].key[i]; i++) {
|
||||||
|
if (fnmatch (opt[index].key[i],
|
||||||
|
pair->key,
|
||||||
|
FNM_NOESCAPE) == 0) {
|
||||||
|
found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
gf_log (xl->name, GF_LOG_WARNING,
|
||||||
|
"option '%s' is not recognized",
|
||||||
|
pair->key);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_insert (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx,
|
||||||
|
const char *type, const char *name)
|
||||||
|
{
|
||||||
|
xlator_t *ixl = NULL;
|
||||||
|
xlator_list_t *xlchild = NULL;
|
||||||
|
xlator_list_t *xlparent = NULL;
|
||||||
|
|
||||||
|
ixl = GF_CALLOC (1, sizeof (*ixl), gf_common_mt_xlator_t);
|
||||||
|
if (!ixl)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
ixl->ctx = ctx;
|
||||||
|
ixl->graph = graph;
|
||||||
|
ixl->options = get_new_dict ();
|
||||||
|
if (!ixl->options)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
ixl->name = gf_strdup (name);
|
||||||
|
if (!ixl->name)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
if (xlator_set_type (ixl, type) == -1) {
|
||||||
|
gf_log ("glusterfs", GF_LOG_ERROR,
|
||||||
|
"%s (%s) initialization failed",
|
||||||
|
name, type);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* children */
|
||||||
|
xlchild = GF_CALLOC (sizeof (*xlchild), 1, gf_common_mt_xlator_list_t);
|
||||||
|
if (!xlchild)
|
||||||
|
goto err;
|
||||||
|
xlchild->xlator = graph->top;
|
||||||
|
ixl->children = xlchild; xlchild = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/* parent */
|
||||||
|
xlparent = GF_CALLOC (sizeof (*xlparent), 1,
|
||||||
|
gf_common_mt_xlator_list_t);
|
||||||
|
if (!xlparent)
|
||||||
|
goto err;
|
||||||
|
xlparent->xlator = ixl;
|
||||||
|
|
||||||
|
ixl->next = graph->first;
|
||||||
|
graph->first = ixl;
|
||||||
|
|
||||||
|
xlparent->next = ((xlator_t *)graph->top)->parents;
|
||||||
|
((xlator_t *)graph->top)->parents = xlparent;
|
||||||
|
|
||||||
|
graph->top = ixl;
|
||||||
|
|
||||||
|
graph->xl_count++;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
err:
|
||||||
|
xlator_destroy (ixl);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_readonly (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
cmd_args_t *cmd_args = NULL;
|
||||||
|
|
||||||
|
cmd_args = &ctx->cmd_args;
|
||||||
|
|
||||||
|
if (!cmd_args->read_only)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ret = glusterfs_graph_insert (graph, ctx, "features/read-only",
|
||||||
|
"readonly-autoload");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_mac_compat (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
cmd_args_t *cmd_args = NULL;
|
||||||
|
|
||||||
|
cmd_args = &ctx->cmd_args;
|
||||||
|
|
||||||
|
#ifdef GF_DARWIN_HOST_OS
|
||||||
|
if (!cmd_args->mac_compat)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ret = glusterfs_graph_insert (graph, ctx, ZR_XLATOR_MAC_COMPAT,
|
||||||
|
"mac-compat-autoload");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
gf_add_cmdline_options (glusterfs_graph_t *graph, cmd_args_t *cmd_args)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
xlator_t *trav = NULL;
|
||||||
|
xlator_cmdline_option_t *cmd_option = NULL;
|
||||||
|
|
||||||
|
trav = graph->first;
|
||||||
|
|
||||||
|
while (trav) {
|
||||||
|
list_for_each_entry (cmd_option,
|
||||||
|
&cmd_args->xlator_options, cmd_args) {
|
||||||
|
if (!fnmatch (cmd_option->volume,
|
||||||
|
trav->name, FNM_NOESCAPE)) {
|
||||||
|
ret = dict_set_str (trav->options,
|
||||||
|
cmd_option->key,
|
||||||
|
cmd_option->value);
|
||||||
|
if (ret == 0) {
|
||||||
|
gf_log (trav->name, GF_LOG_WARNING,
|
||||||
|
"adding option '%s' for "
|
||||||
|
"volume '%s' with value '%s'",
|
||||||
|
cmd_option->key, trav->name,
|
||||||
|
cmd_option->value);
|
||||||
|
} else {
|
||||||
|
gf_log (trav->name, GF_LOG_WARNING,
|
||||||
|
"adding option '%s' for "
|
||||||
|
"volume '%s' failed: %s",
|
||||||
|
cmd_option->key, trav->name,
|
||||||
|
strerror (-ret));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trav = trav->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_validate_options (glusterfs_graph_t *graph)
|
||||||
|
{
|
||||||
|
volume_opt_list_t *vol_opt = NULL;
|
||||||
|
xlator_t *trav = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
trav = graph->first;
|
||||||
|
|
||||||
|
while (trav) {
|
||||||
|
if (list_empty (&trav->volume_options))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
vol_opt = list_entry (trav->volume_options.next,
|
||||||
|
volume_opt_list_t, list);
|
||||||
|
|
||||||
|
ret = validate_xlator_volume_options (trav,
|
||||||
|
vol_opt->given_opt);
|
||||||
|
if (ret) {
|
||||||
|
gf_log (trav->name, GF_LOG_ERROR,
|
||||||
|
"validating translator failed");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
trav = trav->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_init (glusterfs_graph_t *graph)
|
||||||
|
{
|
||||||
|
xlator_t *trav = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
trav = graph->first;
|
||||||
|
|
||||||
|
while (trav) {
|
||||||
|
ret = xlator_init (trav);
|
||||||
|
if (ret) {
|
||||||
|
gf_log (trav->name, GF_LOG_ERROR,
|
||||||
|
"initializing translator failed");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
trav = trav->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_unknown_options (glusterfs_graph_t *graph)
|
||||||
|
{
|
||||||
|
data_pair_t *pair = NULL;
|
||||||
|
xlator_t *trav = NULL;
|
||||||
|
|
||||||
|
trav = graph->first;
|
||||||
|
|
||||||
|
/* Validate again phase */
|
||||||
|
while (trav) {
|
||||||
|
pair = trav->options->members_list;
|
||||||
|
while (pair) {
|
||||||
|
_log_if_option_is_invalid (trav, pair);
|
||||||
|
pair = pair->next;
|
||||||
|
}
|
||||||
|
trav = trav->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
fill_uuid (char *uuid, int size)
|
||||||
|
{
|
||||||
|
char hostname[256] = {0,};
|
||||||
|
struct timeval tv = {0,};
|
||||||
|
struct tm now = {0, };
|
||||||
|
char now_str[32];
|
||||||
|
|
||||||
|
if (gettimeofday (&tv, NULL) == -1) {
|
||||||
|
gf_log ("graph", GF_LOG_ERROR,
|
||||||
|
"gettimeofday: failed %s",
|
||||||
|
strerror (errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gethostname (hostname, 256) == -1) {
|
||||||
|
gf_log ("graph", GF_LOG_ERROR,
|
||||||
|
"gethostname: failed %s",
|
||||||
|
strerror (errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
localtime_r (&tv.tv_sec, &now);
|
||||||
|
strftime (now_str, 32, "%Y/%m/%d-%H:%M:%S", &now);
|
||||||
|
snprintf (uuid, size, "%s-%d-%s:%ld",
|
||||||
|
hostname, getpid(), now_str, tv.tv_usec);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_settop (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx)
|
||||||
|
{
|
||||||
|
const char *volume_name = NULL;
|
||||||
|
xlator_t *trav = NULL;
|
||||||
|
|
||||||
|
volume_name = ctx->cmd_args.volume_name;
|
||||||
|
|
||||||
|
if (!volume_name) {
|
||||||
|
graph->top = graph->first;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (trav = graph->first; trav; trav = trav->next) {
|
||||||
|
if (strcmp (trav->name, volume_name) == 0) {
|
||||||
|
graph->top = trav;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_parent_up (glusterfs_graph_t *graph)
|
||||||
|
{
|
||||||
|
xlator_t *trav = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
trav = graph->first;
|
||||||
|
|
||||||
|
while (trav) {
|
||||||
|
if (!xlator_has_parent (trav)) {
|
||||||
|
ret = xlator_notify (trav, GF_EVENT_PARENT_UP, trav);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
break;
|
||||||
|
|
||||||
|
trav = trav->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_prepare (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx)
|
||||||
|
{
|
||||||
|
xlator_t *trav = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
/* XXX: CHECKSUM */
|
||||||
|
|
||||||
|
/* XXX: attach to -n volname */
|
||||||
|
ret = glusterfs_graph_settop (graph, ctx);
|
||||||
|
if (ret)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* XXX: RO VOLUME */
|
||||||
|
ret = glusterfs_graph_readonly (graph, ctx);
|
||||||
|
if (ret)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* XXX: MAC COMPAT */
|
||||||
|
ret = glusterfs_graph_mac_compat (graph, ctx);
|
||||||
|
if (ret)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* XXX: this->ctx setting */
|
||||||
|
for (trav = graph->first; trav; trav = trav->next) {
|
||||||
|
trav->ctx = ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* XXX: DOB setting */
|
||||||
|
gettimeofday (&graph->dob, NULL);
|
||||||
|
|
||||||
|
fill_uuid (graph->graph_uuid, 128);
|
||||||
|
|
||||||
|
/* XXX: --xlator-option additions */
|
||||||
|
gf_add_cmdline_options (graph, &ctx->cmd_args);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_activate (glusterfs_ctx_t *ctx, glusterfs_graph_t *graph)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
/* XXX: all xlator options validation */
|
||||||
|
ret = glusterfs_graph_validate_options (graph);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/* XXX: perform init () */
|
||||||
|
ret = glusterfs_graph_init (graph);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = glusterfs_graph_unknown_options (graph);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/* XXX: log full graph (_gf_dump_details) */
|
||||||
|
|
||||||
|
list_add (&graph->list, &ctx->graphs);
|
||||||
|
ctx->active = graph;
|
||||||
|
|
||||||
|
/* XXX: attach to master and set active pointer */
|
||||||
|
if (ctx->master)
|
||||||
|
ret = xlator_notify (ctx->master, GF_EVENT_GRAPH_NEW, graph);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/* XXX: perform parent up */
|
||||||
|
ret = glusterfs_graph_parent_up (graph);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
glusterfs_graph_destroy (glusterfs_graph_t *graph)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -33,21 +33,21 @@ static char *text;
|
|||||||
static int text_asize;
|
static int text_asize;
|
||||||
static int text_size;
|
static int text_size;
|
||||||
|
|
||||||
void new_string(void)
|
|
||||||
{
|
|
||||||
text = malloc(START_STRSIZE);
|
|
||||||
text_asize = START_STRSIZE;
|
|
||||||
text_size = 0;
|
|
||||||
*text = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void append_string(const char *str, int size)
|
void append_string(const char *str, int size)
|
||||||
{
|
{
|
||||||
int new_size = text_size + size + 1;
|
int new_size = text_size + size + 1;
|
||||||
if (new_size > text_asize) {
|
if (new_size > text_asize) {
|
||||||
new_size += START_STRSIZE - 1;
|
new_size += START_STRSIZE - 1;
|
||||||
new_size &= -START_STRSIZE;
|
new_size &= -START_STRSIZE;
|
||||||
text = realloc(text, new_size);
|
if (!text) {
|
||||||
|
text = GF_CALLOC (1, new_size,
|
||||||
|
gf_common_mt_char);
|
||||||
|
} else {
|
||||||
|
text = GF_REALLOC (text, new_size);
|
||||||
|
}
|
||||||
|
if (!text)
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"out of memory");
|
||||||
text_asize = new_size;
|
text_asize = new_size;
|
||||||
}
|
}
|
||||||
memcpy(text + text_size, str, size);
|
memcpy(text + text_size, str, size);
|
||||||
@ -55,13 +55,6 @@ void append_string(const char *str, int size)
|
|||||||
text[text_size] = 0;
|
text[text_size] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void alloc_string(const char *str, int size)
|
|
||||||
{
|
|
||||||
text = malloc(size + 1);
|
|
||||||
memcpy(text, str, size);
|
|
||||||
text[size] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
VOLUME [v][o][l][u][m][e]
|
VOLUME [v][o][l][u][m][e]
|
||||||
@ -71,10 +64,10 @@ OPTION [o][p][t][i][o][n]
|
|||||||
TYPE [t][y][p][e]
|
TYPE [t][y][p][e]
|
||||||
%%
|
%%
|
||||||
\#.* ;
|
\#.* ;
|
||||||
{VOLUME} return SECTION_BEGIN;
|
{VOLUME} return VOLUME_BEGIN;
|
||||||
{TYPE} return TYPE;
|
{TYPE} return TYPE;
|
||||||
{END}[-]{VOLUME} return SECTION_END;
|
{END}[-]{VOLUME} return VOLUME_END;
|
||||||
{SUB}{VOLUME}[Ss] return SUBSECTION;
|
{SUB}{VOLUME}[Ss] return SUBVOLUME;
|
||||||
{OPTION} return OPTION;
|
{OPTION} return OPTION;
|
||||||
\" BEGIN(STRING);
|
\" BEGIN(STRING);
|
||||||
<STRING>{
|
<STRING>{
|
||||||
@ -83,12 +76,12 @@ TYPE [t][y][p][e]
|
|||||||
\" {
|
\" {
|
||||||
if (0) {
|
if (0) {
|
||||||
yyunput (0, NULL);
|
yyunput (0, NULL);
|
||||||
}
|
}
|
||||||
BEGIN (INITIAL);
|
BEGIN (INITIAL);
|
||||||
yylval = text;
|
yylval = text;
|
||||||
return STRING_TOK;
|
return STRING_TOK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[^ \t\r\n\"\\]+ { yylval = strdup (yytext) ; return ID; }
|
[^ \t\r\n\"\\]+ { yylval = gf_strdup (yytext) ; return ID; }
|
||||||
[ \t\r\n]+ ;
|
[ \t\r\n]+ ;
|
||||||
%%
|
%%
|
651
libglusterfs/src/graph.y
Normal file
651
libglusterfs/src/graph.y
Normal file
@ -0,0 +1,651 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com>
|
||||||
|
This file is part of GlusterFS.
|
||||||
|
|
||||||
|
GlusterFS is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published
|
||||||
|
by the Free Software Foundation; either version 3 of the License,
|
||||||
|
or (at your option) any later version.
|
||||||
|
|
||||||
|
GlusterFS is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
%token VOLUME_BEGIN VOLUME_END OPTION NEWLINE SUBVOLUME ID WHITESPACE COMMENT TYPE STRING_TOK
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
#include "xlator.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
static int new_volume (char *name);
|
||||||
|
static int volume_type (char *type);
|
||||||
|
static int volume_option (char *key, char *value);
|
||||||
|
static int volume_sub (char *sub);
|
||||||
|
static int volume_end (void);
|
||||||
|
static void sub_error (void);
|
||||||
|
static void type_error (void);
|
||||||
|
static void option_error (void);
|
||||||
|
|
||||||
|
#define YYSTYPE char *
|
||||||
|
#define GF_CMD_BUFFER_LEN (8 * GF_UNIT_KB)
|
||||||
|
|
||||||
|
int yyerror (const char *);
|
||||||
|
int yylex ();
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
%%
|
||||||
|
VOLUMES: VOLUME | VOLUMES VOLUME;
|
||||||
|
|
||||||
|
VOLUME: VOLUME_HEADER VOLUME_DATA VOLUME_FOOTER;
|
||||||
|
VOLUME_HEADER: VOLUME_BEGIN WORD {if (new_volume ($2) == -1) { YYABORT; }};
|
||||||
|
VOLUME_FOOTER: VOLUME_END {if (volume_end () == -1) { YYABORT; }};
|
||||||
|
|
||||||
|
VOLUME_DATA: TYPE_LINE OPTIONS_LINE SUBVOLUME_LINE OPTIONS_LINE |
|
||||||
|
TYPE_LINE SUBVOLUME_LINE OPTIONS_LINE |
|
||||||
|
TYPE_LINE OPTIONS_LINE SUBVOLUME_LINE |
|
||||||
|
TYPE_LINE SUBVOLUME_LINE |
|
||||||
|
TYPE_LINE OPTIONS_LINE |
|
||||||
|
OPTIONS_LINE SUBVOLUME_LINE OPTIONS_LINE | /* error case */
|
||||||
|
OPTIONS_LINE; /* error case */
|
||||||
|
|
||||||
|
TYPE_LINE: TYPE WORD {if (volume_type ($2) == -1) { YYABORT; }} | TYPE { type_error(); YYABORT; };
|
||||||
|
|
||||||
|
SUBVOLUME_LINE: SUBVOLUME WORDS | SUBVOLUME { sub_error (); YYABORT; };
|
||||||
|
|
||||||
|
OPTIONS_LINE: OPTION_LINE | OPTIONS_LINE OPTION_LINE;
|
||||||
|
|
||||||
|
OPTION_LINE: OPTION WORD WORD {if (volume_option ($2, $3) == -1) { YYABORT; }} |
|
||||||
|
OPTION WORD { option_error (); YYABORT; } |
|
||||||
|
OPTION { option_error (); YYABORT; };
|
||||||
|
|
||||||
|
WORDS: WORD {if (volume_sub ($1) == -1) {YYABORT; }} | WORDS WORD { if (volume_sub ($2) == -1) { YYABORT; }};
|
||||||
|
WORD: ID | STRING_TOK ;
|
||||||
|
%%
|
||||||
|
|
||||||
|
xlator_t *curr;
|
||||||
|
glusterfs_graph_t *construct;
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
type_error (void)
|
||||||
|
{
|
||||||
|
extern int yylineno;
|
||||||
|
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"Volume %s, before line %d: Please specify volume type",
|
||||||
|
curr->name, yylineno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
sub_error (void)
|
||||||
|
{
|
||||||
|
extern int yylineno;
|
||||||
|
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"Volume %s, before line %d: Please specify subvolumes",
|
||||||
|
curr->name, yylineno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
option_error (void)
|
||||||
|
{
|
||||||
|
extern int yylineno;
|
||||||
|
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"Volume %s, before line %d: Please specify "
|
||||||
|
"option <key> <value>",
|
||||||
|
curr->name, yylineno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
new_volume (char *name)
|
||||||
|
{
|
||||||
|
extern int yylineno;
|
||||||
|
xlator_t *trav = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
gf_log ("parser", GF_LOG_DEBUG,
|
||||||
|
"Invalid argument name: '%s'", name);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curr) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"new volume (%s) defintion in line %d unexpected",
|
||||||
|
name, yylineno);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
curr = (void *) GF_CALLOC (1, sizeof (*curr),
|
||||||
|
gf_common_mt_xlator_t);
|
||||||
|
|
||||||
|
if (!curr) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
trav = construct->first;
|
||||||
|
|
||||||
|
while (trav) {
|
||||||
|
if (!strcmp (name, trav->name)) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"Line %d: volume '%s' defined again",
|
||||||
|
yylineno, name);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
trav = trav->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
curr->name = gf_strdup (name);
|
||||||
|
if (!curr->name) {
|
||||||
|
GF_FREE (curr);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
curr->options = get_new_dict ();
|
||||||
|
|
||||||
|
if (!curr->options) {
|
||||||
|
GF_FREE (curr->name);
|
||||||
|
GF_FREE (curr);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
curr->next = construct->first;
|
||||||
|
if (curr->next)
|
||||||
|
curr->next->prev = curr;
|
||||||
|
|
||||||
|
curr->graph = construct;
|
||||||
|
|
||||||
|
construct->first = curr;
|
||||||
|
|
||||||
|
construct->xl_count++;
|
||||||
|
|
||||||
|
gf_log ("parser", GF_LOG_TRACE, "New node for '%s'", name);
|
||||||
|
|
||||||
|
out:
|
||||||
|
GF_FREE (name);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
volume_type (char *type)
|
||||||
|
{
|
||||||
|
extern int yylineno;
|
||||||
|
int32_t ret = 0;
|
||||||
|
|
||||||
|
if (!type) {
|
||||||
|
gf_log ("parser", GF_LOG_DEBUG, "Invalid argument type");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = xlator_set_type (curr, type);
|
||||||
|
if (ret) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"Volume '%s', line %d: type '%s' is not valid or "
|
||||||
|
"not found on this machine",
|
||||||
|
curr->name, yylineno, type);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
gf_log ("parser", GF_LOG_TRACE, "Type:%s:%s", curr->name, type);
|
||||||
|
|
||||||
|
out:
|
||||||
|
GF_FREE (type);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
volume_option (char *key, char *value)
|
||||||
|
{
|
||||||
|
extern int yylineno;
|
||||||
|
int ret = 0;
|
||||||
|
char *set_value = NULL;
|
||||||
|
|
||||||
|
if (!key || !value){
|
||||||
|
gf_log ("parser", GF_LOG_ERROR, "Invalid argument");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_value = gf_strdup (value);
|
||||||
|
ret = dict_set_dynstr (curr->options, key, set_value);
|
||||||
|
|
||||||
|
if (ret == 1) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"Volume '%s', line %d: duplicate entry "
|
||||||
|
"('option %s') present",
|
||||||
|
curr->name, yylineno, key);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
gf_log ("parser", GF_LOG_TRACE, "Option:%s:%s:%s",
|
||||||
|
curr->name, key, value);
|
||||||
|
|
||||||
|
out:
|
||||||
|
GF_FREE (key);
|
||||||
|
GF_FREE (value);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
volume_sub (char *sub)
|
||||||
|
{
|
||||||
|
extern int yylineno;
|
||||||
|
xlator_t *trav = NULL;
|
||||||
|
xlator_list_t *xlchild = NULL;
|
||||||
|
xlator_list_t *tmp = NULL;
|
||||||
|
xlator_list_t *xlparent = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (!sub) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR, "Invalid subvolumes argument");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
trav = construct->first;
|
||||||
|
|
||||||
|
while (trav) {
|
||||||
|
if (!strcmp (sub, trav->name))
|
||||||
|
break;
|
||||||
|
trav = trav->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!trav) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"Volume '%s', line %d: subvolume '%s' is not defined "
|
||||||
|
"prior to usage",
|
||||||
|
curr->name, yylineno, sub);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trav == curr) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"Volume '%s', line %d: has '%s' itself as subvolume",
|
||||||
|
curr->name, yylineno, sub);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
xlparent = (void *) GF_CALLOC (1, sizeof (*xlparent),
|
||||||
|
gf_common_mt_xlator_list_t);
|
||||||
|
|
||||||
|
if (!xlparent) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
xlparent->xlator = curr;
|
||||||
|
|
||||||
|
tmp = trav->parents;
|
||||||
|
if (tmp == NULL) {
|
||||||
|
trav->parents = xlparent;
|
||||||
|
} else {
|
||||||
|
while (tmp->next)
|
||||||
|
tmp = tmp->next;
|
||||||
|
tmp->next = xlparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
xlchild = (void *) GF_CALLOC (1, sizeof(*xlchild),
|
||||||
|
gf_common_mt_xlator_list_t);
|
||||||
|
if (!xlchild) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
xlchild->xlator = trav;
|
||||||
|
|
||||||
|
tmp = curr->children;
|
||||||
|
if (tmp == NULL) {
|
||||||
|
curr->children = xlchild;
|
||||||
|
} else {
|
||||||
|
while (tmp->next)
|
||||||
|
tmp = tmp->next;
|
||||||
|
tmp->next = xlchild;
|
||||||
|
}
|
||||||
|
|
||||||
|
gf_log ("parser", GF_LOG_TRACE, "child:%s->%s", curr->name, sub);
|
||||||
|
|
||||||
|
out:
|
||||||
|
GF_FREE (sub);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
volume_end (void)
|
||||||
|
{
|
||||||
|
if (!curr->fops) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"\"type\" not specified for volume %s", curr->name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
gf_log ("parser", GF_LOG_TRACE, "end:%s", curr->name);
|
||||||
|
|
||||||
|
curr = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
yywrap ()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
yyerror (const char *str)
|
||||||
|
{
|
||||||
|
extern char *yytext;
|
||||||
|
extern int yylineno;
|
||||||
|
|
||||||
|
if (curr && curr->name) {
|
||||||
|
if (!strcmp (yytext, "volume")) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"'end-volume' not defined for volume '%s'",
|
||||||
|
curr->name);
|
||||||
|
} else if (!strcmp (yytext, "type")) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"line %d: duplicate 'type' defined for "
|
||||||
|
"volume '%s'",
|
||||||
|
yylineno, curr->name);
|
||||||
|
} else if (!strcmp (yytext, "subvolumes")) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"line %d: duplicate 'subvolumes' defined for "
|
||||||
|
"volume '%s'",
|
||||||
|
yylineno, curr->name);
|
||||||
|
} else if (curr) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"syntax error: line %d (volume '%s'): \"%s\""
|
||||||
|
"\nallowed tokens are 'volume', 'type', "
|
||||||
|
"'subvolumes', 'option', 'end-volume'()",
|
||||||
|
yylineno, curr->name,
|
||||||
|
yytext);
|
||||||
|
} else {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"syntax error: line %d (just after volume "
|
||||||
|
"'%s'): \"%s\"\n(%s)",
|
||||||
|
yylineno, curr->name,
|
||||||
|
yytext,
|
||||||
|
"allowed tokens are 'volume', 'type', "
|
||||||
|
"'subvolumes', 'option', 'end-volume'");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"syntax error in line %d: \"%s\" \n"
|
||||||
|
"(allowed tokens are 'volume', 'type', "
|
||||||
|
"'subvolumes', 'option', 'end-volume')\n",
|
||||||
|
yylineno, yytext);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
execute_cmd (char *cmd, char **result, size_t size)
|
||||||
|
{
|
||||||
|
FILE *fpp = NULL;
|
||||||
|
int i = 0;
|
||||||
|
int status = 0;
|
||||||
|
int character = 0;
|
||||||
|
char *buf = *result;
|
||||||
|
|
||||||
|
fpp = popen (cmd, "r");
|
||||||
|
if (!fpp) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR, "%s: failed to popen", cmd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((character = fgetc (fpp)) != EOF) {
|
||||||
|
if (i == size) {
|
||||||
|
size *= 2;
|
||||||
|
buf = *result = GF_REALLOC (*result, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[i++] = character;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > 0) {
|
||||||
|
i--;
|
||||||
|
buf[i] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
status = pclose (fpp);
|
||||||
|
if (status == -1 || !WIFEXITED (status) ||
|
||||||
|
((WEXITSTATUS (status)) != 0)) {
|
||||||
|
i = -1;
|
||||||
|
buf[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
preprocess (FILE *srcfp, FILE *dstfp)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int i = 0;
|
||||||
|
char *cmd = NULL;
|
||||||
|
char *result = NULL;
|
||||||
|
size_t cmd_buf_size = GF_CMD_BUFFER_LEN;
|
||||||
|
char escaped = 0;
|
||||||
|
char in_backtick = 0;
|
||||||
|
int line = 1;
|
||||||
|
int column = 0;
|
||||||
|
int backtick_line = 0;
|
||||||
|
int backtick_column = 0;
|
||||||
|
int character = 0;
|
||||||
|
|
||||||
|
|
||||||
|
fseek (srcfp, 0L, SEEK_SET);
|
||||||
|
fseek (dstfp, 0L, SEEK_SET);
|
||||||
|
|
||||||
|
cmd = GF_CALLOC (cmd_buf_size, 1,
|
||||||
|
gf_common_mt_char);
|
||||||
|
if (cmd == NULL) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = GF_CALLOC (cmd_buf_size * 2, 1,
|
||||||
|
gf_common_mt_char);
|
||||||
|
if (result == NULL) {
|
||||||
|
GF_FREE (cmd);
|
||||||
|
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((character = fgetc (srcfp)) != EOF) {
|
||||||
|
if ((character == '`') && !escaped) {
|
||||||
|
if (in_backtick) {
|
||||||
|
cmd[i] = '\0';
|
||||||
|
result[0] = '\0';
|
||||||
|
|
||||||
|
ret = execute_cmd (cmd, &result,
|
||||||
|
2 * cmd_buf_size);
|
||||||
|
if (ret < 0) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
fwrite (result, ret, 1, dstfp);
|
||||||
|
} else {
|
||||||
|
i = 0;
|
||||||
|
cmd[i] = '\0';
|
||||||
|
|
||||||
|
backtick_column = column;
|
||||||
|
backtick_line = line;
|
||||||
|
}
|
||||||
|
|
||||||
|
in_backtick = !in_backtick;
|
||||||
|
} else {
|
||||||
|
if (in_backtick) {
|
||||||
|
if (i == cmd_buf_size) {
|
||||||
|
cmd_buf_size *= 2;
|
||||||
|
cmd = GF_REALLOC (cmd, cmd_buf_size);
|
||||||
|
if (cmd == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = GF_REALLOC (result,
|
||||||
|
2 * cmd_buf_size);
|
||||||
|
if (result == NULL) {
|
||||||
|
GF_FREE (cmd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd[i++] = character;
|
||||||
|
} else {
|
||||||
|
fputc (character, dstfp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (character == '\\') {
|
||||||
|
escaped = !escaped;
|
||||||
|
} else {
|
||||||
|
escaped = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (character == '\n') {
|
||||||
|
line++;
|
||||||
|
column = 0;
|
||||||
|
} else {
|
||||||
|
column++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_backtick) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"Unterminated backtick in volume specfication file at line (%d), column (%d).",
|
||||||
|
line, column);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
fseek (srcfp, 0L, SEEK_SET);
|
||||||
|
fseek (dstfp, 0L, SEEK_SET);
|
||||||
|
GF_FREE (cmd);
|
||||||
|
GF_FREE (result);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern FILE *yyin;
|
||||||
|
|
||||||
|
glusterfs_graph_t *
|
||||||
|
glusterfs_graph_new ()
|
||||||
|
{
|
||||||
|
glusterfs_graph_t *graph = NULL;
|
||||||
|
|
||||||
|
graph = GF_CALLOC (1, sizeof (*graph),
|
||||||
|
gf_common_mt_glusterfs_graph_t);
|
||||||
|
if (!graph)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
INIT_LIST_HEAD (&graph->list);
|
||||||
|
|
||||||
|
gettimeofday (&graph->dob, NULL);
|
||||||
|
|
||||||
|
return graph;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
glusterfs_graph_t *
|
||||||
|
glusterfs_graph_construct (FILE *fp)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
glusterfs_graph_t *graph = NULL;
|
||||||
|
FILE *tmp_file = NULL;
|
||||||
|
|
||||||
|
graph = glusterfs_graph_new ();
|
||||||
|
if (!graph)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
tmp_file = tmpfile ();
|
||||||
|
|
||||||
|
if (tmp_file == NULL) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"cannot create temparory file");
|
||||||
|
|
||||||
|
glusterfs_graph_destroy (graph);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = preprocess (fp, tmp_file);
|
||||||
|
if (ret < 0) {
|
||||||
|
gf_log ("parser", GF_LOG_ERROR,
|
||||||
|
"parsing of backticks failed");
|
||||||
|
|
||||||
|
glusterfs_graph_destroy (graph);
|
||||||
|
fclose (tmp_file);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
yyin = tmp_file;
|
||||||
|
|
||||||
|
construct = graph;
|
||||||
|
|
||||||
|
ret = yyparse ();
|
||||||
|
|
||||||
|
construct = NULL;
|
||||||
|
|
||||||
|
fclose (tmp_file);
|
||||||
|
|
||||||
|
if (ret == 1) {
|
||||||
|
gf_log ("parser", GF_LOG_DEBUG,
|
||||||
|
"parsing of volfile failed, please review it "
|
||||||
|
"once more");
|
||||||
|
|
||||||
|
glusterfs_graph_destroy (graph);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return graph;
|
||||||
|
}
|
||||||
|
|
@ -281,7 +281,7 @@ __inode_destroy (inode_t *inode)
|
|||||||
if (!inode->_ctx)
|
if (!inode->_ctx)
|
||||||
goto noctx;
|
goto noctx;
|
||||||
|
|
||||||
for (index = 0; index < inode->table->xl->ctx->xl_count; index++) {
|
for (index = 0; index < inode->table->xl->graph->xl_count; index++) {
|
||||||
if (inode->_ctx[index].key) {
|
if (inode->_ctx[index].key) {
|
||||||
xl = (xlator_t *)(long)inode->_ctx[index].key;
|
xl = (xlator_t *)(long)inode->_ctx[index].key;
|
||||||
old_THIS = THIS;
|
old_THIS = THIS;
|
||||||
@ -474,8 +474,9 @@ __inode_create (inode_table_t *table)
|
|||||||
INIT_LIST_HEAD (&newi->dentry_list);
|
INIT_LIST_HEAD (&newi->dentry_list);
|
||||||
|
|
||||||
newi->_ctx = GF_CALLOC (1, (sizeof (struct _inode_ctx) *
|
newi->_ctx = GF_CALLOC (1, (sizeof (struct _inode_ctx) *
|
||||||
table->xl->ctx->xl_count),
|
table->xl->graph->xl_count),
|
||||||
gf_common_mt_inode_ctx);
|
gf_common_mt_inode_ctx);
|
||||||
|
|
||||||
if (newi->_ctx == NULL) {
|
if (newi->_ctx == NULL) {
|
||||||
gf_log ("inode", GF_LOG_ERROR, "out of memory");
|
gf_log ("inode", GF_LOG_ERROR, "out of memory");
|
||||||
LOCK_DESTROY (&newi->lock);
|
LOCK_DESTROY (&newi->lock);
|
||||||
@ -1173,7 +1174,7 @@ __inode_ctx_put2 (inode_t *inode, xlator_t *xlator, uint64_t value1,
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
int put_idx = -1;
|
int put_idx = -1;
|
||||||
|
|
||||||
for (index = 0; index < xlator->ctx->xl_count; index++) {
|
for (index = 0; index < xlator->graph->xl_count; index++) {
|
||||||
if (!inode->_ctx[index].key) {
|
if (!inode->_ctx[index].key) {
|
||||||
if (put_idx == -1)
|
if (put_idx == -1)
|
||||||
put_idx = index;
|
put_idx = index;
|
||||||
@ -1225,12 +1226,12 @@ __inode_ctx_get2 (inode_t *inode, xlator_t *xlator, uint64_t *value1,
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
for (index = 0; index < xlator->ctx->xl_count; index++) {
|
for (index = 0; index < xlator->graph->xl_count; index++) {
|
||||||
if (inode->_ctx[index].xl_key == xlator)
|
if (inode->_ctx[index].xl_key == xlator)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == xlator->ctx->xl_count) {
|
if (index == xlator->graph->xl_count) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -1277,12 +1278,12 @@ inode_ctx_del2 (inode_t *inode, xlator_t *xlator, uint64_t *value1,
|
|||||||
|
|
||||||
LOCK (&inode->lock);
|
LOCK (&inode->lock);
|
||||||
{
|
{
|
||||||
for (index = 0; index < xlator->ctx->xl_count; index++) {
|
for (index = 0; index < xlator->graph->xl_count; index++) {
|
||||||
if (inode->_ctx[index].xl_key == xlator)
|
if (inode->_ctx[index].xl_key == xlator)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == xlator->ctx->xl_count) {
|
if (index == xlator->graph->xl_count) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
@ -1371,7 +1372,7 @@ inode_dump (inode_t *inode, char *prefix)
|
|||||||
if (!inode->_ctx)
|
if (!inode->_ctx)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (i = 0; i < inode->table->xl->ctx->xl_count; i++) {
|
for (i = 0; i < inode->table->xl->graph->xl_count; i++) {
|
||||||
if (inode->_ctx[i].key) {
|
if (inode->_ctx[i].key) {
|
||||||
xl = (xlator_t *)(long)inode->_ctx[i].key;
|
xl = (xlator_t *)(long)inode->_ctx[i].key;
|
||||||
if (xl->dumpops && xl->dumpops->inodectx)
|
if (xl->dumpops && xl->dumpops->inodectx)
|
||||||
|
@ -174,7 +174,7 @@ gf_latency_toggle (int signum)
|
|||||||
{
|
{
|
||||||
glusterfs_ctx_t *ctx = NULL;
|
glusterfs_ctx_t *ctx = NULL;
|
||||||
|
|
||||||
ctx = get_global_ctx_ptr ();
|
ctx = glusterfs_ctx_get ();
|
||||||
|
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
ctx->measure_latency = !ctx->measure_latency;
|
ctx->measure_latency = !ctx->measure_latency;
|
||||||
|
@ -77,6 +77,7 @@ enum gf_common_mem_types_ {
|
|||||||
gf_common_mt_rpcsvc_conn_t,
|
gf_common_mt_rpcsvc_conn_t,
|
||||||
gf_common_mt_rpcsvc_program_t,
|
gf_common_mt_rpcsvc_program_t,
|
||||||
gf_common_mt_rpcsvc_stage_t,
|
gf_common_mt_rpcsvc_stage_t,
|
||||||
|
gf_common_mt_glusterfs_graph_t,
|
||||||
gf_common_mt_end
|
gf_common_mt_end
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,626 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com>
|
|
||||||
This file is part of GlusterFS.
|
|
||||||
|
|
||||||
GlusterFS is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published
|
|
||||||
by the Free Software Foundation; either version 3 of the License,
|
|
||||||
or (at your option) any later version.
|
|
||||||
|
|
||||||
GlusterFS is distributed in the hope that it will be useful, but
|
|
||||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
%token SECTION_BEGIN SECTION_END OPTION NEWLINE SUBSECTION ID WHITESPACE COMMENT TYPE STRING_TOK
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
|
|
||||||
#include "xlator.h"
|
|
||||||
#include "logging.h"
|
|
||||||
|
|
||||||
static int new_section (char *name);
|
|
||||||
static int section_type (char *type);
|
|
||||||
static int section_option (char *key, char *value);
|
|
||||||
static int section_sub (char *sub);
|
|
||||||
static int section_end (void);
|
|
||||||
static void sub_error (void);
|
|
||||||
static void type_error (void);
|
|
||||||
static void option_error (void);
|
|
||||||
|
|
||||||
#define YYSTYPE char *
|
|
||||||
#define GF_CMD_BUFFER_LEN (8 * GF_UNIT_KB)
|
|
||||||
|
|
||||||
int yyerror (const char *);
|
|
||||||
int yylex ();
|
|
||||||
%}
|
|
||||||
|
|
||||||
|
|
||||||
%%
|
|
||||||
SECTIONS: SECTION | SECTIONS SECTION;
|
|
||||||
|
|
||||||
SECTION: SECTION_HEADER SECTION_DATA SECTION_FOOTER;
|
|
||||||
SECTION_HEADER: SECTION_BEGIN WORD {if( -1 == new_section ($2)) { YYABORT; } };
|
|
||||||
SECTION_FOOTER: SECTION_END {if( -1 == section_end ()) { YYABORT; } };
|
|
||||||
|
|
||||||
SECTION_DATA: TYPE_LINE OPTIONS_LINE SUBSECTION_LINE OPTIONS_LINE |
|
|
||||||
TYPE_LINE SUBSECTION_LINE OPTIONS_LINE |
|
|
||||||
TYPE_LINE OPTIONS_LINE SUBSECTION_LINE |
|
|
||||||
TYPE_LINE SUBSECTION_LINE |
|
|
||||||
TYPE_LINE OPTIONS_LINE |
|
|
||||||
OPTIONS_LINE SUBSECTION_LINE OPTIONS_LINE | /* error case */
|
|
||||||
OPTIONS_LINE; /* error case */
|
|
||||||
|
|
||||||
TYPE_LINE: TYPE WORD {if ( -1 == section_type ($2)) { YYABORT; }} | TYPE { type_error(); YYABORT; };
|
|
||||||
|
|
||||||
SUBSECTION_LINE: SUBSECTION WORDS | SUBSECTION { sub_error (); YYABORT; };
|
|
||||||
|
|
||||||
OPTIONS_LINE: OPTION_LINE | OPTIONS_LINE OPTION_LINE;
|
|
||||||
|
|
||||||
OPTION_LINE: OPTION WORD WORD {if(-1 == section_option($2,$3)){YYABORT;} } |
|
|
||||||
OPTION WORD { option_error (); YYABORT; } |
|
|
||||||
OPTION { option_error (); YYABORT; };
|
|
||||||
|
|
||||||
WORDS: WORD {if (-1 == section_sub ($1)) {YYABORT; } } | WORDS WORD { if (-1 == section_sub ($2)) { YYABORT; } };
|
|
||||||
WORD: ID | STRING_TOK ;
|
|
||||||
%%
|
|
||||||
|
|
||||||
xlator_t *complete_tree = NULL;
|
|
||||||
xlator_t *tree = NULL;
|
|
||||||
glusterfs_ctx_t *gctx;
|
|
||||||
|
|
||||||
static void
|
|
||||||
type_error (void)
|
|
||||||
{
|
|
||||||
extern int yylineno;
|
|
||||||
|
|
||||||
fprintf (stderr, "Volume '%s', before line %d: Please specify volume 'type'.",
|
|
||||||
complete_tree->name, yylineno);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"Volume '%s', before line %d: Please specify volume 'type'.",
|
|
||||||
complete_tree->name, yylineno);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sub_error (void)
|
|
||||||
{
|
|
||||||
extern int yylineno;
|
|
||||||
|
|
||||||
fprintf (stderr, "Volume %s, before line %d: Please specify subvolumes for the volume. ",
|
|
||||||
complete_tree->name, yylineno);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"Volume %s, before line %d: Please specify subvolumes for the volume. ",
|
|
||||||
complete_tree->name, yylineno);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
option_error (void)
|
|
||||||
{
|
|
||||||
extern int yylineno;
|
|
||||||
|
|
||||||
fprintf (stderr, "Volume %s, before line %d: Please specify "
|
|
||||||
"option <key> <value> \n",
|
|
||||||
complete_tree->name, yylineno);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"Volume %s, before line %d: Please specify "
|
|
||||||
"option <key> <value>",
|
|
||||||
complete_tree->name, yylineno);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
cut_tree (xlator_t *tree)
|
|
||||||
{
|
|
||||||
xlator_t *trav = tree, *prev = tree;
|
|
||||||
|
|
||||||
if (!tree) {
|
|
||||||
gf_log ("parser", GF_LOG_DEBUG, "Translator tree not found");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
gf_log ("parser", GF_LOG_DEBUG, "Failed to build translator graph");
|
|
||||||
|
|
||||||
while (prev) {
|
|
||||||
trav = prev->next;
|
|
||||||
dict_destroy (prev->options);
|
|
||||||
FREE (prev->name);
|
|
||||||
FREE (prev);
|
|
||||||
prev = trav;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
new_section (char *name)
|
|
||||||
{
|
|
||||||
extern int yylineno;
|
|
||||||
xlator_t *trav = complete_tree;
|
|
||||||
xlator_t *node = NULL;
|
|
||||||
|
|
||||||
node = (void *) calloc (1, sizeof (*node));
|
|
||||||
if (!node) {
|
|
||||||
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!name) {
|
|
||||||
gf_log ("parser", GF_LOG_DEBUG,
|
|
||||||
"Invalid argument name: '%s'", name);
|
|
||||||
FREE (node);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (trav) {
|
|
||||||
if (!strcmp (name, trav->name)) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"Line %d: volume '%s' defined again\n",
|
|
||||||
yylineno, name);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"Line %d: volume '%s' defined again",
|
|
||||||
yylineno, name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
trav = trav->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
node->ctx = gctx;
|
|
||||||
node->name = name;
|
|
||||||
node->next = complete_tree;
|
|
||||||
if (complete_tree)
|
|
||||||
complete_tree->prev = node;
|
|
||||||
node->options = get_new_dict ();
|
|
||||||
complete_tree = node;
|
|
||||||
|
|
||||||
tree = node;
|
|
||||||
gf_log ("parser", GF_LOG_TRACE, "New node for '%s'", name);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
section_type (char *type)
|
|
||||||
{
|
|
||||||
extern int yylineno;
|
|
||||||
int32_t ret = -1;
|
|
||||||
if (!type) {
|
|
||||||
gf_log ("parser", GF_LOG_DEBUG, "Invalid argument type");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = xlator_set_type (tree, type);
|
|
||||||
if (ret) {
|
|
||||||
fprintf (stderr, "Volume '%s', line %d: type '%s' is not "
|
|
||||||
"valid or not found on this machine\n",
|
|
||||||
complete_tree->name, yylineno, type);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"Volume '%s', line %d: type '%s' is not valid or "
|
|
||||||
"not found on this machine",
|
|
||||||
complete_tree->name, yylineno, type);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
gf_log ("parser", GF_LOG_TRACE, "Type:%s:%s", tree->name, type);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
section_option (char *key, char *value)
|
|
||||||
{
|
|
||||||
extern int yylineno;
|
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (!key || !value){
|
|
||||||
fprintf (stderr, "Invalid argument\n");
|
|
||||||
gf_log ("parser", GF_LOG_ERROR, "Invalid argument");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = dict_set (tree->options, key, str_to_data (value));
|
|
||||||
|
|
||||||
if (ret == 1) {
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"Volume '%s', line %d: duplicate entry "
|
|
||||||
"('option %s') present",
|
|
||||||
tree->name, yylineno, key);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
gf_log ("parser", GF_LOG_TRACE, "Option:%s:%s:%s",
|
|
||||||
tree->name, key, value);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
section_sub (char *sub)
|
|
||||||
{
|
|
||||||
extern int yylineno;
|
|
||||||
xlator_t *trav = complete_tree;
|
|
||||||
xlator_list_t *xlchild, *tmp, *xlparent;
|
|
||||||
|
|
||||||
if (!sub) {
|
|
||||||
fprintf (stderr, "Invalid subvolumes argument\n");
|
|
||||||
gf_log ("parser", GF_LOG_ERROR, "Invalid subvolumes argument");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (trav) {
|
|
||||||
if (!strcmp (sub, trav->name))
|
|
||||||
break;
|
|
||||||
trav = trav->next;
|
|
||||||
}
|
|
||||||
if (!trav) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"Volume '%s', line %d: subvolume '%s' is not "
|
|
||||||
"defined prior to usage\n",
|
|
||||||
complete_tree->name, yylineno, sub);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"Volume '%s', line %d: subvolume '%s' is not defined "
|
|
||||||
"prior to usage",
|
|
||||||
complete_tree->name, yylineno, sub);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trav == tree) {
|
|
||||||
fprintf (stderr, "Volume '%s', line %d: has '%s' itself as "
|
|
||||||
"subvolume\n",
|
|
||||||
complete_tree->name, yylineno, sub);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"Volume '%s', line %d: has '%s' itself as subvolume",
|
|
||||||
complete_tree->name, yylineno, sub);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
xlparent = (void *) calloc (1, sizeof (*xlparent));
|
|
||||||
if (!xlparent) {
|
|
||||||
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
xlparent->xlator = tree;
|
|
||||||
|
|
||||||
tmp = trav->parents;
|
|
||||||
if (tmp == NULL) {
|
|
||||||
trav->parents = xlparent;
|
|
||||||
} else {
|
|
||||||
while (tmp->next)
|
|
||||||
tmp = tmp->next;
|
|
||||||
tmp->next = xlparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
xlchild = (void *) calloc (1, sizeof(*xlchild));
|
|
||||||
if (!xlchild) {
|
|
||||||
FREE (xlparent);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
xlchild->xlator = trav;
|
|
||||||
|
|
||||||
tmp = tree->children;
|
|
||||||
if (tmp == NULL) {
|
|
||||||
tree->children = xlchild;
|
|
||||||
} else {
|
|
||||||
while (tmp->next)
|
|
||||||
tmp = tmp->next;
|
|
||||||
tmp->next = xlchild;
|
|
||||||
}
|
|
||||||
|
|
||||||
gf_log ("parser", GF_LOG_TRACE, "child:%s->%s", tree->name, sub);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
section_end (void)
|
|
||||||
{
|
|
||||||
if (!tree->fops) {
|
|
||||||
fprintf (stderr,
|
|
||||||
"\"type\" not specified for volume %s\n", tree->name);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"\"type\" not specified for volume %s", tree->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
gf_log ("parser", GF_LOG_TRACE, "end:%s", tree->name);
|
|
||||||
|
|
||||||
tree = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
yywrap ()
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
yyerror (const char *str)
|
|
||||||
{
|
|
||||||
extern char *yytext;
|
|
||||||
extern int yylineno;
|
|
||||||
|
|
||||||
if (complete_tree && complete_tree->name)
|
|
||||||
{
|
|
||||||
if (!strcmp (yytext, "volume"))
|
|
||||||
{
|
|
||||||
fprintf (stderr,
|
|
||||||
"'end-volume' not defined for volume '%s'\n",
|
|
||||||
complete_tree->name);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"'end-volume' not defined for volume '%s'",
|
|
||||||
complete_tree->name);
|
|
||||||
}
|
|
||||||
else if (!strcmp (yytext, "type"))
|
|
||||||
{
|
|
||||||
fprintf (stderr, "line %d: duplicate 'type' defined "
|
|
||||||
"for volume '%s'",
|
|
||||||
yylineno, complete_tree->name);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"line %d: duplicate 'type' defined for "
|
|
||||||
"volume '%s'",
|
|
||||||
yylineno, complete_tree->name);
|
|
||||||
}
|
|
||||||
else if (!strcmp (yytext, "subvolumes"))
|
|
||||||
{
|
|
||||||
fprintf (stderr, "line %d: duplicate 'subvolumes' "
|
|
||||||
"defined for volume '%s'",
|
|
||||||
yylineno, complete_tree->name);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"line %d: duplicate 'subvolumes' defined for "
|
|
||||||
"volume '%s'",
|
|
||||||
yylineno, complete_tree->name);
|
|
||||||
}
|
|
||||||
else if (tree)
|
|
||||||
{
|
|
||||||
fprintf (stderr,
|
|
||||||
"syntax error: line %d (volume '%s'): \"%s\""
|
|
||||||
"\nallowed tokens are 'volume', 'type', "
|
|
||||||
"'subvolumes', 'option', 'end-volume'",
|
|
||||||
yylineno, complete_tree->name,
|
|
||||||
yytext);
|
|
||||||
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"syntax error: line %d (volume '%s'): \"%s\""
|
|
||||||
"\nallowed tokens are 'volume', 'type', "
|
|
||||||
"'subvolumes', 'option', 'end-volume'()",
|
|
||||||
yylineno, complete_tree->name,
|
|
||||||
yytext);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf (stderr,
|
|
||||||
"syntax error: line %d (just after volume "
|
|
||||||
"'%s'): \"%s\"\n(%s)",
|
|
||||||
yylineno, complete_tree->name,
|
|
||||||
yytext,
|
|
||||||
"allowed tokens are 'volume', 'type', "
|
|
||||||
"'subvolumes', 'option', 'end-volume'");
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"syntax error: line %d (just after volume "
|
|
||||||
"'%s'): \"%s\"\n(%s)",
|
|
||||||
yylineno, complete_tree->name,
|
|
||||||
yytext,
|
|
||||||
"allowed tokens are 'volume', 'type', "
|
|
||||||
"'subvolumes', 'option', 'end-volume'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf (stderr,
|
|
||||||
"syntax error in line %d: \"%s\" \n"
|
|
||||||
"(allowed tokens are 'volume', 'type', "
|
|
||||||
"'subvolumes', 'option', 'end-volume')\n",
|
|
||||||
yylineno, yytext);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"syntax error in line %d: \"%s\" \n"
|
|
||||||
"(allowed tokens are 'volume', 'type', "
|
|
||||||
"'subvolumes', 'option', 'end-volume')\n",
|
|
||||||
yylineno, yytext);
|
|
||||||
}
|
|
||||||
|
|
||||||
cut_tree (tree);
|
|
||||||
complete_tree = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
execute_cmd (char *cmd, char **result, size_t size)
|
|
||||||
{
|
|
||||||
FILE *fpp = NULL;
|
|
||||||
int i = 0, status = 0;
|
|
||||||
int character = 0;
|
|
||||||
char *buf = *result;
|
|
||||||
|
|
||||||
fpp = popen (cmd, "r");
|
|
||||||
if (!fpp) {
|
|
||||||
gf_log ("parser", GF_LOG_ERROR, "%s: failed to popen", cmd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((character = fgetc (fpp)) != EOF) {
|
|
||||||
if (i == size) {
|
|
||||||
size *= 2;
|
|
||||||
buf = *result = realloc (*result, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf[i++] = character;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i > 0) {
|
|
||||||
i--;
|
|
||||||
buf[i] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pclose (fpp);
|
|
||||||
if (status == -1 || !WIFEXITED (status) ||
|
|
||||||
((WEXITSTATUS (status)) != 0)) {
|
|
||||||
i = -1;
|
|
||||||
buf[0] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
parse_backtick (FILE *srcfp, FILE *dstfp)
|
|
||||||
{
|
|
||||||
int ret = 0, i = 0;
|
|
||||||
char *cmd = NULL, *result = NULL;
|
|
||||||
size_t cmd_buf_size = GF_CMD_BUFFER_LEN;
|
|
||||||
char escaped = 0, in_backtick = 0;
|
|
||||||
int line = 1, column = 0, backtick_line = 0, backtick_column = 0;
|
|
||||||
int character = 0;
|
|
||||||
|
|
||||||
fseek (srcfp, 0L, SEEK_SET);
|
|
||||||
fseek (dstfp, 0L, SEEK_SET);
|
|
||||||
|
|
||||||
cmd = CALLOC (cmd_buf_size, 1);
|
|
||||||
if (cmd == NULL) {
|
|
||||||
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = CALLOC (cmd_buf_size * 2, 1);
|
|
||||||
if (result == NULL) {
|
|
||||||
FREE (cmd);
|
|
||||||
gf_log ("parser", GF_LOG_ERROR, "Out of memory");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((character = fgetc (srcfp)) != EOF) {
|
|
||||||
if ((character == '`') && !escaped) {
|
|
||||||
if (in_backtick) {
|
|
||||||
cmd[i] = '\0';
|
|
||||||
result[0] = '\0';
|
|
||||||
|
|
||||||
ret = execute_cmd (cmd, &result,
|
|
||||||
2 * cmd_buf_size);
|
|
||||||
if (ret < 0) {
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
fwrite (result, ret, 1, dstfp);
|
|
||||||
} else {
|
|
||||||
i = 0;
|
|
||||||
cmd[i] = '\0';
|
|
||||||
|
|
||||||
backtick_column = column;
|
|
||||||
backtick_line = line;
|
|
||||||
}
|
|
||||||
|
|
||||||
in_backtick = !in_backtick;
|
|
||||||
} else {
|
|
||||||
if (in_backtick) {
|
|
||||||
if (i == cmd_buf_size) {
|
|
||||||
cmd_buf_size *= 2;
|
|
||||||
cmd = realloc (cmd, cmd_buf_size);
|
|
||||||
if (cmd == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = realloc (result,
|
|
||||||
2 * cmd_buf_size);
|
|
||||||
if (result == NULL) {
|
|
||||||
free (cmd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd[i++] = character;
|
|
||||||
} else {
|
|
||||||
fputc (character, dstfp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (character == '\\') {
|
|
||||||
escaped = !escaped;
|
|
||||||
} else {
|
|
||||||
escaped = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (character == '\n') {
|
|
||||||
line++;
|
|
||||||
column = 0;
|
|
||||||
} else {
|
|
||||||
column++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_backtick) {
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"Unterminated backtick in volume specfication file at line (%d), column (%d).",
|
|
||||||
line, column);
|
|
||||||
ret = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
fseek (srcfp, 0L, SEEK_SET);
|
|
||||||
fseek (dstfp, 0L, SEEK_SET);
|
|
||||||
free (cmd);
|
|
||||||
free (result);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern FILE *yyin;
|
|
||||||
xlator_t *
|
|
||||||
file_to_xlator_tree (glusterfs_ctx_t *ctx,
|
|
||||||
FILE *fp)
|
|
||||||
{
|
|
||||||
int32_t ret = 0;
|
|
||||||
xlator_t *tmp_tree = NULL;
|
|
||||||
FILE *tmp_file = NULL;
|
|
||||||
char *buffer = NULL;
|
|
||||||
|
|
||||||
tmp_file = tmpfile ();
|
|
||||||
if (NULL == tmp_file) {
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"cannot create temparory file");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = parse_backtick (fp, tmp_file);
|
|
||||||
if (ret < 0) {
|
|
||||||
gf_log ("parser", GF_LOG_ERROR,
|
|
||||||
"parsing of backticks failed");
|
|
||||||
fclose (tmp_file);
|
|
||||||
FREE (buffer);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
gctx = ctx;
|
|
||||||
yyin = tmp_file;
|
|
||||||
ret = yyparse ();
|
|
||||||
|
|
||||||
fclose (tmp_file);
|
|
||||||
FREE (buffer);
|
|
||||||
|
|
||||||
if (1 == ret) {
|
|
||||||
gf_log ("parser", GF_LOG_DEBUG,
|
|
||||||
"parsing of volfile failed, please review it "
|
|
||||||
"once more");
|
|
||||||
tree = complete_tree = NULL;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp_tree = complete_tree;
|
|
||||||
tree = complete_tree = NULL;
|
|
||||||
|
|
||||||
return tmp_tree;
|
|
||||||
}
|
|
@ -143,7 +143,7 @@ FRAME_DESTROY (call_frame_t *frame)
|
|||||||
static inline void
|
static inline void
|
||||||
STACK_DESTROY (call_stack_t *stack)
|
STACK_DESTROY (call_stack_t *stack)
|
||||||
{
|
{
|
||||||
glusterfs_ctx_t *ctx = get_global_ctx_ptr ();
|
glusterfs_ctx_t *ctx = glusterfs_ctx_get ();
|
||||||
|
|
||||||
if (ctx && ctx->measure_latency) {
|
if (ctx && ctx->measure_latency) {
|
||||||
gettimeofday (&stack->frames.end, NULL);
|
gettimeofday (&stack->frames.end, NULL);
|
||||||
@ -330,18 +330,18 @@ copy_frame (call_frame_t *frame)
|
|||||||
{
|
{
|
||||||
list_add (&newstack->all_frames, &oldstack->all_frames);
|
list_add (&newstack->all_frames, &oldstack->all_frames);
|
||||||
newstack->pool->cnt++;
|
newstack->pool->cnt++;
|
||||||
|
|
||||||
}
|
}
|
||||||
UNLOCK (&oldstack->pool->lock);
|
UNLOCK (&oldstack->pool->lock);
|
||||||
|
|
||||||
return &newstack->frames;
|
return &newstack->frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline call_frame_t *
|
static inline call_frame_t *
|
||||||
create_frame (xlator_t *xl, call_pool_t *pool)
|
create_frame (xlator_t *xl, call_pool_t *pool)
|
||||||
{
|
{
|
||||||
call_stack_t *stack = NULL;
|
call_stack_t *stack = NULL;
|
||||||
glusterfs_ctx_t *ctx = get_global_ctx_ptr ();
|
glusterfs_ctx_t *ctx = glusterfs_ctx_get ();
|
||||||
|
|
||||||
if (!xl || !pool) {
|
if (!xl || !pool) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -33,17 +33,20 @@ extern xlator_t global_xlator;
|
|||||||
static pthread_mutex_t gf_proc_dump_mutex;
|
static pthread_mutex_t gf_proc_dump_mutex;
|
||||||
static int gf_dump_fd = -1;
|
static int gf_dump_fd = -1;
|
||||||
|
|
||||||
static void
|
|
||||||
|
static void
|
||||||
gf_proc_dump_lock (void)
|
gf_proc_dump_lock (void)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&gf_proc_dump_mutex);
|
pthread_mutex_lock (&gf_proc_dump_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
|
static void
|
||||||
gf_proc_dump_unlock (void)
|
gf_proc_dump_unlock (void)
|
||||||
{
|
{
|
||||||
pthread_mutex_unlock(&gf_proc_dump_mutex);
|
pthread_mutex_unlock (&gf_proc_dump_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
gf_proc_dump_open (void)
|
gf_proc_dump_open (void)
|
||||||
@ -51,10 +54,10 @@ gf_proc_dump_open (void)
|
|||||||
char path[256];
|
char path[256];
|
||||||
int dump_fd = -1;
|
int dump_fd = -1;
|
||||||
|
|
||||||
memset(path, 0, sizeof(path));
|
memset (path, 0, sizeof (path));
|
||||||
snprintf(path, sizeof(path), "%s.%d",GF_DUMP_LOGFILE_ROOT, getpid());
|
snprintf (path, sizeof (path), "%s.%d", GF_DUMP_LOGFILE_ROOT, getpid ());
|
||||||
|
|
||||||
dump_fd = open(path, O_CREAT|O_RDWR|O_TRUNC|O_APPEND, 0600);
|
dump_fd = open (path, O_CREAT|O_RDWR|O_TRUNC|O_APPEND, 0600);
|
||||||
if (dump_fd < 0) {
|
if (dump_fd < 0) {
|
||||||
gf_log("", GF_LOG_ERROR, "Unable to open file: %s"
|
gf_log("", GF_LOG_ERROR, "Unable to open file: %s"
|
||||||
" errno: %d", path, errno);
|
" errno: %d", path, errno);
|
||||||
@ -65,56 +68,59 @@ gf_proc_dump_open (void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gf_proc_dump_close (void)
|
gf_proc_dump_close (void)
|
||||||
{
|
{
|
||||||
close(gf_dump_fd);
|
close (gf_dump_fd);
|
||||||
gf_dump_fd = -1;
|
gf_dump_fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gf_proc_dump_add_section (char *key, ...)
|
gf_proc_dump_add_section (char *key, ...)
|
||||||
{
|
{
|
||||||
|
|
||||||
char buf[GF_DUMP_MAX_BUF_LEN];
|
char buf[GF_DUMP_MAX_BUF_LEN];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
assert(key);
|
assert(key);
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset (buf, 0, sizeof(buf));
|
||||||
snprintf(buf, GF_DUMP_MAX_BUF_LEN, "\n[");
|
snprintf (buf, GF_DUMP_MAX_BUF_LEN, "\n[");
|
||||||
va_start(ap, key);
|
va_start (ap, key);
|
||||||
vsnprintf(buf + strlen(buf),
|
vsnprintf (buf + strlen(buf),
|
||||||
GF_DUMP_MAX_BUF_LEN - strlen(buf), key, ap);
|
GF_DUMP_MAX_BUF_LEN - strlen (buf), key, ap);
|
||||||
va_end(ap);
|
va_end (ap);
|
||||||
snprintf(buf + strlen(buf),
|
snprintf (buf + strlen(buf),
|
||||||
GF_DUMP_MAX_BUF_LEN - strlen(buf), "]\n");
|
GF_DUMP_MAX_BUF_LEN - strlen (buf), "]\n");
|
||||||
ret = write(gf_dump_fd, buf, strlen(buf));
|
ret = write (gf_dump_fd, buf, strlen (buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gf_proc_dump_write (char *key, char *value,...)
|
gf_proc_dump_write (char *key, char *value,...)
|
||||||
{
|
{
|
||||||
|
|
||||||
char buf[GF_DUMP_MAX_BUF_LEN];
|
char buf[GF_DUMP_MAX_BUF_LEN];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
offset = strlen(key);
|
|
||||||
|
|
||||||
memset(buf, 0, GF_DUMP_MAX_BUF_LEN);
|
|
||||||
snprintf(buf, GF_DUMP_MAX_BUF_LEN, "%s",key);
|
|
||||||
snprintf(buf + offset, GF_DUMP_MAX_BUF_LEN - offset, "=");
|
|
||||||
offset += 1;
|
|
||||||
va_start(ap, value);
|
|
||||||
vsnprintf(buf + offset, GF_DUMP_MAX_BUF_LEN - offset, value, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
offset = strlen(buf);
|
offset = strlen (key);
|
||||||
snprintf(buf + offset, GF_DUMP_MAX_BUF_LEN - offset, "\n");
|
|
||||||
ret = write(gf_dump_fd, buf, strlen(buf));
|
memset (buf, 0, GF_DUMP_MAX_BUF_LEN);
|
||||||
|
snprintf (buf, GF_DUMP_MAX_BUF_LEN, "%s", key);
|
||||||
|
snprintf (buf + offset, GF_DUMP_MAX_BUF_LEN - offset, "=");
|
||||||
|
offset += 1;
|
||||||
|
va_start (ap, value);
|
||||||
|
vsnprintf (buf + offset, GF_DUMP_MAX_BUF_LEN - offset, value, ap);
|
||||||
|
va_end (ap);
|
||||||
|
|
||||||
|
offset = strlen (buf);
|
||||||
|
snprintf (buf + offset, GF_DUMP_MAX_BUF_LEN - offset, "\n");
|
||||||
|
ret = write (gf_dump_fd, buf, strlen (buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -165,20 +171,20 @@ gf_proc_dump_mem_info ()
|
|||||||
#ifdef HAVE_MALLOC_STATS
|
#ifdef HAVE_MALLOC_STATS
|
||||||
struct mallinfo info;
|
struct mallinfo info;
|
||||||
|
|
||||||
memset(&info, 0, sizeof(struct mallinfo));
|
memset (&info, 0, sizeof (struct mallinfo));
|
||||||
info = mallinfo();
|
info = mallinfo ();
|
||||||
|
|
||||||
gf_proc_dump_add_section("mallinfo");
|
gf_proc_dump_add_section ("mallinfo");
|
||||||
gf_proc_dump_write("mallinfo_arena", "%d", info.arena);
|
gf_proc_dump_write ("mallinfo_arena", "%d", info.arena);
|
||||||
gf_proc_dump_write("mallinfo_ordblks", "%d", info.ordblks);
|
gf_proc_dump_write ("mallinfo_ordblks", "%d", info.ordblks);
|
||||||
gf_proc_dump_write("mallinfo_smblks","%d", info.smblks);
|
gf_proc_dump_write ("mallinfo_smblks", "%d", info.smblks);
|
||||||
gf_proc_dump_write("mallinfo_hblks","%d", info.hblks);
|
gf_proc_dump_write ("mallinfo_hblks", "%d", info.hblks);
|
||||||
gf_proc_dump_write("mallinfo_hblkhd", "%d", info.hblkhd);
|
gf_proc_dump_write ("mallinfo_hblkhd", "%d", info.hblkhd);
|
||||||
gf_proc_dump_write("mallinfo_usmblks","%d", info.usmblks);
|
gf_proc_dump_write ("mallinfo_usmblks", "%d", info.usmblks);
|
||||||
gf_proc_dump_write("mallinfo_fsmblks","%d", info.fsmblks);
|
gf_proc_dump_write ("mallinfo_fsmblks", "%d", info.fsmblks);
|
||||||
gf_proc_dump_write("mallinfo_uordblks","%d", info.uordblks);
|
gf_proc_dump_write ("mallinfo_uordblks", "%d", info.uordblks);
|
||||||
gf_proc_dump_write("mallinfo_fordblks", "%d", info.fordblks);
|
gf_proc_dump_write ("mallinfo_fordblks", "%d", info.fordblks);
|
||||||
gf_proc_dump_write("mallinfo_keepcost", "%d", info.keepcost);
|
gf_proc_dump_write ("mallinfo_keepcost", "%d", info.keepcost);
|
||||||
#endif
|
#endif
|
||||||
gf_proc_dump_xlator_mem_info(&global_xlator);
|
gf_proc_dump_xlator_mem_info(&global_xlator);
|
||||||
|
|
||||||
@ -203,12 +209,11 @@ gf_proc_dump_xlator_info (xlator_t *this_xl)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (this_xl->dumpops->priv)
|
if (this_xl->dumpops->priv)
|
||||||
this_xl->dumpops->priv(this_xl);
|
this_xl->dumpops->priv (this_xl);
|
||||||
if (this_xl->dumpops->inode)
|
if (this_xl->dumpops->inode)
|
||||||
this_xl->dumpops->inode(this_xl);
|
this_xl->dumpops->inode (this_xl);
|
||||||
if (this_xl->dumpops->fd)
|
if (this_xl->dumpops->fd)
|
||||||
this_xl->dumpops->fd(this_xl);
|
this_xl->dumpops->fd (this_xl);
|
||||||
|
|
||||||
this_xl = this_xl->next;
|
this_xl = this_xl->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,44 +226,45 @@ gf_proc_dump_info (int signum)
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
glusterfs_ctx_t *ctx = NULL;
|
glusterfs_ctx_t *ctx = NULL;
|
||||||
|
|
||||||
gf_proc_dump_lock();
|
gf_proc_dump_lock ();
|
||||||
ret = gf_proc_dump_open();
|
ret = gf_proc_dump_open ();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
goto out;
|
||||||
gf_proc_dump_mem_info();
|
gf_proc_dump_mem_info ();
|
||||||
ctx = get_global_ctx_ptr();
|
ctx = glusterfs_ctx_get ();
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
iobuf_stats_dump(ctx->iobuf_pool);
|
iobuf_stats_dump (ctx->iobuf_pool);
|
||||||
gf_proc_dump_pending_frames(ctx->pool);
|
gf_proc_dump_pending_frames (ctx->pool);
|
||||||
gf_proc_dump_xlator_info(ctx->graph);
|
gf_proc_dump_xlator_info (ctx->active->first);
|
||||||
}
|
}
|
||||||
|
|
||||||
gf_proc_dump_close();
|
gf_proc_dump_close ();
|
||||||
out:
|
out:
|
||||||
gf_proc_dump_unlock();
|
gf_proc_dump_unlock ();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
|
void
|
||||||
gf_proc_dump_fini (void)
|
gf_proc_dump_fini (void)
|
||||||
{
|
{
|
||||||
pthread_mutex_destroy(&gf_proc_dump_mutex);
|
pthread_mutex_destroy (&gf_proc_dump_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gf_proc_dump_init ()
|
gf_proc_dump_init ()
|
||||||
{
|
{
|
||||||
pthread_mutex_init(&gf_proc_dump_mutex, NULL);
|
pthread_mutex_init (&gf_proc_dump_mutex, NULL);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gf_proc_dump_cleanup (void)
|
gf_proc_dump_cleanup (void)
|
||||||
{
|
{
|
||||||
pthread_mutex_destroy(&gf_proc_dump_mutex);
|
pthread_mutex_destroy (&gf_proc_dump_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,6 +703,7 @@ xlator_set_type (xlator_t *xl,
|
|||||||
gf_log ("xlator", GF_LOG_DEBUG, "%s", dlerror ());
|
gf_log ("xlator", GF_LOG_DEBUG, "%s", dlerror ());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
xl->dlhandle = handle;
|
||||||
|
|
||||||
if (!(xl->fops = dlsym (handle, "fops"))) {
|
if (!(xl->fops = dlsym (handle, "fops"))) {
|
||||||
gf_log ("xlator", GF_LOG_DEBUG, "dlsym(fops) on %s",
|
gf_log ("xlator", GF_LOG_DEBUG, "dlsym(fops) on %s",
|
||||||
@ -813,52 +814,26 @@ xlator_search_by_name (xlator_t *any, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t
|
static int
|
||||||
xlator_init_rec (xlator_t *xl)
|
__xlator_init(xlator_t *xl)
|
||||||
{
|
{
|
||||||
xlator_t *trav = NULL;
|
xlator_t *old_THIS = NULL;
|
||||||
int32_t ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (xl == NULL) {
|
old_THIS = THIS;
|
||||||
gf_log ("xlator", GF_LOG_DEBUG, "invalid argument");
|
THIS = xl;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
trav = xl;
|
ret = xl->init (xl);
|
||||||
while (trav->prev)
|
|
||||||
trav = trav->prev;
|
|
||||||
|
|
||||||
while (trav) {
|
THIS = old_THIS;
|
||||||
ret = -1;
|
|
||||||
if (trav->mem_acct_init)
|
|
||||||
trav->mem_acct_init (trav);
|
|
||||||
if (trav->init && !trav->ready) {
|
|
||||||
ret = xlator_init (trav);
|
|
||||||
if (ret) {
|
|
||||||
gf_log (trav->name, GF_LOG_ERROR,
|
|
||||||
"Initialization of volume '%s' failed,"
|
|
||||||
" review your volfile again",
|
|
||||||
trav->name);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
trav->init_succeeded = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
gf_log (trav->name, GF_LOG_DEBUG, "No init() found");
|
|
||||||
}
|
|
||||||
/* This 'xl' is checked */
|
|
||||||
trav->ready = 1;
|
|
||||||
trav = trav->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t
|
int
|
||||||
xlator_tree_init (xlator_t *xl)
|
xlator_init (xlator_t *xl)
|
||||||
{
|
{
|
||||||
xlator_t *top = NULL;
|
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
if (xl == NULL) {
|
if (xl == NULL) {
|
||||||
@ -866,17 +841,30 @@ xlator_tree_init (xlator_t *xl)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
top = xl;
|
ret = -1;
|
||||||
/*
|
|
||||||
while (top->parents)
|
|
||||||
top = top->parents->xlator;
|
|
||||||
*/
|
|
||||||
ret = xlator_init_rec (top);
|
|
||||||
|
|
||||||
if (ret == 0 && top->notify) {
|
if (xl->mem_acct_init)
|
||||||
top->notify (top, GF_EVENT_PARENT_UP, NULL);
|
xl->mem_acct_init (xl);
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!xl->init) {
|
||||||
|
gf_log (xl->name, GF_LOG_DEBUG, "No init() found");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = __xlator_init (xl);
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
gf_log (xl->name, GF_LOG_ERROR,
|
||||||
|
"Initialization of volume '%s' failed,"
|
||||||
|
" review your volfile again",
|
||||||
|
xl->name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
xl->init_succeeded = 1;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -931,22 +919,6 @@ xlator_notify (xlator_t *xl, int event, void *data, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
xlator_init (xlator_t *xl)
|
|
||||||
{
|
|
||||||
xlator_t *old_THIS = NULL;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
old_THIS = THIS;
|
|
||||||
THIS = xl;
|
|
||||||
|
|
||||||
ret = xl->init (xl);
|
|
||||||
|
|
||||||
THIS = old_THIS;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
xlator_mem_acct_init (xlator_t *xl, int num_types)
|
xlator_mem_acct_init (xlator_t *xl, int num_types)
|
||||||
{
|
{
|
||||||
@ -1064,3 +1036,43 @@ loc_copy (loc_t *dst, loc_t *src)
|
|||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
xlator_list_destroy (xlator_list_t *list)
|
||||||
|
{
|
||||||
|
xlator_list_t *next = NULL;
|
||||||
|
|
||||||
|
while (list) {
|
||||||
|
next = list->next;
|
||||||
|
GF_FREE (list);
|
||||||
|
list = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
xlator_destroy (xlator_t *xl)
|
||||||
|
{
|
||||||
|
if (!xl)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (xl->name)
|
||||||
|
GF_FREE (xl->name);
|
||||||
|
if (xl->type)
|
||||||
|
GF_FREE (xl->type);
|
||||||
|
if (xl->dlhandle)
|
||||||
|
dlclose (xl->dlhandle);
|
||||||
|
if (xl->options)
|
||||||
|
dict_destroy (xl->options);
|
||||||
|
|
||||||
|
xlator_list_destroy (xl->children);
|
||||||
|
|
||||||
|
xlator_list_destroy (xl->parents);
|
||||||
|
|
||||||
|
GF_FREE (xl);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
|
||||||
#include "glusterfs.h"
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "common-utils.h"
|
#include "common-utils.h"
|
||||||
#include "dict.h"
|
#include "dict.h"
|
||||||
@ -819,10 +818,11 @@ struct _xlator {
|
|||||||
dict_t *options;
|
dict_t *options;
|
||||||
|
|
||||||
/* Set after doing dlopen() */
|
/* Set after doing dlopen() */
|
||||||
|
void *dlhandle;
|
||||||
struct xlator_fops *fops;
|
struct xlator_fops *fops;
|
||||||
struct xlator_cbks *cbks;
|
struct xlator_cbks *cbks;
|
||||||
struct xlator_dumpops *dumpops;
|
struct xlator_dumpops *dumpops;
|
||||||
struct list_head volume_options; /* list of volume_option_t */
|
struct list_head volume_options; /* list of volume_option_t */
|
||||||
|
|
||||||
void (*fini) (xlator_t *this);
|
void (*fini) (xlator_t *this);
|
||||||
int32_t (*init) (xlator_t *this);
|
int32_t (*init) (xlator_t *this);
|
||||||
@ -833,12 +833,13 @@ struct _xlator {
|
|||||||
fop_latency_t latencies[GF_FOP_MAXVALUE];
|
fop_latency_t latencies[GF_FOP_MAXVALUE];
|
||||||
|
|
||||||
/* Misc */
|
/* Misc */
|
||||||
glusterfs_ctx_t *ctx;
|
glusterfs_ctx_t *ctx;
|
||||||
inode_table_t *itable;
|
glusterfs_graph_t *graph; /* not set for fuse */
|
||||||
char ready;
|
inode_table_t *itable;
|
||||||
char init_succeeded;
|
char ready;
|
||||||
void *private;
|
char init_succeeded;
|
||||||
struct mem_acct mem_acct;
|
void *private;
|
||||||
|
struct mem_acct mem_acct;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define xlator_has_parent(xl) (xl->parents != NULL)
|
#define xlator_has_parent(xl) (xl->parents != NULL)
|
||||||
@ -852,6 +853,7 @@ xlator_t *file_to_xlator_tree (glusterfs_ctx_t *ctx,
|
|||||||
|
|
||||||
int xlator_notify (xlator_t *this, int32_t event, void *data, ...);
|
int xlator_notify (xlator_t *this, int32_t event, void *data, ...);
|
||||||
int xlator_init (xlator_t *this);
|
int xlator_init (xlator_t *this);
|
||||||
|
int xlator_destroy (xlator_t *xl);
|
||||||
|
|
||||||
int32_t xlator_tree_init (xlator_t *xl);
|
int32_t xlator_tree_init (xlator_t *xl);
|
||||||
int32_t xlator_tree_free (xlator_t *xl);
|
int32_t xlator_tree_free (xlator_t *xl);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
xlator_LTLIBRARIES = afr.la
|
xlator_LTLIBRARIES = afr.la
|
||||||
xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/cluster
|
xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/cluster
|
||||||
|
|
||||||
afr_la_LDFLAGS = -module -avoidversion
|
afr_la_LDFLAGS = -module -avoidversion
|
||||||
|
|
||||||
afr_la_SOURCES = afr.c afr-dir-read.c afr-dir-write.c afr-inode-read.c afr-inode-write.c afr-open.c afr-transaction.c afr-self-heal-data.c afr-self-heal-common.c afr-self-heal-metadata.c afr-self-heal-entry.c afr-self-heal-algorithm.c
|
afr_la_SOURCES = afr.c afr-dir-read.c afr-dir-write.c afr-inode-read.c afr-inode-write.c afr-open.c afr-transaction.c afr-self-heal-data.c afr-self-heal-common.c afr-self-heal-metadata.c afr-self-heal-entry.c afr-self-heal-algorithm.c
|
||||||
afr_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
|
afr_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
|
||||||
@ -9,9 +9,9 @@ afr_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
|
|||||||
noinst_HEADERS = afr.h afr-transaction.h afr-inode-write.h afr-inode-read.h afr-dir-read.h afr-dir-write.h afr-self-heal.h afr-self-heal-common.h afr-self-heal-algorithm.h
|
noinst_HEADERS = afr.h afr-transaction.h afr-inode-write.h afr-inode-read.h afr-dir-read.h afr-dir-write.h afr-self-heal.h afr-self-heal-common.h afr-self-heal-algorithm.h
|
||||||
|
|
||||||
AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
|
AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
|
||||||
-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS)
|
-I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/contrib/md5 -shared -nostartfiles $(GF_CFLAGS)
|
||||||
|
|
||||||
CLEANFILES =
|
CLEANFILES =
|
||||||
|
|
||||||
uninstall-local:
|
uninstall-local:
|
||||||
rm -f $(DESTDIR)$(xlatordir)/replicate.so
|
rm -f $(DESTDIR)$(xlatordir)/replicate.so
|
||||||
|
@ -91,23 +91,31 @@ struct fuse_private {
|
|||||||
size_t volfile_size;
|
size_t volfile_size;
|
||||||
char *mount_point;
|
char *mount_point;
|
||||||
struct iobuf *iobuf;
|
struct iobuf *iobuf;
|
||||||
|
|
||||||
pthread_t fuse_thread;
|
pthread_t fuse_thread;
|
||||||
char fuse_thread_started;
|
char fuse_thread_started;
|
||||||
|
|
||||||
uint32_t direct_io_mode;
|
uint32_t direct_io_mode;
|
||||||
size_t *msg0_len_p;
|
size_t *msg0_len_p;
|
||||||
|
|
||||||
double entry_timeout;
|
double entry_timeout;
|
||||||
double attribute_timeout;
|
double attribute_timeout;
|
||||||
pthread_cond_t first_call_cond;
|
|
||||||
pthread_mutex_t first_call_mutex;
|
pthread_cond_t sync_cond;
|
||||||
char first_call;
|
pthread_mutex_t sync_mutex;
|
||||||
|
char child_up;
|
||||||
|
|
||||||
|
char init_recvd;
|
||||||
|
|
||||||
gf_boolean_t strict_volfile_check;
|
gf_boolean_t strict_volfile_check;
|
||||||
pthread_cond_t child_up_cond;
|
|
||||||
pthread_mutex_t child_up_mutex;
|
|
||||||
char child_up_value;
|
|
||||||
fuse_handler_t **fuse_ops;
|
fuse_handler_t **fuse_ops;
|
||||||
fuse_handler_t **fuse_ops0;
|
fuse_handler_t **fuse_ops0;
|
||||||
pthread_mutex_t fuse_dump_mutex;
|
pthread_mutex_t fuse_dump_mutex;
|
||||||
int fuse_dump_fd;
|
int fuse_dump_fd;
|
||||||
|
|
||||||
|
glusterfs_graph_t *next_graph;
|
||||||
|
xlator_t *active_subvol;
|
||||||
};
|
};
|
||||||
typedef struct fuse_private fuse_private_t;
|
typedef struct fuse_private fuse_private_t;
|
||||||
|
|
||||||
@ -138,8 +146,7 @@ typedef struct fuse_private fuse_private_t;
|
|||||||
free_state (state); \
|
free_state (state); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
xl = frame->this->children ? \
|
xl = fuse_state_subvol (state); \
|
||||||
frame->this->children->xlator : NULL; \
|
|
||||||
\
|
\
|
||||||
frame->root->state = state; \
|
frame->root->state = state; \
|
||||||
frame->root->op = op_num; \
|
frame->root->op = op_num; \
|
||||||
@ -190,6 +197,35 @@ typedef struct {
|
|||||||
} fuse_state_t;
|
} fuse_state_t;
|
||||||
|
|
||||||
|
|
||||||
|
xlator_t *
|
||||||
|
fuse_state_subvol (fuse_state_t *state)
|
||||||
|
{
|
||||||
|
xlator_t *subvol = NULL;
|
||||||
|
|
||||||
|
if (!state)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (state->loc.inode)
|
||||||
|
subvol = state->loc.inode->table->xl;
|
||||||
|
|
||||||
|
if (state->fd)
|
||||||
|
subvol = state->fd->inode->table->xl;
|
||||||
|
|
||||||
|
return subvol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xlator_t *
|
||||||
|
fuse_active_subvol (xlator_t *fuse)
|
||||||
|
{
|
||||||
|
fuse_private_t *priv = NULL;
|
||||||
|
|
||||||
|
priv = fuse->private;
|
||||||
|
|
||||||
|
return priv->active_subvol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_state (fuse_state_t *state)
|
free_state (fuse_state_t *state)
|
||||||
{
|
{
|
||||||
@ -231,7 +267,6 @@ get_state (xlator_t *this, fuse_in_header_t *finh)
|
|||||||
if (!state)
|
if (!state)
|
||||||
return NULL;
|
return NULL;
|
||||||
state->pool = this->ctx->pool;
|
state->pool = this->ctx->pool;
|
||||||
state->itable = this->itable;
|
|
||||||
state->finh = finh;
|
state->finh = finh;
|
||||||
state->this = this;
|
state->this = this;
|
||||||
|
|
||||||
@ -349,12 +384,14 @@ send_fuse_err (xlator_t *this, fuse_in_header_t *finh, int error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inode_t *
|
static inode_t *
|
||||||
fuse_ino_to_inode (uint64_t ino, inode_table_t *table)
|
fuse_ino_to_inode (uint64_t ino, xlator_t *fuse)
|
||||||
{
|
{
|
||||||
inode_t *inode = NULL;
|
inode_t *inode = NULL;
|
||||||
|
xlator_t *active_subvol = NULL;
|
||||||
|
|
||||||
if (ino == 1) {
|
if (ino == 1) {
|
||||||
inode = table->root;
|
active_subvol = fuse_active_subvol (fuse);
|
||||||
|
inode = active_subvol->itable->root;
|
||||||
} else {
|
} else {
|
||||||
inode = (inode_t *) (unsigned long) ino;
|
inode = (inode_t *) (unsigned long) ino;
|
||||||
inode_ref (inode);
|
inode_ref (inode);
|
||||||
@ -390,13 +427,13 @@ fuse_loc_fill (loc_t *loc, fuse_state_t *state, ino_t ino,
|
|||||||
if (name) {
|
if (name) {
|
||||||
parent = loc->parent;
|
parent = loc->parent;
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
parent = fuse_ino_to_inode (par, state->itable);
|
parent = fuse_ino_to_inode (par, state->this);
|
||||||
loc->parent = parent;
|
loc->parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode = loc->inode;
|
inode = loc->inode;
|
||||||
if (!inode) {
|
if (!inode) {
|
||||||
inode = inode_grep (state->itable, parent, name);
|
inode = inode_grep (parent->table, parent, name);
|
||||||
loc->inode = inode;
|
loc->inode = inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,7 +448,7 @@ fuse_loc_fill (loc_t *loc, fuse_state_t *state, ino_t ino,
|
|||||||
} else {
|
} else {
|
||||||
inode = loc->inode;
|
inode = loc->inode;
|
||||||
if (!inode) {
|
if (!inode) {
|
||||||
inode = fuse_ino_to_inode (ino, state->itable);
|
inode = fuse_ino_to_inode (ino, state->this);
|
||||||
loc->inode = inode;
|
loc->inode = inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,13 +630,15 @@ fuse_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
|||||||
{
|
{
|
||||||
fuse_state_t *state = NULL;
|
fuse_state_t *state = NULL;
|
||||||
call_frame_t *prev = NULL;
|
call_frame_t *prev = NULL;
|
||||||
|
inode_table_t *itable = NULL;
|
||||||
|
|
||||||
state = frame->root->state;
|
state = frame->root->state;
|
||||||
prev = cookie;
|
prev = cookie;
|
||||||
|
|
||||||
if (op_ret == -1 && state->is_revalidate == 1) {
|
if (op_ret == -1 && state->is_revalidate == 1) {
|
||||||
|
itable = state->loc.inode->table;
|
||||||
inode_unref (state->loc.inode);
|
inode_unref (state->loc.inode);
|
||||||
state->loc.inode = inode_new (state->itable);
|
state->loc.inode = inode_new (itable);
|
||||||
state->is_revalidate = 2;
|
state->is_revalidate = 2;
|
||||||
|
|
||||||
STACK_WIND (frame, fuse_lookup_cbk,
|
STACK_WIND (frame, fuse_lookup_cbk,
|
||||||
@ -639,7 +678,7 @@ fuse_lookup (xlator_t *this, fuse_in_header_t *finh, void *msg)
|
|||||||
"%"PRIu64": LOOKUP %s", finh->unique,
|
"%"PRIu64": LOOKUP %s", finh->unique,
|
||||||
state->loc.path);
|
state->loc.path);
|
||||||
|
|
||||||
state->loc.inode = inode_new (state->itable);
|
state->loc.inode = inode_new (state->loc.parent->table);
|
||||||
} else {
|
} else {
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_TRACE,
|
gf_log ("glusterfs-fuse", GF_LOG_TRACE,
|
||||||
"%"PRIu64": LOOKUP %s(%"PRId64")", finh->unique,
|
"%"PRIu64": LOOKUP %s(%"PRId64")", finh->unique,
|
||||||
@ -667,7 +706,7 @@ fuse_forget (xlator_t *this, fuse_in_header_t *finh, void *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fuse_inode = fuse_ino_to_inode (finh->nodeid, this->itable);
|
fuse_inode = fuse_ino_to_inode (finh->nodeid, this);
|
||||||
|
|
||||||
inode_forget (fuse_inode, ffi->nlookup);
|
inode_forget (fuse_inode, ffi->nlookup);
|
||||||
inode_unref (fuse_inode);
|
inode_unref (fuse_inode);
|
||||||
@ -1371,7 +1410,7 @@ fuse_mknod (xlator_t *this, fuse_in_header_t *finh, void *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->loc.inode = inode_new (state->itable);
|
state->loc.inode = inode_new (state->loc.parent->table);
|
||||||
|
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_TRACE,
|
gf_log ("glusterfs-fuse", GF_LOG_TRACE,
|
||||||
"%"PRIu64": MKNOD %s", finh->unique,
|
"%"PRIu64": MKNOD %s", finh->unique,
|
||||||
@ -1404,7 +1443,7 @@ fuse_mkdir (xlator_t *this, fuse_in_header_t *finh, void *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->loc.inode = inode_new (state->itable);
|
state->loc.inode = inode_new (state->loc.parent->table);
|
||||||
|
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_TRACE,
|
gf_log ("glusterfs-fuse", GF_LOG_TRACE,
|
||||||
"%"PRIu64": MKDIR %s", finh->unique,
|
"%"PRIu64": MKDIR %s", finh->unique,
|
||||||
@ -1501,7 +1540,7 @@ fuse_symlink (xlator_t *this, fuse_in_header_t *finh, void *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->loc.inode = inode_new (state->itable);
|
state->loc.inode = inode_new (state->loc.parent->table);
|
||||||
|
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_TRACE,
|
gf_log ("glusterfs-fuse", GF_LOG_TRACE,
|
||||||
"%"PRIu64": SYMLINK %s -> %s", finh->unique,
|
"%"PRIu64": SYMLINK %s -> %s", finh->unique,
|
||||||
@ -1541,7 +1580,7 @@ fuse_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
|||||||
}
|
}
|
||||||
buf->ia_blksize = this->ctx->page_size;
|
buf->ia_blksize = this->ctx->page_size;
|
||||||
|
|
||||||
inode_rename (state->itable,
|
inode_rename (state->loc.parent->table,
|
||||||
state->loc.parent, state->loc.name,
|
state->loc.parent, state->loc.name,
|
||||||
state->loc2.parent, state->loc2.name,
|
state->loc2.parent, state->loc2.name,
|
||||||
state->loc.inode, buf);
|
state->loc.inode, buf);
|
||||||
@ -1790,7 +1829,7 @@ fuse_create (xlator_t *this, fuse_in_header_t *finh, void *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->loc.inode = inode_new (state->itable);
|
state->loc.inode = inode_new (state->loc.parent->table);
|
||||||
|
|
||||||
fd = fd_create (state->loc.inode, finh->pid);
|
fd = fd_create (state->loc.inode, finh->pid);
|
||||||
state->fd = fd;
|
state->fd = fd;
|
||||||
@ -2530,9 +2569,7 @@ fuse_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
|||||||
fuse_in_header_t *finh = NULL;
|
fuse_in_header_t *finh = NULL;
|
||||||
data_t *value_data = NULL;
|
data_t *value_data = NULL;
|
||||||
fuse_private_t *priv = NULL;
|
fuse_private_t *priv = NULL;
|
||||||
struct stat st;
|
int ret = -1;
|
||||||
char *file = NULL;
|
|
||||||
int32_t fd = -1;
|
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
data_pair_t *trav = NULL;
|
data_pair_t *trav = NULL;
|
||||||
|
|
||||||
@ -2550,39 +2587,12 @@ fuse_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
|||||||
/* if callback for getxattr */
|
/* if callback for getxattr */
|
||||||
value_data = dict_get (dict, state->name);
|
value_data = dict_get (dict, state->name);
|
||||||
if (value_data) {
|
if (value_data) {
|
||||||
send_fuse_xattr (this, finh, value_data->data,
|
|
||||||
value_data->len, /* Don't return the value for '\0' */
|
|
||||||
state->size);
|
|
||||||
/* if(op_ret >...)...else if...else */
|
|
||||||
} else if (!strcmp (state->name, "user.glusterfs-booster-volfile")) {
|
|
||||||
if (!priv->volfile) {
|
|
||||||
memset (&st, 0, sizeof (st));
|
|
||||||
fd = fileno (this->ctx->specfp);
|
|
||||||
if (fstat (fd, &st) != 0) {
|
|
||||||
gf_log (this->name,
|
|
||||||
GF_LOG_ERROR,
|
|
||||||
"fstat on fd (%d) failed (%s)", fd, strerror (errno));
|
|
||||||
send_fuse_err (this, finh, ENODATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->volfile_size = st.st_size;
|
ret = value_data->len; /* Don't return the value for '\0' */
|
||||||
file = priv->volfile = GF_CALLOC (1, priv->volfile_size,
|
value = value_data->data;
|
||||||
gf_fuse_mt_char);
|
|
||||||
len = lseek (fd, 0, SEEK_SET);
|
|
||||||
while ((len = read (fd, file, GF_UNIT_KB)) > 0) {
|
|
||||||
file += len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
send_fuse_xattr (this, finh, priv->volfile,
|
send_fuse_xattr (this, finh, value, ret, state->size);
|
||||||
priv->volfile_size, state->size);
|
/* if(ret >...)...else if...else */
|
||||||
/* if(op_ret >...)...else if...else */
|
|
||||||
} else if (!strcmp (state->name, "user.glusterfs-booster-path")) {
|
|
||||||
send_fuse_xattr (this, finh, state->loc.path,
|
|
||||||
strlen (state->loc.path) + 1, state->size);
|
|
||||||
} else if (!strcmp (state->name, "user.glusterfs-booster-mount")) {
|
|
||||||
send_fuse_xattr (this, finh, priv->mount_point,
|
|
||||||
strlen (priv->mount_point) + 1, state->size);
|
|
||||||
} else {
|
} else {
|
||||||
send_fuse_err (this, finh, ENODATA);
|
send_fuse_err (this, finh, ENODATA);
|
||||||
} /* if(value_data)...else */
|
} /* if(value_data)...else */
|
||||||
@ -2608,17 +2618,14 @@ fuse_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
|||||||
} else {
|
} else {
|
||||||
/* if failure - no need to check if listxattr or getxattr */
|
/* if failure - no need to check if listxattr or getxattr */
|
||||||
if (op_errno != ENODATA) {
|
if (op_errno != ENODATA) {
|
||||||
if (op_errno == ENOTSUP)
|
if (op_errno == ENOTSUP) {
|
||||||
{
|
|
||||||
GF_LOG_OCCASIONALLY (gf_fuse_xattr_enotsup_log,
|
GF_LOG_OCCASIONALLY (gf_fuse_xattr_enotsup_log,
|
||||||
"glusterfs-fuse",
|
"glusterfs-fuse",
|
||||||
GF_LOG_ERROR,
|
GF_LOG_ERROR,
|
||||||
"extended attribute not "
|
"extended attribute not "
|
||||||
"supported by the backend "
|
"supported by the backend "
|
||||||
"storage");
|
"storage");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_WARNING,
|
gf_log ("glusterfs-fuse", GF_LOG_WARNING,
|
||||||
"%"PRIu64": %s() %s => -1 (%s)",
|
"%"PRIu64": %s() %s => -1 (%s)",
|
||||||
frame->root->unique,
|
frame->root->unique,
|
||||||
@ -2937,7 +2944,7 @@ fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg)
|
|||||||
|
|
||||||
priv = this->private;
|
priv = this->private;
|
||||||
|
|
||||||
if (!priv->first_call) {
|
if (priv->init_recvd) {
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_ERROR,
|
gf_log ("glusterfs-fuse", GF_LOG_ERROR,
|
||||||
"got INIT after first message");
|
"got INIT after first message");
|
||||||
|
|
||||||
@ -2945,6 +2952,8 @@ fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
priv->init_recvd = 1;
|
||||||
|
|
||||||
if (fini->major != FUSE_KERNEL_VERSION) {
|
if (fini->major != FUSE_KERNEL_VERSION) {
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_ERROR,
|
gf_log ("glusterfs-fuse", GF_LOG_ERROR,
|
||||||
"unsupported FUSE protocol version %d.%d",
|
"unsupported FUSE protocol version %d.%d",
|
||||||
@ -3014,6 +3023,13 @@ fuse_destroy (xlator_t *this, fuse_in_header_t *finh, void *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct fuse_first_lookup {
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
pthread_cond_t cond;
|
||||||
|
char fin;
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
fuse_first_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
fuse_first_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
||||||
int32_t op_ret, int32_t op_errno,
|
int32_t op_ret, int32_t op_errno,
|
||||||
@ -3021,8 +3037,10 @@ fuse_first_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
|||||||
struct iatt *postparent)
|
struct iatt *postparent)
|
||||||
{
|
{
|
||||||
fuse_private_t *priv = NULL;
|
fuse_private_t *priv = NULL;
|
||||||
|
struct fuse_first_lookup *stub = NULL;
|
||||||
|
|
||||||
priv = this->private;
|
priv = this->private;
|
||||||
|
stub = frame->local;
|
||||||
|
|
||||||
if (op_ret == 0) {
|
if (op_ret == 0) {
|
||||||
gf_log (this->name, GF_LOG_TRACE,
|
gf_log (this->name, GF_LOG_TRACE,
|
||||||
@ -3031,13 +3049,14 @@ fuse_first_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
|||||||
gf_log (this->name, GF_LOG_DEBUG,
|
gf_log (this->name, GF_LOG_DEBUG,
|
||||||
"first lookup on root failed.");
|
"first lookup on root failed.");
|
||||||
}
|
}
|
||||||
STACK_DESTROY (frame->root);
|
|
||||||
pthread_mutex_lock (&priv->first_call_mutex);
|
pthread_mutex_lock (&stub->mutex);
|
||||||
{
|
{
|
||||||
priv->first_call = 0;
|
stub->fin = 1;
|
||||||
pthread_cond_broadcast (&priv->first_call_cond);
|
pthread_cond_broadcast (&stub->cond);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock (&priv->first_call_mutex);
|
pthread_mutex_unlock (&stub->mutex);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3045,45 +3064,100 @@ fuse_first_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
|||||||
int
|
int
|
||||||
fuse_first_lookup (xlator_t *this)
|
fuse_first_lookup (xlator_t *this)
|
||||||
{
|
{
|
||||||
fuse_private_t *priv = NULL;
|
fuse_private_t *priv = NULL;
|
||||||
loc_t loc;
|
loc_t loc = {0, };
|
||||||
call_frame_t *frame = NULL;
|
call_frame_t *frame = NULL;
|
||||||
xlator_t *xl = NULL;
|
xlator_t *xl = NULL;
|
||||||
dict_t *dict = NULL;
|
dict_t *dict = NULL;
|
||||||
|
struct fuse_first_lookup stub;
|
||||||
|
|
||||||
priv = this->private;
|
priv = this->private;
|
||||||
|
|
||||||
pthread_cond_init (&priv->first_call_cond, NULL);
|
|
||||||
pthread_mutex_init (&priv->first_call_mutex, NULL);
|
|
||||||
|
|
||||||
loc.path = "/";
|
loc.path = "/";
|
||||||
loc.name = "";
|
loc.name = "";
|
||||||
loc.ino = 1;
|
loc.ino = 1;
|
||||||
loc.inode = fuse_ino_to_inode (1, this->itable);
|
loc.inode = fuse_ino_to_inode (1, this);
|
||||||
loc.parent = NULL;
|
loc.parent = NULL;
|
||||||
|
|
||||||
dict = dict_new ();
|
dict = dict_new ();
|
||||||
frame = create_frame (this, this->ctx->pool);
|
frame = create_frame (this, this->ctx->pool);
|
||||||
frame->root->type = GF_OP_TYPE_FOP;
|
frame->root->type = GF_OP_TYPE_FOP;
|
||||||
xl = this->children->xlator;
|
|
||||||
|
xl = priv->active_subvol;
|
||||||
|
|
||||||
|
pthread_mutex_init (&stub.mutex, NULL);
|
||||||
|
pthread_cond_init (&stub.cond, NULL);
|
||||||
|
stub.fin = 0;
|
||||||
|
|
||||||
|
frame->local = &stub;
|
||||||
|
|
||||||
STACK_WIND (frame, fuse_first_lookup_cbk, xl, xl->fops->lookup,
|
STACK_WIND (frame, fuse_first_lookup_cbk, xl, xl->fops->lookup,
|
||||||
&loc, dict);
|
&loc, dict);
|
||||||
dict_unref (dict);
|
dict_unref (dict);
|
||||||
|
|
||||||
pthread_mutex_lock (&priv->first_call_mutex);
|
pthread_mutex_lock (&stub.mutex);
|
||||||
{
|
{
|
||||||
while (priv->first_call) {
|
while (!stub.fin) {
|
||||||
pthread_cond_wait (&priv->first_call_cond,
|
pthread_cond_wait (&stub.cond, &stub.mutex);
|
||||||
&priv->first_call_mutex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock (&priv->first_call_mutex);
|
pthread_mutex_unlock (&stub.mutex);
|
||||||
|
|
||||||
|
pthread_mutex_destroy (&stub.mutex);
|
||||||
|
pthread_cond_destroy (&stub.cond);
|
||||||
|
|
||||||
|
frame->local = NULL;
|
||||||
|
STACK_DESTROY (frame->root);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
fuse_graph_sync (xlator_t *this)
|
||||||
|
{
|
||||||
|
fuse_private_t *priv = NULL;
|
||||||
|
int need_first_lookup = 0;
|
||||||
|
struct timeval now = {0, };
|
||||||
|
struct timespec timeout = {0, };
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
priv = this->private;
|
||||||
|
|
||||||
|
pthread_mutex_lock (&priv->sync_mutex);
|
||||||
|
{
|
||||||
|
if (!priv->next_graph)
|
||||||
|
goto unlock;
|
||||||
|
|
||||||
|
priv->active_subvol = priv->next_graph->top;
|
||||||
|
priv->next_graph = NULL;
|
||||||
|
need_first_lookup = 1;
|
||||||
|
|
||||||
|
gettimeofday (&now, NULL);
|
||||||
|
timeout.tv_sec = now.tv_sec + MAX_FUSE_PROC_DELAY;
|
||||||
|
timeout.tv_nsec = now.tv_usec * 1000;
|
||||||
|
|
||||||
|
while (!priv->child_up) {
|
||||||
|
ret = pthread_cond_timedwait (&priv->sync_cond,
|
||||||
|
&priv->sync_mutex,
|
||||||
|
&timeout);
|
||||||
|
if (ret != 0) {
|
||||||
|
gf_log (this->name, GF_LOG_DEBUG,
|
||||||
|
"timedwait returned non zero value "
|
||||||
|
"ret: %d errno: %d", ret, errno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unlock:
|
||||||
|
pthread_mutex_unlock (&priv->sync_mutex);
|
||||||
|
|
||||||
|
if (need_first_lookup)
|
||||||
|
fuse_first_lookup (this);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
fuse_thread_proc (void *data)
|
fuse_thread_proc (void *data)
|
||||||
@ -3098,10 +3172,6 @@ fuse_thread_proc (void *data)
|
|||||||
void *msg = NULL;
|
void *msg = NULL;
|
||||||
const size_t msg0_size = sizeof (*finh) + 128;
|
const size_t msg0_size = sizeof (*finh) + 128;
|
||||||
fuse_handler_t **fuse_ops = NULL;
|
fuse_handler_t **fuse_ops = NULL;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
struct timeval now;
|
|
||||||
struct timespec timeout;
|
|
||||||
|
|
||||||
this = data;
|
this = data;
|
||||||
priv = this->private;
|
priv = this->private;
|
||||||
@ -3114,28 +3184,10 @@ fuse_thread_proc (void *data)
|
|||||||
->page_size;
|
->page_size;
|
||||||
priv->msg0_len_p = &iov_in[0].iov_len;
|
priv->msg0_len_p = &iov_in[0].iov_len;
|
||||||
|
|
||||||
pthread_mutex_lock (&priv->child_up_mutex);
|
|
||||||
{
|
|
||||||
gettimeofday (&now, NULL);
|
|
||||||
timeout.tv_sec = now.tv_sec + MAX_FUSE_PROC_DELAY;
|
|
||||||
timeout.tv_nsec = now.tv_usec * 1000;
|
|
||||||
|
|
||||||
while (priv->child_up_value) {
|
|
||||||
|
|
||||||
ret = pthread_cond_timedwait (&priv->child_up_cond,
|
|
||||||
&priv->child_up_mutex,
|
|
||||||
&timeout);
|
|
||||||
if (ret != 0) {
|
|
||||||
gf_log (this->name, GF_LOG_DEBUG,
|
|
||||||
" pthread_cond_timedout returned non zero value"
|
|
||||||
" ret: %d errno: %d", ret, errno);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock (&priv->child_up_mutex);
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
if (priv->init_recvd)
|
||||||
|
fuse_graph_sync (this);
|
||||||
|
|
||||||
iobuf = iobuf_get (this->ctx->iobuf_pool);
|
iobuf = iobuf_get (this->ctx->iobuf_pool);
|
||||||
/* Add extra 128 byte to the first iov so that it can
|
/* Add extra 128 byte to the first iov so that it can
|
||||||
* accomodate "ordinary" non-write requests. It's not
|
* accomodate "ordinary" non-write requests. It's not
|
||||||
@ -3161,14 +3213,6 @@ fuse_thread_proc (void *data)
|
|||||||
|
|
||||||
res = readv (priv->fd, iov_in, 2);
|
res = readv (priv->fd, iov_in, 2);
|
||||||
|
|
||||||
if (priv->first_call) {
|
|
||||||
if (priv->first_call > 1) {
|
|
||||||
priv->first_call--;
|
|
||||||
} else {
|
|
||||||
fuse_first_lookup (this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
if (errno == ENODEV || errno == EBADF) {
|
if (errno == ENODEV || errno == EBADF) {
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_NORMAL,
|
gf_log ("glusterfs-fuse", GF_LOG_NORMAL,
|
||||||
@ -3187,11 +3231,13 @@ fuse_thread_proc (void *data)
|
|||||||
goto cont_err;
|
goto cont_err;
|
||||||
}
|
}
|
||||||
if (res < sizeof (finh)) {
|
if (res < sizeof (finh)) {
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_WARNING, "short read on /dev/fuse");
|
gf_log ("glusterfs-fuse", GF_LOG_WARNING,
|
||||||
|
"short read on /dev/fuse");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
finh = (fuse_in_header_t *)iov_in[0].iov_base;
|
finh = (fuse_in_header_t *)iov_in[0].iov_base;
|
||||||
|
|
||||||
if (res != finh->len
|
if (res != finh->len
|
||||||
#ifdef GF_DARWIN_HOST_OS
|
#ifdef GF_DARWIN_HOST_OS
|
||||||
/* work around fuse4bsd/MacFUSE msg size miscalculation bug,
|
/* work around fuse4bsd/MacFUSE msg size miscalculation bug,
|
||||||
@ -3203,7 +3249,8 @@ fuse_thread_proc (void *data)
|
|||||||
res == finh->len + ((struct fuse_write_in *)(finh + 1))->size)
|
res == finh->len + ((struct fuse_write_in *)(finh + 1))->size)
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_WARNING, "inconsistent read on /dev/fuse");
|
gf_log ("glusterfs-fuse", GF_LOG_WARNING,
|
||||||
|
"inconsistent read on /dev/fuse");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3313,8 +3360,8 @@ fuse_priv_dump (xlator_t *this)
|
|||||||
private->entry_timeout);
|
private->entry_timeout);
|
||||||
gf_proc_dump_write("xlator.mount.fuse.attribute_timeout", "%lf",
|
gf_proc_dump_write("xlator.mount.fuse.attribute_timeout", "%lf",
|
||||||
private->attribute_timeout);
|
private->attribute_timeout);
|
||||||
gf_proc_dump_write("xlator.mount.fuse.first_call", "%d",
|
gf_proc_dump_write("xlator.mount.fuse.init_recvd", "%d",
|
||||||
(int)private->first_call);
|
(int)private->init_recvd);
|
||||||
gf_proc_dump_write("xlator.mount.fuse.strict_volfile_check", "%d",
|
gf_proc_dump_write("xlator.mount.fuse.strict_volfile_check", "%d",
|
||||||
(int)private->strict_volfile_check);
|
(int)private->strict_volfile_check);
|
||||||
|
|
||||||
@ -3322,55 +3369,87 @@ fuse_priv_dump (xlator_t *this)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t
|
int
|
||||||
|
fuse_graph_setup (xlator_t *this, glusterfs_graph_t *graph)
|
||||||
|
{
|
||||||
|
inode_table_t *itable = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
fuse_private_t *priv = NULL;
|
||||||
|
|
||||||
|
priv = this->private;
|
||||||
|
|
||||||
|
itable = inode_table_new (0, graph->top);
|
||||||
|
if (!itable)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
((xlator_t *)graph->top)->itable = itable;
|
||||||
|
|
||||||
|
pthread_mutex_lock (&priv->sync_mutex);
|
||||||
|
{
|
||||||
|
priv->next_graph = graph;
|
||||||
|
priv->child_up = 0;
|
||||||
|
|
||||||
|
pthread_cond_signal (&priv->sync_cond);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock (&priv->sync_mutex);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
notify (xlator_t *this, int32_t event, void *data, ...)
|
notify (xlator_t *this, int32_t event, void *data, ...)
|
||||||
{
|
{
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
fuse_private_t *private = NULL;
|
fuse_private_t *private = NULL;
|
||||||
|
glusterfs_graph_t *graph = NULL;
|
||||||
|
|
||||||
private = this->private;
|
private = this->private;
|
||||||
|
|
||||||
switch (event)
|
switch (event)
|
||||||
{
|
{
|
||||||
case GF_EVENT_CHILD_UP:
|
case GF_EVENT_GRAPH_NEW:
|
||||||
case GF_EVENT_CHILD_CONNECTING:
|
graph = data;
|
||||||
{
|
|
||||||
pthread_mutex_lock (&private->child_up_mutex);
|
|
||||||
{
|
|
||||||
private->child_up_value = 0;
|
|
||||||
pthread_cond_broadcast (&private->child_up_cond);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock (&private->child_up_mutex);
|
|
||||||
|
|
||||||
break;
|
ret = fuse_graph_setup (this, graph);
|
||||||
}
|
if (ret)
|
||||||
|
break;
|
||||||
|
|
||||||
case GF_EVENT_PARENT_UP:
|
if (!private->fuse_thread_started) {
|
||||||
{
|
|
||||||
if (!private->fuse_thread_started)
|
|
||||||
{
|
|
||||||
private->fuse_thread_started = 1;
|
private->fuse_thread_started = 1;
|
||||||
|
|
||||||
ret = pthread_create (&private->fuse_thread, NULL,
|
ret = pthread_create (&private->fuse_thread, NULL,
|
||||||
fuse_thread_proc, this);
|
fuse_thread_proc, this);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
|
gf_log (this->name, GF_LOG_DEBUG,
|
||||||
"pthread_create() failed (%s)",
|
"pthread_create() failed (%s)",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
|
break;
|
||||||
/* If fuse thread is not started, that means,
|
|
||||||
its hung, we can't use this process. */
|
|
||||||
raise (SIGTERM);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default_notify (this, GF_EVENT_PARENT_UP, data);
|
break;
|
||||||
|
|
||||||
|
// case GF_EVENT_CHILD_CONNECTING:
|
||||||
|
|
||||||
|
case GF_EVENT_CHILD_UP:
|
||||||
|
{
|
||||||
|
/* set priv->active_subvol */
|
||||||
|
/* set priv->first_lookup = 1 */
|
||||||
|
|
||||||
|
pthread_mutex_lock (&private->sync_mutex);
|
||||||
|
{
|
||||||
|
private->child_up = 1;
|
||||||
|
pthread_cond_broadcast (&private->sync_cond);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock (&private->sync_mutex);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case GF_EVENT_VOLFILE_MODIFIED:
|
case GF_EVENT_VOLFILE_MODIFIED:
|
||||||
{
|
{
|
||||||
gf_log ("fuse", GF_LOG_CRITICAL,
|
gf_log (this->name, GF_LOG_CRITICAL,
|
||||||
"Remote volume file changed, try re-mounting.");
|
"Remote volume file changed, try re-mounting.");
|
||||||
if (private->strict_volfile_check) {
|
if (private->strict_volfile_check) {
|
||||||
//fuse_session_remove_chan (private->ch);
|
//fuse_session_remove_chan (private->ch);
|
||||||
@ -3385,7 +3464,8 @@ notify (xlator_t *this, int32_t event, void *data, ...)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t
|
int32_t
|
||||||
@ -3603,17 +3683,10 @@ init (xlator_t *this_xl)
|
|||||||
priv->fuse_dump_fd = ret;
|
priv->fuse_dump_fd = ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
fsname = this_xl->ctx->cmd_args.volume_file;
|
fsname = this_xl->ctx->cmd_args.volfile;
|
||||||
fsname = (fsname ? fsname : this_xl->ctx->cmd_args.volfile_server);
|
fsname = (fsname ? fsname : this_xl->ctx->cmd_args.volfile_server);
|
||||||
fsname = (fsname ? fsname : "glusterfs");
|
fsname = (fsname ? fsname : "glusterfs");
|
||||||
|
|
||||||
this_xl->itable = inode_table_new (0, this_xl);
|
|
||||||
if (!this_xl->itable) {
|
|
||||||
gf_log ("glusterfs-fuse", GF_LOG_ERROR,
|
|
||||||
"Out of memory");
|
|
||||||
|
|
||||||
goto cleanup_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->fd = gf_fuse_mount (priv->mount_point, fsname,
|
priv->fd = gf_fuse_mount (priv->mount_point, fsname,
|
||||||
"allow_other,default_permissions,"
|
"allow_other,default_permissions,"
|
||||||
@ -3621,14 +3694,10 @@ init (xlator_t *this_xl)
|
|||||||
if (priv->fd == -1)
|
if (priv->fd == -1)
|
||||||
goto cleanup_exit;
|
goto cleanup_exit;
|
||||||
|
|
||||||
this_xl->ctx->top = this_xl;
|
|
||||||
|
|
||||||
priv->first_call = 2;
|
|
||||||
|
|
||||||
pthread_mutex_init (&priv->fuse_dump_mutex, NULL);
|
pthread_mutex_init (&priv->fuse_dump_mutex, NULL);
|
||||||
pthread_cond_init (&priv->child_up_cond, NULL);
|
pthread_cond_init (&priv->sync_cond, NULL);
|
||||||
pthread_mutex_init (&priv->child_up_mutex, NULL);
|
pthread_mutex_init (&priv->sync_mutex, NULL);
|
||||||
priv->child_up_value = 1;
|
priv->child_up = 0;
|
||||||
|
|
||||||
for (i = 0; i < FUSE_OP_HIGH; i++) {
|
for (i = 0; i < FUSE_OP_HIGH; i++) {
|
||||||
if (!fuse_std_ops[i])
|
if (!fuse_std_ops[i])
|
||||||
|
@ -6327,7 +6327,7 @@ protocol_client_handshake (xlator_t *this, transport_t *trans)
|
|||||||
ret = dict_set_str (options, "volfile-key",
|
ret = dict_set_str (options, "volfile-key",
|
||||||
this->ctx->cmd_args.volfile_id);
|
this->ctx->cmd_args.volfile_id);
|
||||||
ret = dict_set_uint32 (options, "volfile-checksum",
|
ret = dict_set_uint32 (options, "volfile-checksum",
|
||||||
this->ctx->volfile_checksum);
|
this->graph->volfile_checksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
dict_len = dict_serialized_length (options);
|
dict_len = dict_serialized_length (options);
|
||||||
|
@ -12,8 +12,9 @@ noinst_HEADERS = server-protocol.h server-helpers.h
|
|||||||
|
|
||||||
AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
|
AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
|
||||||
-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles \
|
-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles \
|
||||||
|
-I$(top_srcdir)/contrib/md5/ \
|
||||||
-DDATADIR=\"$(localstatedir)\" -DCONFDIR=\"$(sysconfdir)/glusterfs\" \
|
-DDATADIR=\"$(localstatedir)\" -DCONFDIR=\"$(sysconfdir)/glusterfs\" \
|
||||||
$(GF_CFLAGS) -I$(top_srcdir)/xlators/protocol/lib/src
|
$(GF_CFLAGS) -I$(top_srcdir)/xlators/protocol/lib/src
|
||||||
|
|
||||||
CLEANFILES =
|
CLEANFILES =
|
||||||
|
|
||||||
|
@ -6406,7 +6406,7 @@ init (xlator_t *this)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
this->ctx->top = this;
|
this->graph->top = this;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
|
@ -5,13 +5,14 @@ xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/storage
|
|||||||
posix_la_LDFLAGS = -module -avoidversion
|
posix_la_LDFLAGS = -module -avoidversion
|
||||||
|
|
||||||
posix_la_SOURCES = posix.c
|
posix_la_SOURCES = posix.c
|
||||||
posix_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
|
posix_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
|
||||||
|
|
||||||
noinst_HEADERS = posix.h
|
noinst_HEADERS = posix.h
|
||||||
|
|
||||||
AM_CFLAGS = -fPIC -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(GF_HOST_OS) -Wall \
|
AM_CFLAGS = -fPIC -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(GF_HOST_OS) -Wall \
|
||||||
-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles \
|
-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles \
|
||||||
|
-I$(top_srcdir)/contrib/md5 \
|
||||||
$(GF_CFLAGS)
|
$(GF_CFLAGS)
|
||||||
|
|
||||||
CLEANFILES =
|
CLEANFILES =
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user