diff options
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/Makefile.am | 2 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.c | 21 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 3 | ||||
-rw-r--r-- | libglusterfs/src/globals.c | 44 | ||||
-rw-r--r-- | libglusterfs/src/globals.h | 7 | ||||
-rw-r--r-- | libglusterfs/src/glusterfs.h | 29 | ||||
-rw-r--r-- | libglusterfs/src/lkowner.h | 92 | ||||
-rw-r--r-- | libglusterfs/src/stack.h | 9 |
8 files changed, 186 insertions, 21 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index 25de376aaeb..34543f62215 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -37,7 +37,7 @@ noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h \ rbthash.h iatt.h latency.h mem-types.h $(CONTRIBDIR)/uuid/uuidd.h \ $(CONTRIBDIR)/uuid/uuid.h $(CONTRIBDIR)/uuid/uuidP.h \ $(CONTRIB_BUILDDIR)/uuid/uuid_types.h syncop.h graph-utils.h trie.h run.h \ - options.h + options.h lkowner.h EXTRA_DIST = graph.l graph.y diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index b9f752b750b..ce1e1f45bff 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -40,6 +40,7 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <signal.h> +#include <stdlib.h> #include "logging.h" #include "common-utils.h" @@ -48,6 +49,7 @@ #include "stack.h" #include "globals.h" #include "md5.h" +#include "lkowner.h" #ifndef AI_ADDRCONFIG #define AI_ADDRCONFIG 0 @@ -1656,6 +1658,25 @@ uuid_utoa_r (uuid_t uuid, char *dst) return dst; } +/*Thread safe conversion function*/ +char * +lkowner_utoa (gf_lkowner_t *lkowner) +{ + char *lkowner_buffer = glusterfs_lkowner_buf_get(); + lkowner_unparse (lkowner, lkowner_buffer, GF_LKOWNER_BUF_SIZE); + return lkowner_buffer; +} + +/*Re-entrant conversion function*/ +char * +lkowner_utoa_r (gf_lkowner_t *lkowner, char *dst, int len) +{ + if(!dst) + return NULL; + lkowner_unparse (lkowner, dst, len); + return dst; +} + void _get_md5_str (char *out_str, size_t outlen, const uint8_t *input, int n) { diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 4e7f981b3fe..d81da35c5b0 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -444,6 +444,9 @@ char valid_internet_address (char *address); char *uuid_utoa (uuid_t uuid); char *uuid_utoa_r (uuid_t uuid, char *dst); +char *lkowner_utoa (gf_lkowner_t *lkowner); +char *lkowner_utoa_r (gf_lkowner_t *lkowner, char *dst, int len); + void _get_md5_str (char *out_str, size_t outlen, const uint8_t *input, int n); void gf_array_insertionsort (void *a, int l, int r, size_t elem_size, diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c index 57946f70480..8b641123f15 100644 --- a/libglusterfs/src/globals.c +++ b/libglusterfs/src/globals.c @@ -293,6 +293,43 @@ glusterfs_uuid_buf_get () return buf; } +/* LKOWNER_BUFFER */ + +static pthread_key_t lkowner_buf_key; +static char global_lkowner_buf[GF_LKOWNER_BUF_SIZE]; +void +glusterfs_lkowner_buf_destroy (void *ptr) +{ + if (ptr) + FREE (ptr); +} + +int +glusterfs_lkowner_buf_init () +{ + int ret = 0; + + ret = pthread_key_create (&lkowner_buf_key, + glusterfs_lkowner_buf_destroy); + return ret; +} + +char * +glusterfs_lkowner_buf_get () +{ + char *buf; + int ret = 0; + + buf = pthread_getspecific (lkowner_buf_key); + if(!buf) { + buf = MALLOC (GF_LKOWNER_BUF_SIZE); + ret = pthread_setspecific (lkowner_buf_key, (void *) buf); + if(ret) + buf = global_lkowner_buf; + } + return buf; +} + int glusterfs_globals_init () { @@ -323,6 +360,13 @@ glusterfs_globals_init () goto out; } + ret = glusterfs_lkowner_buf_init (); + if(ret) { + gf_log ("", GF_LOG_CRITICAL, + "ERROR: glusterfs lkowner buffer init failed"); + goto out; + } + gf_mem_acct_enable_set (); ret = synctask_init (); diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h index 7003351ab55..86e1f0324c4 100644 --- a/libglusterfs/src/globals.h +++ b/libglusterfs/src/globals.h @@ -22,12 +22,6 @@ #define GF_DEFAULT_BASE_PORT 24007 -/* This corresponds to the max 16 number of group IDs that are sent through an - * RPC request. Since NFS is the only one going to set this, we can be safe - * in keeping this size hardcoded. - */ -#define GF_REQUEST_MAXGROUPS 16 - #include "glusterfs.h" /* CTX */ @@ -52,6 +46,7 @@ int synctask_set (void *); /* uuid_buf */ char *glusterfs_uuid_buf_get(); +char *glusterfs_lkowner_buf_get(); /* init */ int glusterfs_globals_init (void); diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 903d2324a06..2f68ab74106 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -45,7 +45,6 @@ #include "list.h" #include "logging.h" - #define GF_YES 1 #define GF_NO 0 @@ -114,6 +113,12 @@ /* TODO: Should we use PATH-MAX? On some systems it may save space */ #define ZR_PATH_MAX 4096 +/* GlusterFS's maximum supported Auxilary GIDs */ +/* TODO: Keeping it to 200, so that we can fit in 2KB buffer for auth data + * in RPC server code, if there is ever need for having more aux-gids, then + * we have to add aux-gid in payload of actors */ +#define GF_MAX_AUX_GROUPS 200 + /* NOTE: add members ONLY at the end (just before _MAXVALUE) */ typedef enum { GF_FOP_NULL = 0, @@ -177,15 +182,6 @@ typedef enum { GF_OP_TYPE_MAX, } gf_op_type_t; -struct gf_flock { - short l_type; - short l_whence; - off_t l_start; - off_t l_len; - pid_t l_pid; - uint64_t l_owner; -}; - /* NOTE: all the miscellaneous flags used by GlusterFS should be listed here */ typedef enum { GF_LK_GETLK = 0, @@ -385,6 +381,19 @@ typedef enum { GF_EVENT_MAXVAL, } glusterfs_event_t; +/* gf_lkowner_t is defined in lkowner.h */ +#include "lkowner.h" + +struct gf_flock { + short l_type; + short l_whence; + off_t l_start; + off_t l_len; + pid_t l_pid; + gf_lkowner_t l_owner; +}; + + extern char *glusterfs_strevent (glusterfs_event_t ev); #define GF_MUST_CHECK __attribute__((warn_unused_result)) diff --git a/libglusterfs/src/lkowner.h b/libglusterfs/src/lkowner.h new file mode 100644 index 00000000000..5fee17b3ddc --- /dev/null +++ b/libglusterfs/src/lkowner.h @@ -0,0 +1,92 @@ +/* + Copyright (c) 2012 Red Hat <http://www.redhat.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 _LK_OWNER_H +#define _LK_OWNER_H + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#define GF_MAX_LOCK_OWNER_LEN 1024 /* 1kB as per NLM */ + +/* 16strings-16strings-... */ +#define GF_LKOWNER_BUF_SIZE ((GF_MAX_LOCK_OWNER_LEN * 2) + \ + (GF_MAX_LOCK_OWNER_LEN / 8)) + +typedef struct gf_lkowner_ { + int len; + char data[GF_MAX_LOCK_OWNER_LEN]; +} gf_lkowner_t; + + +/* LKOWNER to string functions */ +static inline void +lkowner_unparse (gf_lkowner_t *lkowner, char *buf, int buf_len) +{ + int i = 0; + int j = 0; + + for (i = 0; i < lkowner->len; i++) { + if (i && !(i % 8)) { + buf[j] = '-'; + j++; + } + sprintf (&buf[j], "%02x", lkowner->data[i]); + j += 2; + if (j == buf_len) + break; + } + if (j < buf_len) + buf[j] = '\0'; +} + +static inline void +set_lk_owner_from_ptr (gf_lkowner_t *lkowner, void *data) +{ + int i = 0; + int j = 0; + + lkowner->len = sizeof (unsigned long); + for (i = 0, j = 0; i < lkowner->len; i++, j += 8) { + lkowner->data[i] = (char)((((unsigned long)data) >> j) & 0xff); + } +} + +static inline void +set_lk_owner_from_uint64 (gf_lkowner_t *lkowner, uint64_t data) +{ + int i = 0; + int j = 0; + + lkowner->len = 8; + for (i = 0, j = 0; i < lkowner->len; i++, j += 8) { + lkowner->data[i] = (char)((data >> j) & 0xff); + } +} + +/* Return true if the locks have the same owner */ +static inline int +is_same_lkowner (gf_lkowner_t *l1, gf_lkowner_t *l2) +{ + return ((l1->len == l2->len) && !memcmp(l1->data, l2->data, l1->len)); +} + +#endif /* _LK_OWNER_H */ diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h index 546e2f968c1..a5689e0966f 100644 --- a/libglusterfs/src/stack.h +++ b/libglusterfs/src/stack.h @@ -44,6 +44,7 @@ typedef struct _call_pool_t call_pool_t; #include "list.h" #include "common-utils.h" #include "globals.h" +#include "lkowner.h" #define NFS_PID 1 #define LOW_PRIO_PROC_PID -1 @@ -106,9 +107,9 @@ struct _call_stack_t { uid_t uid; gid_t gid; pid_t pid; - uint32_t ngrps; - uint32_t groups[GF_REQUEST_MAXGROUPS]; - uint64_t lk_owner; + uint16_t ngrps; + uint32_t groups[GF_MAX_AUX_GROUPS]; + gf_lkowner_t lk_owner; call_frame_t frames; @@ -360,7 +361,7 @@ copy_frame (call_frame_t *frame) newstack->op = oldstack->op; newstack->type = oldstack->type; memcpy (newstack->groups, oldstack->groups, - sizeof (uint32_t) * GF_REQUEST_MAXGROUPS); + sizeof (gid_t) * GF_MAX_AUX_GROUPS); newstack->unique = oldstack->unique; newstack->frames.this = frame->this; |