summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/common-utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src/common-utils.h')
-rw-r--r--libglusterfs/src/common-utils.h150
1 files changed, 127 insertions, 23 deletions
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 9903edad4..3c99a4212 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -23,6 +23,7 @@
#include <string.h>
#include <assert.h>
#include <pthread.h>
+#include <openssl/md5.h>
#ifndef GF_BSD_HOST_OS
#include <alloca.h>
#endif
@@ -65,6 +66,8 @@ void trap (void);
#define GEOREP "geo-replication"
#define GHADOOP "glusterfs-hadoop"
+#define GF_SELINUX_XATTR_KEY "security.selinux"
+
#define WIPE(statp) do { typeof(*statp) z = {0,}; if (statp) *statp = z; } while (0)
#define IS_EXT_FS(fs_name) \
@@ -75,7 +78,8 @@ void trap (void);
/* Defining this here as it is needed by glusterd for setting
* nfs port in volume status.
*/
-#define GF_NFS3_PORT 38467
+#define GF_NFS3_PORT 2049
+#define GF_CLIENT_PORT_CEILING 1024
enum _gf_boolean
{
@@ -106,15 +110,14 @@ void gf_global_variable_init(void);
in_addr_t gf_resolve_ip (const char *hostname, void **dnscache);
-void gf_log_volume_file (FILE *specfp);
-void gf_print_trace (int32_t signal);
-
-extern char *gf_fop_list[GF_FOP_MAXVALUE];
-extern char *gf_mgmt_list[GF_MGMT_MAXVALUE];
+void gf_log_dump_graph (FILE *specfp, glusterfs_graph_t *graph);
+void gf_print_trace (int32_t signal, glusterfs_ctx_t *ctx);
+int gf_set_log_file_path (cmd_args_t *cmd_args);
#define VECTORSIZE(count) (count * (sizeof (struct iovec)))
#define STRLEN_0(str) (strlen(str) + 1)
+
#define VALIDATE_OR_GOTO(arg,label) do { \
if (!arg) { \
errno = EINVAL; \
@@ -173,25 +176,22 @@ extern char *gf_mgmt_list[GF_MGMT_MAXVALUE];
} \
} while (0)
-
-#define GF_IF_INTERNAL_XATTR_GOTO(pattern, dict, trav, op_errno, label) \
+#define GF_IF_INTERNAL_XATTR_GOTO(pattern, dict, op_errno, label) \
do { \
if (!dict) { \
gf_log (this->name, GF_LOG_ERROR, \
"setxattr dict is null"); \
goto label; \
} \
- trav = dict->members_list; \
- while (trav) { \
- if (!fnmatch (pattern, trav->key, 0)) { \
- op_errno = EPERM; \
- gf_log (this->name, GF_LOG_ERROR, \
- "attempt to set internal" \
- " xattr: %s: %s", trav->key, \
- strerror (op_errno)); \
- goto label; \
- } \
- trav = trav->next; \
+ if (dict_foreach_fnmatch (dict, pattern, \
+ dict_null_foreach_fn, \
+ NULL) > 0) { \
+ op_errno = EPERM; \
+ gf_log (this->name, GF_LOG_ERROR, \
+ "attempt to set internal" \
+ " xattr: %s: %s", pattern, \
+ strerror (op_errno)); \
+ goto label; \
} \
} while (0)
@@ -267,7 +267,7 @@ iov_length (const struct iovec *vector, int count)
static inline struct iovec *
-iov_dup (struct iovec *vector, int count)
+iov_dup (const struct iovec *vector, int count)
{
int bytecount = 0;
int i;
@@ -347,6 +347,65 @@ iov_unload (char *buf, const struct iovec *vector, int count)
}
+static inline size_t
+iov_load (const struct iovec *vector, int count, char *buf, int size)
+{
+ size_t left = size;
+ size_t cp = 0;
+ int ret = 0;
+ int i = 0;
+
+ while (left && i < count) {
+ cp = min (vector[i].iov_len, left);
+ if (vector[i].iov_base != buf + (size - left))
+ memcpy (vector[i].iov_base, buf + (size - left), cp);
+ ret += cp;
+ left -= cp;
+ if (left)
+ i++;
+ }
+
+ return ret;
+}
+
+
+static inline size_t
+iov_copy (const struct iovec *dst, int dcnt,
+ const struct iovec *src, int scnt)
+{
+ size_t ret = 0;
+ size_t left = 0;
+ size_t min_i = 0;
+ int s_i = 0, s_ii = 0;
+ int d_i = 0, d_ii = 0;
+
+ ret = min (iov_length (dst, dcnt), iov_length (src, scnt));
+ left = ret;
+
+ while (left) {
+ min_i = min (dst[d_i].iov_len - d_ii, src[s_i].iov_len - s_ii);
+ memcpy (dst[d_i].iov_base + d_ii, src[s_i].iov_base + s_ii,
+ min_i);
+
+ d_ii += min_i;
+ if (d_ii == dst[d_i].iov_len) {
+ d_ii = 0;
+ d_i++;
+ }
+
+ s_ii += min_i;
+ if (s_ii == src[s_i].iov_len) {
+ s_ii = 0;
+ s_i++;
+ }
+
+ left -= min_i;
+ }
+
+ return ret;
+}
+
+
static inline int
mem_0filled (const char *buf, size_t size)
{
@@ -392,6 +451,34 @@ memdup (const void *ptr, size_t size)
return newptr;
}
+typedef enum {
+ gf_timefmt_default = 0,
+ gf_timefmt_FT = 0, /* YYYY-MM-DD hh:mm:ss */
+ gf_timefmt_Ymd_T, /* YYYY/MM-DD-hh:mm:ss */
+ gf_timefmt_bdT, /* ddd DD hh:mm:ss */
+ gf_timefmt_F_HMS, /* YYYY-MM-DD hhmmss */
+ gf_timefmt_last
+} gf_timefmts;
+
+static inline void
+gf_time_fmt (char *dst, size_t sz_dst, time_t utime, unsigned int fmt)
+{
+ extern void _gf_timestuff (gf_timefmts *, const char ***, const char ***);
+ static gf_timefmts timefmt_last = (gf_timefmts) -1;
+ static const char **fmts;
+ static const char **zeros;
+ struct tm tm;
+
+ if (timefmt_last == -1)
+ _gf_timestuff (&timefmt_last, &fmts, &zeros);
+ if (timefmt_last < fmt) fmt = gf_timefmt_default;
+ if (utime && gmtime_r (&utime, &tm) != NULL) {
+ strftime (dst, sz_dst, fmts[fmt], &tm);
+ } else {
+ strncpy (dst, "N/A", sz_dst);
+ }
+}
+
int
mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks);
/*
@@ -399,14 +486,17 @@ mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks);
* nr
*/
-int32_t gf_roundup_power_of_two (uint32_t nr);
+int
+gf_lstat_dir (const char *path, struct stat *stbuf_in);
+
+int32_t gf_roundup_power_of_two (int32_t nr);
/*
* rounds up nr to next power of two. If nr is already a power of two, next
* power of two is returned.
*/
-int32_t gf_roundup_next_power_of_two (uint32_t nr);
+int32_t gf_roundup_next_power_of_two (int32_t nr);
char *gf_trim (char *string);
int gf_strsplit (const char *str, const char *delim,
@@ -444,7 +534,7 @@ int gf_string2percent_or_bytesize (const char *str, uint64_t *n,
gf_boolean_t *is_percent);
int gf_string2boolean (const char *str, gf_boolean_t *b);
-int gf_string2percent (const char *str, uint32_t *n);
+int gf_string2percent (const char *str, double *n);
int gf_string2time (const char *str, uint32_t *n);
int gf_lockfd (int fd);
@@ -469,6 +559,8 @@ char valid_internet_address (char *address, gf_boolean_t wildcard_acc);
char valid_ipv4_wildcard_check (char *address);
char valid_ipv6_wildcard_check (char *address);
char valid_wildcard_internet_address (char *address);
+gf_boolean_t gf_sock_union_equal_addr (union gf_sock_union *a,
+ union gf_sock_union *b);
char *uuid_utoa (uuid_t uuid);
char *uuid_utoa_r (uuid_t uuid, char *dst);
@@ -487,4 +579,16 @@ void gf_path_strip_trailing_slashes (char *path);
uint64_t get_mem_size ();
int gf_strip_whitespace (char *str, int len);
int gf_canonicalize_path (char *path);
+char *generate_glusterfs_ctx_id (void);
+char *gf_get_reserved_ports();
+int gf_process_reserved_ports (gf_boolean_t ports[]);
+gf_boolean_t gf_ports_reserved (char *blocked_port, gf_boolean_t *ports);
+int gf_get_hostname_from_ip (char *client_ip, char **hostname);
+gf_boolean_t gf_is_local_addr (char *hostname);
+gf_boolean_t gf_is_same_address (char *host1, char *host2);
+void md5_wrapper(const unsigned char *data, size_t len, char *md5);
+
+int gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,
+ void *(*start_routine)(void *), void *arg);
+
#endif /* _COMMON_UTILS_H */