summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/inode.h
blob: 375ff3ee4e578c799cf8c3c469da2ce4e629b177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
   Copyright (c) 2007-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 Affero 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
   Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see
   <http://www.gnu.org/licenses/>.
*/

#ifndef _INODE_H
#define _INODE_H

#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#include <stdint.h>
#include <sys/types.h>

#define DEFAULT_INODE_MEMPOOL_ENTRIES   16384
struct _inode_table;
typedef struct _inode_table inode_table_t;

struct _inode;
typedef struct _inode inode_t;

struct _dentry;
typedef struct _dentry dentry_t;

#include "list.h"
#include "xlator.h"
#include "iatt.h"
#include "uuid.h"


struct _inode_table {
        pthread_mutex_t    lock;
        size_t             hashsize;    /* bucket size of inode hash and dentry hash */
        char              *name;        /* name of the inode table, just for gf_log() */
        inode_t           *root;        /* root directory inode, with number 1 */
        xlator_t          *xl;          /* xlator to be called to do purge */
        uint32_t           lru_limit;   /* maximum LRU cache size */
        struct list_head  *inode_hash;  /* buckets for inode hash table */
        struct list_head  *name_hash;   /* buckets for dentry hash table */
        struct list_head   active;      /* list of inodes currently active (in an fop) */
        uint32_t           active_size; /* count of inodes in active list */
        struct list_head   lru;         /* list of inodes recently used.
                                           lru.next most recent */
        uint32_t           lru_size;    /* count of inodes in lru list  */
        struct list_head   purge;       /* list of inodes to be purged soon */
        uint32_t           purge_size;  /* count of inodes in purge list */

        struct mem_pool   *inode_pool;  /* memory pool for inodes */
        struct mem_pool   *dentry_pool; /* memory pool for dentrys */
        struct mem_pool   *fd_mem_pool; /* memory pool for fd_t */
};


struct _dentry {
        struct list_head   inode_list;   /* list of dentries of inode */
        struct list_head   hash;         /* hash table pointers */
        inode_t           *inode;        /* inode of this directory entry */
        char              *name;         /* name of the directory entry */
        inode_t           *parent;       /* directory of the entry */
};

struct _inode_ctx {
        union {
                uint64_t    key;
                xlator_t   *xl_key;
        };
        union {
                uint64_t    value1;
                void       *ptr1;
        };
        union {
                uint64_t    value2;
                void       *ptr2;
        };
};

struct _inode {
        inode_table_t       *table;         /* the table this inode belongs to */
        uuid_t               gfid;
        gf_lock_t            lock;
        uint64_t             nlookup;
        uint32_t             ref;           /* reference count on this inode */
        ino_t                ino;           /* inode number in the storage (persistent) */
        ia_type_t            ia_type;       /* what kind of file */
        struct list_head     fd_list;       /* list of open files on this inode */
        struct list_head     dentry_list;   /* list of directory entries for this inode */
        struct list_head     hash;          /* hash table pointers */
        struct list_head     list;          /* active/lru/purge */

	struct _inode_ctx   *_ctx;    /* replacement for dict_t *(inode->ctx) */
};


inode_table_t *
inode_table_new (size_t lru_limit, xlator_t *xl);

inode_t *
inode_new (inode_table_t *table);

inode_t *
inode_link (inode_t *inode, inode_t *parent,
            const char *name, struct iatt *stbuf);

void
inode_unlink (inode_t *inode, inode_t *parent, const char *name);

inode_t *
inode_parent (inode_t *inode, ino_t par, const char *name);

inode_t *
inode_ref (inode_t *inode);

inode_t *
inode_unref (inode_t *inode);

int
inode_lookup (inode_t *inode);

int
inode_forget (inode_t *inode, uint64_t nlookup);

int
inode_rename (inode_table_t *table, inode_t *olddir, const char *oldname,
	      inode_t *newdir, const char *newname,
	      inode_t *inode, struct iatt *stbuf);

inode_t *
inode_grep (inode_table_t *table, inode_t *parent, const char *name);

inode_t *
inode_get (inode_table_t *table, ino_t ino, uint64_t gen);

inode_t *
inode_find (inode_table_t *table, uuid_t gfid);

int
inode_path (inode_t *inode, const char *name, char **bufp);

inode_t *
inode_from_path (inode_table_t *table, const char *path);

int
__inode_ctx_put (inode_t *inode, xlator_t *xlator, uint64_t value);

int
inode_ctx_put (inode_t *inode, xlator_t *xlator, uint64_t value);

int
__inode_ctx_get (inode_t *inode, xlator_t *xlator, uint64_t *value);

int
inode_ctx_get (inode_t *inode, xlator_t *xlator, uint64_t *value);

int
inode_ctx_del (inode_t *inode, xlator_t *xlator, uint64_t *value);

int
inode_ctx_put2 (inode_t *inode, xlator_t *xlator, uint64_t value1,
                uint64_t value2);

int
inode_ctx_get2 (inode_t *inode, xlator_t *xlator, uint64_t *value1,
                uint64_t *value2);

int
inode_ctx_del2 (inode_t *inode, xlator_t *xlator, uint64_t *value1,
                uint64_t *value2);

int
__is_root_gfid (uuid_t gfid);
#endif /* _INODE_H */
ab644805af6fe1ac312775e13'>xlators/features/changelog/src/changelog-encoders.c298
-rw-r--r--xlators/features/changelog/src/changelog-ev-handle.c570
-rw-r--r--xlators/features/changelog/src/changelog-helpers.c2987
-rw-r--r--xlators/features/changelog/src/changelog-rpc-common.c525
-rw-r--r--xlators/features/changelog/src/changelog-rpc.c548
-rw-r--r--xlators/features/changelog/src/changelog-rt.c57
-rw-r--r--xlators/features/changelog/src/changelog.c4631
-rw-r--r--xlators/features/changetimerecorder/src/changetimerecorder.c3705
-rw-r--r--xlators/features/changetimerecorder/src/ctr-helper.c450
-rw-r--r--xlators/features/changetimerecorder/src/ctr-xlator-ctx.c557
-rw-r--r--xlators/features/cloudsync/src/cloudsync-common.c42
-rw-r--r--xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c896
-rw-r--r--xlators/features/cloudsync/src/cloudsync.c2460
-rw-r--r--xlators/features/compress/src/cdc-helper.c756
-rw-r--r--xlators/features/compress/src/cdc.c557
-rw-r--r--xlators/features/gfid-access/src/gfid-access.c2135
-rw-r--r--xlators/features/glupy/src/glupy.c2987
-rw-r--r--xlators/features/index/src/index.c4050
-rw-r--r--xlators/features/leases/src/leases-internal.c2013
-rw-r--r--xlators/features/leases/src/leases.c1526
-rw-r--r--xlators/features/locks/src/clear.c701
-rw-r--r--xlators/features/locks/src/common.c1437
-rw-r--r--xlators/features/locks/src/entrylk.c1627
-rw-r--r--xlators/features/locks/src/inodelk.c1669
-rw-r--r--xlators/features/locks/src/posix.c6649
-rw-r--r--xlators/features/locks/src/reservelk.c555
-rw-r--r--xlators/features/locks/tests/unit-test.c88
-rw-r--r--xlators/features/marker/src/marker-common.c69
-rw-r--r--xlators/features/marker/src/marker-quota-helper.c651
-rw-r--r--xlators/features/marker/src/marker-quota.c3491
-rw-r--r--xlators/features/marker/src/marker.c4781
-rw-r--r--xlators/features/namespace/src/namespace.c1784
-rw-r--r--xlators/features/quiesce/src/quiesce.c3506
-rw-r--r--xlators/features/quota/src/quota-enforcer-client.c702
-rw-r--r--xlators/features/quota/src/quota.c8233
-rw-r--r--xlators/features/quota/src/quotad-aggregator.c696
-rw-r--r--xlators/features/quota/src/quotad-helpers.c114
-rw-r--r--xlators/features/quota/src/quotad.c316
-rw-r--r--xlators/features/read-only/src/read-only-common.c555
-rw-r--r--xlators/features/read-only/src/read-only.c167
-rw-r--r--xlators/features/read-only/src/worm-helper.c604
-rw-r--r--xlators/features/read-only/src/worm.c1069
-rw-r--r--xlators/features/sdfs/src/sdfs.c2188
-rw-r--r--xlators/features/selinux/src/selinux.c407
-rw-r--r--xlators/features/shard/src/shard.c10962
-rw-r--r--xlators/features/snapview-client/src/snapview-client.c3892
-rw-r--r--xlators/features/snapview-server/src/snapview-server-helpers.c869
-rw-r--r--xlators/features/snapview-server/src/snapview-server-mgmt.c817
-rw-r--r--xlators/features/snapview-server/src/snapview-server.c4240
-rw-r--r--xlators/features/thin-arbiter/src/thin-arbiter.c433
-rw-r--r--xlators/features/trash/src/trash.c4338
-rw-r--r--xlators/features/upcall/src/upcall-internal.c987
-rw-r--r--xlators/features/upcall/src/upcall.c3205
-rw-r--r--xlators/features/utime/src/utime-helpers.c85
-rw-r--r--xlators/features/utime/src/utime.c198
74 files changed, 61142 insertions, 62912 deletions
diff --git a/xlators/features/arbiter/src/arbiter.c b/xlators/features/arbiter/src/arbiter.c
index cf0841653b7..436f228a566 100644
--- a/xlators/features/arbiter/src/arbiter.c
+++ b/xlators/features/arbiter/src/arbiter.c
@@ -15,357 +15,353 @@
#include "logging.h"
static arbiter_inode_ctx_t *
-__arbiter_inode_ctx_get (inode_t *inode, xlator_t *this)
+__arbiter_inode_ctx_get(inode_t *inode, xlator_t *this)
{
-
- arbiter_inode_ctx_t *ctx = NULL;
- int ret = 0;
- uint64_t ctx_addr = 0;
-
- ret = __inode_ctx_get (inode, this, &ctx_addr);
- if (ret == 0) {
- ctx = (arbiter_inode_ctx_t *) (long) ctx_addr;
- goto out;
- }
-
- ctx = GF_CALLOC (1, sizeof (*ctx), gf_arbiter_mt_inode_ctx_t);
- if (!ctx)
- goto out;
-
- ret = __inode_ctx_put (inode, this, (uint64_t)ctx);
- if (ret) {
- GF_FREE (ctx);
- ctx = NULL;
- gf_log_callingfn (this->name, GF_LOG_ERROR, "failed to "
- "set the inode ctx (%s)",
- uuid_utoa (inode->gfid));
- }
+ arbiter_inode_ctx_t *ctx = NULL;
+ int ret = 0;
+ uint64_t ctx_addr = 0;
+
+ ret = __inode_ctx_get(inode, this, &ctx_addr);
+ if (ret == 0) {
+ ctx = (arbiter_inode_ctx_t *)(long)ctx_addr;
+ goto out;
+ }
+
+ ctx = GF_CALLOC(1, sizeof(*ctx), gf_arbiter_mt_inode_ctx_t);
+ if (!ctx)
+ goto out;
+
+ ret = __inode_ctx_put(inode, this, (uint64_t)ctx);
+ if (ret) {
+ GF_FREE(ctx);
+ ctx = NULL;
+ gf_log_callingfn(this->name, GF_LOG_ERROR,
+ "failed to "
+ "set the inode ctx (%s)",
+ uuid_utoa(inode->gfid));
+ }
out:
- return ctx;
+ return ctx;
}
static arbiter_inode_ctx_t *
-arbiter_inode_ctx_get (inode_t *inode, xlator_t *this)
+arbiter_inode_ctx_get(inode_t *inode, xlator_t *this)
{
- arbiter_inode_ctx_t *ctx = NULL;
-
- LOCK(&inode->lock);
- {
- ctx = __arbiter_inode_ctx_get (inode, this);
- }
- UNLOCK(&inode->lock);
- return ctx;
+ arbiter_inode_ctx_t *ctx = NULL;
+
+ LOCK(&inode->lock);
+ {
+ ctx = __arbiter_inode_ctx_get(inode, this);
+ }
+ UNLOCK(&inode->lock);
+ return ctx;
}
int32_t
-arbiter_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, dict_t *xdata, struct iatt *postparent)
+arbiter_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, dict_t *xdata, struct iatt *postparent)
{
- arbiter_inode_ctx_t *ctx = NULL;
-
- if (op_ret != 0)
- goto unwind;
- ctx = arbiter_inode_ctx_get (inode, this);
- if (!ctx) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
- memcpy (&ctx->iattbuf, buf, sizeof (ctx->iattbuf));
+ arbiter_inode_ctx_t *ctx = NULL;
+
+ if (op_ret != 0)
+ goto unwind;
+ ctx = arbiter_inode_ctx_get(inode, this);
+ if (!ctx) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ memcpy(&ctx->iattbuf, buf, sizeof(ctx->iattbuf));
unwind:
- STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf,
- xdata, postparent);
- return 0;
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, buf, xdata,
+ postparent);
+ return 0;
}
int32_t
-arbiter_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
+arbiter_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- STACK_WIND (frame, arbiter_lookup_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->lookup, loc, xdata);
- return 0;
+ STACK_WIND(frame, arbiter_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, loc, xdata);
+ return 0;
}
int32_t
-arbiter_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
- dict_t *xdata)
+arbiter_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
+ dict_t *xdata)
{
- arbiter_inode_ctx_t *ctx = NULL;
- struct iatt *buf = NULL;
- int32_t op_ret = 0;
- int32_t op_errno = 0;
-
- ctx = arbiter_inode_ctx_get (loc->inode, this);
- if (!ctx) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
- buf = &ctx->iattbuf;
+ arbiter_inode_ctx_t *ctx = NULL;
+ struct iatt *buf = NULL;
+ int32_t op_ret = 0;
+ int32_t op_errno = 0;
+
+ ctx = arbiter_inode_ctx_get(loc->inode, this);
+ if (!ctx) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ buf = &ctx->iattbuf;
unwind:
- STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, buf, buf, NULL);
- return 0;
+ STACK_UNWIND_STRICT(truncate, frame, op_ret, op_errno, buf, buf, NULL);
+ return 0;
}
int32_t
-arbiter_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
- dict_t *xdata)
+arbiter_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ dict_t *xdata)
{
- arbiter_inode_ctx_t *ctx = NULL;
- struct iatt *buf = NULL;
- int32_t op_ret = 0;
- int32_t op_errno = 0;
-
- ctx = arbiter_inode_ctx_get (fd->inode, this);
- if (!ctx) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
- buf = &ctx->iattbuf;
+ arbiter_inode_ctx_t *ctx = NULL;
+ struct iatt *buf = NULL;
+ int32_t op_ret = 0;
+ int32_t op_errno = 0;
+
+ ctx = arbiter_inode_ctx_get(fd->inode, this);
+ if (!ctx) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ buf = &ctx->iattbuf;
unwind:
- STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, buf, buf,
- NULL);
- return 0;
+ STACK_UNWIND_STRICT(ftruncate, frame, op_ret, op_errno, buf, buf, NULL);
+ return 0;
}
-dict_t*
-arbiter_fill_writev_xdata (fd_t *fd, dict_t *xdata, xlator_t *this)
+dict_t *
+arbiter_fill_writev_xdata(fd_t *fd, dict_t *xdata, xlator_t *this)
{
- dict_t *rsp_xdata = NULL;
- int32_t ret = 0;
- int is_append = 1;
-
- if (!fd || !fd->inode || gf_uuid_is_null (fd->inode->gfid)) {
- goto out;
- }
-
- if (!xdata)
- goto out;
-
- rsp_xdata = dict_new();
- if (!rsp_xdata)
- goto out;
-
- if (dict_get (xdata, GLUSTERFS_OPEN_FD_COUNT)) {
- ret = dict_set_uint32 (rsp_xdata, GLUSTERFS_OPEN_FD_COUNT,
- fd->inode->fd_count);
- if (ret < 0) {
- gf_msg_debug (this->name, 0, "Failed to set dict value"
- " for GLUSTERFS_OPEN_FD_COUNT");
- }
+ dict_t *rsp_xdata = NULL;
+ int32_t ret = 0;
+ int is_append = 1;
+
+ if (!fd || !fd->inode || gf_uuid_is_null(fd->inode->gfid)) {
+ goto out;
+ }
+
+ if (!xdata)
+ goto out;
+
+ rsp_xdata = dict_new();
+ if (!rsp_xdata)
+ goto out;
+
+ if (dict_get(xdata, GLUSTERFS_OPEN_FD_COUNT)) {
+ ret = dict_set_uint32(rsp_xdata, GLUSTERFS_OPEN_FD_COUNT,
+ fd->inode->fd_count);
+ if (ret < 0) {
+ gf_msg_debug(this->name, 0,
+ "Failed to set dict value"
+ " for GLUSTERFS_OPEN_FD_COUNT");
}
- if (dict_get (xdata, GLUSTERFS_WRITE_IS_APPEND)) {
- ret = dict_set_uint32 (rsp_xdata, GLUSTERFS_WRITE_IS_APPEND,
- is_append);
- if (ret < 0) {
- gf_msg_debug (this->name, 0, "Failed to set dict value"
- " for GLUSTERFS_WRITE_IS_APPEND");
- }
+ }
+ if (dict_get(xdata, GLUSTERFS_WRITE_IS_APPEND)) {
+ ret = dict_set_uint32(rsp_xdata, GLUSTERFS_WRITE_IS_APPEND, is_append);
+ if (ret < 0) {
+ gf_msg_debug(this->name, 0,
+ "Failed to set dict value"
+ " for GLUSTERFS_WRITE_IS_APPEND");
}
+ }
out:
- return rsp_xdata;
+ return rsp_xdata;
}
int32_t
-arbiter_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *vector, int32_t count, off_t off, uint32_t flags,
- struct iobref *iobref, dict_t *xdata)
+arbiter_writev(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *vector, int32_t count, off_t off, uint32_t flags,
+ struct iobref *iobref, dict_t *xdata)
{
- arbiter_inode_ctx_t *ctx = NULL;
- struct iatt *buf = NULL;
- dict_t *rsp_xdata = NULL;
- int op_ret = 0;
- int op_errno = 0;
-
- ctx = arbiter_inode_ctx_get (fd->inode, this);
- if (!ctx) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
- buf = &ctx->iattbuf;
- op_ret = iov_length (vector, count);
- rsp_xdata = arbiter_fill_writev_xdata (fd, xdata, this);
+ arbiter_inode_ctx_t *ctx = NULL;
+ struct iatt *buf = NULL;
+ dict_t *rsp_xdata = NULL;
+ int op_ret = 0;
+ int op_errno = 0;
+
+ ctx = arbiter_inode_ctx_get(fd->inode, this);
+ if (!ctx) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ buf = &ctx->iattbuf;
+ op_ret = iov_length(vector, count);
+ rsp_xdata = arbiter_fill_writev_xdata(fd, xdata, this);
unwind:
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, buf, buf,
- rsp_xdata);
- if (rsp_xdata)
- dict_unref (rsp_xdata);
- return 0;
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, buf, buf, rsp_xdata);
+ if (rsp_xdata)
+ dict_unref(rsp_xdata);
+ return 0;
}
int32_t
-arbiter_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd,
+arbiter_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd,
int32_t keep_size, off_t offset, size_t len, dict_t *xdata)
{
- arbiter_inode_ctx_t *ctx = NULL;
- struct iatt *buf = NULL;
- int op_ret = 0;
- int op_errno = 0;
-
- ctx = arbiter_inode_ctx_get (fd->inode, this);
- if (!ctx) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
- buf = &ctx->iattbuf;
+ arbiter_inode_ctx_t *ctx = NULL;
+ struct iatt *buf = NULL;
+ int op_ret = 0;
+ int op_errno = 0;
+
+ ctx = arbiter_inode_ctx_get(fd->inode, this);
+ if (!ctx) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ buf = &ctx->iattbuf;
unwind:
- STACK_UNWIND_STRICT(fallocate, frame, op_ret, op_errno, buf, buf, NULL);
- return 0;
+ STACK_UNWIND_STRICT(fallocate, frame, op_ret, op_errno, buf, buf, NULL);
+ return 0;
}
int32_t
-arbiter_discard (call_frame_t *frame, xlator_t *this, fd_t *fd,
- off_t offset, size_t len, dict_t *xdata)
+arbiter_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ size_t len, dict_t *xdata)
{
- arbiter_inode_ctx_t *ctx = NULL;
- struct iatt *buf = NULL;
- int op_ret = 0;
- int op_errno = 0;
-
- ctx = arbiter_inode_ctx_get (fd->inode, this);
- if (!ctx) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
- buf = &ctx->iattbuf;
+ arbiter_inode_ctx_t *ctx = NULL;
+ struct iatt *buf = NULL;
+ int op_ret = 0;
+ int op_errno = 0;
+
+ ctx = arbiter_inode_ctx_get(fd->inode, this);
+ if (!ctx) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ buf = &ctx->iattbuf;
unwind:
- STACK_UNWIND_STRICT(discard, frame, op_ret, op_errno, buf, buf, NULL);
- return 0;
+ STACK_UNWIND_STRICT(discard, frame, op_ret, op_errno, buf, buf, NULL);
+ return 0;
}
int32_t
-arbiter_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd,
- off_t offset, off_t len, dict_t *xdata)
+arbiter_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ off_t len, dict_t *xdata)
{
- arbiter_inode_ctx_t *ctx = NULL;
- struct iatt *buf = NULL;
- int op_ret = 0;
- int op_errno = 0;
-
- ctx = arbiter_inode_ctx_get (fd->inode, this);
- if (!ctx) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
- buf = &ctx->iattbuf;
+ arbiter_inode_ctx_t *ctx = NULL;
+ struct iatt *buf = NULL;
+ int op_ret = 0;
+ int op_errno = 0;
+
+ ctx = arbiter_inode_ctx_get(fd->inode, this);
+ if (!ctx) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ buf = &ctx->iattbuf;
unwind:
- STACK_UNWIND_STRICT(zerofill, frame, op_ret, op_errno, buf, buf, NULL);
- return 0;
+ STACK_UNWIND_STRICT(zerofill, frame, op_ret, op_errno, buf, buf, NULL);
+ return 0;
}
static int32_t
-arbiter_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
- off_t offset, uint32_t flags, dict_t *xdata)
+arbiter_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset, uint32_t flags, dict_t *xdata)
{
- STACK_UNWIND_STRICT (readv, frame, -1, ENOSYS, NULL, 0, NULL, NULL,
- NULL);
- return 0;
+ STACK_UNWIND_STRICT(readv, frame, -1, ENOSYS, NULL, 0, NULL, NULL, NULL);
+ return 0;
}
static int32_t
-arbiter_seek (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
- gf_seek_what_t what, dict_t *xdata)
+arbiter_seek(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ gf_seek_what_t what, dict_t *xdata)
{
- STACK_UNWIND_STRICT (seek, frame, -1, ENOSYS, 0, xdata);
- return 0;
+ STACK_UNWIND_STRICT(seek, frame, -1, ENOSYS, 0, xdata);
+ return 0;
}
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int ret = -1;
-
- ret = xlator_mem_acct_init (this, gf_arbiter_mt_end + 1);
- if (ret)
- gf_log (this->name, GF_LOG_ERROR, "Memory accounting "
- "initialization failed.");
- return ret;
+ int ret = -1;
+
+ ret = xlator_mem_acct_init(this, gf_arbiter_mt_end + 1);
+ if (ret)
+ gf_log(this->name, GF_LOG_ERROR,
+ "Memory accounting "
+ "initialization failed.");
+ return ret;
}
int
-reconfigure (xlator_t *this, dict_t *options)
+reconfigure(xlator_t *this, dict_t *options)
{
-
- return 0;
+ return 0;
}
int
-arbiter_forget (xlator_t *this, inode_t *inode)
+arbiter_forget(xlator_t *this, inode_t *inode)
{
- arbiter_inode_ctx_t *ctx = NULL;
- uint64_t ctx_addr = 0;
-
- inode_ctx_del (inode, this, &ctx_addr);
- if (!ctx_addr)
- return 0;
- ctx = (arbiter_inode_ctx_t *) (long) ctx_addr;
- GF_FREE (ctx);
+ arbiter_inode_ctx_t *ctx = NULL;
+ uint64_t ctx_addr = 0;
+
+ inode_ctx_del(inode, this, &ctx_addr);
+ if (!ctx_addr)
return 0;
+ ctx = (arbiter_inode_ctx_t *)(long)ctx_addr;
+ GF_FREE(ctx);
+ return 0;
}
int32_t
-init (xlator_t *this)
+init(xlator_t *this)
{
+ if (!this->children || this->children->next) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "'arbiter' not configured with exactly one child");
+ return -1;
+ }
- if (!this->children || this->children->next) {
- gf_log (this->name, GF_LOG_ERROR,
- "'arbiter' not configured with exactly one child");
- return -1;
- }
-
- if (!this->parents)
- gf_log (this->name, GF_LOG_ERROR,
- "dangling volume. check volfile ");
+ if (!this->parents)
+ gf_log(this->name, GF_LOG_ERROR, "dangling volume. check volfile ");
- return 0;
+ return 0;
}
void
-fini (xlator_t *this)
+fini(xlator_t *this)
{
- return;
+ return;
}
struct xlator_fops fops = {
- .lookup = arbiter_lookup,
-
- /* Return success for these inode write FOPS without winding it down to
- * posix; this is needed for AFR write transaction logic to work.*/
- .truncate = arbiter_truncate,
- .writev = arbiter_writev,
- .ftruncate = arbiter_ftruncate,
- .fallocate = arbiter_fallocate,
- .discard = arbiter_discard,
- .zerofill = arbiter_zerofill,
-
- /* AFR is not expected to wind these inode read FOPS initiated by the
- * application to the arbiter brick. But in case a bug causes them
- * to be called, we return ENOSYS. */
- .readv = arbiter_readv,
- .seek = arbiter_seek,
-
- /* The following inode read FOPS initiated by the application are not
- * wound by AFR either but internal logic like shd, glfsheal and
- * client side healing in AFR will send them for selfheal/ inode refresh
- * operations etc.,so we need to wind them down to posix:
- *
- * (f)stat, readdir(p), readlink, (f)getxattr.*/
-
- /* All other FOPs not listed here are safe to be wound down to posix.*/
+ .lookup = arbiter_lookup,
+
+ /* Return success for these inode write FOPS without winding it down to
+ * posix; this is needed for AFR write transaction logic to work.*/
+ .truncate = arbiter_truncate,
+ .writev = arbiter_writev,
+ .ftruncate = arbiter_ftruncate,
+ .fallocate = arbiter_fallocate,
+ .discard = arbiter_discard,
+ .zerofill = arbiter_zerofill,
+
+ /* AFR is not expected to wind these inode read FOPS initiated by the
+ * application to the arbiter brick. But in case a bug causes them
+ * to be called, we return ENOSYS. */
+ .readv = arbiter_readv,
+ .seek = arbiter_seek,
+
+ /* The following inode read FOPS initiated by the application are not
+ * wound by AFR either but internal logic like shd, glfsheal and
+ * client side healing in AFR will send them for selfheal/ inode refresh
+ * operations etc.,so we need to wind them down to posix:
+ *
+ * (f)stat, readdir(p), readlink, (f)getxattr.*/
+
+ /* All other FOPs not listed here are safe to be wound down to posix.*/
};
struct xlator_cbks cbks = {
- .forget = arbiter_forget,
+ .forget = arbiter_forget,
};
struct volume_options options[] = {
- { .key = {NULL} },
+ {.key = {NULL}},
};
diff --git a/xlators/features/barrier/src/barrier.c b/xlators/features/barrier/src/barrier.c
index 27f3135c3af..edecae1a55e 100644
--- a/xlators/features/barrier/src/barrier.c
+++ b/xlators/features/barrier/src/barrier.c
@@ -15,792 +15,797 @@
#include "statedump.h"
void
-barrier_local_set_gfid (call_frame_t *frame, uuid_t gfid, xlator_t *this)
-{
- if (gfid) {
- uuid_t *id = GF_MALLOC (sizeof (uuid_t), gf_common_mt_uuid_t);
- if (!id) {
- gf_log (this->name, GF_LOG_WARNING, "Could not set gfid"
- ". gfid will not be dumped in statedump file.");
- return;
- }
- gf_uuid_copy (*id, gfid);
- frame->local = id;
+barrier_local_set_gfid(call_frame_t *frame, uuid_t gfid, xlator_t *this)
+{
+ if (gfid) {
+ uuid_t *id = GF_MALLOC(sizeof(uuid_t), gf_common_mt_uuid_t);
+ if (!id) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "Could not set gfid"
+ ". gfid will not be dumped in statedump file.");
+ return;
}
+ gf_uuid_copy(*id, gfid);
+ frame->local = id;
+ }
}
void
-barrier_local_free_gfid (call_frame_t *frame)
+barrier_local_free_gfid(call_frame_t *frame)
{
- if (frame->local) {
- GF_FREE (frame->local);
- frame->local = NULL;
- }
+ if (frame->local) {
+ GF_FREE(frame->local);
+ frame->local = NULL;
+ }
}
int32_t
-barrier_truncate_cbk_resume (call_frame_t *frame, void *cookie, xlator_t *this,
+barrier_truncate_cbk_resume(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ struct iatt *prebuf, struct iatt *postbuf,
+ dict_t *xdata)
+{
+ barrier_local_free_gfid(frame);
+ STACK_UNWIND_STRICT(truncate, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ return 0;
+}
+
+int32_t
+barrier_ftruncate_cbk_resume(call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *prebuf, struct iatt *postbuf,
dict_t *xdata)
{
- barrier_local_free_gfid (frame);
- STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, prebuf, postbuf,
- xdata);
- return 0;
+ barrier_local_free_gfid(frame);
+ STACK_UNWIND_STRICT(ftruncate, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ return 0;
}
int32_t
-barrier_ftruncate_cbk_resume (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iatt *prebuf, struct iatt *postbuf,
- dict_t *xdata)
-{
- barrier_local_free_gfid (frame);
- STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, prebuf,
- postbuf, xdata);
- return 0;
+barrier_unlink_cbk_resume(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ struct iatt *preparent, struct iatt *postparent,
+ dict_t *xdata)
+{
+ barrier_local_free_gfid(frame);
+ STACK_UNWIND_STRICT(unlink, frame, op_ret, op_errno, preparent, postparent,
+ xdata);
+ return 0;
}
int32_t
-barrier_unlink_cbk_resume (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iatt *preparent, struct iatt *postparent,
- dict_t *xdata)
-{
- barrier_local_free_gfid (frame);
- STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, preparent,
- postparent, xdata);
- return 0;
+barrier_rmdir_cbk_resume(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ struct iatt *preparent, struct iatt *postparent,
+ dict_t *xdata)
+{
+ barrier_local_free_gfid(frame);
+ STACK_UNWIND_STRICT(rmdir, frame, op_ret, op_errno, preparent, postparent,
+ xdata);
+ return 0;
}
int32_t
-barrier_rmdir_cbk_resume (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iatt *preparent, struct iatt *postparent,
+barrier_rename_cbk_resume(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf,
+ struct iatt *preoldparent, struct iatt *postoldparent,
+ struct iatt *prenewparent, struct iatt *postnewparent,
dict_t *xdata)
{
- barrier_local_free_gfid (frame);
- STACK_UNWIND_STRICT (rmdir, frame, op_ret, op_errno, preparent,
- postparent, xdata);
- return 0;
+ barrier_local_free_gfid(frame);
+ STACK_UNWIND_STRICT(rename, frame, op_ret, op_errno, buf, preoldparent,
+ postoldparent, prenewparent, postnewparent, xdata);
+ return 0;
}
int32_t
-barrier_rename_cbk_resume (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *buf,
- struct iatt *preoldparent, struct iatt *postoldparent,
- struct iatt *prenewparent, struct iatt *postnewparent,
- dict_t *xdata)
-{
- barrier_local_free_gfid (frame);
- STACK_UNWIND_STRICT (rename, frame, op_ret, op_errno, buf, preoldparent,
- postoldparent, prenewparent, postnewparent, xdata);
- return 0;
+barrier_writev_cbk_resume(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
+{
+ barrier_local_free_gfid(frame);
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ return 0;
}
int32_t
-barrier_writev_cbk_resume (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iatt *prebuf, struct iatt *postbuf,
- dict_t *xdata)
-{
- barrier_local_free_gfid (frame);
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf,
- xdata);
- return 0;
+barrier_fsync_cbk_resume(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
+{
+ barrier_local_free_gfid(frame);
+ STACK_UNWIND_STRICT(fsync, frame, op_ret, op_errno, prebuf, postbuf, xdata);
+ return 0;
}
int32_t
-barrier_fsync_cbk_resume (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+barrier_removexattr_cbk_resume(call_frame_t *frame, void *cookie,
+ xlator_t *this, int32_t op_ret, int32_t op_errno,
+ dict_t *xdata)
{
- barrier_local_free_gfid (frame);
- STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, prebuf, postbuf,
- xdata);
- return 0;
+ barrier_local_free_gfid(frame);
+ STACK_UNWIND_STRICT(removexattr, frame, op_ret, op_errno, xdata);
+ return 0;
}
int32_t
-barrier_removexattr_cbk_resume (call_frame_t *frame, void *cookie,
+barrier_fremovexattr_cbk_resume(call_frame_t *frame, void *cookie,
xlator_t *this, int32_t op_ret,
int32_t op_errno, dict_t *xdata)
{
- barrier_local_free_gfid (frame);
- STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno, xdata);
- return 0;
+ barrier_local_free_gfid(frame);
+ STACK_UNWIND_STRICT(fremovexattr, frame, op_ret, op_errno, xdata);
+ return 0;
}
int32_t
-barrier_fremovexattr_cbk_resume (call_frame_t *frame, void *cookie,
- xlator_t *this, int32_t op_ret,
- int32_t op_errno, dict_t *xdata)
+barrier_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- barrier_local_free_gfid (frame);
- STACK_UNWIND_STRICT (fremovexattr, frame, op_ret, op_errno, xdata);
- return 0;
+ BARRIER_FOP_CBK(writev, out, frame, this, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+out:
+ return 0;
}
int32_t
-barrier_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf,
- dict_t *xdata)
+barrier_fremovexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- BARRIER_FOP_CBK (writev, out, frame, this, op_ret, op_errno,
- prebuf, postbuf, xdata);
+ BARRIER_FOP_CBK(fremovexattr, out, frame, this, op_ret, op_errno, xdata);
out:
- return 0;
+ return 0;
}
int32_t
-barrier_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+barrier_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- BARRIER_FOP_CBK (fremovexattr, out, frame, this, op_ret, op_errno,
- xdata);
+ BARRIER_FOP_CBK(removexattr, out, frame, this, op_ret, op_errno, xdata);
out:
- return 0;
+ return 0;
}
int32_t
-barrier_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+barrier_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- BARRIER_FOP_CBK (removexattr, out, frame, this, op_ret, op_errno,
- xdata);
+ BARRIER_FOP_CBK(truncate, out, frame, this, op_ret, op_errno, prebuf,
+ postbuf, xdata);
out:
- return 0;
+ return 0;
}
int32_t
-barrier_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+barrier_ftruncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
struct iatt *postbuf, dict_t *xdata)
{
- BARRIER_FOP_CBK (truncate, out, frame, this, op_ret, op_errno, prebuf,
- postbuf, xdata);
+ BARRIER_FOP_CBK(ftruncate, out, frame, this, op_ret, op_errno, prebuf,
+ postbuf, xdata);
out:
- return 0;
+ return 0;
}
int32_t
-barrier_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
-{
- BARRIER_FOP_CBK (ftruncate, out, frame, this, op_ret, op_errno, prebuf,
- postbuf, xdata);
+barrier_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf,
+ struct iatt *preoldparent, struct iatt *postoldparent,
+ struct iatt *prenewparent, struct iatt *postnewparent,
+ dict_t *xdata)
+{
+ BARRIER_FOP_CBK(rename, out, frame, this, op_ret, op_errno, buf,
+ preoldparent, postoldparent, prenewparent, postnewparent,
+ xdata);
out:
- return 0;
+ return 0;
}
int32_t
-barrier_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *buf,
- struct iatt *preoldparent, struct iatt *postoldparent,
- struct iatt *prenewparent, struct iatt *postnewparent,
- dict_t *xdata)
-{
- BARRIER_FOP_CBK (rename, out, frame, this, op_ret, op_errno, buf,
- preoldparent, postoldparent, prenewparent,
- postnewparent, xdata);
+barrier_rmdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
+{
+ BARRIER_FOP_CBK(rmdir, out, frame, this, op_ret, op_errno, preparent,
+ postparent, xdata);
out:
- return 0;
+ return 0;
}
int32_t
-barrier_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+barrier_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, struct iatt *preparent,
struct iatt *postparent, dict_t *xdata)
{
- BARRIER_FOP_CBK (rmdir, out, frame, this, op_ret, op_errno, preparent,
- postparent, xdata);
+ BARRIER_FOP_CBK(unlink, out, frame, this, op_ret, op_errno, preparent,
+ postparent, xdata);
out:
- return 0;
-}
-
-int32_t
-barrier_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
-{
- BARRIER_FOP_CBK (unlink, out, frame, this, op_ret, op_errno, preparent,
- postparent, xdata);
-out:
- return 0;
+ return 0;
}
int32_t
-barrier_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+barrier_fsync_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- BARRIER_FOP_CBK (fsync, out, frame, this, op_ret, op_errno,
- prebuf, postbuf, xdata);
+ BARRIER_FOP_CBK(fsync, out, frame, this, op_ret, op_errno, prebuf, postbuf,
+ xdata);
out:
- return 0;
+ return 0;
}
int32_t
-barrier_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *vector, int32_t count, off_t off, uint32_t flags,
- struct iobref *iobref, dict_t *xdata)
+barrier_writev(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *vector, int32_t count, off_t off, uint32_t flags,
+ struct iobref *iobref, dict_t *xdata)
{
- if (!((flags | fd->flags) & (O_SYNC | O_DSYNC))) {
- STACK_WIND_TAIL (frame, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->writev,
- fd, vector, count, off, flags, iobref, xdata);
-
- return 0;
- }
+ if (!((flags | fd->flags) & (O_SYNC | O_DSYNC))) {
+ STACK_WIND_TAIL(frame, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, vector, count, off,
+ flags, iobref, xdata);
- barrier_local_set_gfid (frame, fd->inode->gfid, this);
- STACK_WIND (frame, barrier_writev_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->writev, fd, vector, count,
- off, flags, iobref, xdata);
return 0;
+ }
+
+ barrier_local_set_gfid(frame, fd->inode->gfid, this);
+ STACK_WIND(frame, barrier_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, vector, count, off, flags,
+ iobref, xdata);
+ return 0;
}
int32_t
-barrier_fremovexattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
- const char *name, dict_t *xdata)
+barrier_fremovexattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ const char *name, dict_t *xdata)
{
- barrier_local_set_gfid (frame, fd->inode->gfid, this);
- STACK_WIND (frame, barrier_fremovexattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->fremovexattr,
- fd, name, xdata);
- return 0;
+ barrier_local_set_gfid(frame, fd->inode->gfid, this);
+ STACK_WIND(frame, barrier_fremovexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fremovexattr, fd, name, xdata);
+ return 0;
}
int32_t
-barrier_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- const char *name, dict_t *xdata)
+barrier_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
{
- barrier_local_set_gfid (frame, loc->inode->gfid, this);
- STACK_WIND (frame, barrier_removexattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->removexattr,
- loc, name, xdata);
- return 0;
+ barrier_local_set_gfid(frame, loc->inode->gfid, this);
+ STACK_WIND(frame, barrier_removexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr, loc, name, xdata);
+ return 0;
}
int32_t
-barrier_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc,
- off_t offset, dict_t *xdata)
+barrier_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
+ dict_t *xdata)
{
- barrier_local_set_gfid (frame, loc->inode->gfid, this);
- STACK_WIND (frame, barrier_truncate_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->truncate,
- loc, offset, xdata);
- return 0;
+ barrier_local_set_gfid(frame, loc->inode->gfid, this);
+ STACK_WIND(frame, barrier_truncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
+ return 0;
}
-
int32_t
-barrier_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
- loc_t *newloc, dict_t *xdata)
+barrier_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc,
+ loc_t *newloc, dict_t *xdata)
{
- barrier_local_set_gfid (frame, oldloc->inode->gfid, this);
- STACK_WIND (frame, barrier_rename_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->rename,
- oldloc, newloc, xdata);
- return 0;
+ barrier_local_set_gfid(frame, oldloc->inode->gfid, this);
+ STACK_WIND(frame, barrier_rename_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rename, oldloc, newloc, xdata);
+ return 0;
}
int
-barrier_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
- dict_t *xdata)
+barrier_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
+ dict_t *xdata)
{
- barrier_local_set_gfid (frame, loc->inode->gfid, this);
- STACK_WIND (frame, barrier_rmdir_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->rmdir,
- loc, flags, xdata);
- return 0;
+ barrier_local_set_gfid(frame, loc->inode->gfid, this);
+ STACK_WIND(frame, barrier_rmdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rmdir, loc, flags, xdata);
+ return 0;
}
int32_t
-barrier_unlink (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int xflag, dict_t *xdata)
+barrier_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
+ dict_t *xdata)
{
- barrier_local_set_gfid (frame, loc->inode->gfid, this);
- STACK_WIND (frame, barrier_unlink_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->unlink,
- loc, xflag, xdata);
- return 0;
+ barrier_local_set_gfid(frame, loc->inode->gfid, this);
+ STACK_WIND(frame, barrier_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, loc, xflag, xdata);
+ return 0;
}
int32_t
-barrier_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd,
- off_t offset, dict_t *xdata)
+barrier_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ dict_t *xdata)
{
- barrier_local_set_gfid (frame, fd->inode->gfid, this);
- STACK_WIND (frame, barrier_ftruncate_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->ftruncate,
- fd, offset, xdata);
- return 0;
+ barrier_local_set_gfid(frame, fd->inode->gfid, this);
+ STACK_WIND(frame, barrier_ftruncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
+ return 0;
}
int32_t
-barrier_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd,
- int32_t flags, dict_t *xdata)
+barrier_fsync(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags,
+ dict_t *xdata)
{
- barrier_local_set_gfid (frame, fd->inode->gfid, this);
- STACK_WIND (frame, barrier_fsync_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->fsync,
- fd, flags, xdata);
- return 0;
+ barrier_local_set_gfid(frame, fd->inode->gfid, this);
+ STACK_WIND(frame, barrier_fsync_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsync, fd, flags, xdata);
+ return 0;
}
call_stub_t *
-__barrier_dequeue (xlator_t *this, struct list_head *queue)
+__barrier_dequeue(xlator_t *this, struct list_head *queue)
{
- call_stub_t *stub = NULL;
- barrier_priv_t *priv = NULL;
+ call_stub_t *stub = NULL;
+ barrier_priv_t *priv = NULL;
- priv = this->private;
- GF_ASSERT (priv);
+ priv = this->private;
+ GF_ASSERT(priv);
- if (list_empty (queue))
- goto out;
+ if (list_empty(queue))
+ goto out;
- stub = list_entry (queue->next, call_stub_t, list);
- list_del_init (&stub->list);
+ stub = list_entry(queue->next, call_stub_t, list);
+ list_del_init(&stub->list);
out:
- return stub;
+ return stub;
}
void
-barrier_dequeue_all (xlator_t *this, struct list_head *queue)
+barrier_dequeue_all(xlator_t *this, struct list_head *queue)
{
- call_stub_t *stub = NULL;
+ call_stub_t *stub = NULL;
- gf_log (this->name, GF_LOG_INFO, "Dequeuing all the barriered fops");
+ gf_log(this->name, GF_LOG_INFO, "Dequeuing all the barriered fops");
- /* TODO: Start the below task in a new thread */
- while ((stub = __barrier_dequeue (this, queue)))
- call_resume (stub);
+ /* TODO: Start the below task in a new thread */
+ while ((stub = __barrier_dequeue(this, queue)))
+ call_resume(stub);
- gf_log (this->name, GF_LOG_INFO, "Dequeuing the barriered fops is "
- "finished");
- return;
+ gf_log(this->name, GF_LOG_INFO,
+ "Dequeuing the barriered fops is "
+ "finished");
+ return;
}
void
-barrier_timeout (void *data)
+barrier_timeout(void *data)
{
- xlator_t *this = NULL;
- barrier_priv_t *priv = NULL;
- struct list_head queue = {0,};
+ xlator_t *this = NULL;
+ barrier_priv_t *priv = NULL;
+ struct list_head queue = {
+ 0,
+ };
- this = data;
- THIS = this;
- priv = this->private;
+ this = data;
+ THIS = this;
+ priv = this->private;
- INIT_LIST_HEAD (&queue);
+ INIT_LIST_HEAD(&queue);
- gf_log (this->name, GF_LOG_CRITICAL, "Disabling barrier because of "
- "the barrier timeout.");
+ gf_log(this->name, GF_LOG_CRITICAL,
+ "Disabling barrier because of "
+ "the barrier timeout.");
- LOCK (&priv->lock);
- {
- __barrier_disable (this, &queue);
- }
- UNLOCK (&priv->lock);
+ LOCK(&priv->lock);
+ {
+ __barrier_disable(this, &queue);
+ }
+ UNLOCK(&priv->lock);
- barrier_dequeue_all (this, &queue);
+ barrier_dequeue_all(this, &queue);
- return;
+ return;
}
void
-__barrier_enqueue (xlator_t *this, call_stub_t *stub)
+__barrier_enqueue(xlator_t *this, call_stub_t *stub)
{
- barrier_priv_t *priv = NULL;
+ barrier_priv_t *priv = NULL;
- priv = this->private;
- GF_ASSERT (priv);
+ priv = this->private;
+ GF_ASSERT(priv);
- list_add_tail (&stub->list, &priv->queue);
- priv->queue_size++;
+ list_add_tail(&stub->list, &priv->queue);
+ priv->queue_size++;
- return;
+ return;
}
void
-__barrier_disable (xlator_t *this, struct list_head *queue)
+__barrier_disable(xlator_t *this, struct list_head *queue)
{
- GF_UNUSED int ret = 0;
- barrier_priv_t *priv = NULL;
+ GF_UNUSED int ret = 0;
+ barrier_priv_t *priv = NULL;
- priv = this->private;
- GF_ASSERT (priv);
+ priv = this->private;
+ GF_ASSERT(priv);
- if (priv->timer) {
- ret = gf_timer_call_cancel (this->ctx, priv->timer);
- priv->timer = NULL;
- }
+ if (priv->timer) {
+ ret = gf_timer_call_cancel(this->ctx, priv->timer);
+ priv->timer = NULL;
+ }
- list_splice_init (&priv->queue, queue);
- priv->queue_size = 0;
- priv->barrier_enabled = _gf_false;
+ list_splice_init(&priv->queue, queue);
+ priv->queue_size = 0;
+ priv->barrier_enabled = _gf_false;
}
int
-__barrier_enable (xlator_t *this, barrier_priv_t *priv)
+__barrier_enable(xlator_t *this, barrier_priv_t *priv)
{
- int ret = -1;
+ int ret = -1;
- priv->timer = gf_timer_call_after (this->ctx, priv->timeout,
- barrier_timeout, (void *) this);
- if (!priv->timer) {
- gf_log (this->name, GF_LOG_CRITICAL, "Couldn't add barrier "
- "timeout event.");
- goto out;
- }
+ priv->timer = gf_timer_call_after(this->ctx, priv->timeout, barrier_timeout,
+ (void *)this);
+ if (!priv->timer) {
+ gf_log(this->name, GF_LOG_CRITICAL,
+ "Couldn't add barrier "
+ "timeout event.");
+ goto out;
+ }
- priv->barrier_enabled = _gf_true;
- ret = 0;
+ priv->barrier_enabled = _gf_true;
+ ret = 0;
out:
- return ret;
+ return ret;
}
int
-notify (xlator_t *this, int event, void *data, ...)
-{
- barrier_priv_t *priv = NULL;
- dict_t *dict = NULL;
- gf_boolean_t past = _gf_false;
- int ret = -1;
- int barrier_enabled = _gf_false;
- struct list_head queue = {0,};
-
- priv = this->private;
- GF_ASSERT (priv);
- INIT_LIST_HEAD (&queue);
-
- switch (event) {
- case GF_EVENT_TRANSLATOR_OP:
- {
- dict = data;
- barrier_enabled = dict_get_str_boolean (dict, "barrier", -1);
-
- if (barrier_enabled == -1) {
- gf_log (this->name, GF_LOG_ERROR, "Could not fetch "
- " barrier key from the dictionary.");
- goto out;
- }
-
- LOCK (&priv->lock);
- {
- past = priv->barrier_enabled;
-
- switch (past) {
- case _gf_false:
- if (barrier_enabled) {
- ret = __barrier_enable (this,priv);
- if (ret)
- goto unlock;
- } else {
- gf_log (this->name, GF_LOG_ERROR,
- "Already disabled.");
- goto unlock;
- }
- break;
-
- case _gf_true:
- if (!barrier_enabled) {
- __barrier_disable(this, &queue);
- } else {
- gf_log (this->name, GF_LOG_ERROR,
- "Already enabled");
- goto unlock;
- }
- break;
- }
- ret = 0;
- }
-unlock:
- UNLOCK (&priv->lock);
-
- if (!list_empty (&queue))
- barrier_dequeue_all (this, &queue);
-
- break;
- }
- default:
- {
- default_notify (this, event, data);
- ret = 0;
+notify(xlator_t *this, int event, void *data, ...)
+{
+ barrier_priv_t *priv = NULL;
+ dict_t *dict = NULL;
+ gf_boolean_t past = _gf_false;
+ int ret = -1;
+ int barrier_enabled = _gf_false;
+ struct list_head queue = {
+ 0,
+ };
+
+ priv = this->private;
+ GF_ASSERT(priv);
+ INIT_LIST_HEAD(&queue);
+
+ switch (event) {
+ case GF_EVENT_TRANSLATOR_OP: {
+ dict = data;
+ barrier_enabled = dict_get_str_boolean(dict, "barrier", -1);
+
+ if (barrier_enabled == -1) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "Could not fetch "
+ " barrier key from the dictionary.");
goto out;
- }
- }
-out:
- return ret;
-}
-
-int
-reconfigure (xlator_t *this, dict_t *options)
-{
- barrier_priv_t *priv = NULL;
- gf_boolean_t past = _gf_false;
- int ret = -1;
- gf_boolean_t barrier_enabled = _gf_false;
- uint32_t timeout = {0,};
- struct list_head queue = {0,};
+ }
- priv = this->private;
- GF_ASSERT (priv);
-
- GF_OPTION_RECONF ("barrier", barrier_enabled, options, bool, out);
- GF_OPTION_RECONF ("barrier-timeout", timeout, options, time, out);
-
- INIT_LIST_HEAD (&queue);
-
- LOCK (&priv->lock);
- {
+ LOCK(&priv->lock);
+ {
past = priv->barrier_enabled;
switch (past) {
- case _gf_false:
+ case _gf_false:
if (barrier_enabled) {
- ret = __barrier_enable (this, priv);
- if (ret) {
- goto unlock;
- }
+ ret = __barrier_enable(this, priv);
+ if (ret)
+ goto unlock;
+ } else {
+ gf_log(this->name, GF_LOG_ERROR,
+ "Already disabled.");
+ goto unlock;
}
break;
- case _gf_true:
+ case _gf_true:
if (!barrier_enabled) {
- __barrier_disable (this, &queue);
-
+ __barrier_disable(this, &queue);
+ } else {
+ gf_log(this->name, GF_LOG_ERROR, "Already enabled");
+ goto unlock;
}
break;
}
- priv->timeout.tv_sec = timeout;
ret = 0;
+ }
+ unlock:
+ UNLOCK(&priv->lock);
+
+ if (!list_empty(&queue))
+ barrier_dequeue_all(this, &queue);
+
+ break;
}
+ default: {
+ default_notify(this, event, data);
+ ret = 0;
+ goto out;
+ }
+ }
+out:
+ return ret;
+}
+
+int
+reconfigure(xlator_t *this, dict_t *options)
+{
+ barrier_priv_t *priv = NULL;
+ gf_boolean_t past = _gf_false;
+ int ret = -1;
+ gf_boolean_t barrier_enabled = _gf_false;
+ uint32_t timeout = {
+ 0,
+ };
+ struct list_head queue = {
+ 0,
+ };
+
+ priv = this->private;
+ GF_ASSERT(priv);
+
+ GF_OPTION_RECONF("barrier", barrier_enabled, options, bool, out);
+ GF_OPTION_RECONF("barrier-timeout", timeout, options, time, out);
+
+ INIT_LIST_HEAD(&queue);
+
+ LOCK(&priv->lock);
+ {
+ past = priv->barrier_enabled;
+
+ switch (past) {
+ case _gf_false:
+ if (barrier_enabled) {
+ ret = __barrier_enable(this, priv);
+ if (ret) {
+ goto unlock;
+ }
+ }
+ break;
+
+ case _gf_true:
+ if (!barrier_enabled) {
+ __barrier_disable(this, &queue);
+ }
+ break;
+ }
+ priv->timeout.tv_sec = timeout;
+ ret = 0;
+ }
unlock:
- UNLOCK (&priv->lock);
+ UNLOCK(&priv->lock);
- if (!list_empty (&queue))
- barrier_dequeue_all (this, &queue);
+ if (!list_empty(&queue))
+ barrier_dequeue_all(this, &queue);
out:
- return ret;
+ return ret;
}
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int ret = -1;
+ int ret = -1;
- ret = xlator_mem_acct_init (this, gf_barrier_mt_end + 1);
- if (ret)
- gf_log (this->name, GF_LOG_ERROR, "Memory accounting "
- "initialization failed.");
+ ret = xlator_mem_acct_init(this, gf_barrier_mt_end + 1);
+ if (ret)
+ gf_log(this->name, GF_LOG_ERROR,
+ "Memory accounting "
+ "initialization failed.");
- return ret;
+ return ret;
}
int
-init (xlator_t *this)
+init(xlator_t *this)
{
- int ret = -1;
- barrier_priv_t *priv = NULL;
- uint32_t timeout = {0,};
+ int ret = -1;
+ barrier_priv_t *priv = NULL;
+ uint32_t timeout = {
+ 0,
+ };
- if (!this->children || this->children->next) {
- gf_log (this->name, GF_LOG_ERROR,
- "'barrier' not configured with exactly one child");
- goto out;
- }
+ if (!this->children || this->children->next) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "'barrier' not configured with exactly one child");
+ goto out;
+ }
- if (!this->parents)
- gf_log (this->name, GF_LOG_WARNING,
- "dangling volume. check volfile ");
+ if (!this->parents)
+ gf_log(this->name, GF_LOG_WARNING, "dangling volume. check volfile ");
- priv = GF_CALLOC (1, sizeof (*priv), gf_barrier_mt_priv_t);
- if (!priv)
- goto out;
+ priv = GF_CALLOC(1, sizeof(*priv), gf_barrier_mt_priv_t);
+ if (!priv)
+ goto out;
- LOCK_INIT (&priv->lock);
+ LOCK_INIT(&priv->lock);
- GF_OPTION_INIT ("barrier", priv->barrier_enabled, bool, out);
- GF_OPTION_INIT ("barrier-timeout", timeout, time, out);
- priv->timeout.tv_sec = timeout;
+ GF_OPTION_INIT("barrier", priv->barrier_enabled, bool, out);
+ GF_OPTION_INIT("barrier-timeout", timeout, time, out);
+ priv->timeout.tv_sec = timeout;
- INIT_LIST_HEAD (&priv->queue);
+ INIT_LIST_HEAD(&priv->queue);
- if (priv->barrier_enabled) {
- ret = __barrier_enable (this, priv);
- if (ret == -1)
- goto out;
- }
+ if (priv->barrier_enabled) {
+ ret = __barrier_enable(this, priv);
+ if (ret == -1)
+ goto out;
+ }
- this->private = priv;
- ret = 0;
+ this->private = priv;
+ ret = 0;
out:
- if (ret && priv)
- GF_FREE (priv);
+ if (ret && priv)
+ GF_FREE(priv);
- return ret;
+ return ret;
}
void
-fini (xlator_t *this)
+fini(xlator_t *this)
{
- barrier_priv_t *priv = NULL;
- struct list_head queue = {0,};
+ barrier_priv_t *priv = NULL;
+ struct list_head queue = {
+ 0,
+ };
- priv = this->private;
- if (!priv)
- goto out;
+ priv = this->private;
+ if (!priv)
+ goto out;
- INIT_LIST_HEAD (&queue);
+ INIT_LIST_HEAD(&queue);
- gf_log (this->name, GF_LOG_INFO, "Disabling barriering and dequeuing "
- "all the queued fops");
- LOCK (&priv->lock);
- {
- __barrier_disable (this, &queue);
- }
- UNLOCK (&priv->lock);
+ gf_log(this->name, GF_LOG_INFO,
+ "Disabling barriering and dequeuing "
+ "all the queued fops");
+ LOCK(&priv->lock);
+ {
+ __barrier_disable(this, &queue);
+ }
+ UNLOCK(&priv->lock);
- if (!list_empty (&queue))
- barrier_dequeue_all (this, &queue);
+ if (!list_empty(&queue))
+ barrier_dequeue_all(this, &queue);
- this->private = NULL;
+ this->private = NULL;
- LOCK_DESTROY (&priv->lock);
- GF_FREE (priv);
+ LOCK_DESTROY(&priv->lock);
+ GF_FREE(priv);
out:
- return;
+ return;
}
static void
-barrier_dump_stub (call_stub_t *stub, char *prefix)
+barrier_dump_stub(call_stub_t *stub, char *prefix)
{
- char key[GF_DUMP_MAX_BUF_LEN] = {0,};
+ char key[GF_DUMP_MAX_BUF_LEN] = {
+ 0,
+ };
- gf_proc_dump_build_key (key, prefix, "fop");
- gf_proc_dump_write (key, "%s", gf_fop_list[stub->fop]);
+ gf_proc_dump_build_key(key, prefix, "fop");
+ gf_proc_dump_write(key, "%s", gf_fop_list[stub->fop]);
- if (stub->frame->local) {
- gf_proc_dump_build_key (key, prefix, "gfid");
- gf_proc_dump_write (key, "%s",
- uuid_utoa (*(uuid_t*)(stub->frame->local)));
- }
- if (stub->args.loc.path) {
- gf_proc_dump_build_key (key, prefix, "path");
- gf_proc_dump_write (key, "%s", stub->args.loc.path);
- }
- if (stub->args.loc.name) {
- gf_proc_dump_build_key (key, prefix, "name");
- gf_proc_dump_write (key, "%s", stub->args.loc.name);
- }
+ if (stub->frame->local) {
+ gf_proc_dump_build_key(key, prefix, "gfid");
+ gf_proc_dump_write(key, "%s",
+ uuid_utoa(*(uuid_t *)(stub->frame->local)));
+ }
+ if (stub->args.loc.path) {
+ gf_proc_dump_build_key(key, prefix, "path");
+ gf_proc_dump_write(key, "%s", stub->args.loc.path);
+ }
+ if (stub->args.loc.name) {
+ gf_proc_dump_build_key(key, prefix, "name");
+ gf_proc_dump_write(key, "%s", stub->args.loc.name);
+ }
- return;
+ return;
}
static void
-__barrier_dump_queue (barrier_priv_t *priv)
+__barrier_dump_queue(barrier_priv_t *priv)
{
- call_stub_t *stub = NULL;
- char key[GF_DUMP_MAX_BUF_LEN] = {0,};
- int i = 0;
+ call_stub_t *stub = NULL;
+ char key[GF_DUMP_MAX_BUF_LEN] = {
+ 0,
+ };
+ int i = 0;
- GF_VALIDATE_OR_GOTO ("barrier", priv, out);
+ GF_VALIDATE_OR_GOTO("barrier", priv, out);
- list_for_each_entry (stub, &priv->queue, list) {
- snprintf (key, sizeof (key), "stub.%d", i++);
- gf_proc_dump_add_section (key);
- barrier_dump_stub(stub, key);
- }
+ list_for_each_entry(stub, &priv->queue, list)
+ {
+ snprintf(key, sizeof(key), "stub.%d", i++);
+ gf_proc_dump_add_section(key);
+ barrier_dump_stub(stub, key);
+ }
out:
- return;
+ return;
}
int
-barrier_dump_priv (xlator_t *this)
-{
- int ret = -1;
- char key[GF_DUMP_MAX_BUF_LEN] = {0,};
- barrier_priv_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO ("barrier", this, out);
-
- priv = this->private;
- if (!priv)
- return 0;
-
- gf_proc_dump_build_key (key, "xlator.features.barrier", "priv");
- gf_proc_dump_add_section (key);
-
- LOCK (&priv->lock);
- {
- gf_proc_dump_build_key (key, "barrier", "enabled");
- gf_proc_dump_write (key, "%d", priv->barrier_enabled);
- gf_proc_dump_build_key (key, "barrier", "timeout");
- gf_proc_dump_write (key, "%"PRId64, priv->timeout.tv_sec);
- if (priv->barrier_enabled) {
- gf_proc_dump_build_key (key, "barrier", "queue_size");
- gf_proc_dump_write (key, "%d", priv->queue_size);
- __barrier_dump_queue (priv);
- }
+barrier_dump_priv(xlator_t *this)
+{
+ int ret = -1;
+ char key[GF_DUMP_MAX_BUF_LEN] = {
+ 0,
+ };
+ barrier_priv_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO("barrier", this, out);
+
+ priv = this->private;
+ if (!priv)
+ return 0;
+
+ gf_proc_dump_build_key(key, "xlator.features.barrier", "priv");
+ gf_proc_dump_add_section(key);
+
+ LOCK(&priv->lock);
+ {
+ gf_proc_dump_build_key(key, "barrier", "enabled");
+ gf_proc_dump_write(key, "%d", priv->barrier_enabled);
+ gf_proc_dump_build_key(key, "barrier", "timeout");
+ gf_proc_dump_write(key, "%" PRId64, priv->timeout.tv_sec);
+ if (priv->barrier_enabled) {
+ gf_proc_dump_build_key(key, "barrier", "queue_size");
+ gf_proc_dump_write(key, "%d", priv->queue_size);
+ __barrier_dump_queue(priv);
}
- UNLOCK (&priv->lock);
+ }
+ UNLOCK(&priv->lock);
out:
- return ret;
+ return ret;
}
struct xlator_fops fops = {
- /* Barrier Class fops */
- .rmdir = barrier_rmdir,
- .unlink = barrier_unlink,
- .rename = barrier_rename,
- .removexattr = barrier_removexattr,
- .fremovexattr = barrier_fremovexattr,
- .truncate = barrier_truncate,
- .ftruncate = barrier_ftruncate,
- .fsync = barrier_fsync,
-
- /* Writes with only O_SYNC flag */
- .writev = barrier_writev,
+ /* Barrier Class fops */
+ .rmdir = barrier_rmdir,
+ .unlink = barrier_unlink,
+ .rename = barrier_rename,
+ .removexattr = barrier_removexattr,
+ .fremovexattr = barrier_fremovexattr,
+ .truncate = barrier_truncate,
+ .ftruncate = barrier_ftruncate,
+ .fsync = barrier_fsync,
+
+ /* Writes with only O_SYNC flag */
+ .writev = barrier_writev,
};
struct xlator_dumpops dumpops = {
- .priv = barrier_dump_priv,
+ .priv = barrier_dump_priv,
};
struct xlator_cbks cbks;
struct volume_options options[] = {
- { .key = {"barrier"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "disable",
- .op_version = {GD_OP_VERSION_3_6_0},
- .flags = OPT_FLAG_SETTABLE,
- .description = "When \"enabled\", blocks acknowledgements to application "
- "for file operations such as rmdir, rename, unlink, "
- "removexattr, fremovexattr, truncate, ftruncate, "
- "write (with O_SYNC), fsync. It is turned \"off\" by "
- "default."
- },
- { .key = {"barrier-timeout"},
- .type = GF_OPTION_TYPE_TIME,
- .default_value = BARRIER_TIMEOUT,
- .op_version = {GD_OP_VERSION_3_6_0},
- .flags = OPT_FLAG_SETTABLE,
- .description = "After 'timeout' seconds since the time 'barrier' "
- "option was set to \"on\", acknowledgements to file "
- "operations are no longer blocked and previously "
- "blocked acknowledgements are sent to the application"
- },
- { .key = {NULL} },
+ {.key = {"barrier"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "disable",
+ .op_version = {GD_OP_VERSION_3_6_0},
+ .flags = OPT_FLAG_SETTABLE,
+ .description = "When \"enabled\", blocks acknowledgements to application "
+ "for file operations such as rmdir, rename, unlink, "
+ "removexattr, fremovexattr, truncate, ftruncate, "
+ "write (with O_SYNC), fsync. It is turned \"off\" by "
+ "default."},
+ {.key = {"barrier-timeout"},
+ .type = GF_OPTION_TYPE_TIME,
+ .default_value = BARRIER_TIMEOUT,
+ .op_version = {GD_OP_VERSION_3_6_0},
+ .flags = OPT_FLAG_SETTABLE,
+ .description = "After 'timeout' seconds since the time 'barrier' "
+ "option was set to \"on\", acknowledgements to file "
+ "operations are no longer blocked and previously "
+ "blocked acknowledgements are sent to the application"},
+ {.key = {NULL}},
};
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot-scrub-status.c b/xlators/features/bit-rot/src/bitd/bit-rot-scrub-status.c
index 210beca7e2f..34e20f9df11 100644
--- a/xlators/features/bit-rot/src/bitd/bit-rot-scrub-status.c
+++ b/xlators/features/bit-rot/src/bitd/bit-rot-scrub-status.c
@@ -14,67 +14,65 @@
#include "bit-rot-scrub-status.h"
void
-br_inc_unsigned_file_count (br_scrub_stats_t *scrub_stat)
+br_inc_unsigned_file_count(br_scrub_stats_t *scrub_stat)
{
- if (!scrub_stat)
- return;
+ if (!scrub_stat)
+ return;
- pthread_mutex_lock (&scrub_stat->lock);
- {
- scrub_stat->unsigned_files++;
- }
- pthread_mutex_unlock (&scrub_stat->lock);
+ pthread_mutex_lock(&scrub_stat->lock);
+ {
+ scrub_stat->unsigned_files++;
+ }
+ pthread_mutex_unlock(&scrub_stat->lock);
}
void
-br_inc_scrubbed_file (br_scrub_stats_t *scrub_stat)
+br_inc_scrubbed_file(br_scrub_stats_t *scrub_stat)
{
- if (!scrub_stat)
- return;
+ if (!scrub_stat)
+ return;
- pthread_mutex_lock (&scrub_stat->lock);
- {
- scrub_stat->scrubbed_files++;
- }
- pthread_mutex_unlock (&scrub_stat->lock);
+ pthread_mutex_lock(&scrub_stat->lock);
+ {
+ scrub_stat->scrubbed_files++;
+ }
+ pthread_mutex_unlock(&scrub_stat->lock);
}
void
-br_update_scrub_start_time (br_scrub_stats_t *scrub_stat, struct timeval *tv)
+br_update_scrub_start_time(br_scrub_stats_t *scrub_stat, struct timeval *tv)
{
- if (!scrub_stat)
- return;
+ if (!scrub_stat)
+ return;
- pthread_mutex_lock (&scrub_stat->lock);
- {
- scrub_stat->scrub_start_tv.tv_sec = tv->tv_sec;
- }
- pthread_mutex_unlock (&scrub_stat->lock);
+ pthread_mutex_lock(&scrub_stat->lock);
+ {
+ scrub_stat->scrub_start_tv.tv_sec = tv->tv_sec;
+ }
+ pthread_mutex_unlock(&scrub_stat->lock);
}
void
-br_update_scrub_finish_time (br_scrub_stats_t *scrub_stat, char *timestr,
- struct timeval *tv)
+br_update_scrub_finish_time(br_scrub_stats_t *scrub_stat, char *timestr,
+ struct timeval *tv)
{
- int lst_size = 0;
+ int lst_size = 0;
- if (!scrub_stat)
- return;
+ if (!scrub_stat)
+ return;
- lst_size = sizeof (scrub_stat->last_scrub_time);
- if (strlen (timestr) >= lst_size)
- return;
+ lst_size = sizeof(scrub_stat->last_scrub_time);
+ if (strlen(timestr) >= lst_size)
+ return;
- pthread_mutex_lock (&scrub_stat->lock);
- {
- scrub_stat->scrub_end_tv.tv_sec = tv->tv_sec;
+ pthread_mutex_lock(&scrub_stat->lock);
+ {
+ scrub_stat->scrub_end_tv.tv_sec = tv->tv_sec;
- scrub_stat->scrub_duration =
- scrub_stat->scrub_end_tv.tv_sec -
- scrub_stat->scrub_start_tv.tv_sec;
+ scrub_stat->scrub_duration = scrub_stat->scrub_end_tv.tv_sec -
+ scrub_stat->scrub_start_tv.tv_sec;
- snprintf (scrub_stat->last_scrub_time, lst_size, "%s",
- timestr);
- }
- pthread_mutex_unlock (&scrub_stat->lock);
+ snprintf(scrub_stat->last_scrub_time, lst_size, "%s", timestr);
+ }
+ pthread_mutex_unlock(&scrub_stat->lock);
}
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
index e2665acab98..b856c168eb7 100644
--- a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
+++ b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
@@ -23,21 +23,21 @@
#include "events.h"
struct br_scrubbers {
- pthread_t scrubthread;
+ pthread_t scrubthread;
- struct list_head list;
+ struct list_head list;
};
struct br_fsscan_entry {
- void *data;
+ void *data;
- loc_t parent;
+ loc_t parent;
- gf_dirent_t *entry;
+ gf_dirent_t *entry;
- struct br_scanfs *fsscan; /* backpointer to subvolume scanner */
+ struct br_scanfs *fsscan; /* backpointer to subvolume scanner */
- struct list_head list;
+ struct list_head list;
};
/**
@@ -46,34 +46,32 @@ struct br_fsscan_entry {
* to the dictionary value.
*/
static int32_t
-bitd_fetch_signature (xlator_t *this, br_child_t *child,
- fd_t *fd, dict_t **xattr, br_isignature_out_t **sign)
+bitd_fetch_signature(xlator_t *this, br_child_t *child, fd_t *fd,
+ dict_t **xattr, br_isignature_out_t **sign)
{
- int32_t ret = -1;
-
- ret = syncop_fgetxattr (child->xl, fd, xattr,
- GLUSTERFS_GET_OBJECT_SIGNATURE, NULL, NULL);
- if (ret < 0) {
- br_log_object (this, "fgetxattr", fd->inode->gfid, -ret);
- goto out;
- }
-
- ret = dict_get_ptr
- (*xattr, GLUSTERFS_GET_OBJECT_SIGNATURE, (void **) sign);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_GET_SIGN_FAILED,
- "failed to extract signature info [GFID: %s]",
- uuid_utoa (fd->inode->gfid));
- goto unref_dict;
- }
-
- return 0;
-
- unref_dict:
- dict_unref (*xattr);
- out:
- return -1;
-
+ int32_t ret = -1;
+
+ ret = syncop_fgetxattr(child->xl, fd, xattr, GLUSTERFS_GET_OBJECT_SIGNATURE,
+ NULL, NULL);
+ if (ret < 0) {
+ br_log_object(this, "fgetxattr", fd->inode->gfid, -ret);
+ goto out;
+ }
+
+ ret = dict_get_ptr(*xattr, GLUSTERFS_GET_OBJECT_SIGNATURE, (void **)sign);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_GET_SIGN_FAILED,
+ "failed to extract signature info [GFID: %s]",
+ uuid_utoa(fd->inode->gfid));
+ goto unref_dict;
+ }
+
+ return 0;
+
+unref_dict:
+ dict_unref(*xattr);
+out:
+ return -1;
}
/**
@@ -86,88 +84,85 @@ bitd_fetch_signature (xlator_t *this, br_child_t *child,
*/
int32_t
-bitd_scrub_post_compute_check (xlator_t *this,
- br_child_t *child,
- fd_t *fd, unsigned long version,
- br_isignature_out_t **signature,
- br_scrub_stats_t *scrub_stat,
- gf_boolean_t skip_stat)
+bitd_scrub_post_compute_check(xlator_t *this, br_child_t *child, fd_t *fd,
+ unsigned long version,
+ br_isignature_out_t **signature,
+ br_scrub_stats_t *scrub_stat,
+ gf_boolean_t skip_stat)
{
- int32_t ret = 0;
- size_t signlen = 0;
- dict_t *xattr = NULL;
- br_isignature_out_t *signptr = NULL;
-
- ret = bitd_fetch_signature (this, child, fd, &xattr, &signptr);
- if (ret < 0) {
- if (!skip_stat)
- br_inc_unsigned_file_count (scrub_stat);
- goto out;
- }
-
- /**
- * Either the object got dirtied during the time the signature was
- * calculated OR the version we saved during pre-compute check does
- * not match now, implying that the object got dirtied and signed in
- * between scrubs pre & post compute checks (checksum window).
- *
- * The log entry looks pretty ugly, but helps in debugging..
- */
- if (signptr->stale || (signptr->version != version)) {
- if (!skip_stat)
- br_inc_unsigned_file_count (scrub_stat);
- gf_msg_debug (this->name, 0, "<STAGE: POST> Object [GFID: %s] "
- "either has a stale signature OR underwent "
- "signing during checksumming {Stale: %d | "
- "Version: %lu,%lu}", uuid_utoa (fd->inode->gfid),
- (signptr->stale) ? 1 : 0, version,
- signptr->version);
- ret = -1;
- goto unref_dict;
- }
-
- signlen = signptr->signaturelen;
- *signature = GF_MALLOC (sizeof (br_isignature_out_t) + signlen,
- gf_common_mt_char);
-
- (void) memcpy (*signature, signptr,
- sizeof (br_isignature_out_t) + signlen);
-
- unref_dict:
- dict_unref (xattr);
- out:
- return ret;
+ int32_t ret = 0;
+ size_t signlen = 0;
+ dict_t *xattr = NULL;
+ br_isignature_out_t *signptr = NULL;
+ ret = bitd_fetch_signature(this, child, fd, &xattr, &signptr);
+ if (ret < 0) {
+ if (!skip_stat)
+ br_inc_unsigned_file_count(scrub_stat);
+ goto out;
+ }
+
+ /**
+ * Either the object got dirtied during the time the signature was
+ * calculated OR the version we saved during pre-compute check does
+ * not match now, implying that the object got dirtied and signed in
+ * between scrubs pre & post compute checks (checksum window).
+ *
+ * The log entry looks pretty ugly, but helps in debugging..
+ */
+ if (signptr->stale || (signptr->version != version)) {
+ if (!skip_stat)
+ br_inc_unsigned_file_count(scrub_stat);
+ gf_msg_debug(this->name, 0,
+ "<STAGE: POST> Object [GFID: %s] "
+ "either has a stale signature OR underwent "
+ "signing during checksumming {Stale: %d | "
+ "Version: %lu,%lu}",
+ uuid_utoa(fd->inode->gfid), (signptr->stale) ? 1 : 0,
+ version, signptr->version);
+ ret = -1;
+ goto unref_dict;
+ }
+
+ signlen = signptr->signaturelen;
+ *signature = GF_MALLOC(sizeof(br_isignature_out_t) + signlen,
+ gf_common_mt_char);
+
+ (void)memcpy(*signature, signptr, sizeof(br_isignature_out_t) + signlen);
+
+unref_dict:
+ dict_unref(xattr);
+out:
+ return ret;
}
static int32_t
-bitd_signature_staleness (xlator_t *this,
- br_child_t *child, fd_t *fd,
- int *stale, unsigned long *version,
- br_scrub_stats_t *scrub_stat, gf_boolean_t skip_stat)
+bitd_signature_staleness(xlator_t *this, br_child_t *child, fd_t *fd,
+ int *stale, unsigned long *version,
+ br_scrub_stats_t *scrub_stat, gf_boolean_t skip_stat)
{
- int32_t ret = -1;
- dict_t *xattr = NULL;
- br_isignature_out_t *signptr = NULL;
+ int32_t ret = -1;
+ dict_t *xattr = NULL;
+ br_isignature_out_t *signptr = NULL;
- ret = bitd_fetch_signature (this, child, fd, &xattr, &signptr);
- if (ret < 0) {
- if (!skip_stat)
- br_inc_unsigned_file_count (scrub_stat);
- goto out;
- }
+ ret = bitd_fetch_signature(this, child, fd, &xattr, &signptr);
+ if (ret < 0) {
+ if (!skip_stat)
+ br_inc_unsigned_file_count(scrub_stat);
+ goto out;
+ }
- /**
- * save version for validation in post compute stage
- * c.f. bitd_scrub_post_compute_check()
- */
- *stale = signptr->stale ? 1 : 0;
- *version = signptr->version;
+ /**
+ * save version for validation in post compute stage
+ * c.f. bitd_scrub_post_compute_check()
+ */
+ *stale = signptr->stale ? 1 : 0;
+ *version = signptr->version;
- dict_unref (xattr);
+ dict_unref(xattr);
- out:
- return ret;
+out:
+ return ret;
}
/**
@@ -179,101 +174,102 @@ bitd_signature_staleness (xlator_t *this,
* - has stale signature
*/
int32_t
-bitd_scrub_pre_compute_check (xlator_t *this, br_child_t *child,
- fd_t *fd, unsigned long *version,
- br_scrub_stats_t *scrub_stat,
- gf_boolean_t skip_stat)
+bitd_scrub_pre_compute_check(xlator_t *this, br_child_t *child, fd_t *fd,
+ unsigned long *version,
+ br_scrub_stats_t *scrub_stat,
+ gf_boolean_t skip_stat)
{
- int stale = 0;
- int32_t ret = -1;
-
- if (bitd_is_bad_file (this, child, NULL, fd)) {
- gf_msg (this->name, GF_LOG_WARNING, 0, BRB_MSG_SKIP_OBJECT,
- "Object [GFID: %s] is marked corrupted, skipping..",
- uuid_utoa (fd->inode->gfid));
- goto out;
- }
-
- ret = bitd_signature_staleness (this, child, fd, &stale, version,
- scrub_stat, skip_stat);
- if (!ret && stale) {
- if (!skip_stat)
- br_inc_unsigned_file_count (scrub_stat);
- gf_msg_debug (this->name, 0, "<STAGE: PRE> Object [GFID: %s] "
- "has stale signature",
- uuid_utoa (fd->inode->gfid));
- ret = -1;
- }
+ int stale = 0;
+ int32_t ret = -1;
+
+ if (bitd_is_bad_file(this, child, NULL, fd)) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRB_MSG_SKIP_OBJECT,
+ "Object [GFID: %s] is marked corrupted, skipping..",
+ uuid_utoa(fd->inode->gfid));
+ goto out;
+ }
+
+ ret = bitd_signature_staleness(this, child, fd, &stale, version, scrub_stat,
+ skip_stat);
+ if (!ret && stale) {
+ if (!skip_stat)
+ br_inc_unsigned_file_count(scrub_stat);
+ gf_msg_debug(this->name, 0,
+ "<STAGE: PRE> Object [GFID: %s] "
+ "has stale signature",
+ uuid_utoa(fd->inode->gfid));
+ ret = -1;
+ }
- out:
- return ret;
+out:
+ return ret;
}
/* static int */
int
-bitd_compare_ckum (xlator_t *this,
- br_isignature_out_t *sign,
- unsigned char *md, inode_t *linked_inode,
- gf_dirent_t *entry, fd_t *fd, br_child_t *child, loc_t *loc)
+bitd_compare_ckum(xlator_t *this, br_isignature_out_t *sign, unsigned char *md,
+ inode_t *linked_inode, gf_dirent_t *entry, fd_t *fd,
+ br_child_t *child, loc_t *loc)
{
- int ret = -1;
- dict_t *xattr = NULL;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
- GF_VALIDATE_OR_GOTO (this->name, sign, out);
- GF_VALIDATE_OR_GOTO (this->name, fd, out);
- GF_VALIDATE_OR_GOTO (this->name, child, out);
- GF_VALIDATE_OR_GOTO (this->name, linked_inode, out);
- GF_VALIDATE_OR_GOTO (this->name, md, out);
- GF_VALIDATE_OR_GOTO (this->name, entry, out);
-
- if (strncmp
- (sign->signature, (char *) md, strlen (sign->signature)) == 0) {
- gf_msg_debug (this->name, 0, "%s [GFID: %s | Brick: %s] "
- "matches calculated checksum", loc->path,
- uuid_utoa (linked_inode->gfid),
- child->brick_path);
- return 0;
- }
-
- gf_msg (this->name, GF_LOG_DEBUG, 0, BRB_MSG_CHECKSUM_MISMATCH,
- "Object checksum mismatch: %s [GFID: %s | Brick: %s]",
- loc->path, uuid_utoa (linked_inode->gfid), child->brick_path);
- gf_msg (this->name, GF_LOG_ALERT, 0, BRB_MSG_CHECKSUM_MISMATCH,
- "CORRUPTION DETECTED: Object %s {Brick: %s | GFID: %s}",
- loc->path, child->brick_path, uuid_utoa (linked_inode->gfid));
-
- /* Perform bad-file marking */
- xattr = dict_new ();
- if (!xattr) {
- ret = -1;
- goto out;
- }
-
- ret = dict_set_int32 (xattr, BITROT_OBJECT_BAD_KEY, _gf_true);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_MARK_BAD_FILE,
- "Error setting bad-file marker for %s [GFID: %s | "
- "Brick: %s]", loc->path, uuid_utoa (linked_inode->gfid),
- child->brick_path);
- goto dictfree;
- }
-
- gf_msg (this->name, GF_LOG_ALERT, 0, BRB_MSG_MARK_CORRUPTED, "Marking"
- " %s [GFID: %s | Brick: %s] as corrupted..", loc->path,
- uuid_utoa (linked_inode->gfid), child->brick_path);
- gf_event (EVENT_BITROT_BAD_FILE, "gfid=%s;path=%s;brick=%s",
- uuid_utoa (linked_inode->gfid), loc->path, child->brick_path);
- ret = syncop_fsetxattr (child->xl, fd, xattr, 0, NULL, NULL);
- if (ret)
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_MARK_BAD_FILE,
- "Error marking object %s [GFID: %s] as corrupted",
- loc->path, uuid_utoa (linked_inode->gfid));
-
- dictfree:
- dict_unref (xattr);
- out:
- return ret;
+ int ret = -1;
+ dict_t *xattr = NULL;
+
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, sign, out);
+ GF_VALIDATE_OR_GOTO(this->name, fd, out);
+ GF_VALIDATE_OR_GOTO(this->name, child, out);
+ GF_VALIDATE_OR_GOTO(this->name, linked_inode, out);
+ GF_VALIDATE_OR_GOTO(this->name, md, out);
+ GF_VALIDATE_OR_GOTO(this->name, entry, out);
+
+ if (strncmp(sign->signature, (char *)md, strlen(sign->signature)) == 0) {
+ gf_msg_debug(this->name, 0,
+ "%s [GFID: %s | Brick: %s] "
+ "matches calculated checksum",
+ loc->path, uuid_utoa(linked_inode->gfid),
+ child->brick_path);
+ return 0;
+ }
+
+ gf_msg(this->name, GF_LOG_DEBUG, 0, BRB_MSG_CHECKSUM_MISMATCH,
+ "Object checksum mismatch: %s [GFID: %s | Brick: %s]", loc->path,
+ uuid_utoa(linked_inode->gfid), child->brick_path);
+ gf_msg(this->name, GF_LOG_ALERT, 0, BRB_MSG_CHECKSUM_MISMATCH,
+ "CORRUPTION DETECTED: Object %s {Brick: %s | GFID: %s}", loc->path,
+ child->brick_path, uuid_utoa(linked_inode->gfid));
+
+ /* Perform bad-file marking */
+ xattr = dict_new();
+ if (!xattr) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_set_int32(xattr, BITROT_OBJECT_BAD_KEY, _gf_true);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_MARK_BAD_FILE,
+ "Error setting bad-file marker for %s [GFID: %s | "
+ "Brick: %s]",
+ loc->path, uuid_utoa(linked_inode->gfid), child->brick_path);
+ goto dictfree;
+ }
+
+ gf_msg(this->name, GF_LOG_ALERT, 0, BRB_MSG_MARK_CORRUPTED,
+ "Marking"
+ " %s [GFID: %s | Brick: %s] as corrupted..",
+ loc->path, uuid_utoa(linked_inode->gfid), child->brick_path);
+ gf_event(EVENT_BITROT_BAD_FILE, "gfid=%s;path=%s;brick=%s",
+ uuid_utoa(linked_inode->gfid), loc->path, child->brick_path);
+ ret = syncop_fsetxattr(child->xl, fd, xattr, 0, NULL, NULL);
+ if (ret)
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_MARK_BAD_FILE,
+ "Error marking object %s [GFID: %s] as corrupted", loc->path,
+ uuid_utoa(linked_inode->gfid));
+
+dictfree:
+ dict_unref(xattr);
+out:
+ return ret;
}
/**
@@ -284,539 +280,552 @@ bitd_compare_ckum (xlator_t *this,
* signs with SHA256).
*/
int
-br_scrubber_scrub_begin (xlator_t *this, struct br_fsscan_entry *fsentry)
+br_scrubber_scrub_begin(xlator_t *this, struct br_fsscan_entry *fsentry)
{
- int32_t ret = -1;
- fd_t *fd = NULL;
- loc_t loc = {0, };
- struct iatt iatt = {0, };
- struct iatt parent_buf = {0, };
- pid_t pid = 0;
- br_child_t *child = NULL;
- unsigned char *md = NULL;
- inode_t *linked_inode = NULL;
- br_isignature_out_t *sign = NULL;
- unsigned long signedversion = 0;
- gf_dirent_t *entry = NULL;
- br_private_t *priv = NULL;
- loc_t *parent = NULL;
- gf_boolean_t skip_stat = _gf_false;
- uuid_t shard_root_gfid = {0,};
-
-
- GF_VALIDATE_OR_GOTO ("bit-rot", fsentry, out);
-
- entry = fsentry->entry;
- parent = &fsentry->parent;
- child = fsentry->data;
-
- priv = this->private;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", entry, out);
- GF_VALIDATE_OR_GOTO ("bit-rot", parent, out);
- GF_VALIDATE_OR_GOTO ("bit-rot", child, out);
- GF_VALIDATE_OR_GOTO ("bit-rot", priv, out);
-
- pid = GF_CLIENT_PID_SCRUB;
-
- ret = br_prepare_loc (this, child, parent, entry, &loc);
- if (!ret)
- goto out;
-
- syncopctx_setfspid (&pid);
-
- ret = syncop_lookup (child->xl, &loc, &iatt, &parent_buf, NULL, NULL);
- if (ret) {
- br_log_object_path (this, "lookup", loc.path, -ret);
- goto out;
- }
-
- linked_inode = inode_link (loc.inode, parent->inode, loc.name, &iatt);
- if (linked_inode)
- inode_lookup (linked_inode);
-
- gf_msg_debug (this->name, 0, "Scrubbing object %s [GFID: %s]",
- entry->d_name, uuid_utoa (linked_inode->gfid));
-
- if (iatt.ia_type != IA_IFREG) {
- gf_msg_debug (this->name, 0, "%s is not a regular file",
- entry->d_name);
- ret = 0;
- goto unref_inode;
- }
-
- if (IS_DHT_LINKFILE_MODE ((&iatt))) {
- gf_msg_debug (this->name, 0, "%s is a dht sticky bit file",
- entry->d_name);
- ret = 0;
- goto unref_inode;
- }
-
- /* skip updating scrub statistics for shard entries */
- gf_uuid_parse (SHARD_ROOT_GFID, shard_root_gfid);
- if (gf_uuid_compare (loc.pargfid, shard_root_gfid) == 0)
- skip_stat = _gf_true;
-
- /**
- * open() an fd for subsequent operations
- */
- fd = fd_create (linked_inode, 0);
- if (!fd) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_FD_CREATE_FAILED,
- "failed to create fd for inode %s",
- uuid_utoa (linked_inode->gfid));
- goto unref_inode;
- }
-
- ret = syncop_open (child->xl, &loc, O_RDWR, fd, NULL, NULL);
- if (ret) {
- br_log_object (this, "open", linked_inode->gfid, -ret);
- ret = -1;
- goto unrefd;
- }
-
- fd_bind (fd);
-
- /**
- * perform pre compute checks before initiating checksum
- * computation
- * - presence of bad object
- * - signature staleness
- */
- ret = bitd_scrub_pre_compute_check (this, child, fd, &signedversion,
- &priv->scrub_stat, skip_stat);
- if (ret)
- goto unrefd; /* skip this object */
-
- /* if all's good, proceed to calculate the hash */
- md = GF_MALLOC (SHA256_DIGEST_LENGTH, gf_common_mt_char);
- if (!md)
- goto unrefd;
-
- ret = br_calculate_obj_checksum (md, child, fd, &iatt);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_CALC_ERROR,
- "error calculating hash for object [GFID: %s]",
- uuid_utoa (fd->inode->gfid));
- ret = -1;
- goto free_md;
- }
-
- /**
- * perform post compute checks as an object's signature may have
- * become stale while scrubber calculated checksum.
- */
- ret = bitd_scrub_post_compute_check (this, child, fd, signedversion,
- &sign, &priv->scrub_stat,
- skip_stat);
- if (ret)
- goto free_md;
-
- ret = bitd_compare_ckum (this, sign, md,
- linked_inode, entry, fd, child, &loc);
-
- if (!skip_stat)
- br_inc_scrubbed_file (&priv->scrub_stat);
-
- GF_FREE (sign); /* allocated on post-compute */
-
- /** fd_unref() takes care of closing fd.. like syncop_close() */
+ int32_t ret = -1;
+ fd_t *fd = NULL;
+ loc_t loc = {
+ 0,
+ };
+ struct iatt iatt = {
+ 0,
+ };
+ struct iatt parent_buf = {
+ 0,
+ };
+ pid_t pid = 0;
+ br_child_t *child = NULL;
+ unsigned char *md = NULL;
+ inode_t *linked_inode = NULL;
+ br_isignature_out_t *sign = NULL;
+ unsigned long signedversion = 0;
+ gf_dirent_t *entry = NULL;
+ br_private_t *priv = NULL;
+ loc_t *parent = NULL;
+ gf_boolean_t skip_stat = _gf_false;
+ uuid_t shard_root_gfid = {
+ 0,
+ };
+
+ GF_VALIDATE_OR_GOTO("bit-rot", fsentry, out);
+
+ entry = fsentry->entry;
+ parent = &fsentry->parent;
+ child = fsentry->data;
+
+ priv = this->private;
+
+ GF_VALIDATE_OR_GOTO("bit-rot", entry, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", parent, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", child, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", priv, out);
+
+ pid = GF_CLIENT_PID_SCRUB;
+
+ ret = br_prepare_loc(this, child, parent, entry, &loc);
+ if (!ret)
+ goto out;
+
+ syncopctx_setfspid(&pid);
+
+ ret = syncop_lookup(child->xl, &loc, &iatt, &parent_buf, NULL, NULL);
+ if (ret) {
+ br_log_object_path(this, "lookup", loc.path, -ret);
+ goto out;
+ }
+
+ linked_inode = inode_link(loc.inode, parent->inode, loc.name, &iatt);
+ if (linked_inode)
+ inode_lookup(linked_inode);
+
+ gf_msg_debug(this->name, 0, "Scrubbing object %s [GFID: %s]", entry->d_name,
+ uuid_utoa(linked_inode->gfid));
+
+ if (iatt.ia_type != IA_IFREG) {
+ gf_msg_debug(this->name, 0, "%s is not a regular file", entry->d_name);
+ ret = 0;
+ goto unref_inode;
+ }
- free_md:
- GF_FREE (md);
- unrefd:
- fd_unref (fd);
- unref_inode:
- inode_unref (linked_inode);
- out:
- loc_wipe (&loc);
- return ret;
+ if (IS_DHT_LINKFILE_MODE((&iatt))) {
+ gf_msg_debug(this->name, 0, "%s is a dht sticky bit file",
+ entry->d_name);
+ ret = 0;
+ goto unref_inode;
+ }
+
+ /* skip updating scrub statistics for shard entries */
+ gf_uuid_parse(SHARD_ROOT_GFID, shard_root_gfid);
+ if (gf_uuid_compare(loc.pargfid, shard_root_gfid) == 0)
+ skip_stat = _gf_true;
+
+ /**
+ * open() an fd for subsequent operations
+ */
+ fd = fd_create(linked_inode, 0);
+ if (!fd) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_FD_CREATE_FAILED,
+ "failed to create fd for inode %s",
+ uuid_utoa(linked_inode->gfid));
+ goto unref_inode;
+ }
+
+ ret = syncop_open(child->xl, &loc, O_RDWR, fd, NULL, NULL);
+ if (ret) {
+ br_log_object(this, "open", linked_inode->gfid, -ret);
+ ret = -1;
+ goto unrefd;
+ }
+
+ fd_bind(fd);
+
+ /**
+ * perform pre compute checks before initiating checksum
+ * computation
+ * - presence of bad object
+ * - signature staleness
+ */
+ ret = bitd_scrub_pre_compute_check(this, child, fd, &signedversion,
+ &priv->scrub_stat, skip_stat);
+ if (ret)
+ goto unrefd; /* skip this object */
+
+ /* if all's good, proceed to calculate the hash */
+ md = GF_MALLOC(SHA256_DIGEST_LENGTH, gf_common_mt_char);
+ if (!md)
+ goto unrefd;
+
+ ret = br_calculate_obj_checksum(md, child, fd, &iatt);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_CALC_ERROR,
+ "error calculating hash for object [GFID: %s]",
+ uuid_utoa(fd->inode->gfid));
+ ret = -1;
+ goto free_md;
+ }
+
+ /**
+ * perform post compute checks as an object's signature may have
+ * become stale while scrubber calculated checksum.
+ */
+ ret = bitd_scrub_post_compute_check(this, child, fd, signedversion, &sign,
+ &priv->scrub_stat, skip_stat);
+ if (ret)
+ goto free_md;
+
+ ret = bitd_compare_ckum(this, sign, md, linked_inode, entry, fd, child,
+ &loc);
+
+ if (!skip_stat)
+ br_inc_scrubbed_file(&priv->scrub_stat);
+
+ GF_FREE(sign); /* allocated on post-compute */
+
+ /** fd_unref() takes care of closing fd.. like syncop_close() */
+
+free_md:
+ GF_FREE(md);
+unrefd:
+ fd_unref(fd);
+unref_inode:
+ inode_unref(linked_inode);
+out:
+ loc_wipe(&loc);
+ return ret;
}
static void
-_br_lock_cleaner (void *arg)
+_br_lock_cleaner(void *arg)
{
- pthread_mutex_t *mutex = arg;
+ pthread_mutex_t *mutex = arg;
- pthread_mutex_unlock (mutex);
+ pthread_mutex_unlock(mutex);
}
static void
-wait_for_scrubbing (xlator_t *this, struct br_scanfs *fsscan)
+wait_for_scrubbing(xlator_t *this, struct br_scanfs *fsscan)
{
- br_private_t *priv = NULL;
- struct br_scrubber *fsscrub = NULL;
+ br_private_t *priv = NULL;
+ struct br_scrubber *fsscrub = NULL;
- priv = this->private;
- fsscrub = &priv->fsscrub;
+ priv = this->private;
+ fsscrub = &priv->fsscrub;
- pthread_cleanup_push (_br_lock_cleaner, &fsscan->waitlock);
- pthread_mutex_lock (&fsscan->waitlock);
+ pthread_cleanup_push(_br_lock_cleaner, &fsscan->waitlock);
+ pthread_mutex_lock(&fsscan->waitlock);
+ {
+ pthread_cleanup_push(_br_lock_cleaner, &fsscrub->mutex);
+ pthread_mutex_lock(&fsscrub->mutex);
{
- pthread_cleanup_push (_br_lock_cleaner, &fsscrub->mutex);
- pthread_mutex_lock (&fsscrub->mutex);
- {
- list_replace_init (&fsscan->queued, &fsscan->ready);
-
- /* wake up scrubbers */
- pthread_cond_broadcast (&fsscrub->cond);
- }
- pthread_mutex_unlock (&fsscrub->mutex);
- pthread_cleanup_pop (0);
-
- while (fsscan->entries != 0)
- pthread_cond_wait
- (&fsscan->waitcond, &fsscan->waitlock);
+ list_replace_init(&fsscan->queued, &fsscan->ready);
+
+ /* wake up scrubbers */
+ pthread_cond_broadcast(&fsscrub->cond);
}
- pthread_mutex_unlock (&fsscan->waitlock);
- pthread_cleanup_pop (0);
+ pthread_mutex_unlock(&fsscrub->mutex);
+ pthread_cleanup_pop(0);
+
+ while (fsscan->entries != 0)
+ pthread_cond_wait(&fsscan->waitcond, &fsscan->waitlock);
+ }
+ pthread_mutex_unlock(&fsscan->waitlock);
+ pthread_cleanup_pop(0);
}
static void
-_br_fsscan_inc_entry_count (struct br_scanfs *fsscan)
+_br_fsscan_inc_entry_count(struct br_scanfs *fsscan)
{
- fsscan->entries++;
+ fsscan->entries++;
}
static void
-_br_fsscan_dec_entry_count (struct br_scanfs *fsscan)
+_br_fsscan_dec_entry_count(struct br_scanfs *fsscan)
{
- if (--fsscan->entries == 0) {
- pthread_mutex_lock (&fsscan->waitlock);
- {
- pthread_cond_signal (&fsscan->waitcond);
- }
- pthread_mutex_unlock (&fsscan->waitlock);
+ if (--fsscan->entries == 0) {
+ pthread_mutex_lock(&fsscan->waitlock);
+ {
+ pthread_cond_signal(&fsscan->waitcond);
}
+ pthread_mutex_unlock(&fsscan->waitlock);
+ }
}
static void
-_br_fsscan_collect_entry (struct br_scanfs *fsscan,
- struct br_fsscan_entry *fsentry)
+_br_fsscan_collect_entry(struct br_scanfs *fsscan,
+ struct br_fsscan_entry *fsentry)
{
- list_add_tail (&fsentry->list, &fsscan->queued);
- _br_fsscan_inc_entry_count (fsscan);
+ list_add_tail(&fsentry->list, &fsscan->queued);
+ _br_fsscan_inc_entry_count(fsscan);
}
-#define NR_ENTRIES (1<<7) /* ..bulk scrubbing */
+#define NR_ENTRIES (1 << 7) /* ..bulk scrubbing */
int
-br_fsscanner_handle_entry (xlator_t *subvol,
- gf_dirent_t *entry, loc_t *parent, void *data)
+br_fsscanner_handle_entry(xlator_t *subvol, gf_dirent_t *entry, loc_t *parent,
+ void *data)
{
- int32_t ret = -1;
- int scrub = 0;
- br_child_t *child = NULL;
- xlator_t *this = NULL;
- struct br_scanfs *fsscan = NULL;
- struct br_fsscan_entry *fsentry = NULL;
+ int32_t ret = -1;
+ int scrub = 0;
+ br_child_t *child = NULL;
+ xlator_t *this = NULL;
+ struct br_scanfs *fsscan = NULL;
+ struct br_fsscan_entry *fsentry = NULL;
- GF_VALIDATE_OR_GOTO ("bit-rot", subvol, error_return);
- GF_VALIDATE_OR_GOTO ("bit-rot", data, error_return);
+ GF_VALIDATE_OR_GOTO("bit-rot", subvol, error_return);
+ GF_VALIDATE_OR_GOTO("bit-rot", data, error_return);
- child = data;
- this = child->this;
- fsscan = &child->fsscan;
+ child = data;
+ this = child->this;
+ fsscan = &child->fsscan;
- _mask_cancellation ();
+ _mask_cancellation();
- fsentry = GF_CALLOC (1, sizeof (*fsentry), gf_br_mt_br_fsscan_entry_t);
- if (!fsentry)
- goto error_return;
+ fsentry = GF_CALLOC(1, sizeof(*fsentry), gf_br_mt_br_fsscan_entry_t);
+ if (!fsentry)
+ goto error_return;
- {
- fsentry->data = data;
- fsentry->fsscan = &child->fsscan;
+ {
+ fsentry->data = data;
+ fsentry->fsscan = &child->fsscan;
- /* copy parent loc */
- ret = loc_copy (&fsentry->parent, parent);
- if (ret)
- goto dealloc;
+ /* copy parent loc */
+ ret = loc_copy(&fsentry->parent, parent);
+ if (ret)
+ goto dealloc;
- /* copy child entry */
- fsentry->entry = entry_copy (entry);
- if (!fsentry->entry)
- goto locwipe;
+ /* copy child entry */
+ fsentry->entry = entry_copy(entry);
+ if (!fsentry->entry)
+ goto locwipe;
- INIT_LIST_HEAD (&fsentry->list);
- }
+ INIT_LIST_HEAD(&fsentry->list);
+ }
- LOCK (&fsscan->entrylock);
- {
- _br_fsscan_collect_entry (fsscan, fsentry);
-
- /**
- * need not be a equality check as entries may be pushed
- * back onto the scanned queue when thread(s) are cleaned.
- */
- if (fsscan->entries >= NR_ENTRIES)
- scrub = 1;
- }
- UNLOCK (&fsscan->entrylock);
+ LOCK(&fsscan->entrylock);
+ {
+ _br_fsscan_collect_entry(fsscan, fsentry);
- _unmask_cancellation ();
+ /**
+ * need not be a equality check as entries may be pushed
+ * back onto the scanned queue when thread(s) are cleaned.
+ */
+ if (fsscan->entries >= NR_ENTRIES)
+ scrub = 1;
+ }
+ UNLOCK(&fsscan->entrylock);
- if (scrub)
- wait_for_scrubbing (this, fsscan);
+ _unmask_cancellation();
- return 0;
+ if (scrub)
+ wait_for_scrubbing(this, fsscan);
- locwipe:
- loc_wipe (&fsentry->parent);
- dealloc:
- GF_FREE (fsentry);
- error_return:
- return -1;
+ return 0;
+
+locwipe:
+ loc_wipe(&fsentry->parent);
+dealloc:
+ GF_FREE(fsentry);
+error_return:
+ return -1;
}
int32_t
-br_fsscan_deactivate (xlator_t *this)
+br_fsscan_deactivate(xlator_t *this)
{
- int ret = 0;
- br_private_t *priv = NULL;
- br_scrub_state_t nstate = 0;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
-
- ret = gf_tw_del_timer (priv->timer_wheel, scrub_monitor->timer);
- if (ret == 0) {
- nstate = BR_SCRUB_STATE_STALLED;
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
- "Volume is under active scrubbing. Pausing scrub..");
- } else {
- nstate = BR_SCRUB_STATE_PAUSED;
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
- "Scrubber paused");
- }
-
- _br_monitor_set_scrub_state (scrub_monitor, nstate);
-
- return 0;
+ int ret = 0;
+ br_private_t *priv = NULL;
+ br_scrub_state_t nstate = 0;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
+
+ ret = gf_tw_del_timer(priv->timer_wheel, scrub_monitor->timer);
+ if (ret == 0) {
+ nstate = BR_SCRUB_STATE_STALLED;
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
+ "Volume is under active scrubbing. Pausing scrub..");
+ } else {
+ nstate = BR_SCRUB_STATE_PAUSED;
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
+ "Scrubber paused");
+ }
+
+ _br_monitor_set_scrub_state(scrub_monitor, nstate);
+
+ return 0;
}
static void
-br_scrubber_log_time (xlator_t *this, const char *sfx)
+br_scrubber_log_time(xlator_t *this, const char *sfx)
{
- char timestr[1024] = {0,};
- struct timeval tv = {0,};
- br_private_t *priv = NULL;
-
- priv = this->private;
-
- gettimeofday (&tv, NULL);
- gf_time_fmt (timestr, sizeof (timestr), tv.tv_sec, gf_timefmt_FT);
-
- if (strcasecmp (sfx, "started") == 0) {
- br_update_scrub_start_time (&priv->scrub_stat, &tv);
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_START,
- "Scrubbing %s at %s", sfx, timestr);
- } else {
- br_update_scrub_finish_time (&priv->scrub_stat, timestr, &tv);
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_FINISH,
- "Scrubbing %s at %s", sfx, timestr);
- }
+ char timestr[1024] = {
+ 0,
+ };
+ struct timeval tv = {
+ 0,
+ };
+ br_private_t *priv = NULL;
+
+ priv = this->private;
+
+ gettimeofday(&tv, NULL);
+ gf_time_fmt(timestr, sizeof(timestr), tv.tv_sec, gf_timefmt_FT);
+
+ if (strcasecmp(sfx, "started") == 0) {
+ br_update_scrub_start_time(&priv->scrub_stat, &tv);
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_START,
+ "Scrubbing %s at %s", sfx, timestr);
+ } else {
+ br_update_scrub_finish_time(&priv->scrub_stat, timestr, &tv);
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_FINISH,
+ "Scrubbing %s at %s", sfx, timestr);
+ }
}
static void
-br_fsscanner_log_time (xlator_t *this, br_child_t *child, const char *sfx)
+br_fsscanner_log_time(xlator_t *this, br_child_t *child, const char *sfx)
{
- char timestr[1024] = {0,};
- struct timeval tv = {0,};
-
- gettimeofday (&tv, NULL);
- gf_time_fmt (timestr, sizeof (timestr), tv.tv_sec, gf_timefmt_FT);
-
- if (strcasecmp (sfx, "started") == 0) {
- gf_msg_debug (this->name, 0, "Scrubbing \"%s\" %s at %s",
- child->brick_path, sfx, timestr);
- } else {
- gf_msg_debug (this->name, 0, "Scrubbing \"%s\" %s at %s",
- child->brick_path, sfx, timestr);
- }
+ char timestr[1024] = {
+ 0,
+ };
+ struct timeval tv = {
+ 0,
+ };
+
+ gettimeofday(&tv, NULL);
+ gf_time_fmt(timestr, sizeof(timestr), tv.tv_sec, gf_timefmt_FT);
+
+ if (strcasecmp(sfx, "started") == 0) {
+ gf_msg_debug(this->name, 0, "Scrubbing \"%s\" %s at %s",
+ child->brick_path, sfx, timestr);
+ } else {
+ gf_msg_debug(this->name, 0, "Scrubbing \"%s\" %s at %s",
+ child->brick_path, sfx, timestr);
+ }
}
void
-br_child_set_scrub_state (br_child_t *child, gf_boolean_t state)
+br_child_set_scrub_state(br_child_t *child, gf_boolean_t state)
{
- child->active_scrubbing = state;
+ child->active_scrubbing = state;
}
static void
-br_fsscanner_wait_until_kicked (xlator_t *this, br_child_t *child)
+br_fsscanner_wait_until_kicked(xlator_t *this, br_child_t *child)
{
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
-
- pthread_cleanup_push (_br_lock_cleaner, &scrub_monitor->wakelock);
- pthread_mutex_lock (&scrub_monitor->wakelock);
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
+
+ pthread_cleanup_push(_br_lock_cleaner, &scrub_monitor->wakelock);
+ pthread_mutex_lock(&scrub_monitor->wakelock);
+ {
+ while (!scrub_monitor->kick)
+ pthread_cond_wait(&scrub_monitor->wakecond,
+ &scrub_monitor->wakelock);
+
+ /* Child lock is to synchronize with disconnect events */
+ pthread_cleanup_push(_br_lock_cleaner, &child->lock);
+ pthread_mutex_lock(&child->lock);
{
- while (!scrub_monitor->kick)
- pthread_cond_wait (&scrub_monitor->wakecond,
- &scrub_monitor->wakelock);
-
- /* Child lock is to synchronize with disconnect events */
- pthread_cleanup_push (_br_lock_cleaner, &child->lock);
- pthread_mutex_lock (&child->lock);
- {
- scrub_monitor->active_child_count++;
- br_child_set_scrub_state (child, _gf_true);
- }
- pthread_mutex_unlock (&child->lock);
- pthread_cleanup_pop (0);
- }
- pthread_mutex_unlock (&scrub_monitor->wakelock);
- pthread_cleanup_pop (0);
+ scrub_monitor->active_child_count++;
+ br_child_set_scrub_state(child, _gf_true);
+ }
+ pthread_mutex_unlock(&child->lock);
+ pthread_cleanup_pop(0);
+ }
+ pthread_mutex_unlock(&scrub_monitor->wakelock);
+ pthread_cleanup_pop(0);
}
static void
-br_scrubber_entry_control (xlator_t *this)
+br_scrubber_entry_control(xlator_t *this)
{
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
-
- LOCK (&scrub_monitor->lock);
- {
- /* Move the state to BR_SCRUB_STATE_ACTIVE */
- if (scrub_monitor->state == BR_SCRUB_STATE_PENDING)
- scrub_monitor->state = BR_SCRUB_STATE_ACTIVE;
- br_scrubber_log_time (this, "started");
- priv->scrub_stat.scrub_running = 1;
- }
- UNLOCK (&scrub_monitor->lock);
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
+
+ LOCK(&scrub_monitor->lock);
+ {
+ /* Move the state to BR_SCRUB_STATE_ACTIVE */
+ if (scrub_monitor->state == BR_SCRUB_STATE_PENDING)
+ scrub_monitor->state = BR_SCRUB_STATE_ACTIVE;
+ br_scrubber_log_time(this, "started");
+ priv->scrub_stat.scrub_running = 1;
+ }
+ UNLOCK(&scrub_monitor->lock);
}
static void
-br_scrubber_exit_control (xlator_t *this)
+br_scrubber_exit_control(xlator_t *this)
{
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
- LOCK (&scrub_monitor->lock);
- {
- br_scrubber_log_time (this, "finished");
- priv->scrub_stat.scrub_running = 0;
-
- if (scrub_monitor->state == BR_SCRUB_STATE_ACTIVE) {
- (void) br_fsscan_activate (this);
- } else {
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
- "Volume waiting to get rescheduled..");
- }
+ LOCK(&scrub_monitor->lock);
+ {
+ br_scrubber_log_time(this, "finished");
+ priv->scrub_stat.scrub_running = 0;
+
+ if (scrub_monitor->state == BR_SCRUB_STATE_ACTIVE) {
+ (void)br_fsscan_activate(this);
+ } else {
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
+ "Volume waiting to get rescheduled..");
}
- UNLOCK (&scrub_monitor->lock);
+ }
+ UNLOCK(&scrub_monitor->lock);
}
static void
-br_fsscanner_entry_control (xlator_t *this, br_child_t *child)
+br_fsscanner_entry_control(xlator_t *this, br_child_t *child)
{
- br_fsscanner_log_time (this, child, "started");
+ br_fsscanner_log_time(this, child, "started");
}
static void
-br_fsscanner_exit_control (xlator_t *this, br_child_t *child)
+br_fsscanner_exit_control(xlator_t *this, br_child_t *child)
{
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
-
- if (!_br_is_child_connected (child)) {
- gf_msg (this->name, GF_LOG_WARNING, 0, BRB_MSG_SCRUB_INFO,
- "Brick [%s] disconnected while scrubbing. Scrubbing "
- "might be incomplete", child->brick_path);
- }
-
- br_fsscanner_log_time (this, child, "finished");
-
- pthread_cleanup_push (_br_lock_cleaner, &scrub_monitor->wakelock);
- pthread_mutex_lock (&scrub_monitor->wakelock);
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
+
+ if (!_br_is_child_connected(child)) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRB_MSG_SCRUB_INFO,
+ "Brick [%s] disconnected while scrubbing. Scrubbing "
+ "might be incomplete",
+ child->brick_path);
+ }
+
+ br_fsscanner_log_time(this, child, "finished");
+
+ pthread_cleanup_push(_br_lock_cleaner, &scrub_monitor->wakelock);
+ pthread_mutex_lock(&scrub_monitor->wakelock);
+ {
+ scrub_monitor->active_child_count--;
+ pthread_cleanup_push(_br_lock_cleaner, &child->lock);
+ pthread_mutex_lock(&child->lock);
{
- scrub_monitor->active_child_count--;
- pthread_cleanup_push (_br_lock_cleaner, &child->lock);
- pthread_mutex_lock (&child->lock);
- {
- br_child_set_scrub_state (child, _gf_false);
- }
- pthread_mutex_unlock (&child->lock);
- pthread_cleanup_pop (0);
-
- if (scrub_monitor->active_child_count == 0) {
- /* The last child has finished scrubbing.
- * Set the kick to false and wake up other
- * children who are waiting for the last
- * child to complete scrubbing.
- */
- scrub_monitor->kick = _gf_false;
- pthread_cond_broadcast (&scrub_monitor->wakecond);
-
- /* Signal monitor thread waiting for the all
- * the children to finish scrubbing.
- */
- pthread_cleanup_push (_br_lock_cleaner,
- &scrub_monitor->donelock);
- pthread_mutex_lock (&scrub_monitor->donelock);
- {
- scrub_monitor->done = _gf_true;
- pthread_cond_signal (&scrub_monitor->donecond);
- }
- pthread_mutex_unlock (&scrub_monitor->donelock);
- pthread_cleanup_pop (0);
- } else {
- while (scrub_monitor->active_child_count)
- pthread_cond_wait (&scrub_monitor->wakecond,
- &scrub_monitor->wakelock);
- }
+ br_child_set_scrub_state(child, _gf_false);
+ }
+ pthread_mutex_unlock(&child->lock);
+ pthread_cleanup_pop(0);
+
+ if (scrub_monitor->active_child_count == 0) {
+ /* The last child has finished scrubbing.
+ * Set the kick to false and wake up other
+ * children who are waiting for the last
+ * child to complete scrubbing.
+ */
+ scrub_monitor->kick = _gf_false;
+ pthread_cond_broadcast(&scrub_monitor->wakecond);
+
+ /* Signal monitor thread waiting for the all
+ * the children to finish scrubbing.
+ */
+ pthread_cleanup_push(_br_lock_cleaner, &scrub_monitor->donelock);
+ pthread_mutex_lock(&scrub_monitor->donelock);
+ {
+ scrub_monitor->done = _gf_true;
+ pthread_cond_signal(&scrub_monitor->donecond);
+ }
+ pthread_mutex_unlock(&scrub_monitor->donelock);
+ pthread_cleanup_pop(0);
+ } else {
+ while (scrub_monitor->active_child_count)
+ pthread_cond_wait(&scrub_monitor->wakecond,
+ &scrub_monitor->wakelock);
}
- pthread_mutex_unlock (&scrub_monitor->wakelock);
- pthread_cleanup_pop (0);
+ }
+ pthread_mutex_unlock(&scrub_monitor->wakelock);
+ pthread_cleanup_pop(0);
}
void *
-br_fsscanner (void *arg)
+br_fsscanner(void *arg)
{
- loc_t loc = {0,};
- br_child_t *child = NULL;
- xlator_t *this = NULL;
- struct br_scanfs *fsscan = NULL;
-
- child = arg;
- this = child->this;
- fsscan = &child->fsscan;
-
- THIS = this;
- loc.inode = child->table->root;
-
- while (1) {
- br_fsscanner_wait_until_kicked (this, child);
- {
- /* precursor for scrub */
- br_fsscanner_entry_control (this, child);
-
- /* scrub */
- (void) syncop_ftw (child->xl,
- &loc, GF_CLIENT_PID_SCRUB,
- child, br_fsscanner_handle_entry);
- if (!list_empty (&fsscan->queued))
- wait_for_scrubbing (this, fsscan);
-
- /* scrub exit criteria */
- br_fsscanner_exit_control (this, child);
- }
+ loc_t loc = {
+ 0,
+ };
+ br_child_t *child = NULL;
+ xlator_t *this = NULL;
+ struct br_scanfs *fsscan = NULL;
+
+ child = arg;
+ this = child->this;
+ fsscan = &child->fsscan;
+
+ THIS = this;
+ loc.inode = child->table->root;
+
+ while (1) {
+ br_fsscanner_wait_until_kicked(this, child);
+ {
+ /* precursor for scrub */
+ br_fsscanner_entry_control(this, child);
+
+ /* scrub */
+ (void)syncop_ftw(child->xl, &loc, GF_CLIENT_PID_SCRUB, child,
+ br_fsscanner_handle_entry);
+ if (!list_empty(&fsscan->queued))
+ wait_for_scrubbing(this, fsscan);
+
+ /* scrub exit criteria */
+ br_fsscanner_exit_control(this, child);
}
+ }
- return NULL;
+ return NULL;
}
/**
@@ -827,263 +836,280 @@ br_fsscanner (void *arg)
* non-pending timer.
*/
void
-br_kickstart_scanner (struct gf_tw_timer_list *timer,
- void *data, unsigned long calltime)
+br_kickstart_scanner(struct gf_tw_timer_list *timer, void *data,
+ unsigned long calltime)
{
- xlator_t *this = NULL;
- struct br_monitor *scrub_monitor = data;
- br_private_t *priv = NULL;
-
- THIS = this = scrub_monitor->this;
- priv = this->private;
-
- /* Reset scrub statistics */
- priv->scrub_stat.scrubbed_files = 0;
- priv->scrub_stat.unsigned_files = 0;
-
- /* Moves state from PENDING to ACTIVE */
- (void) br_scrubber_entry_control (this);
-
- /* kickstart scanning.. */
- pthread_mutex_lock (&scrub_monitor->wakelock);
- {
- scrub_monitor->kick = _gf_true;
- GF_ASSERT (scrub_monitor->active_child_count == 0);
- pthread_cond_broadcast (&scrub_monitor->wakecond);
- }
- pthread_mutex_unlock (&scrub_monitor->wakelock);
-
- return;
+ xlator_t *this = NULL;
+ struct br_monitor *scrub_monitor = data;
+ br_private_t *priv = NULL;
+
+ THIS = this = scrub_monitor->this;
+ priv = this->private;
+
+ /* Reset scrub statistics */
+ priv->scrub_stat.scrubbed_files = 0;
+ priv->scrub_stat.unsigned_files = 0;
+
+ /* Moves state from PENDING to ACTIVE */
+ (void)br_scrubber_entry_control(this);
+
+ /* kickstart scanning.. */
+ pthread_mutex_lock(&scrub_monitor->wakelock);
+ {
+ scrub_monitor->kick = _gf_true;
+ GF_ASSERT(scrub_monitor->active_child_count == 0);
+ pthread_cond_broadcast(&scrub_monitor->wakecond);
+ }
+ pthread_mutex_unlock(&scrub_monitor->wakelock);
+
+ return;
}
static uint32_t
-br_fsscan_calculate_delta (uint32_t times)
+br_fsscan_calculate_delta(uint32_t times)
{
- return times;
+ return times;
}
-#define BR_SCRUB_ONDEMAND (1)
-#define BR_SCRUB_MINUTE (60)
-#define BR_SCRUB_HOURLY (60 * 60)
-#define BR_SCRUB_DAILY (1 * 24 * 60 * 60)
-#define BR_SCRUB_WEEKLY (7 * 24 * 60 * 60)
-#define BR_SCRUB_BIWEEKLY (14 * 24 * 60 * 60)
-#define BR_SCRUB_MONTHLY (30 * 24 * 60 * 60)
+#define BR_SCRUB_ONDEMAND (1)
+#define BR_SCRUB_MINUTE (60)
+#define BR_SCRUB_HOURLY (60 * 60)
+#define BR_SCRUB_DAILY (1 * 24 * 60 * 60)
+#define BR_SCRUB_WEEKLY (7 * 24 * 60 * 60)
+#define BR_SCRUB_BIWEEKLY (14 * 24 * 60 * 60)
+#define BR_SCRUB_MONTHLY (30 * 24 * 60 * 60)
static unsigned int
-br_fsscan_calculate_timeout (scrub_freq_t freq)
+br_fsscan_calculate_timeout(scrub_freq_t freq)
{
- uint32_t timo = 0;
+ uint32_t timo = 0;
- switch (freq) {
+ switch (freq) {
case BR_FSSCRUB_FREQ_MINUTE:
- timo = br_fsscan_calculate_delta (BR_SCRUB_MINUTE);
- break;
+ timo = br_fsscan_calculate_delta(BR_SCRUB_MINUTE);
+ break;
case BR_FSSCRUB_FREQ_HOURLY:
- timo = br_fsscan_calculate_delta (BR_SCRUB_HOURLY);
- break;
+ timo = br_fsscan_calculate_delta(BR_SCRUB_HOURLY);
+ break;
case BR_FSSCRUB_FREQ_DAILY:
- timo = br_fsscan_calculate_delta (BR_SCRUB_DAILY);
- break;
+ timo = br_fsscan_calculate_delta(BR_SCRUB_DAILY);
+ break;
case BR_FSSCRUB_FREQ_WEEKLY:
- timo = br_fsscan_calculate_delta (BR_SCRUB_WEEKLY);
- break;
+ timo = br_fsscan_calculate_delta(BR_SCRUB_WEEKLY);
+ break;
case BR_FSSCRUB_FREQ_BIWEEKLY:
- timo = br_fsscan_calculate_delta (BR_SCRUB_BIWEEKLY);
- break;
+ timo = br_fsscan_calculate_delta(BR_SCRUB_BIWEEKLY);
+ break;
case BR_FSSCRUB_FREQ_MONTHLY:
- timo = br_fsscan_calculate_delta (BR_SCRUB_MONTHLY);
- break;
+ timo = br_fsscan_calculate_delta(BR_SCRUB_MONTHLY);
+ break;
default:
- timo = 0;
- }
+ timo = 0;
+ }
- return timo;
+ return timo;
}
int32_t
-br_fsscan_schedule (xlator_t *this)
+br_fsscan_schedule(xlator_t *this)
{
- uint32_t timo = 0;
- br_private_t *priv = NULL;
- struct timeval tv = {0,};
- char timestr[1024] = {0,};
- struct br_scrubber *fsscrub = NULL;
- struct gf_tw_timer_list *timer = NULL;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
- fsscrub = &priv->fsscrub;
- scrub_monitor = &priv->scrub_monitor;
-
- (void) gettimeofday (&tv, NULL);
- scrub_monitor->boot = tv.tv_sec;
-
- timo = br_fsscan_calculate_timeout (fsscrub->frequency);
- if (timo == 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_ZERO_TIMEOUT_BUG,
- "BUG: Zero schedule timeout");
- goto error_return;
- }
-
- scrub_monitor->timer = GF_CALLOC (1, sizeof (*scrub_monitor->timer),
- gf_br_stub_mt_br_scanner_freq_t);
- if (!scrub_monitor->timer)
- goto error_return;
-
- timer = scrub_monitor->timer;
- INIT_LIST_HEAD (&timer->entry);
-
- timer->data = scrub_monitor;
- timer->expires = timo;
- timer->function = br_kickstart_scanner;
-
- gf_tw_add_timer (priv->timer_wheel, timer);
- _br_monitor_set_scrub_state (scrub_monitor, BR_SCRUB_STATE_PENDING);
-
- gf_time_fmt (timestr, sizeof (timestr),
- (scrub_monitor->boot + timo), gf_timefmt_FT);
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO, "Scrubbing is "
- "scheduled to run at %s", timestr);
-
- return 0;
-
- error_return:
- return -1;
+ uint32_t timo = 0;
+ br_private_t *priv = NULL;
+ struct timeval tv = {
+ 0,
+ };
+ char timestr[1024] = {
+ 0,
+ };
+ struct br_scrubber *fsscrub = NULL;
+ struct gf_tw_timer_list *timer = NULL;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+ fsscrub = &priv->fsscrub;
+ scrub_monitor = &priv->scrub_monitor;
+
+ (void)gettimeofday(&tv, NULL);
+ scrub_monitor->boot = tv.tv_sec;
+
+ timo = br_fsscan_calculate_timeout(fsscrub->frequency);
+ if (timo == 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_ZERO_TIMEOUT_BUG,
+ "BUG: Zero schedule timeout");
+ goto error_return;
+ }
+
+ scrub_monitor->timer = GF_CALLOC(1, sizeof(*scrub_monitor->timer),
+ gf_br_stub_mt_br_scanner_freq_t);
+ if (!scrub_monitor->timer)
+ goto error_return;
+
+ timer = scrub_monitor->timer;
+ INIT_LIST_HEAD(&timer->entry);
+
+ timer->data = scrub_monitor;
+ timer->expires = timo;
+ timer->function = br_kickstart_scanner;
+
+ gf_tw_add_timer(priv->timer_wheel, timer);
+ _br_monitor_set_scrub_state(scrub_monitor, BR_SCRUB_STATE_PENDING);
+
+ gf_time_fmt(timestr, sizeof(timestr), (scrub_monitor->boot + timo),
+ gf_timefmt_FT);
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
+ "Scrubbing is "
+ "scheduled to run at %s",
+ timestr);
+
+ return 0;
+
+error_return:
+ return -1;
}
int32_t
-br_fsscan_activate (xlator_t *this)
+br_fsscan_activate(xlator_t *this)
{
- uint32_t timo = 0;
- char timestr[1024] = {0,};
- struct timeval now = {0,};
- br_private_t *priv = NULL;
- struct br_scrubber *fsscrub = NULL;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
- fsscrub = &priv->fsscrub;
- scrub_monitor = &priv->scrub_monitor;
-
- (void) gettimeofday (&now, NULL);
- timo = br_fsscan_calculate_timeout (fsscrub->frequency);
- if (timo == 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_ZERO_TIMEOUT_BUG,
- "BUG: Zero schedule timeout");
- return -1;
- }
+ uint32_t timo = 0;
+ char timestr[1024] = {
+ 0,
+ };
+ struct timeval now = {
+ 0,
+ };
+ br_private_t *priv = NULL;
+ struct br_scrubber *fsscrub = NULL;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+ fsscrub = &priv->fsscrub;
+ scrub_monitor = &priv->scrub_monitor;
+
+ (void)gettimeofday(&now, NULL);
+ timo = br_fsscan_calculate_timeout(fsscrub->frequency);
+ if (timo == 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_ZERO_TIMEOUT_BUG,
+ "BUG: Zero schedule timeout");
+ return -1;
+ }
- pthread_mutex_lock (&scrub_monitor->donelock);
- {
- scrub_monitor->done = _gf_false;
- }
- pthread_mutex_unlock (&scrub_monitor->donelock);
+ pthread_mutex_lock(&scrub_monitor->donelock);
+ {
+ scrub_monitor->done = _gf_false;
+ }
+ pthread_mutex_unlock(&scrub_monitor->donelock);
- gf_time_fmt (timestr, sizeof (timestr),
- (now.tv_sec + timo), gf_timefmt_FT);
- (void) gf_tw_mod_timer (priv->timer_wheel, scrub_monitor->timer, timo);
+ gf_time_fmt(timestr, sizeof(timestr), (now.tv_sec + timo), gf_timefmt_FT);
+ (void)gf_tw_mod_timer(priv->timer_wheel, scrub_monitor->timer, timo);
- _br_monitor_set_scrub_state (scrub_monitor, BR_SCRUB_STATE_PENDING);
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO, "Scrubbing is "
- "rescheduled to run at %s", timestr);
+ _br_monitor_set_scrub_state(scrub_monitor, BR_SCRUB_STATE_PENDING);
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
+ "Scrubbing is "
+ "rescheduled to run at %s",
+ timestr);
- return 0;
+ return 0;
}
int32_t
-br_fsscan_reschedule (xlator_t *this)
+br_fsscan_reschedule(xlator_t *this)
{
- int32_t ret = 0;
- uint32_t timo = 0;
- char timestr[1024] = {0,};
- struct timeval now = {0,};
- br_private_t *priv = NULL;
- struct br_scrubber *fsscrub = NULL;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
- fsscrub = &priv->fsscrub;
- scrub_monitor = &priv->scrub_monitor;
-
- if (!fsscrub->frequency_reconf)
- return 0;
-
- (void) gettimeofday (&now, NULL);
- timo = br_fsscan_calculate_timeout (fsscrub->frequency);
- if (timo == 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_ZERO_TIMEOUT_BUG,
- "BUG: Zero schedule timeout");
- return -1;
- }
+ int32_t ret = 0;
+ uint32_t timo = 0;
+ char timestr[1024] = {
+ 0,
+ };
+ struct timeval now = {
+ 0,
+ };
+ br_private_t *priv = NULL;
+ struct br_scrubber *fsscrub = NULL;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+ fsscrub = &priv->fsscrub;
+ scrub_monitor = &priv->scrub_monitor;
+
+ if (!fsscrub->frequency_reconf)
+ return 0;
- gf_time_fmt (timestr, sizeof (timestr),
- (now.tv_sec + timo), gf_timefmt_FT);
+ (void)gettimeofday(&now, NULL);
+ timo = br_fsscan_calculate_timeout(fsscrub->frequency);
+ if (timo == 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_ZERO_TIMEOUT_BUG,
+ "BUG: Zero schedule timeout");
+ return -1;
+ }
- pthread_mutex_lock (&scrub_monitor->donelock);
- {
- scrub_monitor->done = _gf_false;
- }
- pthread_mutex_unlock (&scrub_monitor->donelock);
-
- ret = gf_tw_mod_timer_pending (priv->timer_wheel, scrub_monitor->timer, timo);
- if (ret == 0)
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
- "Scrubber is currently running and would be "
- "rescheduled after completion");
- else {
- _br_monitor_set_scrub_state (scrub_monitor, BR_SCRUB_STATE_PENDING);
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
- "Scrubbing rescheduled to run at %s", timestr);
- }
+ gf_time_fmt(timestr, sizeof(timestr), (now.tv_sec + timo), gf_timefmt_FT);
- return 0;
+ pthread_mutex_lock(&scrub_monitor->donelock);
+ {
+ scrub_monitor->done = _gf_false;
+ }
+ pthread_mutex_unlock(&scrub_monitor->donelock);
+
+ ret = gf_tw_mod_timer_pending(priv->timer_wheel, scrub_monitor->timer,
+ timo);
+ if (ret == 0)
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
+ "Scrubber is currently running and would be "
+ "rescheduled after completion");
+ else {
+ _br_monitor_set_scrub_state(scrub_monitor, BR_SCRUB_STATE_PENDING);
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
+ "Scrubbing rescheduled to run at %s", timestr);
+ }
+
+ return 0;
}
int32_t
-br_fsscan_ondemand (xlator_t *this)
+br_fsscan_ondemand(xlator_t *this)
{
- int32_t ret = 0;
- uint32_t timo = 0;
- char timestr[1024] = {0,};
- struct timeval now = {0,};
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
+ int32_t ret = 0;
+ uint32_t timo = 0;
+ char timestr[1024] = {
+ 0,
+ };
+ struct timeval now = {
+ 0,
+ };
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
- (void) gettimeofday (&now, NULL);
+ (void)gettimeofday(&now, NULL);
- timo = BR_SCRUB_ONDEMAND;
+ timo = BR_SCRUB_ONDEMAND;
- gf_time_fmt (timestr, sizeof (timestr),
- (now.tv_sec + timo), gf_timefmt_FT);
-
- pthread_mutex_lock (&scrub_monitor->donelock);
- {
- scrub_monitor->done = _gf_false;
- }
- pthread_mutex_unlock (&scrub_monitor->donelock);
-
- ret = gf_tw_mod_timer_pending (priv->timer_wheel, scrub_monitor->timer,
- timo);
- if (ret == 0)
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
- "Scrubber is currently running and would be "
- "rescheduled after completion");
- else {
- _br_monitor_set_scrub_state (scrub_monitor,
- BR_SCRUB_STATE_PENDING);
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
- "Ondemand Scrubbing scheduled to run at %s", timestr);
- }
+ gf_time_fmt(timestr, sizeof(timestr), (now.tv_sec + timo), gf_timefmt_FT);
- return 0;
+ pthread_mutex_lock(&scrub_monitor->donelock);
+ {
+ scrub_monitor->done = _gf_false;
+ }
+ pthread_mutex_unlock(&scrub_monitor->donelock);
+
+ ret = gf_tw_mod_timer_pending(priv->timer_wheel, scrub_monitor->timer,
+ timo);
+ if (ret == 0)
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
+ "Scrubber is currently running and would be "
+ "rescheduled after completion");
+ else {
+ _br_monitor_set_scrub_state(scrub_monitor, BR_SCRUB_STATE_PENDING);
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
+ "Ondemand Scrubbing scheduled to run at %s", timestr);
+ }
+
+ return 0;
}
-#define BR_SCRUB_THREAD_SCALE_LAZY 0
-#define BR_SCRUB_THREAD_SCALE_NORMAL 0.4
+#define BR_SCRUB_THREAD_SCALE_LAZY 0
+#define BR_SCRUB_THREAD_SCALE_NORMAL 0.4
#define BR_SCRUB_THREAD_SCALE_AGGRESSIVE 1.0
#ifndef M_E
@@ -1096,111 +1122,105 @@ br_fsscan_ondemand (xlator_t *this)
* the scale based on the number of processor cores too.
*/
static unsigned int
-br_scrubber_calc_scale (xlator_t *this,
- br_private_t *priv, scrub_throttle_t throttle)
+br_scrubber_calc_scale(xlator_t *this, br_private_t *priv,
+ scrub_throttle_t throttle)
{
- unsigned int scale = 0;
+ unsigned int scale = 0;
- switch (throttle) {
+ switch (throttle) {
case BR_SCRUB_THROTTLE_VOID:
case BR_SCRUB_THROTTLE_STALLED:
- scale = 0;
- break;
+ scale = 0;
+ break;
case BR_SCRUB_THROTTLE_LAZY:
- scale = priv->child_count *
- pow (M_E, BR_SCRUB_THREAD_SCALE_LAZY);
- break;
+ scale = priv->child_count * pow(M_E, BR_SCRUB_THREAD_SCALE_LAZY);
+ break;
case BR_SCRUB_THROTTLE_NORMAL:
- scale = priv->child_count *
- pow (M_E, BR_SCRUB_THREAD_SCALE_NORMAL);
- break;
+ scale = priv->child_count * pow(M_E, BR_SCRUB_THREAD_SCALE_NORMAL);
+ break;
case BR_SCRUB_THROTTLE_AGGRESSIVE:
- scale = priv->child_count *
- pow (M_E, BR_SCRUB_THREAD_SCALE_AGGRESSIVE);
- break;
+ scale = priv->child_count *
+ pow(M_E, BR_SCRUB_THREAD_SCALE_AGGRESSIVE);
+ break;
default:
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_UNKNOWN_THROTTLE,
- "Unknown throttle %d", throttle);
- }
-
- return scale;
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_UNKNOWN_THROTTLE,
+ "Unknown throttle %d", throttle);
+ }
+ return scale;
}
static br_child_t *
-_br_scrubber_get_next_child (struct br_scrubber *fsscrub)
+_br_scrubber_get_next_child(struct br_scrubber *fsscrub)
{
- br_child_t *child = NULL;
+ br_child_t *child = NULL;
- child = list_first_entry (&fsscrub->scrublist, br_child_t, list);
- list_rotate_left (&fsscrub->scrublist);
+ child = list_first_entry(&fsscrub->scrublist, br_child_t, list);
+ list_rotate_left(&fsscrub->scrublist);
- return child;
+ return child;
}
static void
-_br_scrubber_get_entry (br_child_t *child, struct br_fsscan_entry **fsentry)
+_br_scrubber_get_entry(br_child_t *child, struct br_fsscan_entry **fsentry)
{
- struct br_scanfs *fsscan = &child->fsscan;
+ struct br_scanfs *fsscan = &child->fsscan;
- if (list_empty (&fsscan->ready))
- return;
- *fsentry = list_first_entry
- (&fsscan->ready, struct br_fsscan_entry, list);
- list_del_init (&(*fsentry)->list);
+ if (list_empty(&fsscan->ready))
+ return;
+ *fsentry = list_first_entry(&fsscan->ready, struct br_fsscan_entry, list);
+ list_del_init(&(*fsentry)->list);
}
static void
-_br_scrubber_find_scrubbable_entry (struct br_scrubber *fsscrub,
- struct br_fsscan_entry **fsentry)
+_br_scrubber_find_scrubbable_entry(struct br_scrubber *fsscrub,
+ struct br_fsscan_entry **fsentry)
{
- br_child_t *child = NULL;
- br_child_t *firstchild = NULL;
-
- while (1) {
- while (list_empty (&fsscrub->scrublist))
- pthread_cond_wait (&fsscrub->cond, &fsscrub->mutex);
+ br_child_t *child = NULL;
+ br_child_t *firstchild = NULL;
- firstchild = NULL;
- for (child = _br_scrubber_get_next_child (fsscrub);
- child != firstchild;
- child = _br_scrubber_get_next_child (fsscrub)) {
+ while (1) {
+ while (list_empty(&fsscrub->scrublist))
+ pthread_cond_wait(&fsscrub->cond, &fsscrub->mutex);
- if (!firstchild)
- firstchild = child;
+ firstchild = NULL;
+ for (child = _br_scrubber_get_next_child(fsscrub); child != firstchild;
+ child = _br_scrubber_get_next_child(fsscrub)) {
+ if (!firstchild)
+ firstchild = child;
- _br_scrubber_get_entry (child, fsentry);
- if (*fsentry)
- break;
- }
+ _br_scrubber_get_entry(child, fsentry);
+ if (*fsentry)
+ break;
+ }
- if (*fsentry)
- break;
+ if (*fsentry)
+ break;
- /* nothing to work on.. wait till available */
- pthread_cond_wait (&fsscrub->cond, &fsscrub->mutex);
- }
+ /* nothing to work on.. wait till available */
+ pthread_cond_wait(&fsscrub->cond, &fsscrub->mutex);
+ }
}
static void
-br_scrubber_pick_entry (struct br_scrubber *fsscrub,
- struct br_fsscan_entry **fsentry)
+br_scrubber_pick_entry(struct br_scrubber *fsscrub,
+ struct br_fsscan_entry **fsentry)
{
- pthread_cleanup_push (_br_lock_cleaner, &fsscrub->mutex);
+ pthread_cleanup_push(_br_lock_cleaner, &fsscrub->mutex);
- pthread_mutex_lock (&fsscrub->mutex);
- {
- *fsentry = NULL;
- _br_scrubber_find_scrubbable_entry (fsscrub, fsentry);
- }
- pthread_mutex_unlock (&fsscrub->mutex);
+ pthread_mutex_lock(&fsscrub->mutex);
+ {
+ *fsentry = NULL;
+ _br_scrubber_find_scrubbable_entry(fsscrub, fsentry);
+ }
+ pthread_mutex_unlock(&fsscrub->mutex);
- pthread_cleanup_pop (0);
+ pthread_cleanup_pop(0);
}
struct br_scrub_entry {
- gf_boolean_t scrubbed;
- struct br_fsscan_entry *fsentry;
+ gf_boolean_t scrubbed;
+ struct br_fsscan_entry *fsentry;
};
/**
@@ -1210,686 +1230,698 @@ struct br_scrub_entry {
* in the ->pending queue or when an object is undergoing scrubbing.
*/
static void
-br_scrubber_entry_handle (void *arg)
+br_scrubber_entry_handle(void *arg)
{
- struct br_scanfs *fsscan = NULL;
- struct br_scrub_entry *sentry = NULL;
- struct br_fsscan_entry *fsentry = NULL;
+ struct br_scanfs *fsscan = NULL;
+ struct br_scrub_entry *sentry = NULL;
+ struct br_fsscan_entry *fsentry = NULL;
- sentry = arg;
+ sentry = arg;
- fsentry = sentry->fsentry;
- fsscan = fsentry->fsscan;
+ fsentry = sentry->fsentry;
+ fsscan = fsentry->fsscan;
- LOCK (&fsscan->entrylock);
- {
- if (sentry->scrubbed) {
- _br_fsscan_dec_entry_count (fsscan);
-
- /* cleanup ->entry */
- fsentry->data = NULL;
- fsentry->fsscan = NULL;
- loc_wipe (&fsentry->parent);
- gf_dirent_entry_free (fsentry->entry);
-
- GF_FREE (sentry->fsentry);
- } else {
- /* (re)queue the entry again for scrub */
- _br_fsscan_collect_entry (fsscan, sentry->fsentry);
- }
+ LOCK(&fsscan->entrylock);
+ {
+ if (sentry->scrubbed) {
+ _br_fsscan_dec_entry_count(fsscan);
+
+ /* cleanup ->entry */
+ fsentry->data = NULL;
+ fsentry->fsscan = NULL;
+ loc_wipe(&fsentry->parent);
+ gf_dirent_entry_free(fsentry->entry);
+
+ GF_FREE(sentry->fsentry);
+ } else {
+ /* (re)queue the entry again for scrub */
+ _br_fsscan_collect_entry(fsscan, sentry->fsentry);
}
- UNLOCK (&fsscan->entrylock);
+ }
+ UNLOCK(&fsscan->entrylock);
}
static void
-br_scrubber_scrub_entry (xlator_t *this, struct br_fsscan_entry *fsentry)
+br_scrubber_scrub_entry(xlator_t *this, struct br_fsscan_entry *fsentry)
{
- struct br_scrub_entry sentry = {0, };
-
- sentry.scrubbed = 0;
- sentry.fsentry = fsentry;
-
- pthread_cleanup_push (br_scrubber_entry_handle, &sentry);
- {
- (void) br_scrubber_scrub_begin (this, fsentry);
- sentry.scrubbed = 1;
- }
- pthread_cleanup_pop (1);
+ struct br_scrub_entry sentry = {
+ 0,
+ };
+
+ sentry.scrubbed = 0;
+ sentry.fsentry = fsentry;
+
+ pthread_cleanup_push(br_scrubber_entry_handle, &sentry);
+ {
+ (void)br_scrubber_scrub_begin(this, fsentry);
+ sentry.scrubbed = 1;
+ }
+ pthread_cleanup_pop(1);
}
-void *br_scrubber_proc (void *arg)
+void *
+br_scrubber_proc(void *arg)
{
- xlator_t *this = NULL;
- struct br_scrubber *fsscrub = NULL;
- struct br_fsscan_entry *fsentry = NULL;
+ xlator_t *this = NULL;
+ struct br_scrubber *fsscrub = NULL;
+ struct br_fsscan_entry *fsentry = NULL;
- fsscrub = arg;
- THIS = this = fsscrub->this;
+ fsscrub = arg;
+ THIS = this = fsscrub->this;
- while (1) {
- br_scrubber_pick_entry (fsscrub, &fsentry);
- br_scrubber_scrub_entry (this, fsentry);
- sleep (1);
- }
+ while (1) {
+ br_scrubber_pick_entry(fsscrub, &fsentry);
+ br_scrubber_scrub_entry(this, fsentry);
+ sleep(1);
+ }
- return NULL;
+ return NULL;
}
static int32_t
-br_scrubber_scale_up (xlator_t *this,
- struct br_scrubber *fsscrub,
- unsigned int v1, unsigned int v2)
+br_scrubber_scale_up(xlator_t *this, struct br_scrubber *fsscrub,
+ unsigned int v1, unsigned int v2)
{
- int i = 0;
- int32_t ret = -1;
- int diff = 0;
- struct br_scrubbers *scrub = NULL;
-
- diff = (int)(v2 - v1);
-
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCALING_UP_SCRUBBER,
- "Scaling up scrubbers [%d => %d]", v1, v2);
-
- for (i = 0; i < diff; i++) {
- scrub = GF_CALLOC (diff, sizeof (*scrub),
- gf_br_mt_br_scrubber_t);
- if (!scrub)
- break;
-
- INIT_LIST_HEAD (&scrub->list);
- ret = gf_thread_create (&scrub->scrubthread,
- NULL, br_scrubber_proc, fsscrub,
- "brsproc");
- if (ret)
- break;
-
- fsscrub->nr_scrubbers++;
- list_add_tail (&scrub->list, &fsscrub->scrubbers);
- }
+ int i = 0;
+ int32_t ret = -1;
+ int diff = 0;
+ struct br_scrubbers *scrub = NULL;
- if ((i != diff) && !scrub)
- goto error_return;
+ diff = (int)(v2 - v1);
- if (i != diff) /* degraded scaling.. */
- gf_msg (this->name, GF_LOG_WARNING, 0, BRB_MSG_SCALE_UP_FAILED,
- "Could not fully scale up to %d scrubber(s). Spawned "
- "%d/%d [total scrubber(s): %d]", v2, i, diff, (v1 + i));
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCALING_UP_SCRUBBER,
+ "Scaling up scrubbers [%d => %d]", v1, v2);
- return 0;
+ for (i = 0; i < diff; i++) {
+ scrub = GF_CALLOC(diff, sizeof(*scrub), gf_br_mt_br_scrubber_t);
+ if (!scrub)
+ break;
- error_return:
- return -1;
+ INIT_LIST_HEAD(&scrub->list);
+ ret = gf_thread_create(&scrub->scrubthread, NULL, br_scrubber_proc,
+ fsscrub, "brsproc");
+ if (ret)
+ break;
+
+ fsscrub->nr_scrubbers++;
+ list_add_tail(&scrub->list, &fsscrub->scrubbers);
+ }
+
+ if ((i != diff) && !scrub)
+ goto error_return;
+
+ if (i != diff) /* degraded scaling.. */
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRB_MSG_SCALE_UP_FAILED,
+ "Could not fully scale up to %d scrubber(s). Spawned "
+ "%d/%d [total scrubber(s): %d]",
+ v2, i, diff, (v1 + i));
+
+ return 0;
+
+error_return:
+ return -1;
}
static int32_t
-br_scrubber_scale_down (xlator_t *this,
- struct br_scrubber *fsscrub,
- unsigned int v1, unsigned int v2)
+br_scrubber_scale_down(xlator_t *this, struct br_scrubber *fsscrub,
+ unsigned int v1, unsigned int v2)
{
- int i = 0;
- int diff = 0;
- int32_t ret = -1;
- struct br_scrubbers *scrub = NULL;
-
- diff = (int)(v1 - v2);
+ int i = 0;
+ int diff = 0;
+ int32_t ret = -1;
+ struct br_scrubbers *scrub = NULL;
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCALE_DOWN_SCRUBBER,
- "Scaling down scrubbers [%d => %d]", v1, v2);
+ diff = (int)(v1 - v2);
- for (i = 0 ; i < diff; i++) {
- scrub = list_first_entry
- (&fsscrub->scrubbers, struct br_scrubbers, list);
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCALE_DOWN_SCRUBBER,
+ "Scaling down scrubbers [%d => %d]", v1, v2);
- list_del_init (&scrub->list);
- ret = gf_thread_cleanup_xint (scrub->scrubthread);
- if (ret)
- break;
- GF_FREE (scrub);
+ for (i = 0; i < diff; i++) {
+ scrub = list_first_entry(&fsscrub->scrubbers, struct br_scrubbers,
+ list);
- fsscrub->nr_scrubbers--;
- }
-
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRB_MSG_SCALE_DOWN_FAILED, "Could not fully scale down "
- "to %d scrubber(s). Terminated %d/%d [total "
- "scrubber(s): %d]", v1, i, diff, (v2 - i));
- ret = 0;
- }
+ list_del_init(&scrub->list);
+ ret = gf_thread_cleanup_xint(scrub->scrubthread);
+ if (ret)
+ break;
+ GF_FREE(scrub);
+
+ fsscrub->nr_scrubbers--;
+ }
+
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRB_MSG_SCALE_DOWN_FAILED,
+ "Could not fully scale down "
+ "to %d scrubber(s). Terminated %d/%d [total "
+ "scrubber(s): %d]",
+ v1, i, diff, (v2 - i));
+ ret = 0;
+ }
- return ret;
+ return ret;
}
static int32_t
-br_scrubber_configure (xlator_t *this, br_private_t *priv,
- struct br_scrubber *fsscrub, scrub_throttle_t nthrottle)
+br_scrubber_configure(xlator_t *this, br_private_t *priv,
+ struct br_scrubber *fsscrub, scrub_throttle_t nthrottle)
{
- int32_t ret = 0;
- unsigned int v1 = 0;
- unsigned int v2 = 0;
+ int32_t ret = 0;
+ unsigned int v1 = 0;
+ unsigned int v2 = 0;
- v1 = fsscrub->nr_scrubbers;
- v2 = br_scrubber_calc_scale (this, priv, nthrottle);
+ v1 = fsscrub->nr_scrubbers;
+ v2 = br_scrubber_calc_scale(this, priv, nthrottle);
- if (v1 == v2)
- return 0;
+ if (v1 == v2)
+ return 0;
- if (v1 > v2)
- ret = br_scrubber_scale_down (this, fsscrub, v1, v2);
- else
- ret = br_scrubber_scale_up (this, fsscrub, v1, v2);
+ if (v1 > v2)
+ ret = br_scrubber_scale_down(this, fsscrub, v1, v2);
+ else
+ ret = br_scrubber_scale_up(this, fsscrub, v1, v2);
- return ret;
+ return ret;
}
static int32_t
-br_scrubber_fetch_option (xlator_t *this,
- char *opt, dict_t *options, char **value)
+br_scrubber_fetch_option(xlator_t *this, char *opt, dict_t *options,
+ char **value)
{
- if (options)
- GF_OPTION_RECONF (opt, *value, options, str, error_return);
- else
- GF_OPTION_INIT (opt, *value, str, error_return);
+ if (options)
+ GF_OPTION_RECONF(opt, *value, options, str, error_return);
+ else
+ GF_OPTION_INIT(opt, *value, str, error_return);
- return 0;
+ return 0;
- error_return:
- return -1;
+error_return:
+ return -1;
}
/* internal "throttle" override */
-#define BR_SCRUB_STALLED "STALLED"
+#define BR_SCRUB_STALLED "STALLED"
/* TODO: token buket spec */
static int32_t
-br_scrubber_handle_throttle (xlator_t *this, br_private_t *priv,
- dict_t *options, gf_boolean_t scrubstall)
+br_scrubber_handle_throttle(xlator_t *this, br_private_t *priv, dict_t *options,
+ gf_boolean_t scrubstall)
{
- int32_t ret = 0;
- char *tmp = NULL;
- struct br_scrubber *fsscrub = NULL;
- scrub_throttle_t nthrottle = BR_SCRUB_THROTTLE_VOID;
-
- fsscrub = &priv->fsscrub;
- fsscrub->throttle_reconf = _gf_false;
-
- ret = br_scrubber_fetch_option (this, "scrub-throttle", options, &tmp);
- if (ret)
- goto error_return;
-
- if (scrubstall)
- tmp = BR_SCRUB_STALLED;
-
- if (strcasecmp (tmp, "lazy") == 0)
- nthrottle = BR_SCRUB_THROTTLE_LAZY;
- else if (strcasecmp (tmp, "normal") == 0)
- nthrottle = BR_SCRUB_THROTTLE_NORMAL;
- else if (strcasecmp (tmp, "aggressive") == 0)
- nthrottle = BR_SCRUB_THROTTLE_AGGRESSIVE;
- else if (strcasecmp (tmp, BR_SCRUB_STALLED) == 0)
- nthrottle = BR_SCRUB_THROTTLE_STALLED;
- else
- goto error_return;
-
- /* on failure old throttling value is preserved */
- ret = br_scrubber_configure (this, priv, fsscrub, nthrottle);
- if (ret)
- goto error_return;
-
- if (fsscrub->throttle != nthrottle)
- fsscrub->throttle_reconf = _gf_true;
-
- fsscrub->throttle = nthrottle;
- return 0;
-
- error_return:
- return -1;
+ int32_t ret = 0;
+ char *tmp = NULL;
+ struct br_scrubber *fsscrub = NULL;
+ scrub_throttle_t nthrottle = BR_SCRUB_THROTTLE_VOID;
+
+ fsscrub = &priv->fsscrub;
+ fsscrub->throttle_reconf = _gf_false;
+
+ ret = br_scrubber_fetch_option(this, "scrub-throttle", options, &tmp);
+ if (ret)
+ goto error_return;
+
+ if (scrubstall)
+ tmp = BR_SCRUB_STALLED;
+
+ if (strcasecmp(tmp, "lazy") == 0)
+ nthrottle = BR_SCRUB_THROTTLE_LAZY;
+ else if (strcasecmp(tmp, "normal") == 0)
+ nthrottle = BR_SCRUB_THROTTLE_NORMAL;
+ else if (strcasecmp(tmp, "aggressive") == 0)
+ nthrottle = BR_SCRUB_THROTTLE_AGGRESSIVE;
+ else if (strcasecmp(tmp, BR_SCRUB_STALLED) == 0)
+ nthrottle = BR_SCRUB_THROTTLE_STALLED;
+ else
+ goto error_return;
+
+ /* on failure old throttling value is preserved */
+ ret = br_scrubber_configure(this, priv, fsscrub, nthrottle);
+ if (ret)
+ goto error_return;
+
+ if (fsscrub->throttle != nthrottle)
+ fsscrub->throttle_reconf = _gf_true;
+
+ fsscrub->throttle = nthrottle;
+ return 0;
+
+error_return:
+ return -1;
}
static int32_t
-br_scrubber_handle_stall (xlator_t *this, br_private_t *priv,
- dict_t *options, gf_boolean_t *scrubstall)
+br_scrubber_handle_stall(xlator_t *this, br_private_t *priv, dict_t *options,
+ gf_boolean_t *scrubstall)
{
- int32_t ret = 0;
- char *tmp = NULL;
+ int32_t ret = 0;
+ char *tmp = NULL;
- ret = br_scrubber_fetch_option (this, "scrub-state", options, &tmp);
- if (ret)
- goto error_return;
+ ret = br_scrubber_fetch_option(this, "scrub-state", options, &tmp);
+ if (ret)
+ goto error_return;
- if (strcasecmp (tmp, "pause") == 0) /* anything else is active */
- *scrubstall = _gf_true;
+ if (strcasecmp(tmp, "pause") == 0) /* anything else is active */
+ *scrubstall = _gf_true;
- return 0;
+ return 0;
- error_return:
- return -1;
+error_return:
+ return -1;
}
static int32_t
-br_scrubber_handle_freq (xlator_t *this, br_private_t *priv,
- dict_t *options, gf_boolean_t scrubstall)
+br_scrubber_handle_freq(xlator_t *this, br_private_t *priv, dict_t *options,
+ gf_boolean_t scrubstall)
{
- int32_t ret = -1;
- char *tmp = NULL;
- scrub_freq_t frequency = BR_FSSCRUB_FREQ_HOURLY;
- struct br_scrubber *fsscrub = NULL;
-
- fsscrub = &priv->fsscrub;
- fsscrub->frequency_reconf = _gf_true;
-
- ret = br_scrubber_fetch_option (this, "scrub-freq", options, &tmp);
- if (ret)
- goto error_return;
-
- if (scrubstall)
- tmp = BR_SCRUB_STALLED;
-
- if (strcasecmp (tmp, "hourly") == 0) {
- frequency = BR_FSSCRUB_FREQ_HOURLY;
- } else if (strcasecmp (tmp, "daily") == 0) {
- frequency = BR_FSSCRUB_FREQ_DAILY;
- } else if (strcasecmp (tmp, "weekly") == 0) {
- frequency = BR_FSSCRUB_FREQ_WEEKLY;
- } else if (strcasecmp (tmp, "biweekly") == 0) {
- frequency = BR_FSSCRUB_FREQ_BIWEEKLY;
- } else if (strcasecmp (tmp, "monthly") == 0) {
- frequency = BR_FSSCRUB_FREQ_MONTHLY;
- } else if (strcasecmp (tmp, "minute") == 0) {
- frequency = BR_FSSCRUB_FREQ_MINUTE;
- } else if (strcasecmp (tmp, BR_SCRUB_STALLED) == 0) {
- frequency = BR_FSSCRUB_FREQ_STALLED;
- } else
- goto error_return;
-
- if (fsscrub->frequency == frequency)
- fsscrub->frequency_reconf = _gf_false;
- else
- fsscrub->frequency = frequency;
-
- return 0;
-
- error_return:
- return -1;
+ int32_t ret = -1;
+ char *tmp = NULL;
+ scrub_freq_t frequency = BR_FSSCRUB_FREQ_HOURLY;
+ struct br_scrubber *fsscrub = NULL;
+
+ fsscrub = &priv->fsscrub;
+ fsscrub->frequency_reconf = _gf_true;
+
+ ret = br_scrubber_fetch_option(this, "scrub-freq", options, &tmp);
+ if (ret)
+ goto error_return;
+
+ if (scrubstall)
+ tmp = BR_SCRUB_STALLED;
+
+ if (strcasecmp(tmp, "hourly") == 0) {
+ frequency = BR_FSSCRUB_FREQ_HOURLY;
+ } else if (strcasecmp(tmp, "daily") == 0) {
+ frequency = BR_FSSCRUB_FREQ_DAILY;
+ } else if (strcasecmp(tmp, "weekly") == 0) {
+ frequency = BR_FSSCRUB_FREQ_WEEKLY;
+ } else if (strcasecmp(tmp, "biweekly") == 0) {
+ frequency = BR_FSSCRUB_FREQ_BIWEEKLY;
+ } else if (strcasecmp(tmp, "monthly") == 0) {
+ frequency = BR_FSSCRUB_FREQ_MONTHLY;
+ } else if (strcasecmp(tmp, "minute") == 0) {
+ frequency = BR_FSSCRUB_FREQ_MINUTE;
+ } else if (strcasecmp(tmp, BR_SCRUB_STALLED) == 0) {
+ frequency = BR_FSSCRUB_FREQ_STALLED;
+ } else
+ goto error_return;
+
+ if (fsscrub->frequency == frequency)
+ fsscrub->frequency_reconf = _gf_false;
+ else
+ fsscrub->frequency = frequency;
+
+ return 0;
+
+error_return:
+ return -1;
}
-static void br_scrubber_log_option (xlator_t *this,
- br_private_t *priv, gf_boolean_t scrubstall)
+static void
+br_scrubber_log_option(xlator_t *this, br_private_t *priv,
+ gf_boolean_t scrubstall)
{
- struct br_scrubber *fsscrub = &priv->fsscrub;
- char *scrub_throttle_str[] = {
- [BR_SCRUB_THROTTLE_LAZY] = "lazy",
- [BR_SCRUB_THROTTLE_NORMAL] = "normal",
- [BR_SCRUB_THROTTLE_AGGRESSIVE] = "aggressive",
- };
-
- char *scrub_freq_str[] = {
- [BR_FSSCRUB_FREQ_HOURLY] = "hourly",
- [BR_FSSCRUB_FREQ_DAILY] = "daily",
- [BR_FSSCRUB_FREQ_WEEKLY] = "weekly",
- [BR_FSSCRUB_FREQ_BIWEEKLY] = "biweekly",
- [BR_FSSCRUB_FREQ_MONTHLY] = "monthly (30 days)",
- [BR_FSSCRUB_FREQ_MINUTE] = "every minute",
- };
-
- if (scrubstall)
- return; /* logged as pause */
-
- if (fsscrub->frequency_reconf || fsscrub->throttle_reconf) {
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_TUNABLE,
- "SCRUB TUNABLES:: [Frequency: %s, Throttle: %s]",
- scrub_freq_str[fsscrub->frequency],
- scrub_throttle_str[fsscrub->throttle]);
- }
+ struct br_scrubber *fsscrub = &priv->fsscrub;
+ char *scrub_throttle_str[] = {
+ [BR_SCRUB_THROTTLE_LAZY] = "lazy",
+ [BR_SCRUB_THROTTLE_NORMAL] = "normal",
+ [BR_SCRUB_THROTTLE_AGGRESSIVE] = "aggressive",
+ };
+
+ char *scrub_freq_str[] = {
+ [BR_FSSCRUB_FREQ_HOURLY] = "hourly",
+ [BR_FSSCRUB_FREQ_DAILY] = "daily",
+ [BR_FSSCRUB_FREQ_WEEKLY] = "weekly",
+ [BR_FSSCRUB_FREQ_BIWEEKLY] = "biweekly",
+ [BR_FSSCRUB_FREQ_MONTHLY] = "monthly (30 days)",
+ [BR_FSSCRUB_FREQ_MINUTE] = "every minute",
+ };
+
+ if (scrubstall)
+ return; /* logged as pause */
+
+ if (fsscrub->frequency_reconf || fsscrub->throttle_reconf) {
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_TUNABLE,
+ "SCRUB TUNABLES:: [Frequency: %s, Throttle: %s]",
+ scrub_freq_str[fsscrub->frequency],
+ scrub_throttle_str[fsscrub->throttle]);
+ }
}
int32_t
-br_scrubber_handle_options (xlator_t *this, br_private_t *priv, dict_t *options)
+br_scrubber_handle_options(xlator_t *this, br_private_t *priv, dict_t *options)
{
- int32_t ret = 0;
- gf_boolean_t scrubstall = _gf_false; /* not as dangerous as it sounds */
+ int32_t ret = 0;
+ gf_boolean_t scrubstall = _gf_false; /* not as dangerous as it sounds */
- ret = br_scrubber_handle_stall (this, priv, options, &scrubstall);
- if (ret)
- goto error_return;
+ ret = br_scrubber_handle_stall(this, priv, options, &scrubstall);
+ if (ret)
+ goto error_return;
- ret = br_scrubber_handle_throttle (this, priv, options, scrubstall);
- if (ret)
- goto error_return;
+ ret = br_scrubber_handle_throttle(this, priv, options, scrubstall);
+ if (ret)
+ goto error_return;
- ret = br_scrubber_handle_freq (this, priv, options, scrubstall);
- if (ret)
- goto error_return;
+ ret = br_scrubber_handle_freq(this, priv, options, scrubstall);
+ if (ret)
+ goto error_return;
- br_scrubber_log_option (this, priv, scrubstall);
+ br_scrubber_log_option(this, priv, scrubstall);
- return 0;
+ return 0;
- error_return:
- return -1;
+error_return:
+ return -1;
}
inode_t *
-br_lookup_bad_obj_dir (xlator_t *this, br_child_t *child, uuid_t gfid)
+br_lookup_bad_obj_dir(xlator_t *this, br_child_t *child, uuid_t gfid)
{
- struct iatt statbuf = {0, };
- inode_table_t *table = NULL;
- int32_t ret = -1;
- loc_t loc = {0, };
- inode_t *linked_inode = NULL;
- int32_t op_errno = 0;
-
- GF_VALIDATE_OR_GOTO ("bit-rot-scrubber", this, out);
- GF_VALIDATE_OR_GOTO (this->name, this->private, out);
- GF_VALIDATE_OR_GOTO (this->name, child, out);
-
- table = child->table;
-
- loc.inode = inode_new (table);
- if (!loc.inode) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
- BRB_MSG_NO_MEMORY, "failed to allocate a new inode for"
- "bad object directory");
- goto out;
- }
-
- gf_uuid_copy (loc.gfid, gfid);
-
- ret = syncop_lookup (child->xl, &loc, &statbuf, NULL, NULL, NULL);
- if (ret < 0) {
- op_errno = -ret;
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_LOOKUP_FAILED, "failed to lookup the bad "
- "objects directory (gfid: %s (%s))", uuid_utoa (gfid),
- strerror (op_errno));
- goto out;
- }
-
- linked_inode = inode_link (loc.inode, NULL, NULL, &statbuf);
- if (linked_inode)
- inode_lookup (linked_inode);
+ struct iatt statbuf = {
+ 0,
+ };
+ inode_table_t *table = NULL;
+ int32_t ret = -1;
+ loc_t loc = {
+ 0,
+ };
+ inode_t *linked_inode = NULL;
+ int32_t op_errno = 0;
+
+ GF_VALIDATE_OR_GOTO("bit-rot-scrubber", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, out);
+ GF_VALIDATE_OR_GOTO(this->name, child, out);
+
+ table = child->table;
+
+ loc.inode = inode_new(table);
+ if (!loc.inode) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
+ "failed to allocate a new inode for"
+ "bad object directory");
+ goto out;
+ }
+
+ gf_uuid_copy(loc.gfid, gfid);
+
+ ret = syncop_lookup(child->xl, &loc, &statbuf, NULL, NULL, NULL);
+ if (ret < 0) {
+ op_errno = -ret;
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_LOOKUP_FAILED,
+ "failed to lookup the bad "
+ "objects directory (gfid: %s (%s))",
+ uuid_utoa(gfid), strerror(op_errno));
+ goto out;
+ }
+
+ linked_inode = inode_link(loc.inode, NULL, NULL, &statbuf);
+ if (linked_inode)
+ inode_lookup(linked_inode);
out:
- loc_wipe (&loc);
- return linked_inode;
+ loc_wipe(&loc);
+ return linked_inode;
}
int32_t
-br_read_bad_object_dir (xlator_t *this, br_child_t *child, fd_t *fd,
- dict_t *dict)
+br_read_bad_object_dir(xlator_t *this, br_child_t *child, fd_t *fd,
+ dict_t *dict)
{
- gf_dirent_t entries;
- gf_dirent_t *entry = NULL;
- int32_t ret = -1;
- off_t offset = 0;
- int32_t count = 0;
- char key[PATH_MAX] = {0, };
- dict_t *out_dict = NULL;
-
- INIT_LIST_HEAD (&entries.list);
-
- while ((ret = syncop_readdir (child->xl, fd, 131072, offset, &entries,
- NULL, &out_dict))) {
- if (ret < 0)
- goto out;
-
- list_for_each_entry (entry, &entries.list, list) {
- offset = entry->d_off;
-
- snprintf (key, sizeof (key), "quarantine-%d", count);
-
- /*
- * ignore the dict_set errors for now. The intention is
- * to get as many bad objects as possible instead of
- * erroring out at the first failure.
- */
- ret = dict_set_dynstr_with_alloc (dict, key,
- entry->d_name);
- if (!ret)
- count++;
-
- if (out_dict) {
- dict_copy (out_dict, dict);
- dict_unref (out_dict);
- out_dict = NULL;
- }
- }
-
- gf_dirent_free (&entries);
- }
+ gf_dirent_t entries;
+ gf_dirent_t *entry = NULL;
+ int32_t ret = -1;
+ off_t offset = 0;
+ int32_t count = 0;
+ char key[PATH_MAX] = {
+ 0,
+ };
+ dict_t *out_dict = NULL;
+
+ INIT_LIST_HEAD(&entries.list);
+
+ while ((ret = syncop_readdir(child->xl, fd, 131072, offset, &entries, NULL,
+ &out_dict))) {
+ if (ret < 0)
+ goto out;
+
+ list_for_each_entry(entry, &entries.list, list)
+ {
+ offset = entry->d_off;
- ret = count;
- ret = dict_set_int32 (dict, "count", count);
+ snprintf(key, sizeof(key), "quarantine-%d", count);
-out:
- return ret;
-}
-
-int32_t
-br_get_bad_objects_from_child (xlator_t *this, dict_t *dict, br_child_t *child)
-{
- inode_t *inode = NULL;
- inode_table_t *table = NULL;
- fd_t *fd = NULL;
- int32_t ret = -1;
- loc_t loc = {0, };
- int32_t op_errno = 0;
-
- GF_VALIDATE_OR_GOTO ("bit-rot-scrubber", this, out);
- GF_VALIDATE_OR_GOTO (this->name, this->private, out);
- GF_VALIDATE_OR_GOTO (this->name, child, out);
- GF_VALIDATE_OR_GOTO (this->name, dict, out);
-
- table = child->table;
-
- inode = inode_find (table, BR_BAD_OBJ_CONTAINER);
- if (!inode) {
- inode = br_lookup_bad_obj_dir (this, child,
- BR_BAD_OBJ_CONTAINER);
- if (!inode)
- goto out;
- }
+ /*
+ * ignore the dict_set errors for now. The intention is
+ * to get as many bad objects as possible instead of
+ * erroring out at the first failure.
+ */
+ ret = dict_set_dynstr_with_alloc(dict, key, entry->d_name);
+ if (!ret)
+ count++;
- fd = fd_create (inode, 0);
- if (!fd) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
- BRB_MSG_FD_CREATE_FAILED, "fd creation for the bad "
- "objects directory failed (gfid: %s)",
- uuid_utoa (BR_BAD_OBJ_CONTAINER));
- goto out;
+ if (out_dict) {
+ dict_copy(out_dict, dict);
+ dict_unref(out_dict);
+ out_dict = NULL;
+ }
}
- loc.inode = inode;
- gf_uuid_copy (loc.gfid, inode->gfid);
-
- ret = syncop_opendir (child->xl, &loc, fd, NULL, NULL);
- if (ret < 0) {
- op_errno = -ret;
- fd_unref (fd);
- fd = NULL;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- BRB_MSG_FD_CREATE_FAILED, "failed to open the bad "
- "objects directory %s",
- uuid_utoa (BR_BAD_OBJ_CONTAINER));
- goto out;
- }
+ gf_dirent_free(&entries);
+ }
- fd_bind (fd);
+ ret = count;
+ ret = dict_set_int32(dict, "count", count);
- ret = br_read_bad_object_dir (this, child, fd, dict);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_BAD_OBJ_READDIR_FAIL, "readdir of the bad "
- "objects directory (%s) failed ",
- uuid_utoa (BR_BAD_OBJ_CONTAINER));
- goto out;
- }
+out:
+ return ret;
+}
- ret = 0;
+int32_t
+br_get_bad_objects_from_child(xlator_t *this, dict_t *dict, br_child_t *child)
+{
+ inode_t *inode = NULL;
+ inode_table_t *table = NULL;
+ fd_t *fd = NULL;
+ int32_t ret = -1;
+ loc_t loc = {
+ 0,
+ };
+ int32_t op_errno = 0;
+
+ GF_VALIDATE_OR_GOTO("bit-rot-scrubber", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, out);
+ GF_VALIDATE_OR_GOTO(this->name, child, out);
+ GF_VALIDATE_OR_GOTO(this->name, dict, out);
+
+ table = child->table;
+
+ inode = inode_find(table, BR_BAD_OBJ_CONTAINER);
+ if (!inode) {
+ inode = br_lookup_bad_obj_dir(this, child, BR_BAD_OBJ_CONTAINER);
+ if (!inode)
+ goto out;
+ }
+
+ fd = fd_create(inode, 0);
+ if (!fd) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_FD_CREATE_FAILED,
+ "fd creation for the bad "
+ "objects directory failed (gfid: %s)",
+ uuid_utoa(BR_BAD_OBJ_CONTAINER));
+ goto out;
+ }
+
+ loc.inode = inode;
+ gf_uuid_copy(loc.gfid, inode->gfid);
+
+ ret = syncop_opendir(child->xl, &loc, fd, NULL, NULL);
+ if (ret < 0) {
+ op_errno = -ret;
+ fd_unref(fd);
+ fd = NULL;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, BRB_MSG_FD_CREATE_FAILED,
+ "failed to open the bad "
+ "objects directory %s",
+ uuid_utoa(BR_BAD_OBJ_CONTAINER));
+ goto out;
+ }
+
+ fd_bind(fd);
+
+ ret = br_read_bad_object_dir(this, child, fd, dict);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_BAD_OBJ_READDIR_FAIL,
+ "readdir of the bad "
+ "objects directory (%s) failed ",
+ uuid_utoa(BR_BAD_OBJ_CONTAINER));
+ goto out;
+ }
+
+ ret = 0;
out:
- loc_wipe (&loc);
- if (fd)
- fd_unref (fd);
- return ret;
+ loc_wipe(&loc);
+ if (fd)
+ fd_unref(fd);
+ return ret;
}
int32_t
-br_collect_bad_objects_of_child (xlator_t *this, br_child_t *child,
- dict_t *dict, dict_t *child_dict,
- int32_t total_count)
+br_collect_bad_objects_of_child(xlator_t *this, br_child_t *child, dict_t *dict,
+ dict_t *child_dict, int32_t total_count)
{
-
- int32_t ret = -1;
- int32_t count = 0;
- char key[PATH_MAX] = {0, };
- char main_key[PATH_MAX] = {0, };
- int32_t j = 0;
- int32_t tmp_count = 0;
- char *entry = NULL;
- char tmp[PATH_MAX] = {0, };
- char *path = NULL;
- int32_t len = 0;
-
- ret = dict_get_int32 (child_dict, "count", &count);
+ int32_t ret = -1;
+ int32_t count = 0;
+ char key[PATH_MAX] = {
+ 0,
+ };
+ char main_key[PATH_MAX] = {
+ 0,
+ };
+ int32_t j = 0;
+ int32_t tmp_count = 0;
+ char *entry = NULL;
+ char tmp[PATH_MAX] = {
+ 0,
+ };
+ char *path = NULL;
+ int32_t len = 0;
+
+ ret = dict_get_int32(child_dict, "count", &count);
+ if (ret)
+ goto out;
+
+ tmp_count = total_count;
+
+ for (j = 0; j < count; j++) {
+ snprintf(key, PATH_MAX, "quarantine-%d", j);
+ ret = dict_get_str(child_dict, key, &entry);
if (ret)
- goto out;
-
- tmp_count = total_count;
-
- for (j = 0; j < count; j++) {
- snprintf (key, PATH_MAX, "quarantine-%d", j);
- ret = dict_get_str (child_dict, key, &entry);
- if (ret)
- continue;
-
- ret = dict_get_str (child_dict, entry, &path);
- len = snprintf (tmp, PATH_MAX, "%s ==> BRICK: %s\n path: %s",
- entry, child->brick_path, path);
- if ((len < 0) || (len >= PATH_MAX)) {
- continue;
- }
- snprintf (main_key, PATH_MAX, "quarantine-%d",
- tmp_count);
-
- ret = dict_set_dynstr_with_alloc (dict, main_key, tmp);
- if (!ret)
- tmp_count++;
- path = NULL;
+ continue;
+
+ ret = dict_get_str(child_dict, entry, &path);
+ len = snprintf(tmp, PATH_MAX, "%s ==> BRICK: %s\n path: %s", entry,
+ child->brick_path, path);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ continue;
}
+ snprintf(main_key, PATH_MAX, "quarantine-%d", tmp_count);
- ret = tmp_count;
+ ret = dict_set_dynstr_with_alloc(dict, main_key, tmp);
+ if (!ret)
+ tmp_count++;
+ path = NULL;
+ }
+
+ ret = tmp_count;
out:
- return ret;
+ return ret;
}
int32_t
-br_collect_bad_objects_from_children (xlator_t *this, dict_t *dict)
+br_collect_bad_objects_from_children(xlator_t *this, dict_t *dict)
{
- int32_t ret = -1;
- dict_t *child_dict = NULL;
- int32_t i = 0;
- int32_t total_count = 0;
- br_child_t *child = NULL;
- br_private_t *priv = NULL;
- dict_t *tmp_dict = NULL;
-
- priv = this->private;
- tmp_dict = dict;
-
- for (i = 0; i < priv->child_count; i++) {
- child = &priv->children[i];
- GF_ASSERT (child);
- if (!_br_is_child_connected (child))
- continue;
-
- child_dict = dict_new ();
- if (!child_dict) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
- BRB_MSG_NO_MEMORY, "failed to allocate dict");
- continue;
- }
- ret = br_get_bad_objects_from_child (this, child_dict, child);
- /*
- * Continue asking the remaining children for the list of
- * bad objects even though getting the list from one of them
- * fails.
- */
- if (ret) {
- dict_unref (child_dict);
- continue;
- }
-
- ret = br_collect_bad_objects_of_child (this, child, tmp_dict,
- child_dict, total_count);
- if (ret < 0) {
- dict_unref (child_dict);
- continue;
- }
-
- total_count = ret;
- dict_unref (child_dict);
- child_dict = NULL;
+ int32_t ret = -1;
+ dict_t *child_dict = NULL;
+ int32_t i = 0;
+ int32_t total_count = 0;
+ br_child_t *child = NULL;
+ br_private_t *priv = NULL;
+ dict_t *tmp_dict = NULL;
+
+ priv = this->private;
+ tmp_dict = dict;
+
+ for (i = 0; i < priv->child_count; i++) {
+ child = &priv->children[i];
+ GF_ASSERT(child);
+ if (!_br_is_child_connected(child))
+ continue;
+
+ child_dict = dict_new();
+ if (!child_dict) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
+ "failed to allocate dict");
+ continue;
+ }
+ ret = br_get_bad_objects_from_child(this, child_dict, child);
+ /*
+ * Continue asking the remaining children for the list of
+ * bad objects even though getting the list from one of them
+ * fails.
+ */
+ if (ret) {
+ dict_unref(child_dict);
+ continue;
}
- ret = dict_set_int32 (tmp_dict, "total-count", total_count);
+ ret = br_collect_bad_objects_of_child(this, child, tmp_dict, child_dict,
+ total_count);
+ if (ret < 0) {
+ dict_unref(child_dict);
+ continue;
+ }
+
+ total_count = ret;
+ dict_unref(child_dict);
+ child_dict = NULL;
+ }
- return ret;
+ ret = dict_set_int32(tmp_dict, "total-count", total_count);
+
+ return ret;
}
int32_t
-br_get_bad_objects_list (xlator_t *this, dict_t **dict)
+br_get_bad_objects_list(xlator_t *this, dict_t **dict)
{
- int32_t ret = -1;
- dict_t *tmp_dict = NULL;
+ int32_t ret = -1;
+ dict_t *tmp_dict = NULL;
- GF_VALIDATE_OR_GOTO ("bir-rot-scrubber", this, out);
- GF_VALIDATE_OR_GOTO (this->name, dict, out);
+ GF_VALIDATE_OR_GOTO("bir-rot-scrubber", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, dict, out);
- tmp_dict = *dict;
+ tmp_dict = *dict;
+ if (!tmp_dict) {
+ tmp_dict = dict_new();
if (!tmp_dict) {
- tmp_dict = dict_new ();
- if (!tmp_dict) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
- BRB_MSG_NO_MEMORY, "failed to allocate dict");
- goto out;
- }
- *dict = tmp_dict;
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
+ "failed to allocate dict");
+ goto out;
}
+ *dict = tmp_dict;
+ }
- ret = br_collect_bad_objects_from_children (this, tmp_dict);
+ ret = br_collect_bad_objects_from_children(this, tmp_dict);
out:
- return ret;
+ return ret;
}
static int
-wait_for_scrub_to_finish (xlator_t *this)
+wait_for_scrub_to_finish(xlator_t *this)
{
- int ret = -1;
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", scrub_monitor, out);
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
-
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
- "Waiting for all children to start and finish scrub");
-
- pthread_mutex_lock (&scrub_monitor->donelock);
- {
- while (!scrub_monitor->done)
- pthread_cond_wait (&scrub_monitor->donecond,
- &scrub_monitor->donelock);
- }
- pthread_mutex_unlock (&scrub_monitor->donelock);
- ret = 0;
+ int ret = -1;
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
+
+ GF_VALIDATE_OR_GOTO("bit-rot", scrub_monitor, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
+
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_INFO,
+ "Waiting for all children to start and finish scrub");
+
+ pthread_mutex_lock(&scrub_monitor->donelock);
+ {
+ while (!scrub_monitor->done)
+ pthread_cond_wait(&scrub_monitor->donecond,
+ &scrub_monitor->donelock);
+ }
+ pthread_mutex_unlock(&scrub_monitor->donelock);
+ ret = 0;
out:
- return ret;
+ return ret;
}
/**
@@ -1897,153 +1929,150 @@ out:
* thread that takes care of state machine.
*/
void *
-br_monitor_thread (void *arg)
+br_monitor_thread(void *arg)
{
- int32_t ret = 0;
- xlator_t *this = NULL;
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
-
- this = arg;
- priv = this->private;
-
- /*
- * Since, this is the topmost xlator, THIS has to be set by bit-rot
- * xlator itself (STACK_WIND won't help in this case). Also it has
- * to be done for each thread that gets spawned. Otherwise, a new
- * thread will get global_xlator's pointer when it does "THIS".
- */
- THIS = this;
-
- scrub_monitor = &priv->scrub_monitor;
-
- pthread_mutex_lock (&scrub_monitor->mutex);
- {
- while (!scrub_monitor->inited)
- pthread_cond_wait (&scrub_monitor->cond,
- &scrub_monitor->mutex);
- }
- pthread_mutex_unlock (&scrub_monitor->mutex);
-
- /* this needs to be serialized with reconfigure() */
- pthread_mutex_lock (&priv->lock);
- {
- ret = br_scrub_state_machine (this, _gf_false);
- }
- pthread_mutex_unlock (&priv->lock);
+ int32_t ret = 0;
+ xlator_t *this = NULL;
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
+
+ this = arg;
+ priv = this->private;
+
+ /*
+ * Since, this is the topmost xlator, THIS has to be set by bit-rot
+ * xlator itself (STACK_WIND won't help in this case). Also it has
+ * to be done for each thread that gets spawned. Otherwise, a new
+ * thread will get global_xlator's pointer when it does "THIS".
+ */
+ THIS = this;
+
+ scrub_monitor = &priv->scrub_monitor;
+
+ pthread_mutex_lock(&scrub_monitor->mutex);
+ {
+ while (!scrub_monitor->inited)
+ pthread_cond_wait(&scrub_monitor->cond, &scrub_monitor->mutex);
+ }
+ pthread_mutex_unlock(&scrub_monitor->mutex);
+
+ /* this needs to be serialized with reconfigure() */
+ pthread_mutex_lock(&priv->lock);
+ {
+ ret = br_scrub_state_machine(this, _gf_false);
+ }
+ pthread_mutex_unlock(&priv->lock);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, -ret, BRB_MSG_SSM_FAILED,
+ "Scrub state machine failed");
+ goto out;
+ }
+
+ while (1) {
+ /* Wait for all children to finish scrubbing */
+ ret = wait_for_scrub_to_finish(this);
if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, -ret,
- BRB_MSG_SSM_FAILED,
- "Scrub state machine failed");
- goto out;
+ gf_msg(this->name, GF_LOG_ERROR, -ret, BRB_MSG_SCRUB_WAIT_FAILED,
+ "Scrub wait failed");
+ goto out;
}
- while (1) {
- /* Wait for all children to finish scrubbing */
- ret = wait_for_scrub_to_finish (this);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, -ret,
- BRB_MSG_SCRUB_WAIT_FAILED,
- "Scrub wait failed");
- goto out;
- }
-
- /* scrub exit criteria: Move the state to PENDING */
- br_scrubber_exit_control (this);
- }
+ /* scrub exit criteria: Move the state to PENDING */
+ br_scrubber_exit_control(this);
+ }
out:
- return NULL;
+ return NULL;
}
static void
-br_set_scrub_state (struct br_monitor *scrub_monitor, br_scrub_state_t state)
+br_set_scrub_state(struct br_monitor *scrub_monitor, br_scrub_state_t state)
{
- LOCK (&scrub_monitor->lock);
- {
- _br_monitor_set_scrub_state (scrub_monitor, state);
- }
- UNLOCK (&scrub_monitor->lock);
+ LOCK(&scrub_monitor->lock);
+ {
+ _br_monitor_set_scrub_state(scrub_monitor, state);
+ }
+ UNLOCK(&scrub_monitor->lock);
}
int32_t
-br_scrubber_monitor_init (xlator_t *this, br_private_t *priv)
+br_scrubber_monitor_init(xlator_t *this, br_private_t *priv)
{
- struct br_monitor *scrub_monitor = NULL;
- int ret = 0;
+ struct br_monitor *scrub_monitor = NULL;
+ int ret = 0;
- scrub_monitor = &priv->scrub_monitor;
+ scrub_monitor = &priv->scrub_monitor;
- LOCK_INIT (&scrub_monitor->lock);
- scrub_monitor->this = this;
+ LOCK_INIT(&scrub_monitor->lock);
+ scrub_monitor->this = this;
- scrub_monitor->inited = _gf_false;
- pthread_mutex_init (&scrub_monitor->mutex, NULL);
- pthread_cond_init (&scrub_monitor->cond, NULL);
+ scrub_monitor->inited = _gf_false;
+ pthread_mutex_init(&scrub_monitor->mutex, NULL);
+ pthread_cond_init(&scrub_monitor->cond, NULL);
- scrub_monitor->kick = _gf_false;
- scrub_monitor->active_child_count = 0;
- pthread_mutex_init (&scrub_monitor->wakelock, NULL);
- pthread_cond_init (&scrub_monitor->wakecond, NULL);
+ scrub_monitor->kick = _gf_false;
+ scrub_monitor->active_child_count = 0;
+ pthread_mutex_init(&scrub_monitor->wakelock, NULL);
+ pthread_cond_init(&scrub_monitor->wakecond, NULL);
- scrub_monitor->done = _gf_false;
- pthread_mutex_init (&scrub_monitor->donelock, NULL);
- pthread_cond_init (&scrub_monitor->donecond, NULL);
-
- /* Set the state to INACTIVE */
- br_set_scrub_state (&priv->scrub_monitor, BR_SCRUB_STATE_INACTIVE);
-
- /* Start the monitor thread */
- ret = gf_thread_create (&scrub_monitor->thread, NULL,
- br_monitor_thread, this, "brmon");
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, -ret,
- BRB_MSG_SPAWN_FAILED, "monitor thread creation failed");
- ret = -1;
- goto err;
- }
+ scrub_monitor->done = _gf_false;
+ pthread_mutex_init(&scrub_monitor->donelock, NULL);
+ pthread_cond_init(&scrub_monitor->donecond, NULL);
- return 0;
+ /* Set the state to INACTIVE */
+ br_set_scrub_state(&priv->scrub_monitor, BR_SCRUB_STATE_INACTIVE);
+
+ /* Start the monitor thread */
+ ret = gf_thread_create(&scrub_monitor->thread, NULL, br_monitor_thread,
+ this, "brmon");
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, -ret, BRB_MSG_SPAWN_FAILED,
+ "monitor thread creation failed");
+ ret = -1;
+ goto err;
+ }
+
+ return 0;
err:
- pthread_mutex_destroy (&scrub_monitor->mutex);
- pthread_cond_destroy (&scrub_monitor->cond);
+ pthread_mutex_destroy(&scrub_monitor->mutex);
+ pthread_cond_destroy(&scrub_monitor->cond);
- pthread_mutex_destroy (&scrub_monitor->wakelock);
- pthread_cond_destroy (&scrub_monitor->wakecond);
+ pthread_mutex_destroy(&scrub_monitor->wakelock);
+ pthread_cond_destroy(&scrub_monitor->wakecond);
- pthread_mutex_destroy (&scrub_monitor->donelock);
- pthread_cond_destroy (&scrub_monitor->donecond);
+ pthread_mutex_destroy(&scrub_monitor->donelock);
+ pthread_cond_destroy(&scrub_monitor->donecond);
- LOCK_DESTROY (&scrub_monitor->lock);
+ LOCK_DESTROY(&scrub_monitor->lock);
- return ret;
+ return ret;
}
int32_t
-br_scrubber_init (xlator_t *this, br_private_t *priv)
+br_scrubber_init(xlator_t *this, br_private_t *priv)
{
- struct br_scrubber *fsscrub = NULL;
- int ret = 0;
+ struct br_scrubber *fsscrub = NULL;
+ int ret = 0;
- priv->tbf = tbf_init (NULL, 0);
- if (!priv->tbf)
- return -1;
+ priv->tbf = tbf_init(NULL, 0);
+ if (!priv->tbf)
+ return -1;
- ret = br_scrubber_monitor_init (this, priv);
- if (ret)
- return -1;
+ ret = br_scrubber_monitor_init(this, priv);
+ if (ret)
+ return -1;
- fsscrub = &priv->fsscrub;
+ fsscrub = &priv->fsscrub;
- fsscrub->this = this;
- fsscrub->throttle = BR_SCRUB_THROTTLE_VOID;
+ fsscrub->this = this;
+ fsscrub->throttle = BR_SCRUB_THROTTLE_VOID;
- pthread_mutex_init (&fsscrub->mutex, NULL);
- pthread_cond_init (&fsscrub->cond, NULL);
+ pthread_mutex_init(&fsscrub->mutex, NULL);
+ pthread_cond_init(&fsscrub->cond, NULL);
- fsscrub->nr_scrubbers = 0;
- INIT_LIST_HEAD (&fsscrub->scrubbers);
- INIT_LIST_HEAD (&fsscrub->scrublist);
+ fsscrub->nr_scrubbers = 0;
+ INIT_LIST_HEAD(&fsscrub->scrubbers);
+ INIT_LIST_HEAD(&fsscrub->scrublist);
- return 0;
+ return 0;
}
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot-ssm.c b/xlators/features/bit-rot/src/bitd/bit-rot-ssm.c
index af887a1ff8b..753e31a3b23 100644
--- a/xlators/features/bit-rot/src/bitd/bit-rot-ssm.c
+++ b/xlators/features/bit-rot/src/bitd/bit-rot-ssm.c
@@ -12,78 +12,79 @@
#include "bit-rot-scrub.h"
#include "bit-rot-bitd-messages.h"
-int br_scrub_ssm_noop (xlator_t *this)
+int
+br_scrub_ssm_noop(xlator_t *this)
{
- return 0;
+ return 0;
}
int
-br_scrub_ssm_state_pause (xlator_t *this)
+br_scrub_ssm_state_pause(xlator_t *this)
{
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_GENERIC_SSM_INFO,
- "Scrubber paused");
- _br_monitor_set_scrub_state (scrub_monitor, BR_SCRUB_STATE_PAUSED);
- return 0;
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_GENERIC_SSM_INFO,
+ "Scrubber paused");
+ _br_monitor_set_scrub_state(scrub_monitor, BR_SCRUB_STATE_PAUSED);
+ return 0;
}
int
-br_scrub_ssm_state_ipause (xlator_t *this)
+br_scrub_ssm_state_ipause(xlator_t *this)
{
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_GENERIC_SSM_INFO,
- "Scrubber paused");
- _br_monitor_set_scrub_state (scrub_monitor, BR_SCRUB_STATE_IPAUSED);
- return 0;
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_GENERIC_SSM_INFO,
+ "Scrubber paused");
+ _br_monitor_set_scrub_state(scrub_monitor, BR_SCRUB_STATE_IPAUSED);
+ return 0;
}
int
-br_scrub_ssm_state_active (xlator_t *this)
+br_scrub_ssm_state_active(xlator_t *this)
{
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
- if (scrub_monitor->done) {
- (void) br_fsscan_activate (this);
- } else {
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_GENERIC_SSM_INFO,
- "Scrubbing resumed");
- _br_monitor_set_scrub_state (scrub_monitor, BR_SCRUB_STATE_ACTIVE);
- }
+ if (scrub_monitor->done) {
+ (void)br_fsscan_activate(this);
+ } else {
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_GENERIC_SSM_INFO,
+ "Scrubbing resumed");
+ _br_monitor_set_scrub_state(scrub_monitor, BR_SCRUB_STATE_ACTIVE);
+ }
- return 0;
+ return 0;
}
int
-br_scrub_ssm_state_stall (xlator_t *this)
+br_scrub_ssm_state_stall(xlator_t *this)
{
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_GENERIC_SSM_INFO,
- "Volume is under active scrubbing. Pausing scrub..");
- _br_monitor_set_scrub_state (scrub_monitor, BR_SCRUB_STATE_STALLED);
- return 0;
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_GENERIC_SSM_INFO,
+ "Volume is under active scrubbing. Pausing scrub..");
+ _br_monitor_set_scrub_state(scrub_monitor, BR_SCRUB_STATE_STALLED);
+ return 0;
}
-static br_scrub_ssm_call *
-br_scrub_ssm[BR_SCRUB_MAXSTATES][BR_SCRUB_MAXEVENTS] = {
+static br_scrub_ssm_call *br_scrub_ssm[BR_SCRUB_MAXSTATES][BR_SCRUB_MAXEVENTS] =
+ {
/* INACTIVE */
{br_fsscan_schedule, br_scrub_ssm_state_ipause, br_scrub_ssm_noop},
/* PENDING */
@@ -99,25 +100,25 @@ br_scrub_ssm[BR_SCRUB_MAXSTATES][BR_SCRUB_MAXEVENTS] = {
};
int32_t
-br_scrub_state_machine (xlator_t *this, gf_boolean_t scrub_ondemand)
+br_scrub_state_machine(xlator_t *this, gf_boolean_t scrub_ondemand)
{
- br_private_t *priv = NULL;
- br_scrub_ssm_call *call = NULL;
- struct br_scrubber *fsscrub = NULL;
- br_scrub_state_t currstate = 0;
- br_scrub_event_t event = 0;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
- fsscrub = &priv->fsscrub;
- scrub_monitor = &priv->scrub_monitor;
-
- currstate = scrub_monitor->state;
- if (scrub_ondemand)
- event = BR_SCRUB_EVENT_ONDEMAND;
- else
- event = _br_child_get_scrub_event (fsscrub);
-
- call = br_scrub_ssm[currstate][event];
- return call (this);
+ br_private_t *priv = NULL;
+ br_scrub_ssm_call *call = NULL;
+ struct br_scrubber *fsscrub = NULL;
+ br_scrub_state_t currstate = 0;
+ br_scrub_event_t event = 0;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+ fsscrub = &priv->fsscrub;
+ scrub_monitor = &priv->scrub_monitor;
+
+ currstate = scrub_monitor->state;
+ if (scrub_ondemand)
+ event = BR_SCRUB_EVENT_ONDEMAND;
+ else
+ event = _br_child_get_scrub_event(fsscrub);
+
+ call = br_scrub_ssm[currstate][event];
+ return call(this);
}
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot.c b/xlators/features/bit-rot/src/bitd/bit-rot.c
index cf59232263b..75fa0490c90 100644
--- a/xlators/features/bit-rot/src/bitd/bit-rot.c
+++ b/xlators/features/bit-rot/src/bitd/bit-rot.c
@@ -21,72 +21,72 @@
#include <pthread.h>
#include "bit-rot-bitd-messages.h"
-#define BR_HASH_CALC_READ_SIZE (128 * 1024)
+#define BR_HASH_CALC_READ_SIZE (128 * 1024)
-typedef int32_t (br_child_handler)(xlator_t *, br_child_t *);
+typedef int32_t(br_child_handler)(xlator_t *, br_child_t *);
struct br_child_event {
- xlator_t *this;
+ xlator_t *this;
- br_child_t *child;
+ br_child_t *child;
- br_child_handler *call;
+ br_child_handler *call;
- struct list_head list;
+ struct list_head list;
};
static int
-br_find_child_index (xlator_t *this, xlator_t *child)
+br_find_child_index(xlator_t *this, xlator_t *child)
{
- br_private_t *priv = NULL;
- int i = -1;
- int index = -1;
+ br_private_t *priv = NULL;
+ int i = -1;
+ int index = -1;
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
- GF_VALIDATE_OR_GOTO (this->name, this->private, out);
- GF_VALIDATE_OR_GOTO (this->name, child, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, out);
+ GF_VALIDATE_OR_GOTO(this->name, child, out);
- priv = this->private;
+ priv = this->private;
- for (i = 0; i < priv->child_count; i++) {
- if (child == priv->children[i].xl) {
- index = i;
- break;
- }
+ for (i = 0; i < priv->child_count; i++) {
+ if (child == priv->children[i].xl) {
+ index = i;
+ break;
}
+ }
out:
- return index;
+ return index;
}
br_child_t *
-br_get_child_from_brick_path (xlator_t *this, char *brick_path)
+br_get_child_from_brick_path(xlator_t *this, char *brick_path)
{
- br_private_t *priv = NULL;
- br_child_t *child = NULL;
- br_child_t *tmp = NULL;
- int i = 0;
+ br_private_t *priv = NULL;
+ br_child_t *child = NULL;
+ br_child_t *tmp = NULL;
+ int i = 0;
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
- GF_VALIDATE_OR_GOTO (this->name, this->private, out);
- GF_VALIDATE_OR_GOTO (this->name, brick_path, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, out);
+ GF_VALIDATE_OR_GOTO(this->name, brick_path, out);
- priv = this->private;
+ priv = this->private;
- pthread_mutex_lock (&priv->lock);
- {
- for (i = 0; i < priv->child_count; i++) {
- tmp = &priv->children[i];
- if (!strcmp (tmp->brick_path, brick_path)) {
- child = tmp;
- break;
- }
- }
+ pthread_mutex_lock(&priv->lock);
+ {
+ for (i = 0; i < priv->child_count; i++) {
+ tmp = &priv->children[i];
+ if (!strcmp(tmp->brick_path, brick_path)) {
+ child = tmp;
+ break;
+ }
}
- pthread_mutex_unlock (&priv->lock);
+ }
+ pthread_mutex_unlock(&priv->lock);
out:
- return child;
+ return child;
}
/**
@@ -94,18 +94,18 @@ out:
* needed -- later.
*/
void *
-br_brick_init (void *xl, struct gf_brick_spec *brick)
+br_brick_init(void *xl, struct gf_brick_spec *brick)
{
- return brick;
+ return brick;
}
/**
* and cleanup things here when allocated br_brick_init().
*/
void
-br_brick_fini (void *xl, char *brick, void *data)
+br_brick_fini(void *xl, char *brick, void *data)
{
- return;
+ return;
}
/**
@@ -117,109 +117,109 @@ br_brick_fini (void *xl, char *brick, void *data)
* change stub to handle this change.
*/
static br_isignature_t *
-br_prepare_signature (const unsigned char *sign,
- unsigned long hashlen,
- int8_t hashtype, br_object_t *object)
+br_prepare_signature(const unsigned char *sign, unsigned long hashlen,
+ int8_t hashtype, br_object_t *object)
{
- br_isignature_t *signature = NULL;
+ br_isignature_t *signature = NULL;
- /* TODO: use mem-pool */
- signature = GF_CALLOC (1, signature_size (hashlen + 1),
- gf_br_stub_mt_signature_t);
- if (!signature)
- return NULL;
+ /* TODO: use mem-pool */
+ signature = GF_CALLOC(1, signature_size(hashlen + 1),
+ gf_br_stub_mt_signature_t);
+ if (!signature)
+ return NULL;
- /* object version */
- signature->signedversion = object->signedversion;
+ /* object version */
+ signature->signedversion = object->signedversion;
- /* signature length & type */
- signature->signaturelen = hashlen;
- signature->signaturetype = hashtype;
+ /* signature length & type */
+ signature->signaturelen = hashlen;
+ signature->signaturetype = hashtype;
- /* signature itself */
- memcpy (signature->signature, (char *)sign, hashlen);
- signature->signature[hashlen+1] = '\0';
+ /* signature itself */
+ memcpy(signature->signature, (char *)sign, hashlen);
+ signature->signature[hashlen + 1] = '\0';
- return signature;
+ return signature;
}
gf_boolean_t
-bitd_is_bad_file (xlator_t *this, br_child_t *child, loc_t *loc, fd_t *fd)
+bitd_is_bad_file(xlator_t *this, br_child_t *child, loc_t *loc, fd_t *fd)
{
- int32_t ret = -1;
- dict_t *xattr = NULL;
- inode_t *inode = NULL;
- gf_boolean_t bad_file = _gf_false;
+ int32_t ret = -1;
+ dict_t *xattr = NULL;
+ inode_t *inode = NULL;
+ gf_boolean_t bad_file = _gf_false;
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
- inode = (loc) ? loc->inode : fd->inode;
+ inode = (loc) ? loc->inode : fd->inode;
- if (fd)
- ret = syncop_fgetxattr (child->xl, fd, &xattr,
- BITROT_OBJECT_BAD_KEY, NULL, NULL);
- else if (loc)
- ret = syncop_getxattr (child->xl, loc,
- &xattr, BITROT_OBJECT_BAD_KEY, NULL,
- NULL);
+ if (fd)
+ ret = syncop_fgetxattr(child->xl, fd, &xattr, BITROT_OBJECT_BAD_KEY,
+ NULL, NULL);
+ else if (loc)
+ ret = syncop_getxattr(child->xl, loc, &xattr, BITROT_OBJECT_BAD_KEY,
+ NULL, NULL);
- if (!ret) {
- gf_msg_debug (this->name, 0, "[GFID: %s] is marked corrupted",
- uuid_utoa (inode->gfid));
- bad_file = _gf_true;
- }
+ if (!ret) {
+ gf_msg_debug(this->name, 0, "[GFID: %s] is marked corrupted",
+ uuid_utoa(inode->gfid));
+ bad_file = _gf_true;
+ }
- if (xattr)
- dict_unref (xattr);
+ if (xattr)
+ dict_unref(xattr);
out:
- return bad_file;
+ return bad_file;
}
/**
* Do a lookup on the gfid present within the object.
*/
static int32_t
-br_object_lookup (xlator_t *this, br_object_t *object,
- struct iatt *iatt, inode_t **linked_inode)
+br_object_lookup(xlator_t *this, br_object_t *object, struct iatt *iatt,
+ inode_t **linked_inode)
{
- int ret = -EINVAL;
- loc_t loc = {0, };
- inode_t *inode = NULL;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
- GF_VALIDATE_OR_GOTO (this->name, object, out);
-
- inode = inode_find (object->child->table, object->gfid);
-
- if (inode)
- loc.inode = inode;
- else
- loc.inode = inode_new (object->child->table);
-
- if (!loc.inode) {
- ret = -ENOMEM;
- goto out;
- }
-
- gf_uuid_copy (loc.gfid, object->gfid);
-
- ret = syncop_lookup (object->child->xl, &loc, iatt, NULL, NULL, NULL);
- if (ret < 0)
- goto out;
-
- /*
- * The file might have been deleted by the application
- * after getting the event, but before doing a lookup.
- * So use linked_inode after inode_link is done.
- */
- *linked_inode = inode_link (loc.inode, NULL, NULL, iatt);
- if (*linked_inode)
- inode_lookup (*linked_inode);
+ int ret = -EINVAL;
+ loc_t loc = {
+ 0,
+ };
+ inode_t *inode = NULL;
+
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, object, out);
+
+ inode = inode_find(object->child->table, object->gfid);
+
+ if (inode)
+ loc.inode = inode;
+ else
+ loc.inode = inode_new(object->child->table);
+
+ if (!loc.inode) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ gf_uuid_copy(loc.gfid, object->gfid);
+
+ ret = syncop_lookup(object->child->xl, &loc, iatt, NULL, NULL, NULL);
+ if (ret < 0)
+ goto out;
+
+ /*
+ * The file might have been deleted by the application
+ * after getting the event, but before doing a lookup.
+ * So use linked_inode after inode_link is done.
+ */
+ *linked_inode = inode_link(loc.inode, NULL, NULL, iatt);
+ if (*linked_inode)
+ inode_lookup(*linked_inode);
out:
- loc_wipe (&loc);
- return ret;
+ loc_wipe(&loc);
+ return ret;
}
/**
@@ -228,43 +228,44 @@ out:
* passing xdata -- may be use frame->root->pid itself.
*/
static int32_t
-br_object_open (xlator_t *this,
- br_object_t *object, inode_t *inode, fd_t **openfd)
+br_object_open(xlator_t *this, br_object_t *object, inode_t *inode,
+ fd_t **openfd)
{
- int32_t ret = -1;
- fd_t *fd = NULL;
- loc_t loc = {0, };
-
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
- GF_VALIDATE_OR_GOTO (this->name, object, out);
- GF_VALIDATE_OR_GOTO (this->name, inode, out);
-
- ret = -EINVAL;
- fd = fd_create (inode, 0);
- if (!fd) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_FD_CREATE_FAILED,
- "failed to create fd for the inode %s",
- uuid_utoa (inode->gfid));
- goto out;
- }
-
- loc.inode = inode_ref (inode);
- gf_uuid_copy (loc.gfid, inode->gfid);
-
- ret = syncop_open (object->child->xl, &loc, O_RDONLY, fd, NULL, NULL);
- if (ret) {
- br_log_object (this, "open", inode->gfid, -ret);
- fd_unref (fd);
- fd = NULL;
- } else {
- fd_bind (fd);
- *openfd = fd;
- }
-
- loc_wipe (&loc);
+ int32_t ret = -1;
+ fd_t *fd = NULL;
+ loc_t loc = {
+ 0,
+ };
+
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, object, out);
+ GF_VALIDATE_OR_GOTO(this->name, inode, out);
+
+ ret = -EINVAL;
+ fd = fd_create(inode, 0);
+ if (!fd) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_FD_CREATE_FAILED,
+ "failed to create fd for the inode %s", uuid_utoa(inode->gfid));
+ goto out;
+ }
+
+ loc.inode = inode_ref(inode);
+ gf_uuid_copy(loc.gfid, inode->gfid);
+
+ ret = syncop_open(object->child->xl, &loc, O_RDONLY, fd, NULL, NULL);
+ if (ret) {
+ br_log_object(this, "open", inode->gfid, -ret);
+ fd_unref(fd);
+ fd = NULL;
+ } else {
+ fd_bind(fd);
+ *openfd = fd;
+ }
+
+ loc_wipe(&loc);
out:
- return ret;
+ return ret;
}
/**
@@ -272,287 +273,289 @@ out:
* and return the buffer.
*/
static int32_t
-br_object_read_block_and_sign (xlator_t *this, fd_t *fd, br_child_t *child,
- off_t offset, size_t size, SHA256_CTX *sha256)
+br_object_read_block_and_sign(xlator_t *this, fd_t *fd, br_child_t *child,
+ off_t offset, size_t size, SHA256_CTX *sha256)
{
- int32_t ret = -1;
- tbf_t *tbf = NULL;
- struct iovec *iovec = NULL;
- struct iobref *iobref = NULL;
- br_private_t *priv = NULL;
- int count = 0;
- int i = 0;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
- GF_VALIDATE_OR_GOTO (this->name, fd, out);
- GF_VALIDATE_OR_GOTO (this->name, fd->inode, out);
- GF_VALIDATE_OR_GOTO (this->name, child, out);
- GF_VALIDATE_OR_GOTO (this->name, this->private, out);
-
- priv = this->private;
-
- GF_VALIDATE_OR_GOTO (this->name, priv->tbf, out);
- tbf = priv->tbf;
-
- ret = syncop_readv (child->xl, fd,
- size, offset, 0, &iovec, &count, &iobref, NULL,
- NULL, NULL);
-
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno, BRB_MSG_READV_FAILED,
- "readv on %s failed", uuid_utoa (fd->inode->gfid));
- ret = -1;
- goto out;
- }
+ int32_t ret = -1;
+ tbf_t *tbf = NULL;
+ struct iovec *iovec = NULL;
+ struct iobref *iobref = NULL;
+ br_private_t *priv = NULL;
+ int count = 0;
+ int i = 0;
+
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, fd, out);
+ GF_VALIDATE_OR_GOTO(this->name, fd->inode, out);
+ GF_VALIDATE_OR_GOTO(this->name, child, out);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, out);
+
+ priv = this->private;
+
+ GF_VALIDATE_OR_GOTO(this->name, priv->tbf, out);
+ tbf = priv->tbf;
+
+ ret = syncop_readv(child->xl, fd, size, offset, 0, &iovec, &count, &iobref,
+ NULL, NULL, NULL);
+
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, BRB_MSG_READV_FAILED,
+ "readv on %s failed", uuid_utoa(fd->inode->gfid));
+ ret = -1;
+ goto out;
+ }
- if (ret == 0)
- goto out;
+ if (ret == 0)
+ goto out;
- for (i = 0; i < count; i++) {
- TBF_THROTTLE_BEGIN (tbf, TBF_OP_HASH, iovec[i].iov_len);
- {
- SHA256_Update (sha256, (const unsigned char *)
- (iovec[i].iov_base), iovec[i].iov_len);
- }
- TBF_THROTTLE_BEGIN (tbf, TBF_OP_HASH, iovec[i].iov_len);
+ for (i = 0; i < count; i++) {
+ TBF_THROTTLE_BEGIN(tbf, TBF_OP_HASH, iovec[i].iov_len);
+ {
+ SHA256_Update(sha256, (const unsigned char *)(iovec[i].iov_base),
+ iovec[i].iov_len);
}
+ TBF_THROTTLE_BEGIN(tbf, TBF_OP_HASH, iovec[i].iov_len);
+ }
- out:
- if (iovec)
- GF_FREE (iovec);
+out:
+ if (iovec)
+ GF_FREE(iovec);
- if (iobref)
- iobref_unref (iobref);
+ if (iobref)
+ iobref_unref(iobref);
- return ret;
+ return ret;
}
int32_t
-br_calculate_obj_checksum (unsigned char *md,
- br_child_t *child, fd_t *fd, struct iatt *iatt)
+br_calculate_obj_checksum(unsigned char *md, br_child_t *child, fd_t *fd,
+ struct iatt *iatt)
{
- int32_t ret = -1;
- off_t offset = 0;
- size_t block = BR_HASH_CALC_READ_SIZE;
- xlator_t *this = NULL;
-
- SHA256_CTX sha256;
+ int32_t ret = -1;
+ off_t offset = 0;
+ size_t block = BR_HASH_CALC_READ_SIZE;
+ xlator_t *this = NULL;
- GF_VALIDATE_OR_GOTO ("bit-rot", child, out);
- GF_VALIDATE_OR_GOTO ("bit-rot", iatt, out);
- GF_VALIDATE_OR_GOTO ("bit-rot", fd, out);
+ SHA256_CTX sha256;
- this = child->this;
+ GF_VALIDATE_OR_GOTO("bit-rot", child, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", iatt, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", fd, out);
- SHA256_Init (&sha256);
+ this = child->this;
- while (1) {
- ret = br_object_read_block_and_sign (this, fd, child,
- offset, block, &sha256);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_BLOCK_READ_FAILED, "reading block with "
- "offset %lu of object %s failed", offset,
- uuid_utoa (fd->inode->gfid));
- break;
- }
+ SHA256_Init(&sha256);
- if (ret == 0)
- break;
-
- offset += ret;
+ while (1) {
+ ret = br_object_read_block_and_sign(this, fd, child, offset, block,
+ &sha256);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_BLOCK_READ_FAILED,
+ "reading block with "
+ "offset %lu of object %s failed",
+ offset, uuid_utoa(fd->inode->gfid));
+ break;
}
if (ret == 0)
- SHA256_Final (md, &sha256);
+ break;
- out:
- return ret;
+ offset += ret;
+ }
+
+ if (ret == 0)
+ SHA256_Final(md, &sha256);
+
+out:
+ return ret;
}
static int32_t
-br_object_checksum (unsigned char *md,
- br_object_t *object, fd_t *fd, struct iatt *iatt)
+br_object_checksum(unsigned char *md, br_object_t *object, fd_t *fd,
+ struct iatt *iatt)
{
- return br_calculate_obj_checksum (md, object->child, fd, iatt);
+ return br_calculate_obj_checksum(md, object->child, fd, iatt);
}
static int32_t
-br_object_read_sign (inode_t *linked_inode, fd_t *fd, br_object_t *object,
- struct iatt *iatt)
+br_object_read_sign(inode_t *linked_inode, fd_t *fd, br_object_t *object,
+ struct iatt *iatt)
{
- int32_t ret = -1;
- xlator_t *this = NULL;
- dict_t *xattr = NULL;
- unsigned char *md = NULL;
- br_isignature_t *sign = NULL;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", object, out);
- GF_VALIDATE_OR_GOTO ("bit-rot", linked_inode, out);
- GF_VALIDATE_OR_GOTO ("bit-rot", fd, out);
-
- this = object->this;
-
- md = GF_MALLOC (SHA256_DIGEST_LENGTH, gf_common_mt_char);
- if (!md) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
- "failed to allocate memory for saving hash of the "
- "object %s", uuid_utoa (fd->inode->gfid));
- goto out;
- }
-
- ret = br_object_checksum (md, object, fd, iatt);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_CALC_CHECKSUM_FAILED, "calculating checksum "
- "for the object %s failed",
- uuid_utoa (linked_inode->gfid));
- goto free_signature;
- }
-
- sign = br_prepare_signature (md, SHA256_DIGEST_LENGTH,
- BR_SIGNATURE_TYPE_SHA256, object);
- if (!sign) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_GET_SIGN_FAILED,
- "failed to get the signature for the object %s",
- uuid_utoa (fd->inode->gfid));
- goto free_signature;
- }
-
- xattr = dict_for_key_value
- (GLUSTERFS_SET_OBJECT_SIGNATURE,
- (void *)sign, signature_size (SHA256_DIGEST_LENGTH), _gf_true);
-
- if (!xattr) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_SET_SIGN_FAILED,
- "dict allocation for signing failed for the object %s",
- uuid_utoa (fd->inode->gfid));
- goto free_isign;
- }
-
- ret = syncop_fsetxattr (object->child->xl, fd, xattr, 0, NULL, NULL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_SET_SIGN_FAILED,
- "fsetxattr of signature to the object %s failed",
- uuid_utoa (fd->inode->gfid));
- goto unref_dict;
- }
-
- ret = 0;
-
- unref_dict:
- dict_unref (xattr);
- free_isign:
- GF_FREE (sign);
- free_signature:
- GF_FREE (md);
- out:
- return ret;
+ int32_t ret = -1;
+ xlator_t *this = NULL;
+ dict_t *xattr = NULL;
+ unsigned char *md = NULL;
+ br_isignature_t *sign = NULL;
+
+ GF_VALIDATE_OR_GOTO("bit-rot", object, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", linked_inode, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", fd, out);
+
+ this = object->this;
+
+ md = GF_MALLOC(SHA256_DIGEST_LENGTH, gf_common_mt_char);
+ if (!md) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
+ "failed to allocate memory for saving hash of the "
+ "object %s",
+ uuid_utoa(fd->inode->gfid));
+ goto out;
+ }
+
+ ret = br_object_checksum(md, object, fd, iatt);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_CALC_CHECKSUM_FAILED,
+ "calculating checksum "
+ "for the object %s failed",
+ uuid_utoa(linked_inode->gfid));
+ goto free_signature;
+ }
+
+ sign = br_prepare_signature(md, SHA256_DIGEST_LENGTH,
+ BR_SIGNATURE_TYPE_SHA256, object);
+ if (!sign) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_GET_SIGN_FAILED,
+ "failed to get the signature for the object %s",
+ uuid_utoa(fd->inode->gfid));
+ goto free_signature;
+ }
+
+ xattr = dict_for_key_value(GLUSTERFS_SET_OBJECT_SIGNATURE, (void *)sign,
+ signature_size(SHA256_DIGEST_LENGTH), _gf_true);
+
+ if (!xattr) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_SET_SIGN_FAILED,
+ "dict allocation for signing failed for the object %s",
+ uuid_utoa(fd->inode->gfid));
+ goto free_isign;
+ }
+
+ ret = syncop_fsetxattr(object->child->xl, fd, xattr, 0, NULL, NULL);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_SET_SIGN_FAILED,
+ "fsetxattr of signature to the object %s failed",
+ uuid_utoa(fd->inode->gfid));
+ goto unref_dict;
+ }
+
+ ret = 0;
+
+unref_dict:
+ dict_unref(xattr);
+free_isign:
+ GF_FREE(sign);
+free_signature:
+ GF_FREE(md);
+out:
+ return ret;
}
-static int br_object_sign_softerror (int32_t op_errno)
+static int
+br_object_sign_softerror(int32_t op_errno)
{
- return ((op_errno == ENOENT) || (op_errno == ESTALE)
- || (op_errno == ENODATA));
+ return ((op_errno == ENOENT) || (op_errno == ESTALE) ||
+ (op_errno == ENODATA));
}
void
-br_log_object (xlator_t *this, char *op, uuid_t gfid, int32_t op_errno)
+br_log_object(xlator_t *this, char *op, uuid_t gfid, int32_t op_errno)
{
- int softerror = br_object_sign_softerror (op_errno);
- if (softerror) {
- gf_msg_debug (this->name, 0, "%s() failed on object %s "
- "[reason: %s]", op, uuid_utoa (gfid),
- strerror (op_errno));
- } else {
- gf_msg (this->name, GF_LOG_ERROR, op_errno, BRB_MSG_OP_FAILED,
- "%s() failed on object %s", op, uuid_utoa (gfid));
- }
+ int softerror = br_object_sign_softerror(op_errno);
+ if (softerror) {
+ gf_msg_debug(this->name, 0,
+ "%s() failed on object %s "
+ "[reason: %s]",
+ op, uuid_utoa(gfid), strerror(op_errno));
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, BRB_MSG_OP_FAILED,
+ "%s() failed on object %s", op, uuid_utoa(gfid));
+ }
}
void
-br_log_object_path (xlator_t *this, char *op,
- const char *path, int32_t op_errno)
+br_log_object_path(xlator_t *this, char *op, const char *path, int32_t op_errno)
{
- int softerror = br_object_sign_softerror (op_errno);
- if (softerror) {
- gf_msg_debug (this->name, 0, "%s() failed on object %s "
- "[reason: %s]", op, path, strerror (op_errno));
- } else {
- gf_msg (this->name, GF_LOG_ERROR, op_errno, BRB_MSG_OP_FAILED,
- "%s() failed on object %s", op, path);
- }
+ int softerror = br_object_sign_softerror(op_errno);
+ if (softerror) {
+ gf_msg_debug(this->name, 0,
+ "%s() failed on object %s "
+ "[reason: %s]",
+ op, path, strerror(op_errno));
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, BRB_MSG_OP_FAILED,
+ "%s() failed on object %s", op, path);
+ }
}
static void
-br_trigger_sign (xlator_t *this, br_child_t *child,
- inode_t *linked_inode, loc_t *loc, gf_boolean_t need_reopen)
+br_trigger_sign(xlator_t *this, br_child_t *child, inode_t *linked_inode,
+ loc_t *loc, gf_boolean_t need_reopen)
{
- fd_t *fd = NULL;
- int32_t ret = -1;
- uint32_t val = 0;
- dict_t *dict = NULL;
- pid_t pid = GF_CLIENT_PID_BITD;
-
- syncopctx_setfspid (&pid);
-
- val = (need_reopen == _gf_true) ? BR_OBJECT_REOPEN : BR_OBJECT_RESIGN;
-
- dict = dict_new ();
- if (!dict)
- goto out;
-
- ret = dict_set_uint32 (dict, BR_REOPEN_SIGN_HINT_KEY, val);
- if (ret)
- goto cleanup_dict;
-
- ret = -1;
- fd = fd_create (linked_inode, 0);
- if (!fd) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_FD_CREATE_FAILED,
- "Failed to create fd [GFID %s]",
- uuid_utoa (linked_inode->gfid));
- goto cleanup_dict;
- }
-
- ret = syncop_open (child->xl, loc, O_RDWR, fd, NULL, NULL);
- if (ret) {
- br_log_object (this, "open", linked_inode->gfid, -ret);
- goto unref_fd;
- }
-
- fd_bind (fd);
-
- ret = syncop_fsetxattr (child->xl, fd, dict, 0, NULL, NULL);
- if (ret)
- br_log_object (this, "fsetxattr", linked_inode->gfid, -ret);
-
- /* passthough: fd_unref() */
-
- unref_fd:
- fd_unref (fd);
- cleanup_dict:
- dict_unref (dict);
- out:
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, 0, BRB_MSG_TRIGGER_SIGN,
- "Could not trigger signingd for %s (reopen hint: %d)",
- uuid_utoa (linked_inode->gfid), val);
- }
+ fd_t *fd = NULL;
+ int32_t ret = -1;
+ uint32_t val = 0;
+ dict_t *dict = NULL;
+ pid_t pid = GF_CLIENT_PID_BITD;
+
+ syncopctx_setfspid(&pid);
+
+ val = (need_reopen == _gf_true) ? BR_OBJECT_REOPEN : BR_OBJECT_RESIGN;
+
+ dict = dict_new();
+ if (!dict)
+ goto out;
+
+ ret = dict_set_uint32(dict, BR_REOPEN_SIGN_HINT_KEY, val);
+ if (ret)
+ goto cleanup_dict;
+
+ ret = -1;
+ fd = fd_create(linked_inode, 0);
+ if (!fd) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_FD_CREATE_FAILED,
+ "Failed to create fd [GFID %s]", uuid_utoa(linked_inode->gfid));
+ goto cleanup_dict;
+ }
+
+ ret = syncop_open(child->xl, loc, O_RDWR, fd, NULL, NULL);
+ if (ret) {
+ br_log_object(this, "open", linked_inode->gfid, -ret);
+ goto unref_fd;
+ }
+
+ fd_bind(fd);
+
+ ret = syncop_fsetxattr(child->xl, fd, dict, 0, NULL, NULL);
+ if (ret)
+ br_log_object(this, "fsetxattr", linked_inode->gfid, -ret);
+
+ /* passthough: fd_unref() */
+
+unref_fd:
+ fd_unref(fd);
+cleanup_dict:
+ dict_unref(dict);
+out:
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRB_MSG_TRIGGER_SIGN,
+ "Could not trigger signingd for %s (reopen hint: %d)",
+ uuid_utoa(linked_inode->gfid), val);
+ }
}
static void
-br_object_resign (xlator_t *this,
- br_object_t *object, inode_t *linked_inode)
+br_object_resign(xlator_t *this, br_object_t *object, inode_t *linked_inode)
{
- loc_t loc = {0, };
+ loc_t loc = {
+ 0,
+ };
- loc.inode = inode_ref (linked_inode);
- gf_uuid_copy (loc.gfid, linked_inode->gfid);
+ loc.inode = inode_ref(linked_inode);
+ gf_uuid_copy(loc.gfid, linked_inode->gfid);
- br_trigger_sign (this, object->child, linked_inode, &loc, _gf_false);
+ br_trigger_sign(this, object->child, linked_inode, &loc, _gf_false);
- loc_wipe (&loc);
+ loc_wipe(&loc);
}
/**
@@ -560,122 +563,125 @@ br_object_resign (xlator_t *this,
* some form of priority scheduling and/or read burstness to avoid starving
* (or kicking) client I/O's.
*/
-static int32_t br_sign_object (br_object_t *object)
+static int32_t
+br_sign_object(br_object_t *object)
{
- int32_t ret = -1;
- inode_t *linked_inode = NULL;
- xlator_t *this = NULL;
- fd_t *fd = NULL;
- struct iatt iatt = {0, };
- pid_t pid = GF_CLIENT_PID_BITD;
- br_sign_state_t sign_info = BR_SIGN_NORMAL;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", object, out);
-
- this = object->this;
-
- /**
- * FIXME: This is required as signing an object is restricted to
- * clients with special frame->root->pid. Change the way client
- * pid is set.
- */
- syncopctx_setfspid (&pid);
-
- ret = br_object_lookup (this, object, &iatt, &linked_inode);
- if (ret) {
- br_log_object (this, "lookup", object->gfid, -ret);
- goto out;
- }
-
- /**
- * For fd's that have notified for reopening, we send an explicit
- * open() followed by a dummy write() call. This triggers the
- * actual signing of the object.
- */
- sign_info = ntohl (object->sign_info);
- if (sign_info == BR_SIGN_REOPEN_WAIT) {
- br_object_resign (this, object, linked_inode);
- goto unref_inode;
- }
-
- ret = br_object_open (this, object, linked_inode, &fd);
- if (!fd) {
- br_log_object (this, "open", object->gfid, -ret);
- goto unref_inode;
- }
-
- /**
- * we have an open file descriptor on the object. from here on,
- * do not be generous to file operation errors.
- */
- gf_msg_debug (this->name, 0, "Signing object [%s]",
- uuid_utoa (linked_inode->gfid));
-
- ret = br_object_read_sign (linked_inode, fd, object, &iatt);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_READ_AND_SIGN_FAILED, "reading and signing of "
- "the object %s failed", uuid_utoa (linked_inode->gfid));
- goto unref_fd;
- }
-
- ret = 0;
-
- unref_fd:
- fd_unref (fd);
- unref_inode:
- inode_unref (linked_inode);
- out:
- return ret;
+ int32_t ret = -1;
+ inode_t *linked_inode = NULL;
+ xlator_t *this = NULL;
+ fd_t *fd = NULL;
+ struct iatt iatt = {
+ 0,
+ };
+ pid_t pid = GF_CLIENT_PID_BITD;
+ br_sign_state_t sign_info = BR_SIGN_NORMAL;
+
+ GF_VALIDATE_OR_GOTO("bit-rot", object, out);
+
+ this = object->this;
+
+ /**
+ * FIXME: This is required as signing an object is restricted to
+ * clients with special frame->root->pid. Change the way client
+ * pid is set.
+ */
+ syncopctx_setfspid(&pid);
+
+ ret = br_object_lookup(this, object, &iatt, &linked_inode);
+ if (ret) {
+ br_log_object(this, "lookup", object->gfid, -ret);
+ goto out;
+ }
+
+ /**
+ * For fd's that have notified for reopening, we send an explicit
+ * open() followed by a dummy write() call. This triggers the
+ * actual signing of the object.
+ */
+ sign_info = ntohl(object->sign_info);
+ if (sign_info == BR_SIGN_REOPEN_WAIT) {
+ br_object_resign(this, object, linked_inode);
+ goto unref_inode;
+ }
+
+ ret = br_object_open(this, object, linked_inode, &fd);
+ if (!fd) {
+ br_log_object(this, "open", object->gfid, -ret);
+ goto unref_inode;
+ }
+
+ /**
+ * we have an open file descriptor on the object. from here on,
+ * do not be generous to file operation errors.
+ */
+ gf_msg_debug(this->name, 0, "Signing object [%s]",
+ uuid_utoa(linked_inode->gfid));
+
+ ret = br_object_read_sign(linked_inode, fd, object, &iatt);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_READ_AND_SIGN_FAILED,
+ "reading and signing of "
+ "the object %s failed",
+ uuid_utoa(linked_inode->gfid));
+ goto unref_fd;
+ }
+
+ ret = 0;
+
+unref_fd:
+ fd_unref(fd);
+unref_inode:
+ inode_unref(linked_inode);
+out:
+ return ret;
}
-static br_object_t *__br_pick_object (br_private_t *priv)
+static br_object_t *
+__br_pick_object(br_private_t *priv)
{
- br_object_t *object = NULL;
+ br_object_t *object = NULL;
- while (list_empty (&priv->obj_queue->objects)) {
- pthread_cond_wait (&priv->object_cond, &priv->lock);
- }
+ while (list_empty(&priv->obj_queue->objects)) {
+ pthread_cond_wait(&priv->object_cond, &priv->lock);
+ }
- object = list_first_entry
- (&priv->obj_queue->objects, br_object_t, list);
- list_del_init (&object->list);
+ object = list_first_entry(&priv->obj_queue->objects, br_object_t, list);
+ list_del_init(&object->list);
- return object;
+ return object;
}
/**
* This is the place where the signing of the objects is triggered.
*/
void *
-br_process_object (void *arg)
+br_process_object(void *arg)
{
- xlator_t *this = NULL;
- br_object_t *object = NULL;
- br_private_t *priv = NULL;
- int32_t ret = -1;
-
- this = arg;
- priv = this->private;
-
- THIS = this;
-
- for (;;) {
- pthread_mutex_lock (&priv->lock);
- {
- object = __br_pick_object (priv);
- }
- pthread_mutex_unlock (&priv->lock);
-
- ret = br_sign_object (object);
- if (ret && !br_object_sign_softerror (-ret))
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_SIGN_FAILED, "SIGNING FAILURE [%s]",
- uuid_utoa (object->gfid));
- GF_FREE (object);
+ xlator_t *this = NULL;
+ br_object_t *object = NULL;
+ br_private_t *priv = NULL;
+ int32_t ret = -1;
+
+ this = arg;
+ priv = this->private;
+
+ THIS = this;
+
+ for (;;) {
+ pthread_mutex_lock(&priv->lock);
+ {
+ object = __br_pick_object(priv);
}
+ pthread_mutex_unlock(&priv->lock);
- return NULL;
+ ret = br_sign_object(object);
+ if (ret && !br_object_sign_softerror(-ret))
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_SIGN_FAILED,
+ "SIGNING FAILURE [%s]", uuid_utoa(object->gfid));
+ GF_FREE(object);
+ }
+
+ return NULL;
}
/**
@@ -692,98 +698,98 @@ br_process_object (void *arg)
* NOTE: use call_time to instrument signing time in br_sign_object().
*/
void
-br_add_object_to_queue (struct gf_tw_timer_list *timer,
- void *data, unsigned long call_time)
+br_add_object_to_queue(struct gf_tw_timer_list *timer, void *data,
+ unsigned long call_time)
{
- br_object_t *object = NULL;
- xlator_t *this = NULL;
- br_private_t *priv = NULL;
-
- object = data;
- this = object->this;
- priv = this->private;
-
- THIS = this;
-
- pthread_mutex_lock (&priv->lock);
- {
- list_add_tail (&object->list, &priv->obj_queue->objects);
- pthread_cond_broadcast (&priv->object_cond);
- }
- pthread_mutex_unlock (&priv->lock);
-
- if (timer)
- mem_put (timer);
- return;
+ br_object_t *object = NULL;
+ xlator_t *this = NULL;
+ br_private_t *priv = NULL;
+
+ object = data;
+ this = object->this;
+ priv = this->private;
+
+ THIS = this;
+
+ pthread_mutex_lock(&priv->lock);
+ {
+ list_add_tail(&object->list, &priv->obj_queue->objects);
+ pthread_cond_broadcast(&priv->object_cond);
+ }
+ pthread_mutex_unlock(&priv->lock);
+
+ if (timer)
+ mem_put(timer);
+ return;
}
static br_object_t *
-br_initialize_object (xlator_t *this, br_child_t *child, changelog_event_t *ev)
+br_initialize_object(xlator_t *this, br_child_t *child, changelog_event_t *ev)
{
- br_object_t *object = NULL;
+ br_object_t *object = NULL;
- object = GF_CALLOC (1, sizeof (*object), gf_br_mt_br_object_t);
- if (!object)
- goto out;
- INIT_LIST_HEAD (&object->list);
+ object = GF_CALLOC(1, sizeof(*object), gf_br_mt_br_object_t);
+ if (!object)
+ goto out;
+ INIT_LIST_HEAD(&object->list);
- object->this = this;
- object->child = child;
- gf_uuid_copy (object->gfid, ev->u.releasebr.gfid);
+ object->this = this;
+ object->child = child;
+ gf_uuid_copy(object->gfid, ev->u.releasebr.gfid);
- /* NOTE: it's BE, but no worry */
- object->signedversion = ev->u.releasebr.version;
- object->sign_info = ev->u.releasebr.sign_info;
+ /* NOTE: it's BE, but no worry */
+ object->signedversion = ev->u.releasebr.version;
+ object->sign_info = ev->u.releasebr.sign_info;
out:
- return object;
+ return object;
}
static struct gf_tw_timer_list *
-br_initialize_timer (xlator_t *this, br_object_t *object, br_child_t *child,
- changelog_event_t *ev)
+br_initialize_timer(xlator_t *this, br_object_t *object, br_child_t *child,
+ changelog_event_t *ev)
{
- br_private_t *priv = NULL;
- struct gf_tw_timer_list *timer = NULL;
+ br_private_t *priv = NULL;
+ struct gf_tw_timer_list *timer = NULL;
- priv = this->private;
+ priv = this->private;
- timer = mem_get0 (child->timer_pool);
- if (!timer)
- goto out;
- INIT_LIST_HEAD (&timer->entry);
+ timer = mem_get0(child->timer_pool);
+ if (!timer)
+ goto out;
+ INIT_LIST_HEAD(&timer->entry);
- timer->expires = priv->expiry_time;
- if (!timer->expires)
- timer->expires = 1;
+ timer->expires = priv->expiry_time;
+ if (!timer->expires)
+ timer->expires = 1;
- timer->data = object;
- timer->function = br_add_object_to_queue;
- gf_tw_add_timer (priv->timer_wheel, timer);
+ timer->data = object;
+ timer->function = br_add_object_to_queue;
+ gf_tw_add_timer(priv->timer_wheel, timer);
out:
- return timer;
+ return timer;
}
static int32_t
-br_schedule_object_reopen (xlator_t *this, br_object_t *object,
- br_child_t *child, changelog_event_t *ev)
+br_schedule_object_reopen(xlator_t *this, br_object_t *object,
+ br_child_t *child, changelog_event_t *ev)
{
- struct gf_tw_timer_list *timer = NULL;
-
- timer = br_initialize_timer (this, object, child, ev);
- if (!timer)
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_SET_TIMER_FAILED,
- "Failed to allocate object expiry timer [GFID: %s]",
- uuid_utoa (object->gfid));
- return timer ? 0 : -1;
+ struct gf_tw_timer_list *timer = NULL;
+
+ timer = br_initialize_timer(this, object, child, ev);
+ if (!timer)
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_SET_TIMER_FAILED,
+ "Failed to allocate object expiry timer [GFID: %s]",
+ uuid_utoa(object->gfid));
+ return timer ? 0 : -1;
}
static int32_t
-br_object_quicksign (xlator_t *this, br_object_t *object)
+br_object_quicksign(xlator_t *this, br_object_t *object)
{
- br_add_object_to_queue (NULL, object, 0ULL);
- return 0;
+ br_add_object_to_queue(NULL, object, 0ULL);
+ return 0;
}
/**
@@ -796,148 +802,146 @@ br_object_quicksign (xlator_t *this, br_object_t *object)
* object as a single alloc and bifurcate their respective pointers.
*/
void
-br_brick_callback (void *xl, char *brick,
- void *data, changelog_event_t *ev)
+br_brick_callback(void *xl, char *brick, void *data, changelog_event_t *ev)
{
- int32_t ret = 0;
- uuid_t gfid = {0,};
- xlator_t *this = NULL;
- br_object_t *object = NULL;
- br_child_t *child = NULL;
- br_sign_state_t sign_info = BR_SIGN_INVALID;
-
- this = xl;
-
- GF_VALIDATE_OR_GOTO (this->name, ev, out);
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
- GF_VALIDATE_OR_GOTO (this->name, this->private, out);
-
- GF_ASSERT (ev->ev_type == CHANGELOG_OP_TYPE_BR_RELEASE);
- GF_ASSERT (!gf_uuid_is_null (ev->u.releasebr.gfid));
-
- gf_uuid_copy (gfid, ev->u.releasebr.gfid);
-
- gf_msg_debug (this->name, 0, "RELEASE EVENT [GFID %s]",
- uuid_utoa (gfid));
-
- child = br_get_child_from_brick_path (this, brick);
- if (!child) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_GET_SUBVOL_FAILED,
- "failed to get the subvolume for the brick %s", brick);
- goto out;
- }
-
- object = br_initialize_object (this, child, ev);
- if (!object) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
- "failed to allocate object memory [GFID: %s]",
- uuid_utoa (gfid));
- goto out;
- }
-
- /* sanity check */
- sign_info = ntohl (object->sign_info);
- GF_ASSERT (sign_info != BR_SIGN_NORMAL);
-
- if (sign_info == BR_SIGN_REOPEN_WAIT)
- ret = br_schedule_object_reopen (this, object, child, ev);
- else
- ret = br_object_quicksign (this, object);
-
- if (ret)
- goto free_object;
-
- gf_msg_debug (this->name, 0, "->callback: brick [%s], type [%d]\n",
- brick, ev->ev_type);
- return;
-
- free_object:
- GF_FREE (object);
- out:
- return;
+ int32_t ret = 0;
+ uuid_t gfid = {
+ 0,
+ };
+ xlator_t *this = NULL;
+ br_object_t *object = NULL;
+ br_child_t *child = NULL;
+ br_sign_state_t sign_info = BR_SIGN_INVALID;
+
+ this = xl;
+
+ GF_VALIDATE_OR_GOTO(this->name, ev, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, out);
+
+ GF_ASSERT(ev->ev_type == CHANGELOG_OP_TYPE_BR_RELEASE);
+ GF_ASSERT(!gf_uuid_is_null(ev->u.releasebr.gfid));
+
+ gf_uuid_copy(gfid, ev->u.releasebr.gfid);
+
+ gf_msg_debug(this->name, 0, "RELEASE EVENT [GFID %s]", uuid_utoa(gfid));
+
+ child = br_get_child_from_brick_path(this, brick);
+ if (!child) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_GET_SUBVOL_FAILED,
+ "failed to get the subvolume for the brick %s", brick);
+ goto out;
+ }
+
+ object = br_initialize_object(this, child, ev);
+ if (!object) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
+ "failed to allocate object memory [GFID: %s]", uuid_utoa(gfid));
+ goto out;
+ }
+
+ /* sanity check */
+ sign_info = ntohl(object->sign_info);
+ GF_ASSERT(sign_info != BR_SIGN_NORMAL);
+
+ if (sign_info == BR_SIGN_REOPEN_WAIT)
+ ret = br_schedule_object_reopen(this, object, child, ev);
+ else
+ ret = br_object_quicksign(this, object);
+
+ if (ret)
+ goto free_object;
+
+ gf_msg_debug(this->name, 0, "->callback: brick [%s], type [%d]\n", brick,
+ ev->ev_type);
+ return;
+
+free_object:
+ GF_FREE(object);
+out:
+ return;
}
void
-br_fill_brick_spec (struct gf_brick_spec *brick, char *path)
+br_fill_brick_spec(struct gf_brick_spec *brick, char *path)
{
- brick->brick_path = gf_strdup (path);
- brick->filter = CHANGELOG_OP_TYPE_BR_RELEASE;
-
- brick->init = br_brick_init;
- brick->fini = br_brick_fini;
- brick->callback = br_brick_callback;
- brick->connected = NULL;
- brick->disconnected = NULL;
+ brick->brick_path = gf_strdup(path);
+ brick->filter = CHANGELOG_OP_TYPE_BR_RELEASE;
+
+ brick->init = br_brick_init;
+ brick->fini = br_brick_fini;
+ brick->callback = br_brick_callback;
+ brick->connected = NULL;
+ brick->disconnected = NULL;
}
static gf_boolean_t
-br_check_object_need_sign (xlator_t *this, dict_t *xattr, br_child_t *child)
+br_check_object_need_sign(xlator_t *this, dict_t *xattr, br_child_t *child)
{
- int32_t ret = -1;
- gf_boolean_t need_sign = _gf_false;
- br_isignature_out_t *sign = NULL;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
- GF_VALIDATE_OR_GOTO (this->name, xattr, out);
- GF_VALIDATE_OR_GOTO (this->name, child, out);
-
- ret = dict_get_ptr (xattr, GLUSTERFS_GET_OBJECT_SIGNATURE,
- (void **)&sign);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_GET_SIGN_FAILED,
- "failed to get object signature info");
- goto out;
- }
+ int32_t ret = -1;
+ gf_boolean_t need_sign = _gf_false;
+ br_isignature_out_t *sign = NULL;
- /* Object has been opened and hence dirty. Do not sign it */
- if (sign->stale)
- need_sign = _gf_true;
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, xattr, out);
+ GF_VALIDATE_OR_GOTO(this->name, child, out);
-out:
- return need_sign;
-}
+ ret = dict_get_ptr(xattr, GLUSTERFS_GET_OBJECT_SIGNATURE, (void **)&sign);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_GET_SIGN_FAILED,
+ "failed to get object signature info");
+ goto out;
+ }
+ /* Object has been opened and hence dirty. Do not sign it */
+ if (sign->stale)
+ need_sign = _gf_true;
+out:
+ return need_sign;
+}
int32_t
-br_prepare_loc (xlator_t *this, br_child_t *child, loc_t *parent,
- gf_dirent_t *entry, loc_t *loc)
+br_prepare_loc(xlator_t *this, br_child_t *child, loc_t *parent,
+ gf_dirent_t *entry, loc_t *loc)
{
- int32_t ret = -1;
- inode_t *inode = NULL;
-
- inode = inode_grep (child->table, parent->inode, entry->d_name);
- if (!inode)
- loc->inode = inode_new (child->table);
- else {
- loc->inode = inode;
- if (loc->inode->ia_type != IA_IFREG) {
- gf_msg_debug (this->name, 0, "%s is not a regular "
- "file", entry->d_name);
- ret = 0;
- goto out;
- }
- }
-
- loc->parent = inode_ref (parent->inode);
- gf_uuid_copy (loc->pargfid, parent->inode->gfid);
-
- ret = inode_path (parent->inode, entry->d_name, (char **)&loc->path);
- if (ret < 0 || !loc->path) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_PATH_FAILED,
- "inode_path on %s (parent: %s) failed", entry->d_name,
- uuid_utoa (parent->inode->gfid));
- goto out;
- }
-
- loc->name = strrchr (loc->path, '/');
- if (loc->name)
- loc->name++;
-
- ret = 1;
+ int32_t ret = -1;
+ inode_t *inode = NULL;
+
+ inode = inode_grep(child->table, parent->inode, entry->d_name);
+ if (!inode)
+ loc->inode = inode_new(child->table);
+ else {
+ loc->inode = inode;
+ if (loc->inode->ia_type != IA_IFREG) {
+ gf_msg_debug(this->name, 0,
+ "%s is not a regular "
+ "file",
+ entry->d_name);
+ ret = 0;
+ goto out;
+ }
+ }
+
+ loc->parent = inode_ref(parent->inode);
+ gf_uuid_copy(loc->pargfid, parent->inode->gfid);
+
+ ret = inode_path(parent->inode, entry->d_name, (char **)&loc->path);
+ if (ret < 0 || !loc->path) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_PATH_FAILED,
+ "inode_path on %s (parent: %s) failed", entry->d_name,
+ uuid_utoa(parent->inode->gfid));
+ goto out;
+ }
+
+ loc->name = strrchr(loc->path, '/');
+ if (loc->name)
+ loc->name++;
+
+ ret = 1;
out:
- return ret;
+ return ret;
}
/**
@@ -951,150 +955,161 @@ out:
* (though not back to itself :))
*/
int
-bitd_oneshot_crawl (xlator_t *subvol,
- gf_dirent_t *entry, loc_t *parent, void *data)
+bitd_oneshot_crawl(xlator_t *subvol, gf_dirent_t *entry, loc_t *parent,
+ void *data)
{
- int op_errno = 0;
- br_child_t *child = NULL;
- xlator_t *this = NULL;
- loc_t loc = {0, };
- struct iatt iatt = {0, };
- struct iatt parent_buf = {0, };
- dict_t *xattr = NULL;
- int32_t ret = -1;
- inode_t *linked_inode = NULL;
- gf_boolean_t need_signing = _gf_false;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", subvol, out);
- GF_VALIDATE_OR_GOTO ("bit-rot", data, out);
-
- child = data;
- this = child->this;
-
- ret = br_prepare_loc (this, child, parent, entry, &loc);
- if (!ret)
- goto out;
-
- ret = syncop_lookup (child->xl, &loc, &iatt, &parent_buf, NULL, NULL);
- if (ret) {
- br_log_object_path (this, "lookup", loc.path, -ret);
- goto out;
- }
-
- linked_inode = inode_link (loc.inode, parent->inode, loc.name, &iatt);
- if (linked_inode)
- inode_lookup (linked_inode);
-
- if (iatt.ia_type != IA_IFREG) {
- gf_msg_debug (this->name, 0, "%s is not a regular file, "
- "skipping..", entry->d_name);
- ret = 0;
- goto unref_inode;
- }
+ int op_errno = 0;
+ br_child_t *child = NULL;
+ xlator_t *this = NULL;
+ loc_t loc = {
+ 0,
+ };
+ struct iatt iatt = {
+ 0,
+ };
+ struct iatt parent_buf = {
+ 0,
+ };
+ dict_t *xattr = NULL;
+ int32_t ret = -1;
+ inode_t *linked_inode = NULL;
+ gf_boolean_t need_signing = _gf_false;
+
+ GF_VALIDATE_OR_GOTO("bit-rot", subvol, out);
+ GF_VALIDATE_OR_GOTO("bit-rot", data, out);
+
+ child = data;
+ this = child->this;
+
+ ret = br_prepare_loc(this, child, parent, entry, &loc);
+ if (!ret)
+ goto out;
+
+ ret = syncop_lookup(child->xl, &loc, &iatt, &parent_buf, NULL, NULL);
+ if (ret) {
+ br_log_object_path(this, "lookup", loc.path, -ret);
+ goto out;
+ }
+
+ linked_inode = inode_link(loc.inode, parent->inode, loc.name, &iatt);
+ if (linked_inode)
+ inode_lookup(linked_inode);
+
+ if (iatt.ia_type != IA_IFREG) {
+ gf_msg_debug(this->name, 0,
+ "%s is not a regular file, "
+ "skipping..",
+ entry->d_name);
+ ret = 0;
+ goto unref_inode;
+ }
+
+ /**
+ * As of now, 2 cases are possible and handled.
+ * 1) GlusterFS is upgraded from a previous version which does not
+ * have any idea about bit-rot and have data in the filesystem.
+ * In this case syncop_getxattr fails with ENODATA and the object
+ * is signed. (In real, when crawler sends lookup, bit-rot-stub
+ * creates the xattrs before returning lookup reply)
+ * 2) Bit-rot was not enabled or BitD was does for some reasons, during
+ * which some files were created, but since BitD was down, were not
+ * signed.
+ * If the file was just created and was being written some data when
+ * the down BitD came up, then bit-rot stub should be intelligent to
+ * identify this case (by comparing the ongoing version or by checking
+ * if there are any fds present for that inode) and handle properly.
+ */
+
+ if (bitd_is_bad_file(this, child, &loc, NULL)) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRB_MSG_SKIP_OBJECT,
+ "Entry [%s] is marked corrupted.. skipping.", loc.path);
+ goto unref_inode;
+ }
+
+ ret = syncop_getxattr(child->xl, &loc, &xattr,
+ GLUSTERFS_GET_OBJECT_SIGNATURE, NULL, NULL);
+ if (ret < 0) {
+ op_errno = -ret;
+ br_log_object(this, "getxattr", linked_inode->gfid, op_errno);
/**
- * As of now, 2 cases are possible and handled.
- * 1) GlusterFS is upgraded from a previous version which does not
- * have any idea about bit-rot and have data in the filesystem.
- * In this case syncop_getxattr fails with ENODATA and the object
- * is signed. (In real, when crawler sends lookup, bit-rot-stub
- * creates the xattrs before returning lookup reply)
- * 2) Bit-rot was not enabled or BitD was does for some reasons, during
- * which some files were created, but since BitD was down, were not
- * signed.
- * If the file was just created and was being written some data when
- * the down BitD came up, then bit-rot stub should be intelligent to
- * identify this case (by comparing the ongoing version or by checking
- * if there are any fds present for that inode) and handle properly.
+ * No need to sign the zero byte objects as the signing
+ * happens upon first modification of the object.
*/
+ if (op_errno == ENODATA && (iatt.ia_size != 0))
+ need_signing = _gf_true;
+ if (op_errno == EINVAL)
+ gf_msg(this->name, GF_LOG_WARNING, 0,
+ BRB_MSG_PARTIAL_VERSION_PRESENCE,
+ "Partial "
+ "version xattr presence detected, ignoring "
+ "[GFID: %s]",
+ uuid_utoa(linked_inode->gfid));
+ } else {
+ need_signing = br_check_object_need_sign(this, xattr, child);
+ }
+
+ if (!need_signing)
+ goto unref_dict;
+
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_TRIGGER_SIGN,
+ "Triggering signing for %s [GFID: %s | Brick: %s]", loc.path,
+ uuid_utoa(linked_inode->gfid), child->brick_path);
+ br_trigger_sign(this, child, linked_inode, &loc, _gf_true);
+
+ ret = 0;
+
+unref_dict:
+ if (xattr)
+ dict_unref(xattr);
+unref_inode:
+ inode_unref(linked_inode);
+out:
+ loc_wipe(&loc);
- if (bitd_is_bad_file (this, child, &loc, NULL)) {
- gf_msg (this->name, GF_LOG_WARNING, 0, BRB_MSG_SKIP_OBJECT,
- "Entry [%s] is marked corrupted.. skipping.", loc.path);
- goto unref_inode;
- }
-
- ret = syncop_getxattr (child->xl, &loc, &xattr,
- GLUSTERFS_GET_OBJECT_SIGNATURE, NULL, NULL);
- if (ret < 0) {
- op_errno = -ret;
- br_log_object (this, "getxattr", linked_inode->gfid, op_errno);
-
- /**
- * No need to sign the zero byte objects as the signing
- * happens upon first modification of the object.
- */
- if (op_errno == ENODATA && (iatt.ia_size != 0))
- need_signing = _gf_true;
- if (op_errno == EINVAL)
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRB_MSG_PARTIAL_VERSION_PRESENCE, "Partial "
- "version xattr presence detected, ignoring "
- "[GFID: %s]", uuid_utoa (linked_inode->gfid));
- } else {
- need_signing = br_check_object_need_sign (this, xattr, child);
- }
-
- if (!need_signing)
- goto unref_dict;
-
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_TRIGGER_SIGN,
- "Triggering signing for %s [GFID: %s | Brick: %s]",
- loc.path, uuid_utoa (linked_inode->gfid), child->brick_path);
- br_trigger_sign (this, child, linked_inode, &loc, _gf_true);
-
- ret = 0;
-
- unref_dict:
- if (xattr)
- dict_unref (xattr);
- unref_inode:
- inode_unref (linked_inode);
- out:
- loc_wipe (&loc);
-
- return ret;
+ return ret;
}
#define BR_CRAWL_THROTTLE_COUNT 50
-#define BR_CRAWL_THROTTLE_ZZZ 5
+#define BR_CRAWL_THROTTLE_ZZZ 5
void *
-br_oneshot_signer (void *arg)
+br_oneshot_signer(void *arg)
{
- loc_t loc = {0,};
- xlator_t *this = NULL;
- br_child_t *child = NULL;
+ loc_t loc = {
+ 0,
+ };
+ xlator_t *this = NULL;
+ br_child_t *child = NULL;
- child = arg;
- this = child->this;
+ child = arg;
+ this = child->this;
- THIS = this;
+ THIS = this;
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_CRAWLING_START,
- "Crawling brick [%s], scanning for unsigned objects",
- child->brick_path);
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_CRAWLING_START,
+ "Crawling brick [%s], scanning for unsigned objects",
+ child->brick_path);
- loc.inode = child->table->root;
- (void) syncop_ftw_throttle
- (child->xl, &loc,
- GF_CLIENT_PID_BITD, child, bitd_oneshot_crawl,
- BR_CRAWL_THROTTLE_COUNT, BR_CRAWL_THROTTLE_ZZZ);
+ loc.inode = child->table->root;
+ (void)syncop_ftw_throttle(child->xl, &loc, GF_CLIENT_PID_BITD, child,
+ bitd_oneshot_crawl, BR_CRAWL_THROTTLE_COUNT,
+ BR_CRAWL_THROTTLE_ZZZ);
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_CRAWLING_FINISH,
- "Completed crawling brick [%s]", child->brick_path);
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_CRAWLING_FINISH,
+ "Completed crawling brick [%s]", child->brick_path);
- return NULL;
+ return NULL;
}
static void
-br_set_child_state (br_child_t *child, br_child_state_t state)
+br_set_child_state(br_child_t *child, br_child_state_t state)
{
- pthread_mutex_lock (&child->lock);
- {
- _br_set_child_state (child, state);
- }
- pthread_mutex_unlock (&child->lock);
+ pthread_mutex_lock(&child->lock);
+ {
+ _br_set_child_state(child, state);
+ }
+ pthread_mutex_unlock(&child->lock);
}
/**
@@ -1109,160 +1124,159 @@ br_set_child_state (br_child_t *child, br_child_state_t state)
* notifications.
*/
static int32_t
-br_enact_signer (xlator_t *this, br_child_t *child, br_stub_init_t *stub)
+br_enact_signer(xlator_t *this, br_child_t *child, br_stub_init_t *stub)
{
- int32_t ret = 0;
- br_private_t *priv = NULL;
- struct gf_brick_spec *brick = NULL;
-
- priv = this->private;
-
- brick = GF_CALLOC (1, sizeof (struct gf_brick_spec),
- gf_common_mt_gf_brick_spec_t);
- if (!brick)
- goto error_return;
-
- br_fill_brick_spec (brick, stub->export);
- ret = gf_changelog_register_generic
- (brick, 1, 1, this->ctx->cmd_args.log_file, -1, this);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- BRB_MSG_REGISTER_FAILED, "Register to changelog "
- "failed");
- goto dealloc;
- }
-
- child->threadrunning = 0;
- ret = gf_thread_create (&child->thread, NULL, br_oneshot_signer, child,
- "brosign");
- if (ret)
- gf_msg (this->name, GF_LOG_WARNING, 0, BRB_MSG_SPAWN_FAILED,
- "failed to spawn FS crawler thread");
- else
- child->threadrunning = 1;
-
- /* it's OK to continue, "old" objects would be signed when modified */
- list_add_tail (&child->list, &priv->signing);
- return 0;
-
- dealloc:
- GF_FREE (brick);
- error_return:
- return -1;
+ int32_t ret = 0;
+ br_private_t *priv = NULL;
+ struct gf_brick_spec *brick = NULL;
+
+ priv = this->private;
+
+ brick = GF_CALLOC(1, sizeof(struct gf_brick_spec),
+ gf_common_mt_gf_brick_spec_t);
+ if (!brick)
+ goto error_return;
+
+ br_fill_brick_spec(brick, stub->export);
+ ret = gf_changelog_register_generic(brick, 1, 1,
+ this->ctx->cmd_args.log_file, -1, this);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, BRB_MSG_REGISTER_FAILED,
+ "Register to changelog "
+ "failed");
+ goto dealloc;
+ }
+
+ child->threadrunning = 0;
+ ret = gf_thread_create(&child->thread, NULL, br_oneshot_signer, child,
+ "brosign");
+ if (ret)
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRB_MSG_SPAWN_FAILED,
+ "failed to spawn FS crawler thread");
+ else
+ child->threadrunning = 1;
+
+ /* it's OK to continue, "old" objects would be signed when modified */
+ list_add_tail(&child->list, &priv->signing);
+ return 0;
+
+dealloc:
+ GF_FREE(brick);
+error_return:
+ return -1;
}
static int32_t
-br_launch_scrubber (xlator_t *this, br_child_t *child,
- struct br_scanfs *fsscan, struct br_scrubber *fsscrub)
+br_launch_scrubber(xlator_t *this, br_child_t *child, struct br_scanfs *fsscan,
+ struct br_scrubber *fsscrub)
{
- int32_t ret = -1;
- br_private_t *priv = NULL;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
-
- scrub_monitor = &priv->scrub_monitor;
- ret = gf_thread_create (&child->thread, NULL, br_fsscanner, child,
- "brfsscan");
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ALERT, 0, BRB_MSG_SPAWN_FAILED,
- "failed to spawn bitrot scrubber daemon [Brick: %s]",
- child->brick_path);
- goto error_return;
- }
-
- /* Signal monitor to kick off state machine*/
- pthread_mutex_lock (&scrub_monitor->mutex);
- {
- if (!scrub_monitor->inited)
- pthread_cond_signal (&scrub_monitor->cond);
- scrub_monitor->inited = _gf_true;
- }
- pthread_mutex_unlock (&scrub_monitor->mutex);
-
- /**
- * Everything has been setup.. add this subvolume to scrubbers
- * list.
- */
- pthread_mutex_lock (&fsscrub->mutex);
- {
- list_add_tail (&child->list, &fsscrub->scrublist);
- pthread_cond_broadcast (&fsscrub->cond);
- }
- pthread_mutex_unlock (&fsscrub->mutex);
+ int32_t ret = -1;
+ br_private_t *priv = NULL;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+
+ scrub_monitor = &priv->scrub_monitor;
+ ret = gf_thread_create(&child->thread, NULL, br_fsscanner, child,
+ "brfsscan");
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ALERT, 0, BRB_MSG_SPAWN_FAILED,
+ "failed to spawn bitrot scrubber daemon [Brick: %s]",
+ child->brick_path);
+ goto error_return;
+ }
+
+ /* Signal monitor to kick off state machine*/
+ pthread_mutex_lock(&scrub_monitor->mutex);
+ {
+ if (!scrub_monitor->inited)
+ pthread_cond_signal(&scrub_monitor->cond);
+ scrub_monitor->inited = _gf_true;
+ }
+ pthread_mutex_unlock(&scrub_monitor->mutex);
+
+ /**
+ * Everything has been setup.. add this subvolume to scrubbers
+ * list.
+ */
+ pthread_mutex_lock(&fsscrub->mutex);
+ {
+ list_add_tail(&child->list, &fsscrub->scrublist);
+ pthread_cond_broadcast(&fsscrub->cond);
+ }
+ pthread_mutex_unlock(&fsscrub->mutex);
+
+ return 0;
- return 0;
-
- error_return:
- return -1;
+error_return:
+ return -1;
}
static int32_t
-br_enact_scrubber (xlator_t *this, br_child_t *child)
+br_enact_scrubber(xlator_t *this, br_child_t *child)
{
- int32_t ret = 0;
- br_private_t *priv = NULL;
- struct br_scanfs *fsscan = NULL;
- struct br_scrubber *fsscrub = NULL;
+ int32_t ret = 0;
+ br_private_t *priv = NULL;
+ struct br_scanfs *fsscan = NULL;
+ struct br_scrubber *fsscrub = NULL;
- priv = this->private;
+ priv = this->private;
- fsscan = &child->fsscan;
- fsscrub = &priv->fsscrub;
+ fsscan = &child->fsscan;
+ fsscrub = &priv->fsscrub;
- /**
- * if this child already witnesses a successful connection earlier
- * there's no need to initialize mutexes, condvars, etc..
- */
- if (_br_child_witnessed_connection (child))
- return br_launch_scrubber (this, child, fsscan, fsscrub);
+ /**
+ * if this child already witnesses a successful connection earlier
+ * there's no need to initialize mutexes, condvars, etc..
+ */
+ if (_br_child_witnessed_connection(child))
+ return br_launch_scrubber(this, child, fsscan, fsscrub);
- LOCK_INIT (&fsscan->entrylock);
- pthread_mutex_init (&fsscan->waitlock, NULL);
- pthread_cond_init (&fsscan->waitcond, NULL);
+ LOCK_INIT(&fsscan->entrylock);
+ pthread_mutex_init(&fsscan->waitlock, NULL);
+ pthread_cond_init(&fsscan->waitcond, NULL);
- fsscan->entries = 0;
- INIT_LIST_HEAD (&fsscan->queued);
- INIT_LIST_HEAD (&fsscan->ready);
+ fsscan->entries = 0;
+ INIT_LIST_HEAD(&fsscan->queued);
+ INIT_LIST_HEAD(&fsscan->ready);
- ret = br_launch_scrubber (this, child, fsscan, fsscrub);
- if (ret)
- goto error_return;
+ ret = br_launch_scrubber(this, child, fsscan, fsscrub);
+ if (ret)
+ goto error_return;
- return 0;
+ return 0;
- error_return:
- LOCK_DESTROY (&fsscan->entrylock);
- pthread_mutex_destroy (&fsscan->waitlock);
- pthread_cond_destroy (&fsscan->waitcond);
+error_return:
+ LOCK_DESTROY(&fsscan->entrylock);
+ pthread_mutex_destroy(&fsscan->waitlock);
+ pthread_cond_destroy(&fsscan->waitcond);
- return -1;
+ return -1;
}
static int32_t
-br_child_enaction (xlator_t *this, br_child_t *child, br_stub_init_t *stub)
+br_child_enaction(xlator_t *this, br_child_t *child, br_stub_init_t *stub)
{
- int32_t ret = -1;
- br_private_t *priv = this->private;
+ int32_t ret = -1;
+ br_private_t *priv = this->private;
- pthread_mutex_lock (&child->lock);
- {
- if (priv->iamscrubber)
- ret = br_enact_scrubber (this, child);
- else
- ret = br_enact_signer (this, child, stub);
-
- if (!ret) {
- child->witnessed = 1;
- _br_set_child_state (child, BR_CHILD_STATE_CONNECTED);
- gf_msg (this->name, GF_LOG_INFO,
- 0, BRB_MSG_CONNECTED_TO_BRICK,
- "Connected to brick %s..", child->brick_path);
- }
+ pthread_mutex_lock(&child->lock);
+ {
+ if (priv->iamscrubber)
+ ret = br_enact_scrubber(this, child);
+ else
+ ret = br_enact_signer(this, child, stub);
+
+ if (!ret) {
+ child->witnessed = 1;
+ _br_set_child_state(child, BR_CHILD_STATE_CONNECTED);
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_CONNECTED_TO_BRICK,
+ "Connected to brick %s..", child->brick_path);
}
- pthread_mutex_unlock (&child->lock);
+ }
+ pthread_mutex_unlock(&child->lock);
- return ret;
+ return ret;
}
/**
@@ -1273,129 +1287,132 @@ br_child_enaction (xlator_t *this, br_child_t *child, br_stub_init_t *stub)
* process either acts as a signer or a scrubber.
*/
int32_t
-br_brick_connect (xlator_t *this, br_child_t *child)
+br_brick_connect(xlator_t *this, br_child_t *child)
{
- int32_t ret = -1;
- loc_t loc = {0, };
- struct iatt buf = {0, };
- struct iatt parent = {0, };
- br_stub_init_t *stub = NULL;
- dict_t *xattr = NULL;
- int op_errno = 0;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", this, out);
- GF_VALIDATE_OR_GOTO (this->name, child, out);
- GF_VALIDATE_OR_GOTO (this->name, this->private, out);
-
- br_child_set_scrub_state (child, _gf_false);
- br_set_child_state (child, BR_CHILD_STATE_INITIALIZING);
-
- loc.inode = inode_ref (child->table->root);
- gf_uuid_copy (loc.gfid, loc.inode->gfid);
- loc.path = gf_strdup ("/");
-
- ret = syncop_lookup (child->xl, &loc, &buf, &parent, NULL, NULL);
- if (ret) {
- op_errno = -ret;
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- BRB_MSG_LOOKUP_FAILED, "lookup on root failed");
- goto wipeloc;
- }
-
- ret = syncop_getxattr (child->xl, &loc, &xattr,
- GLUSTERFS_GET_BR_STUB_INIT_TIME, NULL, NULL);
- if (ret) {
- op_errno = -ret;
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- BRB_MSG_GET_INFO_FAILED, "failed to get stub info");
- goto wipeloc;
- }
-
- ret = dict_get_ptr (xattr, GLUSTERFS_GET_BR_STUB_INIT_TIME,
- (void **)&stub);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_GET_INFO_FAILED,
- "failed to extract stub information");
- goto free_dict;
- }
-
- memcpy (child->brick_path, stub->export, strlen (stub->export) + 1);
- child->tv.tv_sec = ntohl (stub->timebuf[0]);
- child->tv.tv_usec = ntohl (stub->timebuf[1]);
-
- ret = br_child_enaction (this, child, stub);
-
- free_dict:
- dict_unref (xattr);
- wipeloc:
- loc_wipe (&loc);
- out:
- if (ret)
- br_set_child_state (child, BR_CHILD_STATE_CONNFAILED);
- return ret;
+ int32_t ret = -1;
+ loc_t loc = {
+ 0,
+ };
+ struct iatt buf = {
+ 0,
+ };
+ struct iatt parent = {
+ 0,
+ };
+ br_stub_init_t *stub = NULL;
+ dict_t *xattr = NULL;
+ int op_errno = 0;
+
+ GF_VALIDATE_OR_GOTO("bit-rot", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, child, out);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, out);
+
+ br_child_set_scrub_state(child, _gf_false);
+ br_set_child_state(child, BR_CHILD_STATE_INITIALIZING);
+
+ loc.inode = inode_ref(child->table->root);
+ gf_uuid_copy(loc.gfid, loc.inode->gfid);
+ loc.path = gf_strdup("/");
+
+ ret = syncop_lookup(child->xl, &loc, &buf, &parent, NULL, NULL);
+ if (ret) {
+ op_errno = -ret;
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, BRB_MSG_LOOKUP_FAILED,
+ "lookup on root failed");
+ goto wipeloc;
+ }
+
+ ret = syncop_getxattr(child->xl, &loc, &xattr,
+ GLUSTERFS_GET_BR_STUB_INIT_TIME, NULL, NULL);
+ if (ret) {
+ op_errno = -ret;
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, BRB_MSG_GET_INFO_FAILED,
+ "failed to get stub info");
+ goto wipeloc;
+ }
+
+ ret = dict_get_ptr(xattr, GLUSTERFS_GET_BR_STUB_INIT_TIME, (void **)&stub);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_GET_INFO_FAILED,
+ "failed to extract stub information");
+ goto free_dict;
+ }
+
+ memcpy(child->brick_path, stub->export, strlen(stub->export) + 1);
+ child->tv.tv_sec = ntohl(stub->timebuf[0]);
+ child->tv.tv_usec = ntohl(stub->timebuf[1]);
+
+ ret = br_child_enaction(this, child, stub);
+
+free_dict:
+ dict_unref(xattr);
+wipeloc:
+ loc_wipe(&loc);
+out:
+ if (ret)
+ br_set_child_state(child, BR_CHILD_STATE_CONNFAILED);
+ return ret;
}
/* TODO: cleanup signer */
static int32_t
-br_cleanup_signer (xlator_t *this, br_child_t *child)
+br_cleanup_signer(xlator_t *this, br_child_t *child)
{
- return 0;
+ return 0;
}
static int32_t
-br_cleanup_scrubber (xlator_t *this, br_child_t *child)
+br_cleanup_scrubber(xlator_t *this, br_child_t *child)
{
- int32_t ret = 0;
- br_private_t *priv = NULL;
- struct br_scrubber *fsscrub = NULL;
- struct br_monitor *scrub_monitor = NULL;
-
- priv = this->private;
- fsscrub = &priv->fsscrub;
- scrub_monitor = &priv->scrub_monitor;
-
- if (_br_is_child_scrub_active (child)) {
- scrub_monitor->active_child_count--;
- br_child_set_scrub_state (child, _gf_false);
- }
-
- /**
- * 0x0: child (brick) goes out of rotation
- *
- * This is fully safe w.r.t. entries for this child being actively
- * scrubbed. Each of the scrubber thread(s) would finish scrubbing
- * the entry (probably failing due to disconnection) and either
- * putting the entry back into the queue or continuing further.
- * Either way, pending entries for this child's queue need not be
- * drained; entries just sit there in the queued/ready list to be
- * consumed later upon re-connection.
- */
- pthread_mutex_lock (&fsscrub->mutex);
- {
- list_del_init (&child->list);
- }
- pthread_mutex_unlock (&fsscrub->mutex);
-
- /**
- * 0x1: cleanup scanner thread
- *
- * The pending timer needs to be removed _after_ cleaning up the
- * filesystem scanner (scheduling the next scrub time is not a
- * cancellation point).
- */
- ret = gf_thread_cleanup_xint (child->thread);
- if (ret)
- gf_msg (this->name, GF_LOG_INFO,
- 0, BRB_MSG_SCRUB_THREAD_CLEANUP,
- "Error cleaning up scanner thread");
-
- gf_msg (this->name, GF_LOG_INFO,
- 0, BRB_MSG_SCRUBBER_CLEANED,
- "Cleaned up scrubber for brick [%s]", child->brick_path);
-
- return 0;
+ int32_t ret = 0;
+ br_private_t *priv = NULL;
+ struct br_scrubber *fsscrub = NULL;
+ struct br_monitor *scrub_monitor = NULL;
+
+ priv = this->private;
+ fsscrub = &priv->fsscrub;
+ scrub_monitor = &priv->scrub_monitor;
+
+ if (_br_is_child_scrub_active(child)) {
+ scrub_monitor->active_child_count--;
+ br_child_set_scrub_state(child, _gf_false);
+ }
+
+ /**
+ * 0x0: child (brick) goes out of rotation
+ *
+ * This is fully safe w.r.t. entries for this child being actively
+ * scrubbed. Each of the scrubber thread(s) would finish scrubbing
+ * the entry (probably failing due to disconnection) and either
+ * putting the entry back into the queue or continuing further.
+ * Either way, pending entries for this child's queue need not be
+ * drained; entries just sit there in the queued/ready list to be
+ * consumed later upon re-connection.
+ */
+ pthread_mutex_lock(&fsscrub->mutex);
+ {
+ list_del_init(&child->list);
+ }
+ pthread_mutex_unlock(&fsscrub->mutex);
+
+ /**
+ * 0x1: cleanup scanner thread
+ *
+ * The pending timer needs to be removed _after_ cleaning up the
+ * filesystem scanner (scheduling the next scrub time is not a
+ * cancellation point).
+ */
+ ret = gf_thread_cleanup_xint(child->thread);
+ if (ret)
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUB_THREAD_CLEANUP,
+ "Error cleaning up scanner thread");
+
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_SCRUBBER_CLEANED,
+ "Cleaned up scrubber for brick [%s]", child->brick_path);
+
+ return 0;
}
/**
@@ -1404,38 +1421,38 @@ br_cleanup_scrubber (xlator_t *this, br_child_t *child)
* the inode table, it's just reused taking care of stale inodes)
*/
int32_t
-br_brick_disconnect (xlator_t *this, br_child_t *child)
+br_brick_disconnect(xlator_t *this, br_child_t *child)
{
- int32_t ret = 0;
- struct br_monitor *scrub_monitor = NULL;
- br_private_t *priv = this->private;
+ int32_t ret = 0;
+ struct br_monitor *scrub_monitor = NULL;
+ br_private_t *priv = this->private;
+
+ scrub_monitor = &priv->scrub_monitor;
+
+ /* Lock order should be wakelock and then child lock to
+ * dead locks.
+ */
+ pthread_mutex_lock(&scrub_monitor->wakelock);
+ {
+ pthread_mutex_lock(&child->lock);
+ {
+ if (!_br_is_child_connected(child))
+ goto unblock;
- scrub_monitor = &priv->scrub_monitor;
+ /* child is on death row.. */
+ _br_set_child_state(child, BR_CHILD_STATE_DISCONNECTED);
- /* Lock order should be wakelock and then child lock to
- * dead locks.
- */
- pthread_mutex_lock (&scrub_monitor->wakelock);
- {
- pthread_mutex_lock (&child->lock);
- {
- if (!_br_is_child_connected (child))
- goto unblock;
-
- /* child is on death row.. */
- _br_set_child_state (child, BR_CHILD_STATE_DISCONNECTED);
-
- if (priv->iamscrubber)
- ret = br_cleanup_scrubber (this, child);
- else
- ret = br_cleanup_signer (this, child);
- }
- unblock:
- pthread_mutex_unlock (&child->lock);
+ if (priv->iamscrubber)
+ ret = br_cleanup_scrubber(this, child);
+ else
+ ret = br_cleanup_signer(this, child);
}
- pthread_mutex_unlock (&scrub_monitor->wakelock);
+ unblock:
+ pthread_mutex_unlock(&child->lock);
+ }
+ pthread_mutex_unlock(&scrub_monitor->wakelock);
- return ret;
+ return ret;
}
/**
@@ -1444,275 +1461,278 @@ br_brick_disconnect (xlator_t *this, br_child_t *child)
* information regarding that brick (such as brick path).
*/
void *
-br_handle_events (void *arg)
+br_handle_events(void *arg)
{
- int32_t ret = 0;
- xlator_t *this = NULL;
- br_private_t *priv = NULL;
- br_child_t *child = NULL;
- struct br_child_event *childev = NULL;
-
- this = arg;
- priv = this->private;
-
- /*
- * Since, this is the topmost xlator, THIS has to be set by bit-rot
- * xlator itself (STACK_WIND won't help in this case). Also it has
- * to be done for each thread that gets spawned. Otherwise, a new
- * thread will get global_xlator's pointer when it does "THIS".
- */
- THIS = this;
-
- while (1) {
- pthread_mutex_lock (&priv->lock);
- {
- while (list_empty (&priv->bricks))
- pthread_cond_wait (&priv->cond, &priv->lock);
-
- childev = list_first_entry
- (&priv->bricks, struct br_child_event, list);
- list_del_init (&childev->list);
- }
- pthread_mutex_unlock (&priv->lock);
-
- child = childev->child;
- ret = childev->call (this, child);
- if (ret)
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_SUBVOL_CONNECT_FAILED,
- "callback handler for subvolume [%s] failed",
- child->xl->name);
- GF_FREE (childev);
+ int32_t ret = 0;
+ xlator_t *this = NULL;
+ br_private_t *priv = NULL;
+ br_child_t *child = NULL;
+ struct br_child_event *childev = NULL;
+
+ this = arg;
+ priv = this->private;
+
+ /*
+ * Since, this is the topmost xlator, THIS has to be set by bit-rot
+ * xlator itself (STACK_WIND won't help in this case). Also it has
+ * to be done for each thread that gets spawned. Otherwise, a new
+ * thread will get global_xlator's pointer when it does "THIS".
+ */
+ THIS = this;
+
+ while (1) {
+ pthread_mutex_lock(&priv->lock);
+ {
+ while (list_empty(&priv->bricks))
+ pthread_cond_wait(&priv->cond, &priv->lock);
+
+ childev = list_first_entry(&priv->bricks, struct br_child_event,
+ list);
+ list_del_init(&childev->list);
}
+ pthread_mutex_unlock(&priv->lock);
- return NULL;
+ child = childev->child;
+ ret = childev->call(this, child);
+ if (ret)
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_SUBVOL_CONNECT_FAILED,
+ "callback handler for subvolume [%s] failed",
+ child->xl->name);
+ GF_FREE(childev);
+ }
+
+ return NULL;
}
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int32_t ret = -1;
+ int32_t ret = -1;
- if (!this)
- return ret;
-
- ret = xlator_mem_acct_init (this, gf_br_stub_mt_end + 1);
+ if (!this)
+ return ret;
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0, BRB_MSG_MEM_ACNT_FAILED,
- "Memory accounting init failed");
- return ret;
- }
+ ret = xlator_mem_acct_init(this, gf_br_stub_mt_end + 1);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRB_MSG_MEM_ACNT_FAILED,
+ "Memory accounting init failed");
return ret;
+ }
+
+ return ret;
}
static void
-_br_qchild_event (xlator_t *this, br_child_t *child, br_child_handler *call)
+_br_qchild_event(xlator_t *this, br_child_t *child, br_child_handler *call)
{
- br_private_t *priv = NULL;
- struct br_child_event *childev = NULL;
+ br_private_t *priv = NULL;
+ struct br_child_event *childev = NULL;
- priv = this->private;
+ priv = this->private;
- childev = GF_CALLOC (1, sizeof (*childev), gf_br_mt_br_child_event_t);
- if (!childev) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
- "Event unhandled for child.. [Brick: %s]",
- child->xl->name);
- return;
- }
+ childev = GF_CALLOC(1, sizeof(*childev), gf_br_mt_br_child_event_t);
+ if (!childev) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
+ "Event unhandled for child.. [Brick: %s]", child->xl->name);
+ return;
+ }
- INIT_LIST_HEAD (&childev->list);
- childev->this = this;
- childev->child = child;
- childev->call = call;
+ INIT_LIST_HEAD(&childev->list);
+ childev->this = this;
+ childev->child = child;
+ childev->call = call;
- list_add_tail (&childev->list, &priv->bricks);
+ list_add_tail(&childev->list, &priv->bricks);
}
int
-br_scrubber_status_get (xlator_t *this, dict_t **dict)
+br_scrubber_status_get(xlator_t *this, dict_t **dict)
{
- int ret = -1;
- br_private_t *priv = NULL;
- struct br_scrub_stats *scrub_stats = NULL;
-
- priv = this->private;
-
- GF_VALIDATE_OR_GOTO ("bit-rot", priv, out);
-
- scrub_stats = &priv->scrub_stat;
-
- ret = br_get_bad_objects_list (this, dict);
- if (ret) {
- gf_msg_debug (this->name, 0, "Failed to collect corrupt "
- "files");
- }
-
- ret = dict_set_int8 (*dict, "scrub-running",
- scrub_stats->scrub_running);
- if (ret) {
- gf_msg_debug (this->name, 0, "Failed setting scrub_running "
- "entry to the dictionary");
- }
-
- ret = dict_set_uint64 (*dict, "scrubbed-files",
- scrub_stats->scrubbed_files);
- if (ret) {
- gf_msg_debug (this->name, 0, "Failed to setting scrubbed file "
- "entry to the dictionary");
- }
-
- ret = dict_set_uint64 (*dict, "unsigned-files",
- scrub_stats->unsigned_files);
- if (ret) {
- gf_msg_debug (this->name, 0, "Failed to set unsigned file count"
- " entry to the dictionary");
- }
-
- ret = dict_set_uint64 (*dict, "scrub-duration",
- scrub_stats->scrub_duration);
- if (ret) {
- gf_msg_debug (this->name, 0, "Failed to set scrub duration"
- " entry to the dictionary");
- }
-
- ret = dict_set_dynstr_with_alloc (*dict, "last-scrub-time",
- scrub_stats->last_scrub_time);
- if (ret) {
- gf_msg_debug (this->name, 0, "Failed to set "
- "last scrub time value");
- }
+ int ret = -1;
+ br_private_t *priv = NULL;
+ struct br_scrub_stats *scrub_stats = NULL;
+
+ priv = this->private;
+
+ GF_VALIDATE_OR_GOTO("bit-rot", priv, out);
+
+ scrub_stats = &priv->scrub_stat;
+
+ ret = br_get_bad_objects_list(this, dict);
+ if (ret) {
+ gf_msg_debug(this->name, 0,
+ "Failed to collect corrupt "
+ "files");
+ }
+
+ ret = dict_set_int8(*dict, "scrub-running", scrub_stats->scrub_running);
+ if (ret) {
+ gf_msg_debug(this->name, 0,
+ "Failed setting scrub_running "
+ "entry to the dictionary");
+ }
+
+ ret = dict_set_uint64(*dict, "scrubbed-files", scrub_stats->scrubbed_files);
+ if (ret) {
+ gf_msg_debug(this->name, 0,
+ "Failed to setting scrubbed file "
+ "entry to the dictionary");
+ }
+
+ ret = dict_set_uint64(*dict, "unsigned-files", scrub_stats->unsigned_files);
+ if (ret) {
+ gf_msg_debug(this->name, 0,
+ "Failed to set unsigned file count"
+ " entry to the dictionary");
+ }
+
+ ret = dict_set_uint64(*dict, "scrub-duration", scrub_stats->scrub_duration);
+ if (ret) {
+ gf_msg_debug(this->name, 0,
+ "Failed to set scrub duration"
+ " entry to the dictionary");
+ }
+
+ ret = dict_set_dynstr_with_alloc(*dict, "last-scrub-time",
+ scrub_stats->last_scrub_time);
+ if (ret) {
+ gf_msg_debug(this->name, 0,
+ "Failed to set "
+ "last scrub time value");
+ }
out:
- return ret;
+ return ret;
}
int
-notify (xlator_t *this, int32_t event, void *data, ...)
+notify(xlator_t *this, int32_t event, void *data, ...)
{
- int idx = -1;
- int ret = -1;
- xlator_t *subvol = NULL;
- br_child_t *child = NULL;
- br_private_t *priv = NULL;
- dict_t *output = NULL;
- va_list ap;
- struct br_monitor *scrub_monitor = NULL;
+ int idx = -1;
+ int ret = -1;
+ xlator_t *subvol = NULL;
+ br_child_t *child = NULL;
+ br_private_t *priv = NULL;
+ dict_t *output = NULL;
+ va_list ap;
+ struct br_monitor *scrub_monitor = NULL;
- subvol = (xlator_t *)data;
- priv = this->private;
- scrub_monitor = &priv->scrub_monitor;
+ subvol = (xlator_t *)data;
+ priv = this->private;
+ scrub_monitor = &priv->scrub_monitor;
- gf_msg_trace (this->name, 0, "Notification received: %d", event);
+ gf_msg_trace(this->name, 0, "Notification received: %d", event);
- idx = br_find_child_index (this, subvol);
+ idx = br_find_child_index(this, subvol);
- switch (event) {
+ switch (event) {
case GF_EVENT_CHILD_UP:
- if (idx < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_INVALID_SUBVOL, "Got event %d from "
- "invalid subvolume", event);
- goto out;
- }
-
- pthread_mutex_lock (&priv->lock);
- {
- child = &priv->children[idx];
- if (child->child_up == 1)
- goto unblock_0;
- priv->up_children++;
-
- child->child_up = 1;
- child->xl = subvol;
- if (!child->table)
- child->table = inode_table_new (4096, subvol);
-
- _br_qchild_event (this, child, br_brick_connect);
- pthread_cond_signal (&priv->cond);
- }
+ if (idx < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_INVALID_SUBVOL,
+ "Got event %d from "
+ "invalid subvolume",
+ event);
+ goto out;
+ }
+
+ pthread_mutex_lock(&priv->lock);
+ {
+ child = &priv->children[idx];
+ if (child->child_up == 1)
+ goto unblock_0;
+ priv->up_children++;
+
+ child->child_up = 1;
+ child->xl = subvol;
+ if (!child->table)
+ child->table = inode_table_new(4096, subvol);
+
+ _br_qchild_event(this, child, br_brick_connect);
+ pthread_cond_signal(&priv->cond);
+ }
unblock_0:
- pthread_mutex_unlock (&priv->lock);
+ pthread_mutex_unlock(&priv->lock);
- if (priv->up_children == priv->child_count)
- default_notify (this, event, data);
- break;
+ if (priv->up_children == priv->child_count)
+ default_notify(this, event, data);
+ break;
case GF_EVENT_CHILD_DOWN:
- if (idx < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_INVALID_SUBVOL_CHILD,
- "Got event %d from invalid subvolume", event);
- goto out;
- }
-
- pthread_mutex_lock (&priv->lock);
- {
- child = &priv->children[idx];
- if (child->child_up == 0)
- goto unblock_1;
-
- child->child_up = 0;
- priv->up_children--;
-
- _br_qchild_event (this, child, br_brick_disconnect);
- pthread_cond_signal (&priv->cond);
- }
+ if (idx < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ BRB_MSG_INVALID_SUBVOL_CHILD,
+ "Got event %d from invalid subvolume", event);
+ goto out;
+ }
+
+ pthread_mutex_lock(&priv->lock);
+ {
+ child = &priv->children[idx];
+ if (child->child_up == 0)
+ goto unblock_1;
+
+ child->child_up = 0;
+ priv->up_children--;
+
+ _br_qchild_event(this, child, br_brick_disconnect);
+ pthread_cond_signal(&priv->cond);
+ }
unblock_1:
- pthread_mutex_unlock (&priv->lock);
+ pthread_mutex_unlock(&priv->lock);
- if (priv->up_children == 0)
- default_notify (this, event, data);
- break;
+ if (priv->up_children == 0)
+ default_notify(this, event, data);
+ break;
case GF_EVENT_SCRUB_STATUS:
- gf_msg_debug (this->name, GF_LOG_INFO, "BitRot scrub status "
- "called");
- va_start (ap, data);
- output = va_arg (ap, dict_t *);
- va_end (ap);
-
- ret = br_scrubber_status_get (this, &output);
- gf_msg_debug (this->name, 0, "returning %d", ret);
- break;
+ gf_msg_debug(this->name, GF_LOG_INFO,
+ "BitRot scrub status "
+ "called");
+ va_start(ap, data);
+ output = va_arg(ap, dict_t *);
+ va_end(ap);
+
+ ret = br_scrubber_status_get(this, &output);
+ gf_msg_debug(this->name, 0, "returning %d", ret);
+ break;
case GF_EVENT_SCRUB_ONDEMAND:
- gf_log (this->name, GF_LOG_INFO, "BitRot scrub ondemand "
- "called");
-
- if (scrub_monitor->state != BR_SCRUB_STATE_PENDING) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_RESCHEDULE_SCRUBBER_FAILED,
- "on demand scrub schedule failed. Scrubber is "
- "not in pending state. Current state is %d",
- scrub_monitor->state);
- return -2;
- }
-
- /* Needs synchronization with reconfigure thread */
- pthread_mutex_lock (&priv->lock);
- {
- ret = br_scrub_state_machine (this, _gf_true);
- }
- pthread_mutex_unlock (&priv->lock);
-
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_RESCHEDULE_SCRUBBER_FAILED,
- "Could not schedule ondemand scrubbing. "
- "Scrubbing will continue according to "
- "old frequency.");
- }
- gf_msg_debug (this->name, 0, "returning %d", ret);
- break;
+ gf_log(this->name, GF_LOG_INFO,
+ "BitRot scrub ondemand "
+ "called");
+
+ if (scrub_monitor->state != BR_SCRUB_STATE_PENDING) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ BRB_MSG_RESCHEDULE_SCRUBBER_FAILED,
+ "on demand scrub schedule failed. Scrubber is "
+ "not in pending state. Current state is %d",
+ scrub_monitor->state);
+ return -2;
+ }
+
+ /* Needs synchronization with reconfigure thread */
+ pthread_mutex_lock(&priv->lock);
+ {
+ ret = br_scrub_state_machine(this, _gf_true);
+ }
+ pthread_mutex_unlock(&priv->lock);
+
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ BRB_MSG_RESCHEDULE_SCRUBBER_FAILED,
+ "Could not schedule ondemand scrubbing. "
+ "Scrubbing will continue according to "
+ "old frequency.");
+ }
+ gf_msg_debug(this->name, 0, "returning %d", ret);
+ break;
default:
- default_notify (this, event, data);
- }
+ default_notify(this, event, data);
+ }
- out:
- return 0;
+out:
+ return 0;
}
/**
@@ -1720,62 +1740,62 @@ notify (xlator_t *this, int32_t event, void *data, ...)
*/
static void
-br_fini_signer (xlator_t *this, br_private_t *priv)
+br_fini_signer(xlator_t *this, br_private_t *priv)
{
- int i = 0;
+ int i = 0;
- for (; i < BR_WORKERS; i++) {
- (void) gf_thread_cleanup_xint (priv->obj_queue->workers[i]);
- }
+ for (; i < BR_WORKERS; i++) {
+ (void)gf_thread_cleanup_xint(priv->obj_queue->workers[i]);
+ }
- pthread_cond_destroy (&priv->object_cond);
+ pthread_cond_destroy(&priv->object_cond);
}
static int32_t
-br_init_signer (xlator_t *this, br_private_t *priv)
+br_init_signer(xlator_t *this, br_private_t *priv)
{
- int i = 0;
- int32_t ret = -1;
+ int i = 0;
+ int32_t ret = -1;
- /* initialize gfchangelog xlator context */
- ret = gf_changelog_init (this);
- if (ret)
- goto out;
+ /* initialize gfchangelog xlator context */
+ ret = gf_changelog_init(this);
+ if (ret)
+ goto out;
- pthread_cond_init (&priv->object_cond, NULL);
-
- priv->obj_queue = GF_CALLOC (1, sizeof (*priv->obj_queue),
- gf_br_mt_br_ob_n_wk_t);
- if (!priv->obj_queue)
- goto cleanup_cond;
- INIT_LIST_HEAD (&priv->obj_queue->objects);
-
- for (i = 0; i < BR_WORKERS; i++) {
- ret = gf_thread_create (&priv->obj_queue->workers[i], NULL,
- br_process_object, this, "brpobj");
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, -ret,
- BRB_MSG_SPAWN_FAILED, "thread creation"
- " failed");
- ret = -1;
- goto cleanup_threads;
- }
- }
+ pthread_cond_init(&priv->object_cond, NULL);
- return 0;
+ priv->obj_queue = GF_CALLOC(1, sizeof(*priv->obj_queue),
+ gf_br_mt_br_ob_n_wk_t);
+ if (!priv->obj_queue)
+ goto cleanup_cond;
+ INIT_LIST_HEAD(&priv->obj_queue->objects);
- cleanup_threads:
- for (i--; i >= 0; i--) {
- (void) gf_thread_cleanup_xint (priv->obj_queue->workers[i]);
+ for (i = 0; i < BR_WORKERS; i++) {
+ ret = gf_thread_create(&priv->obj_queue->workers[i], NULL,
+ br_process_object, this, "brpobj");
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, -ret, BRB_MSG_SPAWN_FAILED,
+ "thread creation"
+ " failed");
+ ret = -1;
+ goto cleanup_threads;
}
+ }
+
+ return 0;
+
+cleanup_threads:
+ for (i--; i >= 0; i--) {
+ (void)gf_thread_cleanup_xint(priv->obj_queue->workers[i]);
+ }
- GF_FREE (priv->obj_queue);
+ GF_FREE(priv->obj_queue);
- cleanup_cond:
- /* that's explicit */
- pthread_cond_destroy (&priv->object_cond);
- out:
- return -1;
+cleanup_cond:
+ /* that's explicit */
+ pthread_cond_destroy(&priv->object_cond);
+out:
+ return -1;
}
/**
@@ -1784,360 +1804,356 @@ br_init_signer (xlator_t *this, br_private_t *priv)
* throttle.
*/
static int32_t
-br_rate_limit_signer (xlator_t *this, int child_count, int numbricks)
+br_rate_limit_signer(xlator_t *this, int child_count, int numbricks)
{
- br_private_t *priv = NULL;
- tbf_opspec_t spec = {0,};
-
- priv = this->private;
-
- spec.op = TBF_OP_HASH;
- spec.rate = 0;
- spec.maxlimit = 0;
-
-/**
- * OK. Most implementations of TBF I've come across generate tokens
- * every second (UML, etc..) and some chose sub-second granularity
- * (blk-iothrottle cgroups). TBF algorithm itself does not enforce
- * any logic for choosing generation interval and it seems pretty
- * logical as one could jack up token count per interval w.r.t.
- * generation rate.
- *
- * Value used here is chosen based on a series of test(s) performed
- * to balance object signing time and not maxing out on all available
- * CPU cores. It's obvious to have seconds granularity and jack up
- * token count per interval, thereby achieving close to similar
- * results. Let's stick to this as it seems to be working fine for
- * the set of ops that are throttled.
- **/
- spec.token_gen_interval = 600000; /* In usec */
-
+ br_private_t *priv = NULL;
+ tbf_opspec_t spec = {
+ 0,
+ };
+
+ priv = this->private;
+
+ spec.op = TBF_OP_HASH;
+ spec.rate = 0;
+ spec.maxlimit = 0;
+
+ /**
+ * OK. Most implementations of TBF I've come across generate tokens
+ * every second (UML, etc..) and some chose sub-second granularity
+ * (blk-iothrottle cgroups). TBF algorithm itself does not enforce
+ * any logic for choosing generation interval and it seems pretty
+ * logical as one could jack up token count per interval w.r.t.
+ * generation rate.
+ *
+ * Value used here is chosen based on a series of test(s) performed
+ * to balance object signing time and not maxing out on all available
+ * CPU cores. It's obvious to have seconds granularity and jack up
+ * token count per interval, thereby achieving close to similar
+ * results. Let's stick to this as it seems to be working fine for
+ * the set of ops that are throttled.
+ **/
+ spec.token_gen_interval = 600000; /* In usec */
#ifdef BR_RATE_LIMIT_SIGNER
- double contribution = 0;
- contribution = ((double)1 - ((double)child_count / (double)numbricks));
- if (contribution == 0)
- contribution = 1;
- spec.rate = BR_HASH_CALC_READ_SIZE * contribution;
- spec.maxlimit = BR_WORKERS * BR_HASH_CALC_READ_SIZE;
+ double contribution = 0;
+ contribution = ((double)1 - ((double)child_count / (double)numbricks));
+ if (contribution == 0)
+ contribution = 1;
+ spec.rate = BR_HASH_CALC_READ_SIZE * contribution;
+ spec.maxlimit = BR_WORKERS * BR_HASH_CALC_READ_SIZE;
#endif
- if (!spec.rate)
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_RATE_LIMIT_INFO,
- "[Rate Limit Info] \"FULL THROTTLE\"");
- else
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_RATE_LIMIT_INFO,
- "[Rate Limit Info] \"tokens/sec (rate): %lu, "
- "maxlimit: %lu\"", spec.rate, spec.maxlimit);
-
- priv->tbf = tbf_init (&spec, 1);
- return priv->tbf ? 0 : -1;
+ if (!spec.rate)
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_RATE_LIMIT_INFO,
+ "[Rate Limit Info] \"FULL THROTTLE\"");
+ else
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_RATE_LIMIT_INFO,
+ "[Rate Limit Info] \"tokens/sec (rate): %lu, "
+ "maxlimit: %lu\"",
+ spec.rate, spec.maxlimit);
+
+ priv->tbf = tbf_init(&spec, 1);
+ return priv->tbf ? 0 : -1;
}
static int32_t
-br_signer_handle_options (xlator_t *this, br_private_t *priv, dict_t *options)
+br_signer_handle_options(xlator_t *this, br_private_t *priv, dict_t *options)
{
- if (options)
- GF_OPTION_RECONF ("expiry-time", priv->expiry_time,
- options, uint32, error_return);
- else
- GF_OPTION_INIT ("expiry-time", priv->expiry_time,
- uint32, error_return);
+ if (options)
+ GF_OPTION_RECONF("expiry-time", priv->expiry_time, options, uint32,
+ error_return);
+ else
+ GF_OPTION_INIT("expiry-time", priv->expiry_time, uint32, error_return);
- return 0;
+ return 0;
error_return:
- return -1;
+ return -1;
}
static int32_t
-br_signer_init (xlator_t *this, br_private_t *priv)
+br_signer_init(xlator_t *this, br_private_t *priv)
{
- int32_t ret = 0;
- int numbricks = 0;
+ int32_t ret = 0;
+ int numbricks = 0;
- GF_OPTION_INIT ("expiry-time", priv->expiry_time, uint32, error_return);
- GF_OPTION_INIT ("brick-count", numbricks, int32, error_return);
+ GF_OPTION_INIT("expiry-time", priv->expiry_time, uint32, error_return);
+ GF_OPTION_INIT("brick-count", numbricks, int32, error_return);
- ret = br_rate_limit_signer (this, priv->child_count, numbricks);
- if (ret)
- goto error_return;
+ ret = br_rate_limit_signer(this, priv->child_count, numbricks);
+ if (ret)
+ goto error_return;
- ret = br_init_signer (this, priv);
- if (ret)
- goto cleanup_tbf;
+ ret = br_init_signer(this, priv);
+ if (ret)
+ goto cleanup_tbf;
- return 0;
-
- cleanup_tbf:
- /* cleanup TBF */
- error_return:
- return -1;
+ return 0;
+cleanup_tbf:
+ /* cleanup TBF */
+error_return:
+ return -1;
}
static void
-br_free_scrubber_monitor (xlator_t *this, br_private_t *priv)
+br_free_scrubber_monitor(xlator_t *this, br_private_t *priv)
{
- struct br_monitor *scrub_monitor = &priv->scrub_monitor;
+ struct br_monitor *scrub_monitor = &priv->scrub_monitor;
- if (scrub_monitor->timer) {
- (void) gf_tw_del_timer (priv->timer_wheel, scrub_monitor->timer);
+ if (scrub_monitor->timer) {
+ (void)gf_tw_del_timer(priv->timer_wheel, scrub_monitor->timer);
- GF_FREE (scrub_monitor->timer);
- scrub_monitor->timer = NULL;
- }
+ GF_FREE(scrub_monitor->timer);
+ scrub_monitor->timer = NULL;
+ }
- (void) gf_thread_cleanup_xint (scrub_monitor->thread);
+ (void)gf_thread_cleanup_xint(scrub_monitor->thread);
- /* Clean up cond and mutex variables */
- pthread_mutex_destroy (&scrub_monitor->mutex);
- pthread_cond_destroy (&scrub_monitor->cond);
+ /* Clean up cond and mutex variables */
+ pthread_mutex_destroy(&scrub_monitor->mutex);
+ pthread_cond_destroy(&scrub_monitor->cond);
- pthread_mutex_destroy (&scrub_monitor->wakelock);
- pthread_cond_destroy (&scrub_monitor->wakecond);
+ pthread_mutex_destroy(&scrub_monitor->wakelock);
+ pthread_cond_destroy(&scrub_monitor->wakecond);
- pthread_mutex_destroy (&scrub_monitor->donelock);
- pthread_cond_destroy (&scrub_monitor->donecond);
+ pthread_mutex_destroy(&scrub_monitor->donelock);
+ pthread_cond_destroy(&scrub_monitor->donecond);
- LOCK_DESTROY (&scrub_monitor->lock);
+ LOCK_DESTROY(&scrub_monitor->lock);
}
static void
-br_free_children (xlator_t *this, br_private_t *priv, int count)
+br_free_children(xlator_t *this, br_private_t *priv, int count)
{
- br_child_t *child = NULL;
+ br_child_t *child = NULL;
- for (--count; count >= 0; count--) {
- child = &priv->children[count];
- mem_pool_destroy (child->timer_pool);
- pthread_mutex_destroy (&child->lock);
- }
+ for (--count; count >= 0; count--) {
+ child = &priv->children[count];
+ mem_pool_destroy(child->timer_pool);
+ pthread_mutex_destroy(&child->lock);
+ }
- GF_FREE (priv->children);
- priv->children = NULL;
+ GF_FREE(priv->children);
+ priv->children = NULL;
}
static int
-br_init_children (xlator_t *this, br_private_t *priv)
+br_init_children(xlator_t *this, br_private_t *priv)
{
- int i = 0;
- br_child_t *child = NULL;
- xlator_list_t *trav = NULL;
-
- priv->child_count = xlator_subvolume_count (this);
- priv->children = GF_CALLOC (priv->child_count, sizeof (*priv->children),
- gf_br_mt_br_child_t);
- if (!priv->children)
- goto err;
-
- trav = this->children;
- while (trav) {
- child = &priv->children[i];
-
- pthread_mutex_init (&child->lock, NULL);
- child->witnessed = 0;
-
- br_set_child_state (child, BR_CHILD_STATE_DISCONNECTED);
-
- child->this = this;
- child->xl = trav->xlator;
-
- child->timer_pool = mem_pool_new
- (struct gf_tw_timer_list, 4096);
- if (!child->timer_pool) {
- gf_msg (this->name, GF_LOG_ERROR,
- ENOMEM, BRB_MSG_NO_MEMORY,
- "failed to allocate mem-pool for timer");
- errno = ENOMEM;
- goto freechild;
- }
-
- INIT_LIST_HEAD (&child->list);
-
- i++;
- trav = trav->next;
+ int i = 0;
+ br_child_t *child = NULL;
+ xlator_list_t *trav = NULL;
+
+ priv->child_count = xlator_subvolume_count(this);
+ priv->children = GF_CALLOC(priv->child_count, sizeof(*priv->children),
+ gf_br_mt_br_child_t);
+ if (!priv->children)
+ goto err;
+
+ trav = this->children;
+ while (trav) {
+ child = &priv->children[i];
+
+ pthread_mutex_init(&child->lock, NULL);
+ child->witnessed = 0;
+
+ br_set_child_state(child, BR_CHILD_STATE_DISCONNECTED);
+
+ child->this = this;
+ child->xl = trav->xlator;
+
+ child->timer_pool = mem_pool_new(struct gf_tw_timer_list, 4096);
+ if (!child->timer_pool) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
+ "failed to allocate mem-pool for timer");
+ errno = ENOMEM;
+ goto freechild;
}
- return 0;
+ INIT_LIST_HEAD(&child->list);
+
+ i++;
+ trav = trav->next;
+ }
+
+ return 0;
- freechild:
- br_free_children (this, priv, i);
- err:
- return -1;
+freechild:
+ br_free_children(this, priv, i);
+err:
+ return -1;
}
int32_t
-init (xlator_t *this)
+init(xlator_t *this)
{
- int32_t ret = -1;
- br_private_t *priv = NULL;
-
- if (!this->children) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRB_MSG_NO_CHILD,
- "FATAL: no children");
- goto out;
- }
-
- priv = GF_CALLOC (1, sizeof (*priv), gf_br_mt_br_private_t);
- if (!priv) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
- "failed to allocate memory (->priv)");
- goto out;
- }
+ int32_t ret = -1;
+ br_private_t *priv = NULL;
- GF_OPTION_INIT ("scrubber", priv->iamscrubber, bool, free_priv);
+ if (!this->children) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_NO_CHILD,
+ "FATAL: no children");
+ goto out;
+ }
- ret = br_init_children (this, priv);
- if (ret)
- goto free_priv;
+ priv = GF_CALLOC(1, sizeof(*priv), gf_br_mt_br_private_t);
+ if (!priv) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
+ "failed to allocate memory (->priv)");
+ goto out;
+ }
- pthread_mutex_init (&priv->lock, NULL);
- pthread_cond_init (&priv->cond, NULL);
+ GF_OPTION_INIT("scrubber", priv->iamscrubber, bool, free_priv);
- INIT_LIST_HEAD (&priv->bricks);
- INIT_LIST_HEAD (&priv->signing);
+ ret = br_init_children(this, priv);
+ if (ret)
+ goto free_priv;
- priv->timer_wheel = glusterfs_ctx_tw_get (this->ctx);
- if (!priv->timer_wheel) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_TIMER_WHEEL_UNAVAILABLE,
- "global timer wheel unavailable");
- goto cleanup;
- }
+ pthread_mutex_init(&priv->lock, NULL);
+ pthread_cond_init(&priv->cond, NULL);
- this->private = priv;
+ INIT_LIST_HEAD(&priv->bricks);
+ INIT_LIST_HEAD(&priv->signing);
- if (!priv->iamscrubber) {
- ret = br_signer_init (this, priv);
- if (!ret)
- ret = br_signer_handle_options (this, priv, NULL);
- } else {
- ret = br_scrubber_init (this, priv);
- if (!ret)
- ret = br_scrubber_handle_options (this, priv, NULL);
- }
+ priv->timer_wheel = glusterfs_ctx_tw_get(this->ctx);
+ if (!priv->timer_wheel) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_TIMER_WHEEL_UNAVAILABLE,
+ "global timer wheel unavailable");
+ goto cleanup;
+ }
- if (ret)
- goto cleanup;
+ this->private = priv;
- ret = gf_thread_create (&priv->thread, NULL, br_handle_events, this,
- "brhevent");
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, -ret,
- BRB_MSG_SPAWN_FAILED, "thread creation failed");
- ret = -1;
- }
+ if (!priv->iamscrubber) {
+ ret = br_signer_init(this, priv);
+ if (!ret)
+ ret = br_signer_handle_options(this, priv, NULL);
+ } else {
+ ret = br_scrubber_init(this, priv);
+ if (!ret)
+ ret = br_scrubber_handle_options(this, priv, NULL);
+ }
- if (!ret) {
- gf_msg (this->name, GF_LOG_INFO, 0, BRB_MSG_BITROT_LOADED,
- "bit-rot xlator loaded in \"%s\" mode",
- (priv->iamscrubber) ? "SCRUBBER" : "SIGNER");
- return 0;
- }
+ if (ret)
+ goto cleanup;
- cleanup:
- (void) pthread_cond_destroy (&priv->cond);
- (void) pthread_mutex_destroy (&priv->lock);
+ ret = gf_thread_create(&priv->thread, NULL, br_handle_events, this,
+ "brhevent");
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, -ret, BRB_MSG_SPAWN_FAILED,
+ "thread creation failed");
+ ret = -1;
+ }
- br_free_children (this, priv, priv->child_count);
+ if (!ret) {
+ gf_msg(this->name, GF_LOG_INFO, 0, BRB_MSG_BITROT_LOADED,
+ "bit-rot xlator loaded in \"%s\" mode",
+ (priv->iamscrubber) ? "SCRUBBER" : "SIGNER");
+ return 0;
+ }
- free_priv:
- GF_FREE (priv);
- out:
- this->private = NULL;
- return -1;
+cleanup:
+ (void)pthread_cond_destroy(&priv->cond);
+ (void)pthread_mutex_destroy(&priv->lock);
+
+ br_free_children(this, priv, priv->child_count);
+
+free_priv:
+ GF_FREE(priv);
+out:
+ this->private = NULL;
+ return -1;
}
void
-fini (xlator_t *this)
+fini(xlator_t *this)
{
- br_private_t *priv = this->private;
+ br_private_t *priv = this->private;
- if (!priv)
- return;
+ if (!priv)
+ return;
- if (!priv->iamscrubber)
- br_fini_signer (this, priv);
- else
- (void) br_free_scrubber_monitor (this, priv);
+ if (!priv->iamscrubber)
+ br_fini_signer(this, priv);
+ else
+ (void)br_free_scrubber_monitor(this, priv);
- br_free_children (this, priv, priv->child_count);
+ br_free_children(this, priv, priv->child_count);
- this->private = NULL;
- GF_FREE (priv);
+ this->private = NULL;
+ GF_FREE(priv);
- glusterfs_ctx_tw_put (this->ctx);
+ glusterfs_ctx_tw_put(this->ctx);
- return;
+ return;
}
static void
-br_reconfigure_monitor (xlator_t *this)
+br_reconfigure_monitor(xlator_t *this)
{
- int32_t ret = 0;
-
- ret = br_scrub_state_machine (this, _gf_false);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRB_MSG_RESCHEDULE_SCRUBBER_FAILED,
- "Could not reschedule scrubber for the volume. Scrubbing "
- "will continue according to old frequency.");
- }
+ int32_t ret = 0;
+
+ ret = br_scrub_state_machine(this, _gf_false);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRB_MSG_RESCHEDULE_SCRUBBER_FAILED,
+ "Could not reschedule scrubber for the volume. Scrubbing "
+ "will continue according to old frequency.");
+ }
}
static int
-br_reconfigure_scrubber (xlator_t *this, dict_t *options)
+br_reconfigure_scrubber(xlator_t *this, dict_t *options)
{
- int32_t ret = -1;
- br_private_t *priv = NULL;
+ int32_t ret = -1;
+ br_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- pthread_mutex_lock (&priv->lock);
- {
- ret = br_scrubber_handle_options (this, priv, options);
- }
- pthread_mutex_unlock (&priv->lock);
+ pthread_mutex_lock(&priv->lock);
+ {
+ ret = br_scrubber_handle_options(this, priv, options);
+ }
+ pthread_mutex_unlock(&priv->lock);
- if (ret)
- goto err;
+ if (ret)
+ goto err;
- /* change state for all _up_ subvolume(s) */
- pthread_mutex_lock (&priv->lock);
- {
- br_reconfigure_monitor (this);
- }
- pthread_mutex_unlock (&priv->lock);
+ /* change state for all _up_ subvolume(s) */
+ pthread_mutex_lock(&priv->lock);
+ {
+ br_reconfigure_monitor(this);
+ }
+ pthread_mutex_unlock(&priv->lock);
- err:
- return ret;
+err:
+ return ret;
}
static int
-br_reconfigure_signer (xlator_t *this, dict_t *options)
+br_reconfigure_signer(xlator_t *this, dict_t *options)
{
- br_private_t *priv = this->private;
+ br_private_t *priv = this->private;
- return br_signer_handle_options (this, priv, options);
+ return br_signer_handle_options(this, priv, options);
}
int
-reconfigure (xlator_t *this, dict_t *options)
+reconfigure(xlator_t *this, dict_t *options)
{
- int ret = 0;
- br_private_t *priv = NULL;
+ int ret = 0;
+ br_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- if (priv->iamscrubber)
- ret = br_reconfigure_scrubber (this, options);
- else
- ret = br_reconfigure_signer (this, options);
+ if (priv->iamscrubber)
+ ret = br_reconfigure_scrubber(this, options);
+ else
+ ret = br_reconfigure_signer(this, options);
- return ret;
+ return ret;
}
struct xlator_fops fops;
@@ -2145,49 +2161,55 @@ struct xlator_fops fops;
struct xlator_cbks cbks;
struct volume_options options[] = {
- { .key = {"expiry-time"},
- .type = GF_OPTION_TYPE_INT,
- .default_value = SIGNING_TIMEOUT,
- .op_version = {GD_OP_VERSION_3_7_0},
- .flags = OPT_FLAG_SETTABLE,
- .description = "Waiting time for an object on which it waits "
- "before it is signed",
- },
- { .key = {"brick-count"},
- .type = GF_OPTION_TYPE_STR,
- .description = "Total number of bricks for the current node for "
- "all volumes in the trusted storage pool.",
- },
- { .key = {"scrubber", "scrub"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "false",
- .op_version = {GD_OP_VERSION_3_7_0},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_FORCE,
- .description = "option to run as a scrubber",
- },
- { .key = {"scrub-throttle"},
- .type = GF_OPTION_TYPE_STR,
- .default_value = "lazy",
- .op_version = {GD_OP_VERSION_3_7_0},
- .flags = OPT_FLAG_SETTABLE,
- .description = "Scrub-throttle value is a measure of how fast "
- "or slow the scrubber scrubs the filesystem for "
- "volume <VOLNAME>",
- },
- { .key = {"scrub-freq"},
- .type = GF_OPTION_TYPE_STR,
- .default_value = "biweekly",
- .op_version = {GD_OP_VERSION_3_7_0},
- .flags = OPT_FLAG_SETTABLE,
- .description = "Scrub frequency for volume <VOLNAME>",
- },
- { .key = {"scrub-state"},
- .type = GF_OPTION_TYPE_STR,
- .default_value = "active",
- .op_version = {GD_OP_VERSION_4_0_0},
- .flags = OPT_FLAG_SETTABLE,
- .description = "Pause/Resume scrub. Upon resume, scrubber "
- "continues from where it left off.",
- },
- { .key = {NULL} },
+ {
+ .key = {"expiry-time"},
+ .type = GF_OPTION_TYPE_INT,
+ .default_value = SIGNING_TIMEOUT,
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .flags = OPT_FLAG_SETTABLE,
+ .description = "Waiting time for an object on which it waits "
+ "before it is signed",
+ },
+ {
+ .key = {"brick-count"},
+ .type = GF_OPTION_TYPE_STR,
+ .description = "Total number of bricks for the current node for "
+ "all volumes in the trusted storage pool.",
+ },
+ {
+ .key = {"scrubber", "scrub"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "false",
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_FORCE,
+ .description = "option to run as a scrubber",
+ },
+ {
+ .key = {"scrub-throttle"},
+ .type = GF_OPTION_TYPE_STR,
+ .default_value = "lazy",
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .flags = OPT_FLAG_SETTABLE,
+ .description = "Scrub-throttle value is a measure of how fast "
+ "or slow the scrubber scrubs the filesystem for "
+ "volume <VOLNAME>",
+ },
+ {
+ .key = {"scrub-freq"},
+ .type = GF_OPTION_TYPE_STR,
+ .default_value = "biweekly",
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .flags = OPT_FLAG_SETTABLE,
+ .description = "Scrub frequency for volume <VOLNAME>",
+ },
+ {
+ .key = {"scrub-state"},
+ .type = GF_OPTION_TYPE_STR,
+ .default_value = "active",
+ .op_version = {GD_OP_VERSION_4_0_0},
+ .flags = OPT_FLAG_SETTABLE,
+ .description = "Pause/Resume scrub. Upon resume, scrubber "
+ "continues from where it left off.",
+ },
+ {.key = {NULL}},
};
diff --git a/xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c b/xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c
index 42398bbf2ca..cb567297b60 100644
--- a/xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c
+++ b/xlators/features/bit-rot/src/stub/bit-rot-stub-helpers.c
@@ -11,89 +11,88 @@
#include "bit-rot-stub.h"
br_stub_fd_t *
-br_stub_fd_new (void)
+br_stub_fd_new(void)
{
- br_stub_fd_t *br_stub_fd = NULL;
+ br_stub_fd_t *br_stub_fd = NULL;
- br_stub_fd = GF_CALLOC (1, sizeof (*br_stub_fd),
- gf_br_stub_mt_br_stub_fd_t);
+ br_stub_fd = GF_CALLOC(1, sizeof(*br_stub_fd), gf_br_stub_mt_br_stub_fd_t);
- return br_stub_fd;
+ return br_stub_fd;
}
int
-__br_stub_fd_ctx_set (xlator_t *this, fd_t *fd, br_stub_fd_t *br_stub_fd)
+__br_stub_fd_ctx_set(xlator_t *this, fd_t *fd, br_stub_fd_t *br_stub_fd)
{
- uint64_t value = 0;
- int ret = -1;
+ uint64_t value = 0;
+ int ret = -1;
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, out);
- GF_VALIDATE_OR_GOTO (this->name, fd, out);
- GF_VALIDATE_OR_GOTO (this->name, br_stub_fd, out);
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, fd, out);
+ GF_VALIDATE_OR_GOTO(this->name, br_stub_fd, out);
- value = (uint64_t)(long) br_stub_fd;
+ value = (uint64_t)(long)br_stub_fd;
- ret = __fd_ctx_set (fd, this, value);
+ ret = __fd_ctx_set(fd, this, value);
out:
- return ret;
+ return ret;
}
br_stub_fd_t *
-__br_stub_fd_ctx_get (xlator_t *this, fd_t *fd)
+__br_stub_fd_ctx_get(xlator_t *this, fd_t *fd)
{
- br_stub_fd_t *br_stub_fd = NULL;
- uint64_t value = 0;
- int ret = -1;
+ br_stub_fd_t *br_stub_fd = NULL;
+ uint64_t value = 0;
+ int ret = -1;
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, out);
- GF_VALIDATE_OR_GOTO (this->name, fd, out);
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, fd, out);
- ret = __fd_ctx_get (fd, this, &value);
- if (ret)
- return NULL;
+ ret = __fd_ctx_get(fd, this, &value);
+ if (ret)
+ return NULL;
- br_stub_fd = (br_stub_fd_t *) ((long) value);
+ br_stub_fd = (br_stub_fd_t *)((long)value);
out:
- return br_stub_fd;
+ return br_stub_fd;
}
br_stub_fd_t *
-br_stub_fd_ctx_get (xlator_t *this, fd_t *fd)
+br_stub_fd_ctx_get(xlator_t *this, fd_t *fd)
{
- br_stub_fd_t *br_stub_fd = NULL;
+ br_stub_fd_t *br_stub_fd = NULL;
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, out);
- GF_VALIDATE_OR_GOTO (this->name, fd, out);
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, fd, out);
- LOCK (&fd->lock);
- {
- br_stub_fd = __br_stub_fd_ctx_get (this, fd);
- }
- UNLOCK (&fd->lock);
+ LOCK(&fd->lock);
+ {
+ br_stub_fd = __br_stub_fd_ctx_get(this, fd);
+ }
+ UNLOCK(&fd->lock);
out:
- return br_stub_fd;
+ return br_stub_fd;
}
int32_t
-br_stub_fd_ctx_set (xlator_t *this, fd_t *fd, br_stub_fd_t *br_stub_fd)
+br_stub_fd_ctx_set(xlator_t *this, fd_t *fd, br_stub_fd_t *br_stub_fd)
{
- int32_t ret = -1;
+ int32_t ret = -1;
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, out);
- GF_VALIDATE_OR_GOTO (this->name, fd, out);
- GF_VALIDATE_OR_GOTO (this->name, br_stub_fd, out);
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, fd, out);
+ GF_VALIDATE_OR_GOTO(this->name, br_stub_fd, out);
- LOCK (&fd->lock);
- {
- ret = __br_stub_fd_ctx_set (this, fd, br_stub_fd);
- }
- UNLOCK (&fd->lock);
+ LOCK(&fd->lock);
+ {
+ ret = __br_stub_fd_ctx_set(this, fd, br_stub_fd);
+ }
+ UNLOCK(&fd->lock);
out:
- return ret;
+ return ret;
}
/**
@@ -101,114 +100,114 @@ out:
* @gfid: gfid of the bad object being added to the bad objects directory
*/
int
-br_stub_add (xlator_t *this, uuid_t gfid)
+br_stub_add(xlator_t *this, uuid_t gfid)
{
- char gfid_path[BR_PATH_MAX_PLUS] = {0};
- char bad_gfid_path[BR_PATH_MAX_PLUS] = {0};
- int ret = 0;
- br_stub_private_t *priv = NULL;
- struct stat st = {0};
-
- priv = this->private;
- GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, !gf_uuid_is_null (gfid),
- out, errno, EINVAL);
+ char gfid_path[BR_PATH_MAX_PLUS] = {0};
+ char bad_gfid_path[BR_PATH_MAX_PLUS] = {0};
+ int ret = 0;
+ br_stub_private_t *priv = NULL;
+ struct stat st = {0};
+
+ priv = this->private;
+ GF_ASSERT_AND_GOTO_WITH_ERROR(this->name, !gf_uuid_is_null(gfid), out,
+ errno, EINVAL);
+
+ snprintf(gfid_path, sizeof(gfid_path), "%s/%s", priv->stub_basepath,
+ uuid_utoa(gfid));
+
+ ret = sys_stat(gfid_path, &st);
+ if (!ret)
+ goto out;
+ snprintf(bad_gfid_path, sizeof(bad_gfid_path), "%s/stub-%s",
+ priv->stub_basepath, uuid_utoa(priv->bad_object_dir_gfid));
+
+ ret = sys_link(bad_gfid_path, gfid_path);
+ if (ret) {
+ if ((errno != ENOENT) && (errno != EMLINK) && (errno != EEXIST))
+ goto out;
- snprintf (gfid_path, sizeof (gfid_path), "%s/%s",
- priv->stub_basepath, uuid_utoa (gfid));
-
- ret = sys_stat (gfid_path, &st);
- if (!ret)
- goto out;
- snprintf (bad_gfid_path, sizeof (bad_gfid_path), "%s/stub-%s",
- priv->stub_basepath, uuid_utoa (priv->bad_object_dir_gfid));
-
- ret = sys_link (bad_gfid_path, gfid_path);
- if (ret) {
- if ((errno != ENOENT) && (errno != EMLINK) && (errno != EEXIST))
- goto out;
-
- /*
- * Continue with success. At least we'll have half of the
- * functionality, in the sense, object is marked bad and
- * would be inaccessible. It's only scrub status that would
- * show up less number of objects. That's fine as we'll have
- * the log files that will have the missing information.
- */
- gf_msg (this->name, GF_LOG_WARNING, errno, BRS_MSG_LINK_FAIL,
- "failed to record gfid [%s]", uuid_utoa (gfid));
- }
+ /*
+ * Continue with success. At least we'll have half of the
+ * functionality, in the sense, object is marked bad and
+ * would be inaccessible. It's only scrub status that would
+ * show up less number of objects. That's fine as we'll have
+ * the log files that will have the missing information.
+ */
+ gf_msg(this->name, GF_LOG_WARNING, errno, BRS_MSG_LINK_FAIL,
+ "failed to record gfid [%s]", uuid_utoa(gfid));
+ }
- return 0;
+ return 0;
out:
- return -1;
+ return -1;
}
int
-br_stub_del (xlator_t *this, uuid_t gfid)
+br_stub_del(xlator_t *this, uuid_t gfid)
{
- int32_t op_errno __attribute__((unused)) = 0;
- br_stub_private_t *priv = NULL;
- int ret = 0;
- char gfid_path[BR_PATH_MAX_PLUS] = {0};
-
- priv = this->private;
- GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, !gf_uuid_is_null (gfid),
- out, op_errno, EINVAL);
- snprintf (gfid_path, sizeof (gfid_path), "%s/%s",
- priv->stub_basepath, uuid_utoa (gfid));
- ret = sys_unlink (gfid_path);
- if (ret && (errno != ENOENT)) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- BRS_MSG_BAD_OBJ_UNLINK_FAIL,
- "%s: failed to delete bad object link from quarantine "
- "directory", gfid_path);
- ret = -errno;
- goto out;
- }
-
- ret = 0;
+ int32_t op_errno __attribute__((unused)) = 0;
+ br_stub_private_t *priv = NULL;
+ int ret = 0;
+ char gfid_path[BR_PATH_MAX_PLUS] = {0};
+
+ priv = this->private;
+ GF_ASSERT_AND_GOTO_WITH_ERROR(this->name, !gf_uuid_is_null(gfid), out,
+ op_errno, EINVAL);
+ snprintf(gfid_path, sizeof(gfid_path), "%s/%s", priv->stub_basepath,
+ uuid_utoa(gfid));
+ ret = sys_unlink(gfid_path);
+ if (ret && (errno != ENOENT)) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, BRS_MSG_BAD_OBJ_UNLINK_FAIL,
+ "%s: failed to delete bad object link from quarantine "
+ "directory",
+ gfid_path);
+ ret = -errno;
+ goto out;
+ }
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
static int
-br_stub_check_stub_directory (xlator_t *this, char *fullpath)
+br_stub_check_stub_directory(xlator_t *this, char *fullpath)
{
- int ret = 0;
- struct stat st = {0,};
- char oldpath[BR_PATH_MAX_PLUS] = {0};
- br_stub_private_t *priv = NULL;
-
- priv = this->private;
-
- snprintf (oldpath, sizeof (oldpath), "%s/%s",
- priv->export, OLD_BR_STUB_QUARANTINE_DIR);
-
- ret = sys_stat (fullpath, &st);
- if (!ret && !S_ISDIR (st.st_mode))
- goto error_return;
- if (ret) {
- if (errno != ENOENT)
- goto error_return;
- ret = sys_stat (oldpath, &st);
- if (ret)
- ret = mkdir_p (fullpath, 0600, _gf_true);
- else
- ret = sys_rename (oldpath, fullpath);
- }
-
+ int ret = 0;
+ struct stat st = {
+ 0,
+ };
+ char oldpath[BR_PATH_MAX_PLUS] = {0};
+ br_stub_private_t *priv = NULL;
+
+ priv = this->private;
+
+ snprintf(oldpath, sizeof(oldpath), "%s/%s", priv->export,
+ OLD_BR_STUB_QUARANTINE_DIR);
+
+ ret = sys_stat(fullpath, &st);
+ if (!ret && !S_ISDIR(st.st_mode))
+ goto error_return;
+ if (ret) {
+ if (errno != ENOENT)
+ goto error_return;
+ ret = sys_stat(oldpath, &st);
if (ret)
- gf_msg (this->name, GF_LOG_ERROR, errno,
- BRS_MSG_BAD_OBJECT_DIR_FAIL,
- "failed to create stub directory [%s]", fullpath);
- return ret;
+ ret = mkdir_p(fullpath, 0600, _gf_true);
+ else
+ ret = sys_rename(oldpath, fullpath);
+ }
+
+ if (ret)
+ gf_msg(this->name, GF_LOG_ERROR, errno, BRS_MSG_BAD_OBJECT_DIR_FAIL,
+ "failed to create stub directory [%s]", fullpath);
+ return ret;
error_return:
- gf_msg (this->name, GF_LOG_ERROR, errno,
- BRS_MSG_BAD_OBJECT_DIR_FAIL,
- "Failed to verify stub directory [%s]", fullpath);
- return -1;
+ gf_msg(this->name, GF_LOG_ERROR, errno, BRS_MSG_BAD_OBJECT_DIR_FAIL,
+ "Failed to verify stub directory [%s]", fullpath);
+ return -1;
}
/**
@@ -216,397 +215,405 @@ error_return:
* directory.
*/
static int
-br_stub_check_stub_file (xlator_t *this, char *path)
+br_stub_check_stub_file(xlator_t *this, char *path)
{
- int ret = 0;
- int fd = -1;
- struct stat st = {0,};
-
- ret = sys_stat (path, &st);
- if (!ret && !S_ISREG (st.st_mode))
- goto error_return;
- if (ret) {
- if (errno != ENOENT)
- goto error_return;
- fd = sys_creat (path, 0);
- if (fd < 0)
- gf_msg (this->name, GF_LOG_ERROR, errno,
- BRS_MSG_BAD_OBJECT_DIR_FAIL,
- "Failed to create stub file [%s]", path);
- }
-
- if (fd >= 0) {
- sys_close (fd);
- ret = 0;
- }
+ int ret = 0;
+ int fd = -1;
+ struct stat st = {
+ 0,
+ };
+
+ ret = sys_stat(path, &st);
+ if (!ret && !S_ISREG(st.st_mode))
+ goto error_return;
+ if (ret) {
+ if (errno != ENOENT)
+ goto error_return;
+ fd = sys_creat(path, 0);
+ if (fd < 0)
+ gf_msg(this->name, GF_LOG_ERROR, errno, BRS_MSG_BAD_OBJECT_DIR_FAIL,
+ "Failed to create stub file [%s]", path);
+ }
+
+ if (fd >= 0) {
+ sys_close(fd);
+ ret = 0;
+ }
- return ret;
+ return ret;
error_return:
- gf_msg (this->name, GF_LOG_ERROR, errno,
- BRS_MSG_BAD_OBJECT_DIR_FAIL, "Failed to verify stub file [%s]", path);
- return -1;
+ gf_msg(this->name, GF_LOG_ERROR, errno, BRS_MSG_BAD_OBJECT_DIR_FAIL,
+ "Failed to verify stub file [%s]", path);
+ return -1;
}
int
-br_stub_dir_create (xlator_t *this, br_stub_private_t *priv)
+br_stub_dir_create(xlator_t *this, br_stub_private_t *priv)
{
- int ret = -1;
- char fullpath[BR_PATH_MAX_PLUS] = {0,};
- char stub_gfid_path[BR_PATH_MAX_PLUS] = {0,};
-
- gf_uuid_copy (priv->bad_object_dir_gfid, BR_BAD_OBJ_CONTAINER);
-
- if (snprintf (fullpath, sizeof (fullpath), "%s",
- priv->stub_basepath) >= sizeof (fullpath))
- goto out;
-
- if (snprintf (stub_gfid_path, sizeof (stub_gfid_path), "%s/stub-%s",
- priv->stub_basepath, uuid_utoa (priv->bad_object_dir_gfid))
- >= sizeof (stub_gfid_path))
- goto out;
-
- ret = br_stub_check_stub_directory (this, fullpath);
- if (ret)
- goto out;
- ret = br_stub_check_stub_file (this, stub_gfid_path);
- if (ret)
- goto out;
-
- return 0;
+ int ret = -1;
+ char fullpath[BR_PATH_MAX_PLUS] = {
+ 0,
+ };
+ char stub_gfid_path[BR_PATH_MAX_PLUS] = {
+ 0,
+ };
+
+ gf_uuid_copy(priv->bad_object_dir_gfid, BR_BAD_OBJ_CONTAINER);
+
+ if (snprintf(fullpath, sizeof(fullpath), "%s", priv->stub_basepath) >=
+ sizeof(fullpath))
+ goto out;
+
+ if (snprintf(stub_gfid_path, sizeof(stub_gfid_path), "%s/stub-%s",
+ priv->stub_basepath, uuid_utoa(priv->bad_object_dir_gfid)) >=
+ sizeof(stub_gfid_path))
+ goto out;
+
+ ret = br_stub_check_stub_directory(this, fullpath);
+ if (ret)
+ goto out;
+ ret = br_stub_check_stub_file(this, stub_gfid_path);
+ if (ret)
+ goto out;
+
+ return 0;
out:
- return -1;
+ return -1;
}
call_stub_t *
-__br_stub_dequeue (struct list_head *callstubs)
+__br_stub_dequeue(struct list_head *callstubs)
{
- call_stub_t *stub = NULL;
+ call_stub_t *stub = NULL;
- if (!list_empty (callstubs)) {
- stub = list_entry (callstubs->next, call_stub_t, list);
- list_del_init (&stub->list);
- }
+ if (!list_empty(callstubs)) {
+ stub = list_entry(callstubs->next, call_stub_t, list);
+ list_del_init(&stub->list);
+ }
- return stub;
+ return stub;
}
void
-__br_stub_enqueue (struct list_head *callstubs, call_stub_t *stub)
+__br_stub_enqueue(struct list_head *callstubs, call_stub_t *stub)
{
- list_add_tail (&stub->list, callstubs);
+ list_add_tail(&stub->list, callstubs);
}
void
-br_stub_worker_enqueue (xlator_t *this, call_stub_t *stub)
+br_stub_worker_enqueue(xlator_t *this, call_stub_t *stub)
{
- br_stub_private_t *priv = NULL;
-
- priv = this->private;
- pthread_mutex_lock (&priv->container.bad_lock);
- {
- __br_stub_enqueue (&priv->container.bad_queue, stub);
- pthread_cond_signal (&priv->container.bad_cond);
- }
- pthread_mutex_unlock (&priv->container.bad_lock);
+ br_stub_private_t *priv = NULL;
+
+ priv = this->private;
+ pthread_mutex_lock(&priv->container.bad_lock);
+ {
+ __br_stub_enqueue(&priv->container.bad_queue, stub);
+ pthread_cond_signal(&priv->container.bad_cond);
+ }
+ pthread_mutex_unlock(&priv->container.bad_lock);
}
void *
-br_stub_worker (void *data)
+br_stub_worker(void *data)
{
- br_stub_private_t *priv = NULL;
- xlator_t *this = NULL;
- call_stub_t *stub = NULL;
-
+ br_stub_private_t *priv = NULL;
+ xlator_t *this = NULL;
+ call_stub_t *stub = NULL;
- THIS = data;
- this = data;
- priv = this->private;
+ THIS = data;
+ this = data;
+ priv = this->private;
- for (;;) {
- pthread_mutex_lock (&priv->container.bad_lock);
- {
- while (list_empty (&priv->container.bad_queue)) {
- (void) pthread_cond_wait (&priv->container.bad_cond,
- &priv->container.bad_lock);
- }
-
- stub = __br_stub_dequeue (&priv->container.bad_queue);
- }
- pthread_mutex_unlock (&priv->container.bad_lock);
+ for (;;) {
+ pthread_mutex_lock(&priv->container.bad_lock);
+ {
+ while (list_empty(&priv->container.bad_queue)) {
+ (void)pthread_cond_wait(&priv->container.bad_cond,
+ &priv->container.bad_lock);
+ }
- if (stub) /* guard against spurious wakeups */
- call_resume (stub);
+ stub = __br_stub_dequeue(&priv->container.bad_queue);
}
+ pthread_mutex_unlock(&priv->container.bad_lock);
- return NULL;
+ if (stub) /* guard against spurious wakeups */
+ call_resume(stub);
+ }
+
+ return NULL;
}
int32_t
-br_stub_lookup_wrapper (call_frame_t *frame, xlator_t *this,
- loc_t *loc, dict_t *xattr_req)
+br_stub_lookup_wrapper(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ dict_t *xattr_req)
{
- br_stub_private_t *priv = NULL;
- struct stat lstatbuf = {0};
- int ret = 0;
- int32_t op_errno = EINVAL;
- int32_t op_ret = -1;
- struct iatt stbuf = {0, };
- struct iatt postparent = {0,};
- dict_t *xattr = NULL;
- gf_boolean_t ver_enabled = _gf_false;
-
- BR_STUB_VER_ENABLED_IN_CALLPATH(frame, ver_enabled);
- priv = this->private;
- BR_STUB_VER_COND_GOTO (priv, (!ver_enabled), done);
-
- VALIDATE_OR_GOTO (loc, done);
- if (gf_uuid_compare (loc->gfid, priv->bad_object_dir_gfid))
- goto done;
-
- ret = sys_lstat (priv->stub_basepath, &lstatbuf);
- if (ret) {
- gf_msg_debug (this->name, errno, "Stat failed on stub bad "
- "object dir");
- op_errno = errno;
- goto done;
- } else if (!S_ISDIR (lstatbuf.st_mode)) {
- gf_msg_debug (this->name, errno, "bad object container is not "
- "a directory");
- op_errno = ENOTDIR;
- goto done;
- }
-
- iatt_from_stat (&stbuf, &lstatbuf);
- gf_uuid_copy (stbuf.ia_gfid, priv->bad_object_dir_gfid);
-
- op_ret = op_errno = 0;
- xattr = dict_new ();
- if (!xattr) {
- op_ret = -1;
- op_errno = ENOMEM;
- }
+ br_stub_private_t *priv = NULL;
+ struct stat lstatbuf = {0};
+ int ret = 0;
+ int32_t op_errno = EINVAL;
+ int32_t op_ret = -1;
+ struct iatt stbuf = {
+ 0,
+ };
+ struct iatt postparent = {
+ 0,
+ };
+ dict_t *xattr = NULL;
+ gf_boolean_t ver_enabled = _gf_false;
+
+ BR_STUB_VER_ENABLED_IN_CALLPATH(frame, ver_enabled);
+ priv = this->private;
+ BR_STUB_VER_COND_GOTO(priv, (!ver_enabled), done);
+
+ VALIDATE_OR_GOTO(loc, done);
+ if (gf_uuid_compare(loc->gfid, priv->bad_object_dir_gfid))
+ goto done;
+
+ ret = sys_lstat(priv->stub_basepath, &lstatbuf);
+ if (ret) {
+ gf_msg_debug(this->name, errno,
+ "Stat failed on stub bad "
+ "object dir");
+ op_errno = errno;
+ goto done;
+ } else if (!S_ISDIR(lstatbuf.st_mode)) {
+ gf_msg_debug(this->name, errno,
+ "bad object container is not "
+ "a directory");
+ op_errno = ENOTDIR;
+ goto done;
+ }
+
+ iatt_from_stat(&stbuf, &lstatbuf);
+ gf_uuid_copy(stbuf.ia_gfid, priv->bad_object_dir_gfid);
+
+ op_ret = op_errno = 0;
+ xattr = dict_new();
+ if (!xattr) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ }
done:
- STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno,
- loc->inode, &stbuf, xattr, &postparent);
- if (xattr)
- dict_unref (xattr);
- return 0;
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, loc->inode, &stbuf,
+ xattr, &postparent);
+ if (xattr)
+ dict_unref(xattr);
+ return 0;
}
static int
-is_bad_gfid_file_current (char *filename, uuid_t gfid)
+is_bad_gfid_file_current(char *filename, uuid_t gfid)
{
- char current_stub_gfid[GF_UUID_BUF_SIZE + 16] = {0, };
+ char current_stub_gfid[GF_UUID_BUF_SIZE + 16] = {
+ 0,
+ };
- snprintf (current_stub_gfid, sizeof current_stub_gfid,
- "stub-%s", uuid_utoa(gfid));
- return (!strcmp(filename, current_stub_gfid));
+ snprintf(current_stub_gfid, sizeof current_stub_gfid, "stub-%s",
+ uuid_utoa(gfid));
+ return (!strcmp(filename, current_stub_gfid));
}
static void
-check_delete_stale_bad_file (xlator_t *this, char *filename)
+check_delete_stale_bad_file(xlator_t *this, char *filename)
{
- int ret = 0;
- struct stat st = {0};
- char filepath[BR_PATH_MAX_PLUS] = {0};
- br_stub_private_t *priv = NULL;
+ int ret = 0;
+ struct stat st = {0};
+ char filepath[BR_PATH_MAX_PLUS] = {0};
+ br_stub_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- if (is_bad_gfid_file_current (filename, priv->bad_object_dir_gfid))
- return;
+ if (is_bad_gfid_file_current(filename, priv->bad_object_dir_gfid))
+ return;
- snprintf (filepath, sizeof (filepath), "%s/%s",
- priv->stub_basepath, filename);
+ snprintf(filepath, sizeof(filepath), "%s/%s", priv->stub_basepath,
+ filename);
- ret = sys_stat (filepath, &st);
- if (!ret && st.st_nlink == 1)
- sys_unlink (filepath);
+ ret = sys_stat(filepath, &st);
+ if (!ret && st.st_nlink == 1)
+ sys_unlink(filepath);
}
static int
-br_stub_fill_readdir (fd_t *fd, br_stub_fd_t *fctx, DIR *dir, off_t off,
- size_t size, gf_dirent_t *entries)
+br_stub_fill_readdir(fd_t *fd, br_stub_fd_t *fctx, DIR *dir, off_t off,
+ size_t size, gf_dirent_t *entries)
{
- off_t in_case = -1;
- off_t last_off = 0;
- size_t filled = 0;
- int count = 0;
- int32_t this_size = -1;
- gf_dirent_t *this_entry = NULL;
- xlator_t *this = NULL;
- struct dirent *entry = NULL;
- struct dirent scratch[2] = {{0,},};
-
- this = THIS;
- if (!off) {
- rewinddir (dir);
- } else {
- seekdir (dir, off);
+ off_t in_case = -1;
+ off_t last_off = 0;
+ size_t filled = 0;
+ int count = 0;
+ int32_t this_size = -1;
+ gf_dirent_t *this_entry = NULL;
+ xlator_t *this = NULL;
+ struct dirent *entry = NULL;
+ struct dirent scratch[2] = {
+ {
+ 0,
+ },
+ };
+
+ this = THIS;
+ if (!off) {
+ rewinddir(dir);
+ } else {
+ seekdir(dir, off);
#ifndef GF_LINUX_HOST_OS
- if ((u_long)telldir(dir) != off &&
- off != fctx->bad_object.dir_eof) {
- gf_msg (THIS->name, GF_LOG_ERROR, 0,
- BRS_MSG_BAD_OBJECT_DIR_SEEK_FAIL,
- "seekdir(0x%llx) failed on dir=%p: "
- "Invalid argument (offset reused from "
- "another DIR * structure?)", off, dir);
- errno = EINVAL;
- count = -1;
- goto out;
- }
-#endif /* GF_LINUX_HOST_OS */
+ if ((u_long)telldir(dir) != off && off != fctx->bad_object.dir_eof) {
+ gf_msg(THIS->name, GF_LOG_ERROR, 0,
+ BRS_MSG_BAD_OBJECT_DIR_SEEK_FAIL,
+ "seekdir(0x%llx) failed on dir=%p: "
+ "Invalid argument (offset reused from "
+ "another DIR * structure?)",
+ off, dir);
+ errno = EINVAL;
+ count = -1;
+ goto out;
}
-
- while (filled <= size) {
- in_case = (u_long)telldir (dir);
-
- if (in_case == -1) {
- gf_msg (THIS->name, GF_LOG_ERROR, 0,
- BRS_MSG_BAD_OBJECT_DIR_TELL_FAIL,
- "telldir failed on dir=%p: %s",
- dir, strerror (errno));
- goto out;
- }
-
- errno = 0;
- entry = sys_readdir (dir, scratch);
- if (!entry || errno != 0) {
- if (errno == EBADF) {
- gf_msg (THIS->name, GF_LOG_WARNING, 0,
- BRS_MSG_BAD_OBJECT_DIR_READ_FAIL,
- "readdir failed on dir=%p: %s",
- dir, strerror (errno));
- goto out;
- }
- break;
- }
-
- if (!strcmp (entry->d_name, ".") ||
- !strcmp (entry->d_name, ".."))
- continue;
-
- if (!strncmp (entry->d_name, "stub-",
- strlen ("stub-"))) {
- check_delete_stale_bad_file (this, entry->d_name);
- continue;
- }
-
- this_size = max (sizeof (gf_dirent_t),
- sizeof (gfs3_dirplist))
- + strlen (entry->d_name) + 1;
-
- if (this_size + filled > size) {
- seekdir (dir, in_case);
-#ifndef GF_LINUX_HOST_OS
- if ((u_long)telldir(dir) != in_case &&
- in_case != fctx->bad_object.dir_eof) {
- gf_msg (THIS->name, GF_LOG_ERROR, 0,
- BRS_MSG_BAD_OBJECT_DIR_SEEK_FAIL,
- "seekdir(0x%llx) failed on dir=%p: "
- "Invalid argument (offset reused from "
- "another DIR * structure?)",
- in_case, dir);
- errno = EINVAL;
- count = -1;
- goto out;
- }
#endif /* GF_LINUX_HOST_OS */
- break;
- }
-
- this_entry = gf_dirent_for_name (entry->d_name);
-
- if (!this_entry) {
- gf_msg (THIS->name, GF_LOG_ERROR, 0,
- BRS_MSG_NO_MEMORY,
- "could not create gf_dirent for entry %s: (%s)",
- entry->d_name, strerror (errno));
- goto out;
- }
- /*
- * we store the offset of next entry here, which is
- * probably not intended, but code using syncop_readdir()
- * (glfs-heal.c, afr-self-heald.c, pump.c) rely on it
- * for directory read resumption.
- */
- last_off = (u_long)telldir(dir);
- this_entry->d_off = last_off;
- this_entry->d_ino = entry->d_ino;
-
- list_add_tail (&this_entry->list, &entries->list);
-
- filled += this_size;
- count++;
- }
+ }
- if ((!sys_readdir (dir, scratch) && (errno == 0))) {
- /* Indicate EOF */
- errno = ENOENT;
- /* Remember EOF offset for later detection */
- fctx->bad_object.dir_eof = last_off;
+ while (filled <= size) {
+ in_case = (u_long)telldir(dir);
+
+ if (in_case == -1) {
+ gf_msg(THIS->name, GF_LOG_ERROR, 0,
+ BRS_MSG_BAD_OBJECT_DIR_TELL_FAIL,
+ "telldir failed on dir=%p: %s", dir, strerror(errno));
+ goto out;
}
-out:
- return count;
-}
-int32_t
-br_stub_readdir_wrapper (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t off, dict_t *xdata)
-{
- br_stub_fd_t *fctx = NULL;
- DIR *dir = NULL;
- int ret = -1;
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- int count = 0;
- gf_dirent_t entries;
- gf_boolean_t xdata_unref = _gf_false;
- dict_t *dict = NULL;
-
- INIT_LIST_HEAD (&entries.list);
-
- fctx = br_stub_fd_ctx_get (this, fd);
- if (!fctx) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRS_MSG_GET_FD_CONTEXT_FAILED,
- "pfd is NULL, fd=%p", fd);
- op_errno = -ret;
- goto done;
+ errno = 0;
+ entry = sys_readdir(dir, scratch);
+ if (!entry || errno != 0) {
+ if (errno == EBADF) {
+ gf_msg(THIS->name, GF_LOG_WARNING, 0,
+ BRS_MSG_BAD_OBJECT_DIR_READ_FAIL,
+ "readdir failed on dir=%p: %s", dir, strerror(errno));
+ goto out;
+ }
+ break;
}
- dir = fctx->bad_object.dir;
+ if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
+ continue;
- if (!dir) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRS_MSG_BAD_HANDLE_DIR_NULL,
- "dir is NULL for fd=%p", fd);
- op_errno = EINVAL;
- goto done;
+ if (!strncmp(entry->d_name, "stub-", strlen("stub-"))) {
+ check_delete_stale_bad_file(this, entry->d_name);
+ continue;
}
- count = br_stub_fill_readdir (fd, fctx, dir, off, size, &entries);
+ this_size = max(sizeof(gf_dirent_t), sizeof(gfs3_dirplist)) +
+ strlen(entry->d_name) + 1;
- /* pick ENOENT to indicate EOF */
- op_errno = errno;
- op_ret = count;
+ if (this_size + filled > size) {
+ seekdir(dir, in_case);
+#ifndef GF_LINUX_HOST_OS
+ if ((u_long)telldir(dir) != in_case &&
+ in_case != fctx->bad_object.dir_eof) {
+ gf_msg(THIS->name, GF_LOG_ERROR, 0,
+ BRS_MSG_BAD_OBJECT_DIR_SEEK_FAIL,
+ "seekdir(0x%llx) failed on dir=%p: "
+ "Invalid argument (offset reused from "
+ "another DIR * structure?)",
+ in_case, dir);
+ errno = EINVAL;
+ count = -1;
+ goto out;
+ }
+#endif /* GF_LINUX_HOST_OS */
+ break;
+ }
+
+ this_entry = gf_dirent_for_name(entry->d_name);
- dict = xdata;
- (void) br_stub_bad_objects_path (this, fd, &entries, &dict);
- if (!xdata && dict) {
- xdata = dict;
- xdata_unref = _gf_true;
+ if (!this_entry) {
+ gf_msg(THIS->name, GF_LOG_ERROR, 0, BRS_MSG_NO_MEMORY,
+ "could not create gf_dirent for entry %s: (%s)",
+ entry->d_name, strerror(errno));
+ goto out;
}
+ /*
+ * we store the offset of next entry here, which is
+ * probably not intended, but code using syncop_readdir()
+ * (glfs-heal.c, afr-self-heald.c, pump.c) rely on it
+ * for directory read resumption.
+ */
+ last_off = (u_long)telldir(dir);
+ this_entry->d_off = last_off;
+ this_entry->d_ino = entry->d_ino;
+
+ list_add_tail(&this_entry->list, &entries->list);
+
+ filled += this_size;
+ count++;
+ }
+
+ if ((!sys_readdir(dir, scratch) && (errno == 0))) {
+ /* Indicate EOF */
+ errno = ENOENT;
+ /* Remember EOF offset for later detection */
+ fctx->bad_object.dir_eof = last_off;
+ }
+out:
+ return count;
+}
+
+int32_t
+br_stub_readdir_wrapper(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ size_t size, off_t off, dict_t *xdata)
+{
+ br_stub_fd_t *fctx = NULL;
+ DIR *dir = NULL;
+ int ret = -1;
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ int count = 0;
+ gf_dirent_t entries;
+ gf_boolean_t xdata_unref = _gf_false;
+ dict_t *dict = NULL;
+
+ INIT_LIST_HEAD(&entries.list);
+
+ fctx = br_stub_fd_ctx_get(this, fd);
+ if (!fctx) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_GET_FD_CONTEXT_FAILED,
+ "pfd is NULL, fd=%p", fd);
+ op_errno = -ret;
+ goto done;
+ }
+
+ dir = fctx->bad_object.dir;
+
+ if (!dir) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_BAD_HANDLE_DIR_NULL,
+ "dir is NULL for fd=%p", fd);
+ op_errno = EINVAL;
+ goto done;
+ }
+
+ count = br_stub_fill_readdir(fd, fctx, dir, off, size, &entries);
+
+ /* pick ENOENT to indicate EOF */
+ op_errno = errno;
+ op_ret = count;
+
+ dict = xdata;
+ (void)br_stub_bad_objects_path(this, fd, &entries, &dict);
+ if (!xdata && dict) {
+ xdata = dict;
+ xdata_unref = _gf_true;
+ }
done:
- STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, &entries, xdata);
- gf_dirent_free (&entries);
- if (xdata_unref)
- dict_unref (xdata);
- return 0;
+ STACK_UNWIND_STRICT(readdir, frame, op_ret, op_errno, &entries, xdata);
+ gf_dirent_free(&entries);
+ if (xdata_unref)
+ dict_unref(xdata);
+ return 0;
}
/**
@@ -642,168 +649,165 @@ done:
* path will not be printed in scrub and only the gfid will be there.
**/
int
-br_stub_bad_objects_path (xlator_t *this, fd_t *fd, gf_dirent_t *entries,
- dict_t **dict)
+br_stub_bad_objects_path(xlator_t *this, fd_t *fd, gf_dirent_t *entries,
+ dict_t **dict)
{
- gf_dirent_t *entry = NULL;
- inode_t *inode = NULL;
- char *hpath = NULL;
- uuid_t gfid = {0};
- int ret = -1;
- dict_t *tmp_dict = NULL;
- char str_gfid[64] = {0};
-
- if (list_empty(&entries->list))
- return 0;
+ gf_dirent_t *entry = NULL;
+ inode_t *inode = NULL;
+ char *hpath = NULL;
+ uuid_t gfid = {0};
+ int ret = -1;
+ dict_t *tmp_dict = NULL;
+ char str_gfid[64] = {0};
+
+ if (list_empty(&entries->list))
+ return 0;
- tmp_dict = *dict;
+ tmp_dict = *dict;
+ if (!tmp_dict) {
+ tmp_dict = dict_new();
+ /*
+ * If the allocation of dict fails then no need treat it
+ * it as a error. This path (or function) is executed when
+ * "gluster volume bitrot <volume name> scrub status" is
+ * executed, to get the list of the corrupted objects.
+ * And the motive of this function is to get the paths of
+ * the corrupted objects. If the dict allocation fails, then
+ * the scrub status will only show the gfids of those corrupted
+ * objects (which is the behavior as of the time of this patch
+ * being worked upon). So just return and only the gfids will
+ * be shown.
+ */
if (!tmp_dict) {
- tmp_dict = dict_new ();
- /*
- * If the allocation of dict fails then no need treat it
- * it as a error. This path (or function) is executed when
- * "gluster volume bitrot <volume name> scrub status" is
- * executed, to get the list of the corrupted objects.
- * And the motive of this function is to get the paths of
- * the corrupted objects. If the dict allocation fails, then
- * the scrub status will only show the gfids of those corrupted
- * objects (which is the behavior as of the time of this patch
- * being worked upon). So just return and only the gfids will
- * be shown.
- */
- if (!tmp_dict) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRS_MSG_NO_MEMORY,
- "failed to allocate new dict for saving the paths "
- "of the corrupted objects. Scrub status will only "
- "display the gfid");
- goto out;
- }
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_NO_MEMORY,
+ "failed to allocate new dict for saving the paths "
+ "of the corrupted objects. Scrub status will only "
+ "display the gfid");
+ goto out;
}
+ }
- list_for_each_entry (entry, &entries->list, list) {
- gf_uuid_clear (gfid);
- gf_uuid_parse (entry->d_name, gfid);
-
- inode = inode_find (fd->inode->table, gfid);
-
- /* No need to check the return value here.
- * Because @hpath is examined.
- */
- (void) br_stub_get_path_of_gfid (this, fd->inode, inode,
- gfid, &hpath);
-
- if (hpath) {
- gf_msg_debug (this->name, 0, "path of the corrupted "
- "object (gfid: %s) is %s",
- uuid_utoa (gfid), hpath);
- br_stub_entry_xattr_fill (this, hpath, entry, tmp_dict);
- } else
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRS_MSG_PATH_GET_FAILED,
- "failed to get the path for the inode %s",
- uuid_utoa_r (gfid, str_gfid));
-
- inode = NULL;
- hpath = NULL;
- }
+ list_for_each_entry(entry, &entries->list, list)
+ {
+ gf_uuid_clear(gfid);
+ gf_uuid_parse(entry->d_name, gfid);
- ret = 0;
- *dict = tmp_dict;
+ inode = inode_find(fd->inode->table, gfid);
+
+ /* No need to check the return value here.
+ * Because @hpath is examined.
+ */
+ (void)br_stub_get_path_of_gfid(this, fd->inode, inode, gfid, &hpath);
+
+ if (hpath) {
+ gf_msg_debug(this->name, 0,
+ "path of the corrupted "
+ "object (gfid: %s) is %s",
+ uuid_utoa(gfid), hpath);
+ br_stub_entry_xattr_fill(this, hpath, entry, tmp_dict);
+ } else
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_PATH_GET_FAILED,
+ "failed to get the path for the inode %s",
+ uuid_utoa_r(gfid, str_gfid));
+
+ inode = NULL;
+ hpath = NULL;
+ }
+
+ ret = 0;
+ *dict = tmp_dict;
out:
- return ret;
- }
+ return ret;
+}
int
-br_stub_get_path_of_gfid (xlator_t *this, inode_t *parent, inode_t *inode,
- uuid_t gfid, char **path)
+br_stub_get_path_of_gfid(xlator_t *this, inode_t *parent, inode_t *inode,
+ uuid_t gfid, char **path)
{
- int32_t ret = -1;
- char gfid_str[64] = {0};
-
- GF_VALIDATE_OR_GOTO ("bitrot-stub", this, out);
- GF_VALIDATE_OR_GOTO (this->name, parent, out);
- GF_VALIDATE_OR_GOTO (this->name, path, out);
-
- /* Above, No need to validate the @inode for hard resolution. Because
- * inode can be NULL and if it is NULL, then syncop_gfid_to_path_hard
- * will allocate a new inode and proceed. So no need to bother about
- * @inode. Because we need it only to send a syncop_getxattr call
- * from inside syncop_gfid_to_path_hard. And getxattr fetches the
- * path from the backend.
- */
-
- ret = syncop_gfid_to_path_hard (parent->table, FIRST_CHILD (this), gfid,
- inode, path, _gf_true);
+ int32_t ret = -1;
+ char gfid_str[64] = {0};
+
+ GF_VALIDATE_OR_GOTO("bitrot-stub", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, parent, out);
+ GF_VALIDATE_OR_GOTO(this->name, path, out);
+
+ /* Above, No need to validate the @inode for hard resolution. Because
+ * inode can be NULL and if it is NULL, then syncop_gfid_to_path_hard
+ * will allocate a new inode and proceed. So no need to bother about
+ * @inode. Because we need it only to send a syncop_getxattr call
+ * from inside syncop_gfid_to_path_hard. And getxattr fetches the
+ * path from the backend.
+ */
+
+ ret = syncop_gfid_to_path_hard(parent->table, FIRST_CHILD(this), gfid,
+ inode, path, _gf_true);
+ if (ret < 0)
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_PATH_GET_FAILED,
+ "failed to get the path xattr from disk for the "
+ " gfid %s. Trying to get path from the memory",
+ uuid_utoa_r(gfid, gfid_str));
+
+ /*
+ * Try with soft resolution of path if hard resolve fails. Because
+ * checking the xattr on disk to get the path of a inode (or gfid)
+ * is dependent on whether that option is enabled in the posix
+ * xlator or not. If it is not enabled, then hard resolution by
+ * checking the on disk xattr fails.
+ *
+ * Thus in such situations fall back to the soft resolution which
+ * mainly depends on the inode_path() function. And for using
+ * inode_path, @inode has to be linked i.e. a successful lookup should
+ * have happened on the gfid (or the path) to link the inode to the
+ * inode table. And if @inode is NULL, means, the inode has not been
+ * found in the inode table and better not to do inode_path() on the
+ * inode which has not been linked.
+ */
+ if (ret < 0 && inode) {
+ ret = syncop_gfid_to_path_hard(parent->table, FIRST_CHILD(this), gfid,
+ inode, path, _gf_false);
if (ret < 0)
- gf_msg (this->name, GF_LOG_WARNING, 0, BRS_MSG_PATH_GET_FAILED,
- "failed to get the path xattr from disk for the "
- " gfid %s. Trying to get path from the memory",
- uuid_utoa_r (gfid, gfid_str));
-
- /*
- * Try with soft resolution of path if hard resolve fails. Because
- * checking the xattr on disk to get the path of a inode (or gfid)
- * is dependent on whether that option is enabled in the posix
- * xlator or not. If it is not enabled, then hard resolution by
- * checking the on disk xattr fails.
- *
- * Thus in such situations fall back to the soft resolution which
- * mainly depends on the inode_path() function. And for using
- * inode_path, @inode has to be linked i.e. a successful lookup should
- * have happened on the gfid (or the path) to link the inode to the
- * inode table. And if @inode is NULL, means, the inode has not been
- * found in the inode table and better not to do inode_path() on the
- * inode which has not been linked.
- */
- if (ret < 0 && inode) {
- ret = syncop_gfid_to_path_hard (parent->table,
- FIRST_CHILD (this), gfid, inode,
- path, _gf_false);
- if (ret < 0)
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRS_MSG_PATH_GET_FAILED,
- "failed to get the path from the memory for gfid %s",
- uuid_utoa_r (gfid, gfid_str));
- }
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_PATH_GET_FAILED,
+ "failed to get the path from the memory for gfid %s",
+ uuid_utoa_r(gfid, gfid_str));
+ }
out:
- return ret;
+ return ret;
}
-
/**
-* NOTE: If the file has multiple hardlinks (in gluster volume
-* namespace), the path would be one of the hardlinks. Its up to
-* the user to find the remaining hardlinks (using find -samefile)
-* and remove them.
-**/
+ * NOTE: If the file has multiple hardlinks (in gluster volume
+ * namespace), the path would be one of the hardlinks. Its up to
+ * the user to find the remaining hardlinks (using find -samefile)
+ * and remove them.
+ **/
void
-br_stub_entry_xattr_fill (xlator_t *this, char *hpath, gf_dirent_t *entry,
- dict_t *dict)
+br_stub_entry_xattr_fill(xlator_t *this, char *hpath, gf_dirent_t *entry,
+ dict_t *dict)
{
- int32_t ret = -1;
-
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, out);
- GF_VALIDATE_OR_GOTO (this->name, hpath, out);
-
- /*
- * Use the entry->d_name (which is nothing but the gfid of the
- * corrupted object) as the key. And the value will be the actual
- * path of that object (or file).
- *
- * ALso ignore the dict_set errors. scrubber will get the gfid of
- * the corrupted object for sure. So, for now lets just log the
- * dict_set_dynstr failure and move on.
- */
-
- ret = dict_set_dynstr (dict, entry->d_name, hpath);
- if (ret)
- gf_msg (this->name, GF_LOG_WARNING, 0, BRS_MSG_DICT_SET_FAILED,
- "failed to set the actual path %s as the value in the "
- "dict for the corrupted object %s", hpath,
- entry->d_name);
+ int32_t ret = -1;
+
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, hpath, out);
+
+ /*
+ * Use the entry->d_name (which is nothing but the gfid of the
+ * corrupted object) as the key. And the value will be the actual
+ * path of that object (or file).
+ *
+ * ALso ignore the dict_set errors. scrubber will get the gfid of
+ * the corrupted object for sure. So, for now lets just log the
+ * dict_set_dynstr failure and move on.
+ */
+
+ ret = dict_set_dynstr(dict, entry->d_name, hpath);
+ if (ret)
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_DICT_SET_FAILED,
+ "failed to set the actual path %s as the value in the "
+ "dict for the corrupted object %s",
+ hpath, entry->d_name);
out:
- return;
+ return;
}
diff --git a/xlators/features/bit-rot/src/stub/bit-rot-stub.c b/xlators/features/bit-rot/src/stub/bit-rot-stub.c
index f7fdd491809..2f5cc2b18dd 100644
--- a/xlators/features/bit-rot/src/stub/bit-rot-stub.c
+++ b/xlators/features/bit-rot/src/stub/bit-rot-stub.c
@@ -24,171 +24,170 @@
#include "bit-rot-stub-messages.h"
#include "bit-rot-common.h"
-#define BR_STUB_REQUEST_COOKIE 0x1
+#define BR_STUB_REQUEST_COOKIE 0x1
-void *br_stub_signth (void *);
+void *
+br_stub_signth(void *);
struct br_stub_signentry {
- unsigned long v;
+ unsigned long v;
- call_stub_t *stub;
+ call_stub_t *stub;
- struct list_head list;
+ struct list_head list;
};
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int32_t ret = -1;
+ int32_t ret = -1;
- if (!this)
- return ret;
+ if (!this)
+ return ret;
- ret = xlator_mem_acct_init (this, gf_br_stub_mt_end + 1);
-
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0, BRS_MSG_MEM_ACNT_FAILED,
- "Memory accounting init failed");
- return ret;
- }
+ ret = xlator_mem_acct_init(this, gf_br_stub_mt_end + 1);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_MEM_ACNT_FAILED,
+ "Memory accounting init failed");
return ret;
+ }
+
+ return ret;
}
int
-br_stub_bad_object_container_init (xlator_t *this, br_stub_private_t *priv)
-{
- pthread_attr_t w_attr;
- int ret = -1;
-
- ret = pthread_cond_init(&priv->container.bad_cond, NULL);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_BAD_OBJ_THREAD_FAIL,
- "pthread_cond_init failed (%d)", ret);
- goto out;
- }
-
- ret = pthread_mutex_init(&priv->container.bad_lock, NULL);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_BAD_OBJ_THREAD_FAIL,
- "pthread_mutex_init failed (%d)", ret);
- goto cleanup_cond;
- }
-
- ret = pthread_attr_init (&w_attr);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_BAD_OBJ_THREAD_FAIL,
- "pthread_attr_init failed (%d)", ret);
- goto cleanup_lock;
- }
-
- ret = pthread_attr_setstacksize (&w_attr, BAD_OBJECT_THREAD_STACK_SIZE);
- if (ret == EINVAL) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRS_MSG_BAD_OBJ_THREAD_FAIL,
- "Using default thread stack size");
- }
-
- INIT_LIST_HEAD (&priv->container.bad_queue);
- ret = br_stub_dir_create (this, priv);
- if (ret < 0)
- goto cleanup_lock;
-
- ret = gf_thread_create (&priv->container.thread, &w_attr,
- br_stub_worker, this, "brswrker");
- if (ret)
- goto cleanup_attr;
-
- return 0;
+br_stub_bad_object_container_init(xlator_t *this, br_stub_private_t *priv)
+{
+ pthread_attr_t w_attr;
+ int ret = -1;
+
+ ret = pthread_cond_init(&priv->container.bad_cond, NULL);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_BAD_OBJ_THREAD_FAIL,
+ "pthread_cond_init failed (%d)", ret);
+ goto out;
+ }
+
+ ret = pthread_mutex_init(&priv->container.bad_lock, NULL);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_BAD_OBJ_THREAD_FAIL,
+ "pthread_mutex_init failed (%d)", ret);
+ goto cleanup_cond;
+ }
+
+ ret = pthread_attr_init(&w_attr);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_BAD_OBJ_THREAD_FAIL,
+ "pthread_attr_init failed (%d)", ret);
+ goto cleanup_lock;
+ }
+
+ ret = pthread_attr_setstacksize(&w_attr, BAD_OBJECT_THREAD_STACK_SIZE);
+ if (ret == EINVAL) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_BAD_OBJ_THREAD_FAIL,
+ "Using default thread stack size");
+ }
+
+ INIT_LIST_HEAD(&priv->container.bad_queue);
+ ret = br_stub_dir_create(this, priv);
+ if (ret < 0)
+ goto cleanup_lock;
+
+ ret = gf_thread_create(&priv->container.thread, &w_attr, br_stub_worker,
+ this, "brswrker");
+ if (ret)
+ goto cleanup_attr;
+
+ return 0;
cleanup_attr:
- pthread_attr_destroy (&w_attr);
+ pthread_attr_destroy(&w_attr);
cleanup_lock:
- pthread_mutex_destroy (&priv->container.bad_lock);
+ pthread_mutex_destroy(&priv->container.bad_lock);
cleanup_cond:
- pthread_cond_destroy (&priv->container.bad_cond);
+ pthread_cond_destroy(&priv->container.bad_cond);
out:
- return -1;
+ return -1;
}
int32_t
-init (xlator_t *this)
+init(xlator_t *this)
{
- int ret = 0;
- char *tmp = NULL;
- struct timeval tv = {0,};
- br_stub_private_t *priv = NULL;
+ int ret = 0;
+ char *tmp = NULL;
+ struct timeval tv = {
+ 0,
+ };
+ br_stub_private_t *priv = NULL;
- if (!this->children) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRS_MSG_NO_CHILD,
- "FATAL: no children");
- goto error_return;
- }
+ if (!this->children) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_NO_CHILD,
+ "FATAL: no children");
+ goto error_return;
+ }
- priv = GF_CALLOC (1, sizeof (*priv), gf_br_stub_mt_private_t);
- if (!priv)
- goto error_return;
+ priv = GF_CALLOC(1, sizeof(*priv), gf_br_stub_mt_private_t);
+ if (!priv)
+ goto error_return;
- priv->local_pool = mem_pool_new (br_stub_local_t, 512);
- if (!priv->local_pool)
- goto free_priv;
+ priv->local_pool = mem_pool_new(br_stub_local_t, 512);
+ if (!priv->local_pool)
+ goto free_priv;
- GF_OPTION_INIT ("bitrot", priv->do_versioning, bool, free_mempool);
+ GF_OPTION_INIT("bitrot", priv->do_versioning, bool, free_mempool);
- GF_OPTION_INIT ("export", tmp, str, free_mempool);
+ GF_OPTION_INIT("export", tmp, str, free_mempool);
- if (snprintf (priv->export, PATH_MAX, "%s", tmp) >= PATH_MAX)
- goto free_mempool;
+ if (snprintf(priv->export, PATH_MAX, "%s", tmp) >= PATH_MAX)
+ goto free_mempool;
- if (snprintf (priv->stub_basepath, sizeof (priv->stub_basepath),
- "%s/%s", priv->export, BR_STUB_QUARANTINE_DIR) >=
- sizeof (priv->stub_basepath))
- goto free_mempool;
+ if (snprintf(priv->stub_basepath, sizeof(priv->stub_basepath), "%s/%s",
+ priv->export,
+ BR_STUB_QUARANTINE_DIR) >= sizeof(priv->stub_basepath))
+ goto free_mempool;
- (void) gettimeofday (&tv, NULL);
+ (void)gettimeofday(&tv, NULL);
- /* boot time is in network endian format */
- priv->boot[0] = htonl (tv.tv_sec);
- priv->boot[1] = htonl (tv.tv_usec);
+ /* boot time is in network endian format */
+ priv->boot[0] = htonl(tv.tv_sec);
+ priv->boot[1] = htonl(tv.tv_usec);
- pthread_mutex_init (&priv->lock, NULL);
- pthread_cond_init (&priv->cond, NULL);
- INIT_LIST_HEAD (&priv->squeue);
+ pthread_mutex_init(&priv->lock, NULL);
+ pthread_cond_init(&priv->cond, NULL);
+ INIT_LIST_HEAD(&priv->squeue);
- /* Thread creations need 'this' to be passed so that THIS can be
- * assigned inside the thread. So setting this->private here.
- */
- this->private = priv;
+ /* Thread creations need 'this' to be passed so that THIS can be
+ * assigned inside the thread. So setting this->private here.
+ */
+ this->private = priv;
- ret = gf_thread_create (&priv->signth, NULL, br_stub_signth, this,
- "brssign");
- if (ret != 0)
- goto cleanup_lock;
+ ret = gf_thread_create(&priv->signth, NULL, br_stub_signth, this,
+ "brssign");
+ if (ret != 0)
+ goto cleanup_lock;
- ret = br_stub_bad_object_container_init (this, priv);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRS_MSG_BAD_CONTAINER_FAIL,
- "failed to launch the thread for storing bad gfids");
- goto cleanup_lock;
- }
+ ret = br_stub_bad_object_container_init(this, priv);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_BAD_CONTAINER_FAIL,
+ "failed to launch the thread for storing bad gfids");
+ goto cleanup_lock;
+ }
- gf_msg_debug (this->name, 0, "bit-rot stub loaded");
+ gf_msg_debug(this->name, 0, "bit-rot stub loaded");
- return 0;
+ return 0;
- cleanup_lock:
- pthread_cond_destroy (&priv->cond);
- pthread_mutex_destroy (&priv->lock);
- free_mempool:
- mem_pool_destroy (priv->local_pool);
- free_priv:
- GF_FREE (priv);
- this->private = NULL;
- error_return:
- return -1;
+cleanup_lock:
+ pthread_cond_destroy(&priv->cond);
+ pthread_mutex_destroy(&priv->lock);
+free_mempool:
+ mem_pool_destroy(priv->local_pool);
+free_priv:
+ GF_FREE(priv);
+ this->private = NULL;
+error_return:
+ return -1;
}
/* TODO:
@@ -205,178 +204,173 @@ init (xlator_t *this)
* Ex: ICAP.
*/
int32_t
-reconfigure (xlator_t *this, dict_t *options)
+reconfigure(xlator_t *this, dict_t *options)
{
- int32_t ret = -1;
- br_stub_private_t *priv = NULL;
+ int32_t ret = -1;
+ br_stub_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- GF_OPTION_RECONF ("bitrot", priv->do_versioning, options, bool, out);
+ GF_OPTION_RECONF("bitrot", priv->do_versioning, options, bool, out);
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
int
-notify (xlator_t *this, int event, void *data, ...)
+notify(xlator_t *this, int event, void *data, ...)
{
- br_stub_private_t *priv = NULL;
-
- if (!this)
- return 0;
+ br_stub_private_t *priv = NULL;
- priv = this->private;
- if (!priv)
- return 0;
+ if (!this)
+ return 0;
- default_notify (this, event, data);
+ priv = this->private;
+ if (!priv)
return 0;
+
+ default_notify(this, event, data);
+ return 0;
}
void
-fini (xlator_t *this)
+fini(xlator_t *this)
{
- int32_t ret = 0;
- br_stub_private_t *priv = this->private;
- struct br_stub_signentry *sigstub = NULL;
- call_stub_t *stub = NULL;
+ int32_t ret = 0;
+ br_stub_private_t *priv = this->private;
+ struct br_stub_signentry *sigstub = NULL;
+ call_stub_t *stub = NULL;
- if (!priv)
- return;
+ if (!priv)
+ return;
- ret = gf_thread_cleanup_xint (priv->signth);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_CANCEL_SIGN_THREAD_FAILED,
- "Could not cancel sign serializer thread");
- goto out;
- }
- priv->signth = 0;
+ ret = gf_thread_cleanup_xint(priv->signth);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_CANCEL_SIGN_THREAD_FAILED,
+ "Could not cancel sign serializer thread");
+ goto out;
+ }
+ priv->signth = 0;
- while (!list_empty (&priv->squeue)) {
- sigstub = list_first_entry (&priv->squeue,
- struct br_stub_signentry, list);
- list_del_init (&sigstub->list);
+ while (!list_empty(&priv->squeue)) {
+ sigstub = list_first_entry(&priv->squeue, struct br_stub_signentry,
+ list);
+ list_del_init(&sigstub->list);
- call_stub_destroy (sigstub->stub);
- GF_FREE (sigstub);
- }
+ call_stub_destroy(sigstub->stub);
+ GF_FREE(sigstub);
+ }
- pthread_mutex_destroy (&priv->lock);
- pthread_cond_destroy (&priv->cond);
+ pthread_mutex_destroy(&priv->lock);
+ pthread_cond_destroy(&priv->cond);
- ret = gf_thread_cleanup_xint (priv->container.thread);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_CANCEL_SIGN_THREAD_FAILED,
- "Could not cancel sign serializer thread");
- goto out;
- }
+ ret = gf_thread_cleanup_xint(priv->container.thread);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_CANCEL_SIGN_THREAD_FAILED,
+ "Could not cancel sign serializer thread");
+ goto out;
+ }
- priv->container.thread = 0;
+ priv->container.thread = 0;
- while (!list_empty (&priv->container.bad_queue)) {
- stub = list_first_entry (&priv->container.bad_queue, call_stub_t,
- list);
- list_del_init (&stub->list);
- call_stub_destroy (stub);
- }
+ while (!list_empty(&priv->container.bad_queue)) {
+ stub = list_first_entry(&priv->container.bad_queue, call_stub_t, list);
+ list_del_init(&stub->list);
+ call_stub_destroy(stub);
+ }
- if (priv->local_pool) {
- mem_pool_destroy (priv->local_pool);
- priv->local_pool = NULL;
- }
+ if (priv->local_pool) {
+ mem_pool_destroy(priv->local_pool);
+ priv->local_pool = NULL;
+ }
- pthread_mutex_destroy (&priv->container.bad_lock);
- pthread_cond_destroy (&priv->container.bad_cond);
+ pthread_mutex_destroy(&priv->container.bad_lock);
+ pthread_cond_destroy(&priv->container.bad_cond);
- this->private = NULL;
- GF_FREE (priv);
+ this->private = NULL;
+ GF_FREE(priv);
- out:
- return;
+out:
+ return;
}
static int
-br_stub_alloc_versions (br_version_t **obuf,
- br_signature_t **sbuf, size_t signaturelen)
+br_stub_alloc_versions(br_version_t **obuf, br_signature_t **sbuf,
+ size_t signaturelen)
{
- void *mem = NULL;
- size_t size = 0;
+ void *mem = NULL;
+ size_t size = 0;
- if (obuf)
- size += sizeof (br_version_t);
- if (sbuf)
- size += sizeof (br_signature_t) + signaturelen;
+ if (obuf)
+ size += sizeof(br_version_t);
+ if (sbuf)
+ size += sizeof(br_signature_t) + signaturelen;
- mem = GF_CALLOC (1, size, gf_br_stub_mt_version_t);
- if (!mem)
- goto error_return;
+ mem = GF_CALLOC(1, size, gf_br_stub_mt_version_t);
+ if (!mem)
+ goto error_return;
- if (obuf) {
- *obuf = (br_version_t *)mem;
- mem = ((char *)mem + sizeof (br_version_t));
- }
- if (sbuf) {
- *sbuf = (br_signature_t *)mem;
- }
+ if (obuf) {
+ *obuf = (br_version_t *)mem;
+ mem = ((char *)mem + sizeof(br_version_t));
+ }
+ if (sbuf) {
+ *sbuf = (br_signature_t *)mem;
+ }
- return 0;
+ return 0;
- error_return:
- return -1;
+error_return:
+ return -1;
}
static void
-br_stub_dealloc_versions (void *mem)
+br_stub_dealloc_versions(void *mem)
{
- GF_FREE (mem);
+ GF_FREE(mem);
}
static br_stub_local_t *
-br_stub_alloc_local (xlator_t *this)
+br_stub_alloc_local(xlator_t *this)
{
- br_stub_private_t *priv = this->private;
+ br_stub_private_t *priv = this->private;
- return mem_get0 (priv->local_pool);
+ return mem_get0(priv->local_pool);
}
static void
-br_stub_dealloc_local (br_stub_local_t *ptr)
+br_stub_dealloc_local(br_stub_local_t *ptr)
{
- if (!ptr)
- return;
+ if (!ptr)
+ return;
- mem_put (ptr);
+ mem_put(ptr);
}
static int
-br_stub_prepare_version_request (xlator_t *this, dict_t *dict,
+br_stub_prepare_version_request(xlator_t *this, dict_t *dict,
br_version_t *obuf, unsigned long oversion)
{
- br_stub_private_t *priv = NULL;
+ br_stub_private_t *priv = NULL;
- priv = this->private;
- br_set_ongoingversion (obuf, oversion, priv->boot);
+ priv = this->private;
+ br_set_ongoingversion(obuf, oversion, priv->boot);
- return dict_set_static_bin (dict, BITROT_CURRENT_VERSION_KEY,
- (void *)obuf, sizeof (br_version_t));
+ return dict_set_static_bin(dict, BITROT_CURRENT_VERSION_KEY, (void *)obuf,
+ sizeof(br_version_t));
}
static int
-br_stub_prepare_signing_request (dict_t *dict,
- br_signature_t *sbuf,
- br_isignature_t *sign, size_t signaturelen)
+br_stub_prepare_signing_request(dict_t *dict, br_signature_t *sbuf,
+ br_isignature_t *sign, size_t signaturelen)
{
- size_t size = 0;
+ size_t size = 0;
- br_set_signature (sbuf, sign, signaturelen, &size);
+ br_set_signature(sbuf, sign, signaturelen, &size);
- return dict_set_static_bin (dict, BITROT_SIGNING_VERSION_KEY,
- (void *)sbuf, size);
+ return dict_set_static_bin(dict, BITROT_SIGNING_VERSION_KEY, (void *)sbuf,
+ size);
}
/**
@@ -386,253 +380,250 @@ br_stub_prepare_signing_request (dict_t *dict,
* initializes the transient inode version.
*/
static int
-br_stub_init_inode_versions (xlator_t *this, fd_t *fd, inode_t *inode,
- unsigned long version, gf_boolean_t markdirty,
- gf_boolean_t bad_object, uint64_t *ctx_addr)
-{
- int32_t ret = 0;
- br_stub_inode_ctx_t *ctx = NULL;
-
- ctx = GF_CALLOC (1, sizeof (br_stub_inode_ctx_t),
- gf_br_stub_mt_inode_ctx_t);
- if (!ctx)
- goto error_return;
-
- INIT_LIST_HEAD (&ctx->fd_list);
- (markdirty) ? __br_stub_mark_inode_dirty (ctx)
- : __br_stub_mark_inode_synced (ctx);
- __br_stub_set_ongoing_version (ctx, version);
-
- if (bad_object)
- __br_stub_mark_object_bad (ctx);
-
- if (fd) {
- ret = br_stub_add_fd_to_inode (this, fd, ctx);
- if (ret)
- goto free_ctx;
- }
+br_stub_init_inode_versions(xlator_t *this, fd_t *fd, inode_t *inode,
+ unsigned long version, gf_boolean_t markdirty,
+ gf_boolean_t bad_object, uint64_t *ctx_addr)
+{
+ int32_t ret = 0;
+ br_stub_inode_ctx_t *ctx = NULL;
+
+ ctx = GF_CALLOC(1, sizeof(br_stub_inode_ctx_t), gf_br_stub_mt_inode_ctx_t);
+ if (!ctx)
+ goto error_return;
+
+ INIT_LIST_HEAD(&ctx->fd_list);
+ (markdirty) ? __br_stub_mark_inode_dirty(ctx)
+ : __br_stub_mark_inode_synced(ctx);
+ __br_stub_set_ongoing_version(ctx, version);
- ret = br_stub_set_inode_ctx (this, inode, ctx);
+ if (bad_object)
+ __br_stub_mark_object_bad(ctx);
+
+ if (fd) {
+ ret = br_stub_add_fd_to_inode(this, fd, ctx);
if (ret)
- goto free_ctx;
+ goto free_ctx;
+ }
- if (ctx_addr)
- *ctx_addr = (uint64_t) ctx;
- return 0;
+ ret = br_stub_set_inode_ctx(this, inode, ctx);
+ if (ret)
+ goto free_ctx;
+
+ if (ctx_addr)
+ *ctx_addr = (uint64_t)ctx;
+ return 0;
free_ctx:
- GF_FREE (ctx);
- error_return:
- return -1;
+ GF_FREE(ctx);
+error_return:
+ return -1;
}
/**
* modify the ongoing version of an inode.
*/
static int
-br_stub_mod_inode_versions (xlator_t *this,
- fd_t *fd, inode_t *inode, unsigned long version)
+br_stub_mod_inode_versions(xlator_t *this, fd_t *fd, inode_t *inode,
+ unsigned long version)
{
- int32_t ret = -1;
- br_stub_inode_ctx_t *ctx = 0;
+ int32_t ret = -1;
+ br_stub_inode_ctx_t *ctx = 0;
- LOCK (&inode->lock);
- {
- ctx = __br_stub_get_ongoing_version_ctx (this, inode, NULL);
- if (ctx == NULL)
- goto unblock;
- if (__br_stub_is_inode_dirty (ctx)) {
- __br_stub_set_ongoing_version (ctx, version);
- __br_stub_mark_inode_synced (ctx);
- }
-
- ret = 0;
+ LOCK(&inode->lock);
+ {
+ ctx = __br_stub_get_ongoing_version_ctx(this, inode, NULL);
+ if (ctx == NULL)
+ goto unblock;
+ if (__br_stub_is_inode_dirty(ctx)) {
+ __br_stub_set_ongoing_version(ctx, version);
+ __br_stub_mark_inode_synced(ctx);
}
+
+ ret = 0;
+ }
unblock:
- UNLOCK (&inode->lock);
+ UNLOCK(&inode->lock);
- return ret;
+ return ret;
}
static void
-br_stub_fill_local (br_stub_local_t *local,
- call_stub_t *stub, fd_t *fd, inode_t *inode, uuid_t gfid,
- int versioningtype, unsigned long memversion)
+br_stub_fill_local(br_stub_local_t *local, call_stub_t *stub, fd_t *fd,
+ inode_t *inode, uuid_t gfid, int versioningtype,
+ unsigned long memversion)
{
- local->fopstub = stub;
- local->versioningtype = versioningtype;
- local->u.context.version = memversion;
- if (fd)
- local->u.context.fd = fd_ref (fd);
- if (inode)
- local->u.context.inode = inode_ref (inode);
- gf_uuid_copy (local->u.context.gfid, gfid);
+ local->fopstub = stub;
+ local->versioningtype = versioningtype;
+ local->u.context.version = memversion;
+ if (fd)
+ local->u.context.fd = fd_ref(fd);
+ if (inode)
+ local->u.context.inode = inode_ref(inode);
+ gf_uuid_copy(local->u.context.gfid, gfid);
}
static void
-br_stub_cleanup_local (br_stub_local_t *local)
+br_stub_cleanup_local(br_stub_local_t *local)
{
- if (!local)
- return;
+ if (!local)
+ return;
- local->fopstub = NULL;
- local->versioningtype = 0;
- local->u.context.version = 0;
- if (local->u.context.fd) {
- fd_unref (local->u.context.fd);
- local->u.context.fd = NULL;
- }
- if (local->u.context.inode) {
- inode_unref (local->u.context.inode);
- local->u.context.inode = NULL;
- }
- memset (local->u.context.gfid, '\0', sizeof (uuid_t));
+ local->fopstub = NULL;
+ local->versioningtype = 0;
+ local->u.context.version = 0;
+ if (local->u.context.fd) {
+ fd_unref(local->u.context.fd);
+ local->u.context.fd = NULL;
+ }
+ if (local->u.context.inode) {
+ inode_unref(local->u.context.inode);
+ local->u.context.inode = NULL;
+ }
+ memset(local->u.context.gfid, '\0', sizeof(uuid_t));
}
static int
-br_stub_need_versioning (xlator_t *this,
- fd_t *fd, gf_boolean_t *versioning,
- gf_boolean_t *modified, br_stub_inode_ctx_t **ctx)
-{
- int32_t ret = -1;
- uint64_t ctx_addr = 0;
- br_stub_inode_ctx_t *c = NULL;
- unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
-
- *versioning = _gf_false;
- *modified = _gf_false;
-
- /* Bitrot stub inode context was initialized only in lookup, create
- * and mknod cbk path. Object versioning was enabled by default
- * irrespective of bitrot enabled or not. But it's made optional now.
- * As a consequence there could be cases where getting inode ctx would
- * fail because it's not set yet.
- * e.g., If versioning (with bitrot enable) is enabled while I/O is
- * happening, it could directly get other fops like writev without
- * lookup, where getting inode ctx would fail. Hence initialize the
- * inode ctx on failure to get ctx. This is done in all places where
- * applicable.
- */
- ret = br_stub_get_inode_ctx (this, fd->inode, &ctx_addr);
- if (ret < 0) {
- ret = br_stub_init_inode_versions (this, fd, fd->inode, version,
- _gf_true, _gf_false,
- &ctx_addr);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_GET_INODE_CONTEXT_FAILED, "failed to "
- " init the inode context for the inode %s",
- uuid_utoa (fd->inode->gfid));
- goto error_return;
- }
+br_stub_need_versioning(xlator_t *this, fd_t *fd, gf_boolean_t *versioning,
+ gf_boolean_t *modified, br_stub_inode_ctx_t **ctx)
+{
+ int32_t ret = -1;
+ uint64_t ctx_addr = 0;
+ br_stub_inode_ctx_t *c = NULL;
+ unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
+
+ *versioning = _gf_false;
+ *modified = _gf_false;
+
+ /* Bitrot stub inode context was initialized only in lookup, create
+ * and mknod cbk path. Object versioning was enabled by default
+ * irrespective of bitrot enabled or not. But it's made optional now.
+ * As a consequence there could be cases where getting inode ctx would
+ * fail because it's not set yet.
+ * e.g., If versioning (with bitrot enable) is enabled while I/O is
+ * happening, it could directly get other fops like writev without
+ * lookup, where getting inode ctx would fail. Hence initialize the
+ * inode ctx on failure to get ctx. This is done in all places where
+ * applicable.
+ */
+ ret = br_stub_get_inode_ctx(this, fd->inode, &ctx_addr);
+ if (ret < 0) {
+ ret = br_stub_init_inode_versions(this, fd, fd->inode, version,
+ _gf_true, _gf_false, &ctx_addr);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ BRS_MSG_GET_INODE_CONTEXT_FAILED,
+ "failed to "
+ " init the inode context for the inode %s",
+ uuid_utoa(fd->inode->gfid));
+ goto error_return;
}
+ }
- c = (br_stub_inode_ctx_t *) (long) ctx_addr;
+ c = (br_stub_inode_ctx_t *)(long)ctx_addr;
- LOCK (&fd->inode->lock);
- {
- if (__br_stub_is_inode_dirty (c))
- *versioning = _gf_true;
- if (__br_stub_is_inode_modified (c))
- *modified = _gf_true;
- }
- UNLOCK (&fd->inode->lock);
+ LOCK(&fd->inode->lock);
+ {
+ if (__br_stub_is_inode_dirty(c))
+ *versioning = _gf_true;
+ if (__br_stub_is_inode_modified(c))
+ *modified = _gf_true;
+ }
+ UNLOCK(&fd->inode->lock);
- if (ctx)
- *ctx = c;
- return 0;
+ if (ctx)
+ *ctx = c;
+ return 0;
- error_return:
- return -1;
+error_return:
+ return -1;
}
static int32_t
-br_stub_anon_fd_ctx (xlator_t *this, fd_t *fd, br_stub_inode_ctx_t *ctx)
-{
- int32_t ret = -1;
- br_stub_fd_t *br_stub_fd = NULL;
-
- br_stub_fd = br_stub_fd_ctx_get (this, fd);
- if (!br_stub_fd) {
- ret = br_stub_add_fd_to_inode (this, fd, ctx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_ADD_FD_TO_INODE, "failed to add fd to "
- "the inode (gfid: %s)",
- uuid_utoa (fd->inode->gfid));
- goto out;
- }
+br_stub_anon_fd_ctx(xlator_t *this, fd_t *fd, br_stub_inode_ctx_t *ctx)
+{
+ int32_t ret = -1;
+ br_stub_fd_t *br_stub_fd = NULL;
+
+ br_stub_fd = br_stub_fd_ctx_get(this, fd);
+ if (!br_stub_fd) {
+ ret = br_stub_add_fd_to_inode(this, fd, ctx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_ADD_FD_TO_INODE,
+ "failed to add fd to "
+ "the inode (gfid: %s)",
+ uuid_utoa(fd->inode->gfid));
+ goto out;
}
+ }
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
static int
-br_stub_versioning_prep (call_frame_t *frame,
- xlator_t *this, fd_t *fd, br_stub_inode_ctx_t *ctx)
-{
- int32_t ret = -1;
- br_stub_local_t *local = NULL;
-
- local = br_stub_alloc_local (this);
- if (!local) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, BRS_MSG_NO_MEMORY,
- "local allocation failed (gfid: %s)",
- uuid_utoa (fd->inode->gfid));
- goto error_return;
- }
-
- if (fd_is_anonymous (fd)) {
- ret = br_stub_anon_fd_ctx (this, fd, ctx);
- if (ret)
- goto free_local;
- }
+br_stub_versioning_prep(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ br_stub_inode_ctx_t *ctx)
+{
+ int32_t ret = -1;
+ br_stub_local_t *local = NULL;
+
+ local = br_stub_alloc_local(this);
+ if (!local) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRS_MSG_NO_MEMORY,
+ "local allocation failed (gfid: %s)",
+ uuid_utoa(fd->inode->gfid));
+ goto error_return;
+ }
+
+ if (fd_is_anonymous(fd)) {
+ ret = br_stub_anon_fd_ctx(this, fd, ctx);
+ if (ret)
+ goto free_local;
+ }
- frame->local = local;
+ frame->local = local;
- return 0;
+ return 0;
- free_local:
- br_stub_dealloc_local (local);
- error_return:
- return -1;
+free_local:
+ br_stub_dealloc_local(local);
+error_return:
+ return -1;
}
static int
-br_stub_mark_inode_modified (xlator_t *this, br_stub_local_t *local)
-{
- fd_t *fd = NULL;
- int32_t ret = 0;
- uint64_t ctx_addr = 0;
- br_stub_inode_ctx_t *ctx = NULL;
- unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
-
- fd = local->u.context.fd;
-
- ret = br_stub_get_inode_ctx (this, fd->inode, &ctx_addr);
- if (ret < 0) {
- ret = br_stub_init_inode_versions (this, fd, fd->inode, version,
- _gf_true, _gf_false,
- &ctx_addr);
- if (ret)
- goto error_return;
- }
+br_stub_mark_inode_modified(xlator_t *this, br_stub_local_t *local)
+{
+ fd_t *fd = NULL;
+ int32_t ret = 0;
+ uint64_t ctx_addr = 0;
+ br_stub_inode_ctx_t *ctx = NULL;
+ unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
- ctx = (br_stub_inode_ctx_t *) (long) ctx_addr;
+ fd = local->u.context.fd;
- LOCK (&fd->inode->lock);
- {
- __br_stub_set_inode_modified (ctx);
- }
- UNLOCK (&fd->inode->lock);
+ ret = br_stub_get_inode_ctx(this, fd->inode, &ctx_addr);
+ if (ret < 0) {
+ ret = br_stub_init_inode_versions(this, fd, fd->inode, version,
+ _gf_true, _gf_false, &ctx_addr);
+ if (ret)
+ goto error_return;
+ }
- return 0;
+ ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
- error_return:
- return -1;
+ LOCK(&fd->inode->lock);
+ {
+ __br_stub_set_inode_modified(ctx);
+ }
+ UNLOCK(&fd->inode->lock);
+
+ return 0;
+
+error_return:
+ return -1;
}
/**
@@ -644,71 +635,68 @@ br_stub_mark_inode_modified (xlator_t *this, br_stub_local_t *local)
* and error is returned upwards.
*/
static int
-br_stub_check_bad_object (xlator_t *this, inode_t *inode, int32_t *op_ret,
- int32_t *op_errno)
-{
- int ret = -1;
- unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
-
- ret = br_stub_is_bad_object (this, inode);
- if (ret == -2) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRS_MSG_BAD_OBJECT_ACCESS,
- "%s is a bad object. Returning",
- uuid_utoa (inode->gfid));
- *op_ret = -1;
- *op_errno = EIO;
- }
-
- if (ret == -1) {
- ret = br_stub_init_inode_versions (this, NULL, inode, version,
- _gf_true, _gf_false, NULL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_GET_INODE_CONTEXT_FAILED,
- "failed to init inode context for %s",
- uuid_utoa (inode->gfid));
- *op_ret = -1;
- *op_errno = EINVAL;
- }
+br_stub_check_bad_object(xlator_t *this, inode_t *inode, int32_t *op_ret,
+ int32_t *op_errno)
+{
+ int ret = -1;
+ unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
+
+ ret = br_stub_is_bad_object(this, inode);
+ if (ret == -2) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_BAD_OBJECT_ACCESS,
+ "%s is a bad object. Returning", uuid_utoa(inode->gfid));
+ *op_ret = -1;
+ *op_errno = EIO;
+ }
+
+ if (ret == -1) {
+ ret = br_stub_init_inode_versions(this, NULL, inode, version, _gf_true,
+ _gf_false, NULL);
+ if (ret) {
+ gf_msg(
+ this->name, GF_LOG_ERROR, 0, BRS_MSG_GET_INODE_CONTEXT_FAILED,
+ "failed to init inode context for %s", uuid_utoa(inode->gfid));
+ *op_ret = -1;
+ *op_errno = EINVAL;
}
+ }
- return ret;
+ return ret;
}
/**
* callback for inode/fd versioning
*/
int
-br_stub_fd_incversioning_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xdata)
-{
- fd_t *fd = NULL;
- inode_t *inode = NULL;
- unsigned long version = 0;
- br_stub_local_t *local = NULL;
-
- local = (br_stub_local_t *)frame->local;
- if (op_ret < 0)
- goto done;
- fd = local->u.context.fd;
- inode = local->u.context.inode;
- version = local->u.context.version;
-
- op_ret = br_stub_mod_inode_versions (this, fd, inode, version);
- if (op_ret < 0)
- op_errno = EINVAL;
-
- done:
- if (op_ret < 0) {
- frame->local = NULL;
- call_unwind_error (local->fopstub, -1, op_errno);
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
- } else {
- call_resume (local->fopstub);
- }
- return 0;
+br_stub_fd_incversioning_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, dict_t *xdata)
+{
+ fd_t *fd = NULL;
+ inode_t *inode = NULL;
+ unsigned long version = 0;
+ br_stub_local_t *local = NULL;
+
+ local = (br_stub_local_t *)frame->local;
+ if (op_ret < 0)
+ goto done;
+ fd = local->u.context.fd;
+ inode = local->u.context.inode;
+ version = local->u.context.version;
+
+ op_ret = br_stub_mod_inode_versions(this, fd, inode, version);
+ if (op_ret < 0)
+ op_errno = EINVAL;
+
+done:
+ if (op_ret < 0) {
+ frame->local = NULL;
+ call_unwind_error(local->fopstub, -1, op_errno);
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
+ } else {
+ call_resume(local->fopstub);
+ }
+ return 0;
}
/**
@@ -745,98 +733,93 @@ br_stub_fd_incversioning_cbk (call_frame_t *frame,
*/
int
-br_stub_fd_versioning (xlator_t *this, call_frame_t *frame,
- call_stub_t *stub, dict_t *dict, fd_t *fd,
- br_stub_version_cbk *callback, unsigned long memversion,
- int versioningtype, int durable)
+br_stub_fd_versioning(xlator_t *this, call_frame_t *frame, call_stub_t *stub,
+ dict_t *dict, fd_t *fd, br_stub_version_cbk *callback,
+ unsigned long memversion, int versioningtype, int durable)
{
- int32_t ret = -1;
- int flags = 0;
- dict_t *xdata = NULL;
- br_stub_local_t *local = NULL;
+ int32_t ret = -1;
+ int flags = 0;
+ dict_t *xdata = NULL;
+ br_stub_local_t *local = NULL;
- xdata = dict_new ();
- if (!xdata)
- goto done;
+ xdata = dict_new();
+ if (!xdata)
+ goto done;
+
+ ret = dict_set_int32(xdata, GLUSTERFS_INTERNAL_FOP_KEY, 1);
+ if (ret)
+ goto dealloc_xdata;
- ret = dict_set_int32 (xdata, GLUSTERFS_INTERNAL_FOP_KEY, 1);
+ if (durable) {
+ ret = dict_set_int32(xdata, GLUSTERFS_DURABLE_OP, 0);
if (ret)
- goto dealloc_xdata;
+ goto dealloc_xdata;
+ }
- if (durable) {
- ret = dict_set_int32 (xdata, GLUSTERFS_DURABLE_OP, 0);
- if (ret)
- goto dealloc_xdata;
- }
+ local = frame->local;
- local = frame->local;
+ br_stub_fill_local(local, stub, fd, fd->inode, fd->inode->gfid,
+ versioningtype, memversion);
- br_stub_fill_local (local, stub, fd,
- fd->inode, fd->inode->gfid,
- versioningtype, memversion);
+ STACK_WIND(frame, callback, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata);
- STACK_WIND (frame, callback,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->fsetxattr,
- fd, dict, flags, xdata);
+ ret = 0;
- ret = 0;
-
- dealloc_xdata:
- dict_unref (xdata);
- done:
- return ret;
+dealloc_xdata:
+ dict_unref(xdata);
+done:
+ return ret;
}
static int
-br_stub_perform_incversioning (xlator_t *this,
- call_frame_t *frame, call_stub_t *stub,
- fd_t *fd, br_stub_inode_ctx_t *ctx)
-{
- int32_t ret = -1;
- dict_t *dict = NULL;
- br_version_t *obuf = NULL;
- unsigned long writeback_version = 0;
- int op_errno = 0;
- br_stub_local_t *local = NULL;
-
- op_errno = EINVAL;
- local = frame->local;
-
- writeback_version = __br_stub_writeback_version (ctx);
-
- op_errno = ENOMEM;
- dict = dict_new ();
- if (!dict)
- goto done;
- ret = br_stub_alloc_versions (&obuf, NULL, 0);
- if (ret)
- goto dealloc_dict;
- ret = br_stub_prepare_version_request (this, dict,
- obuf, writeback_version);
- if (ret)
- goto dealloc_versions;
-
- ret = br_stub_fd_versioning
- (this, frame, stub, dict,
- fd, br_stub_fd_incversioning_cbk, writeback_version,
- BR_STUB_INCREMENTAL_VERSIONING, !WRITEBACK_DURABLE);
-
- dealloc_versions:
- br_stub_dealloc_versions (obuf);
- dealloc_dict:
- dict_unref (dict);
- done:
- if (ret) {
- if (local)
- frame->local = NULL;
- call_unwind_error (stub, -1, op_errno);
- if (local) {
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
- }
+br_stub_perform_incversioning(xlator_t *this, call_frame_t *frame,
+ call_stub_t *stub, fd_t *fd,
+ br_stub_inode_ctx_t *ctx)
+{
+ int32_t ret = -1;
+ dict_t *dict = NULL;
+ br_version_t *obuf = NULL;
+ unsigned long writeback_version = 0;
+ int op_errno = 0;
+ br_stub_local_t *local = NULL;
+
+ op_errno = EINVAL;
+ local = frame->local;
+
+ writeback_version = __br_stub_writeback_version(ctx);
+
+ op_errno = ENOMEM;
+ dict = dict_new();
+ if (!dict)
+ goto done;
+ ret = br_stub_alloc_versions(&obuf, NULL, 0);
+ if (ret)
+ goto dealloc_dict;
+ ret = br_stub_prepare_version_request(this, dict, obuf, writeback_version);
+ if (ret)
+ goto dealloc_versions;
+
+ ret = br_stub_fd_versioning(
+ this, frame, stub, dict, fd, br_stub_fd_incversioning_cbk,
+ writeback_version, BR_STUB_INCREMENTAL_VERSIONING, !WRITEBACK_DURABLE);
+
+dealloc_versions:
+ br_stub_dealloc_versions(obuf);
+dealloc_dict:
+ dict_unref(dict);
+done:
+ if (ret) {
+ if (local)
+ frame->local = NULL;
+ call_unwind_error(stub, -1, op_errno);
+ if (local) {
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
}
+ }
- return ret;
+ return ret;
}
/** {{{ */
@@ -844,247 +827,242 @@ br_stub_perform_incversioning (xlator_t *this,
/* fsetxattr() */
int32_t
-br_stub_perform_objsign (call_frame_t *frame, xlator_t *this,
- fd_t *fd, dict_t *dict, int flags, dict_t *xdata)
+br_stub_perform_objsign(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ dict_t *dict, int flags, dict_t *xdata)
{
- STACK_WIND (frame, default_fsetxattr_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->fsetxattr, fd,
- dict, flags, xdata);
+ STACK_WIND(frame, default_fsetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata);
- dict_unref (xdata);
- return 0;
+ dict_unref(xdata);
+ return 0;
}
void *
-br_stub_signth (void *arg)
+br_stub_signth(void *arg)
{
- xlator_t *this = arg;
- br_stub_private_t *priv = this->private;
- struct br_stub_signentry *sigstub = NULL;
-
- THIS = this;
- while (1) {
+ xlator_t *this = arg;
+ br_stub_private_t *priv = this->private;
+ struct br_stub_signentry *sigstub = NULL;
- pthread_mutex_lock (&priv->lock);
- {
- while (list_empty (&priv->squeue))
- pthread_cond_wait (&priv->cond, &priv->lock);
+ THIS = this;
+ while (1) {
+ pthread_mutex_lock(&priv->lock);
+ {
+ while (list_empty(&priv->squeue))
+ pthread_cond_wait(&priv->cond, &priv->lock);
- sigstub = list_first_entry
- (&priv->squeue, struct br_stub_signentry, list);
- list_del_init (&sigstub->list);
- }
- pthread_mutex_unlock (&priv->lock);
+ sigstub = list_first_entry(&priv->squeue, struct br_stub_signentry,
+ list);
+ list_del_init(&sigstub->list);
+ }
+ pthread_mutex_unlock(&priv->lock);
- call_resume (sigstub->stub);
+ call_resume(sigstub->stub);
- GF_FREE (sigstub);
- }
+ GF_FREE(sigstub);
+ }
- return NULL;
+ return NULL;
}
static gf_boolean_t
-br_stub_internal_xattr (dict_t *dict) {
-
- if (dict_get (dict, GLUSTERFS_SET_OBJECT_SIGNATURE) ||
- dict_get (dict, GLUSTERFS_GET_OBJECT_SIGNATURE) ||
- dict_get (dict, BR_REOPEN_SIGN_HINT_KEY) ||
- dict_get (dict, BITROT_OBJECT_BAD_KEY) ||
- dict_get (dict, BITROT_SIGNING_VERSION_KEY) ||
- dict_get (dict, BITROT_CURRENT_VERSION_KEY))
- return _gf_true;
+br_stub_internal_xattr(dict_t *dict)
+{
+ if (dict_get(dict, GLUSTERFS_SET_OBJECT_SIGNATURE) ||
+ dict_get(dict, GLUSTERFS_GET_OBJECT_SIGNATURE) ||
+ dict_get(dict, BR_REOPEN_SIGN_HINT_KEY) ||
+ dict_get(dict, BITROT_OBJECT_BAD_KEY) ||
+ dict_get(dict, BITROT_SIGNING_VERSION_KEY) ||
+ dict_get(dict, BITROT_CURRENT_VERSION_KEY))
+ return _gf_true;
- return _gf_false;
+ return _gf_false;
}
int
-orderq (struct list_head *elem1, struct list_head *elem2)
+orderq(struct list_head *elem1, struct list_head *elem2)
{
- struct br_stub_signentry *s1 = NULL;
- struct br_stub_signentry *s2 = NULL;
+ struct br_stub_signentry *s1 = NULL;
+ struct br_stub_signentry *s2 = NULL;
- s1 = list_entry (elem1, struct br_stub_signentry, list);
- s2 = list_entry (elem2, struct br_stub_signentry, list);
+ s1 = list_entry(elem1, struct br_stub_signentry, list);
+ s2 = list_entry(elem2, struct br_stub_signentry, list);
- return (s1->v > s2->v);
+ return (s1->v > s2->v);
}
static int
-br_stub_compare_sign_version (xlator_t *this,
- inode_t *inode,
- br_signature_t *sbuf,
- dict_t *dict, int *fakesuccess)
-{
- int32_t ret = -1;
- uint64_t tmp_ctx = 0;
- gf_boolean_t invalid = _gf_false;
- br_stub_inode_ctx_t *ctx = NULL;
-
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, out);
- GF_VALIDATE_OR_GOTO (this->name, inode, out);
- GF_VALIDATE_OR_GOTO (this->name, sbuf, out);
- GF_VALIDATE_OR_GOTO (this->name, dict, out);
-
- ret = br_stub_get_inode_ctx (this, inode, &tmp_ctx);
- if (ret) {
- dict_del (dict, BITROT_SIGNING_VERSION_KEY);
- goto out;
- }
-
- ctx = (br_stub_inode_ctx_t *)(long)tmp_ctx;
-
- LOCK (&inode->lock);
- {
- if (ctx->currentversion < sbuf->signedversion) {
- invalid = _gf_true;
- } else if (ctx->currentversion > sbuf->signedversion) {
- gf_msg_debug (this->name, 0, "\"Signing version\" "
- "(%lu) lower than \"Current version \" "
- "(%lu)", ctx->currentversion,
- sbuf->signedversion);
- *fakesuccess = 1;
- }
- }
- UNLOCK (&inode->lock);
-
- if (invalid) {
- ret = -1;
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRS_MSG_SIGN_VERSION_ERROR, "Signing version exceeds "
- "current version [%lu > %lu]", sbuf->signedversion,
- ctx->currentversion);
- }
+br_stub_compare_sign_version(xlator_t *this, inode_t *inode,
+ br_signature_t *sbuf, dict_t *dict,
+ int *fakesuccess)
+{
+ int32_t ret = -1;
+ uint64_t tmp_ctx = 0;
+ gf_boolean_t invalid = _gf_false;
+ br_stub_inode_ctx_t *ctx = NULL;
+
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, inode, out);
+ GF_VALIDATE_OR_GOTO(this->name, sbuf, out);
+ GF_VALIDATE_OR_GOTO(this->name, dict, out);
+
+ ret = br_stub_get_inode_ctx(this, inode, &tmp_ctx);
+ if (ret) {
+ dict_del(dict, BITROT_SIGNING_VERSION_KEY);
+ goto out;
+ }
+
+ ctx = (br_stub_inode_ctx_t *)(long)tmp_ctx;
+
+ LOCK(&inode->lock);
+ {
+ if (ctx->currentversion < sbuf->signedversion) {
+ invalid = _gf_true;
+ } else if (ctx->currentversion > sbuf->signedversion) {
+ gf_msg_debug(this->name, 0,
+ "\"Signing version\" "
+ "(%lu) lower than \"Current version \" "
+ "(%lu)",
+ ctx->currentversion, sbuf->signedversion);
+ *fakesuccess = 1;
+ }
+ }
+ UNLOCK(&inode->lock);
+
+ if (invalid) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_SIGN_VERSION_ERROR,
+ "Signing version exceeds "
+ "current version [%lu > %lu]",
+ sbuf->signedversion, ctx->currentversion);
+ }
- out:
- return ret;
+out:
+ return ret;
}
static int
-br_stub_prepare_signature (xlator_t *this,
- dict_t *dict, inode_t *inode,
- br_isignature_t *sign, int *fakesuccess)
+br_stub_prepare_signature(xlator_t *this, dict_t *dict, inode_t *inode,
+ br_isignature_t *sign, int *fakesuccess)
{
- int32_t ret = 0;
- size_t signaturelen = 0;
- br_signature_t *sbuf = NULL;
+ int32_t ret = 0;
+ size_t signaturelen = 0;
+ br_signature_t *sbuf = NULL;
- if (!br_is_signature_type_valid (sign->signaturetype))
- goto error_return;
+ if (!br_is_signature_type_valid(sign->signaturetype))
+ goto error_return;
- signaturelen = sign->signaturelen;
- ret = br_stub_alloc_versions (NULL, &sbuf, signaturelen);
- if (ret)
- goto error_return;
- ret = br_stub_prepare_signing_request (dict, sbuf, sign, signaturelen);
- if (ret)
- goto dealloc_versions;
+ signaturelen = sign->signaturelen;
+ ret = br_stub_alloc_versions(NULL, &sbuf, signaturelen);
+ if (ret)
+ goto error_return;
+ ret = br_stub_prepare_signing_request(dict, sbuf, sign, signaturelen);
+ if (ret)
+ goto dealloc_versions;
- ret = br_stub_compare_sign_version (this, inode,
- sbuf, dict, fakesuccess);
- if (ret)
- goto dealloc_versions;
+ ret = br_stub_compare_sign_version(this, inode, sbuf, dict, fakesuccess);
+ if (ret)
+ goto dealloc_versions;
- return 0;
+ return 0;
- dealloc_versions:
- br_stub_dealloc_versions (sbuf);
- error_return:
- return -1;
+dealloc_versions:
+ br_stub_dealloc_versions(sbuf);
+error_return:
+ return -1;
}
static void
-br_stub_handle_object_signature (call_frame_t *frame,
- xlator_t *this, fd_t *fd, dict_t *dict,
- br_isignature_t *sign, dict_t *xdata)
-{
- int32_t ret = -1;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- int fakesuccess = 0;
- br_stub_private_t *priv = NULL;
- struct br_stub_signentry *sigstub = NULL;
-
- priv = this->private;
-
- if (frame->root->pid != GF_CLIENT_PID_BITD)
- goto dofop;
-
- ret = br_stub_prepare_signature (this, dict,
- fd->inode, sign, &fakesuccess);
- if (ret)
- goto dofop;
- if (fakesuccess) {
- op_ret = op_errno = 0;
- goto dofop;
- }
-
- dict_del (dict, GLUSTERFS_SET_OBJECT_SIGNATURE);
-
- ret = -1;
- if (!xdata) {
- xdata = dict_new ();
- if (!xdata)
- goto dofop;
- } else {
- dict_ref (xdata);
- }
+br_stub_handle_object_signature(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ dict_t *dict, br_isignature_t *sign,
+ dict_t *xdata)
+{
+ int32_t ret = -1;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ int fakesuccess = 0;
+ br_stub_private_t *priv = NULL;
+ struct br_stub_signentry *sigstub = NULL;
+
+ priv = this->private;
+
+ if (frame->root->pid != GF_CLIENT_PID_BITD)
+ goto dofop;
+
+ ret = br_stub_prepare_signature(this, dict, fd->inode, sign, &fakesuccess);
+ if (ret)
+ goto dofop;
+ if (fakesuccess) {
+ op_ret = op_errno = 0;
+ goto dofop;
+ }
+
+ dict_del(dict, GLUSTERFS_SET_OBJECT_SIGNATURE);
+
+ ret = -1;
+ if (!xdata) {
+ xdata = dict_new();
+ if (!xdata)
+ goto dofop;
+ } else {
+ dict_ref(xdata);
+ }
- ret = dict_set_int32 (xdata, GLUSTERFS_DURABLE_OP, 0);
- if (ret)
- goto unref_dict;
+ ret = dict_set_int32(xdata, GLUSTERFS_DURABLE_OP, 0);
+ if (ret)
+ goto unref_dict;
- /* prepare dispatch stub to order object signing */
- sigstub = GF_CALLOC (1, sizeof (*sigstub), gf_br_stub_mt_sigstub_t);
- if (!sigstub)
- goto unref_dict;
+ /* prepare dispatch stub to order object signing */
+ sigstub = GF_CALLOC(1, sizeof(*sigstub), gf_br_stub_mt_sigstub_t);
+ if (!sigstub)
+ goto unref_dict;
- INIT_LIST_HEAD (&sigstub->list);
- sigstub->v = ntohl (sign->signedversion);
- sigstub->stub = fop_fsetxattr_stub (frame, br_stub_perform_objsign,
- fd, dict, 0, xdata);
- if (!sigstub->stub)
- goto cleanup_stub;
+ INIT_LIST_HEAD(&sigstub->list);
+ sigstub->v = ntohl(sign->signedversion);
+ sigstub->stub = fop_fsetxattr_stub(frame, br_stub_perform_objsign, fd, dict,
+ 0, xdata);
+ if (!sigstub->stub)
+ goto cleanup_stub;
- pthread_mutex_lock (&priv->lock);
- {
- list_add_order (&sigstub->list, &priv->squeue, orderq);
- pthread_cond_signal (&priv->cond);
- }
- pthread_mutex_unlock (&priv->lock);
+ pthread_mutex_lock(&priv->lock);
+ {
+ list_add_order(&sigstub->list, &priv->squeue, orderq);
+ pthread_cond_signal(&priv->cond);
+ }
+ pthread_mutex_unlock(&priv->lock);
- return;
+ return;
- cleanup_stub:
- GF_FREE (sigstub);
- unref_dict:
- dict_unref (xdata);
- dofop:
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, NULL);
+cleanup_stub:
+ GF_FREE(sigstub);
+unref_dict:
+ dict_unref(xdata);
+dofop:
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, NULL);
}
int32_t
-br_stub_fsetxattr_resume (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+br_stub_fsetxattr_resume(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- int32_t ret = -1;
- br_stub_local_t *local = NULL;
+ int32_t ret = -1;
+ br_stub_local_t *local = NULL;
- local = frame->local;
- frame->local = NULL;
+ local = frame->local;
+ frame->local = NULL;
- ret = br_stub_mark_inode_modified (this, local);
- if (ret) {
- op_ret = -1;
- op_errno = EINVAL;
- }
+ ret = br_stub_mark_inode_modified(this, local);
+ if (ret) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ }
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, xdata);
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, xdata);
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
- return 0;
+ return 0;
}
/**
@@ -1122,65 +1100,64 @@ br_stub_fsetxattr_resume (call_frame_t *frame, void *cookie, xlator_t *this,
* }
*/
static void
-br_stub_handle_object_reopen (call_frame_t *frame,
- xlator_t *this, fd_t *fd, uint32_t val)
-{
- int32_t ret = -1;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- call_stub_t *stub = NULL;
- gf_boolean_t inc_version = _gf_false;
- gf_boolean_t modified = _gf_false;
- br_stub_inode_ctx_t *ctx = NULL;
- br_stub_local_t *local = NULL;
- gf_boolean_t goback = _gf_true;
-
- ret = br_stub_need_versioning (this, fd, &inc_version, &modified, &ctx);
- if (ret)
- goto unwind;
+br_stub_handle_object_reopen(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ uint32_t val)
+{
+ int32_t ret = -1;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ call_stub_t *stub = NULL;
+ gf_boolean_t inc_version = _gf_false;
+ gf_boolean_t modified = _gf_false;
+ br_stub_inode_ctx_t *ctx = NULL;
+ br_stub_local_t *local = NULL;
+ gf_boolean_t goback = _gf_true;
+
+ ret = br_stub_need_versioning(this, fd, &inc_version, &modified, &ctx);
+ if (ret)
+ goto unwind;
+
+ LOCK(&fd->inode->lock);
+ {
+ if ((val == BR_OBJECT_REOPEN) && inc_version)
+ goback = _gf_false;
+ if (val == BR_OBJECT_RESIGN && ctx->info_sign == BR_SIGN_NORMAL) {
+ __br_stub_mark_inode_synced(ctx);
+ __br_stub_set_inode_modified(ctx);
+ }
+ (void)__br_stub_inode_sign_state(ctx, GF_FOP_FSETXATTR, fd);
+ }
+ UNLOCK(&fd->inode->lock);
+
+ if (goback) {
+ op_ret = op_errno = 0;
+ goto unwind;
+ }
+
+ ret = br_stub_versioning_prep(frame, this, fd, ctx);
+ if (ret)
+ goto unwind;
+ local = frame->local;
+
+ stub = fop_fsetxattr_cbk_stub(frame, br_stub_fsetxattr_resume, 0, 0, NULL);
+ if (!stub) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_STUB_ALLOC_FAILED,
+ "failed to allocate stub for fsetxattr fop (gfid: %s),"
+ " unwinding",
+ uuid_utoa(fd->inode->gfid));
+ goto cleanup_local;
+ }
+
+ (void)br_stub_perform_incversioning(this, frame, stub, fd, ctx);
+ return;
+
+cleanup_local:
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
- LOCK (&fd->inode->lock);
- {
- if ((val == BR_OBJECT_REOPEN) && inc_version)
- goback = _gf_false;
- if (val == BR_OBJECT_RESIGN &&
- ctx->info_sign == BR_SIGN_NORMAL) {
- __br_stub_mark_inode_synced (ctx);
- __br_stub_set_inode_modified (ctx);
- }
- (void) __br_stub_inode_sign_state (ctx, GF_FOP_FSETXATTR, fd);
- }
- UNLOCK (&fd->inode->lock);
-
- if (goback) {
- op_ret = op_errno = 0;
- goto unwind;
- }
-
- ret = br_stub_versioning_prep (frame, this, fd, ctx);
- if (ret)
- goto unwind;
- local = frame->local;
-
- stub = fop_fsetxattr_cbk_stub (frame, br_stub_fsetxattr_resume,
- 0, 0, NULL);
- if (!stub) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRS_MSG_STUB_ALLOC_FAILED,
- "failed to allocate stub for fsetxattr fop (gfid: %s),"
- " unwinding", uuid_utoa (fd->inode->gfid));
- goto cleanup_local;
- }
-
- (void) br_stub_perform_incversioning (this, frame, stub, fd, ctx);
- return;
-
- cleanup_local:
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
-
- unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, NULL);
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, NULL);
}
/**
@@ -1191,89 +1168,87 @@ br_stub_handle_object_reopen (call_frame_t *frame,
* to mark the object as bad.
*/
int
-br_stub_fsetxattr_bad_object_cbk (call_frame_t *frame, void *cookie,
- xlator_t *this, int32_t op_ret,
- int32_t op_errno, dict_t *xdata)
-{
- br_stub_local_t *local = NULL;
- int32_t ret = -1;
-
- local = frame->local;
- frame->local = NULL;
-
- if (op_ret < 0)
- goto unwind;
-
- /*
- * What to do if marking the object as bad fails? (i.e. in memory
- * marking within the inode context. If we are here means fsetxattr
- * fop has succeeded on disk and the bad object xattr has been set).
- * We can return failure to scruber, but there is nothing the scrubber
- * can do with it (it might assume that the on disk setxattr itself has
- * failed). The main purpose of this operation is to help identify the
- * bad object by checking the inode context itself (thus avoiding the
- * necessity of doing a getxattr fop on the disk).
- *
- * So as of now, success itself is being returned even though inode
- * context set operation fails.
- * In future if there is any change in the policy which can handle this,
- * then appropriate response should be sent (i.e. success or error).
- */
- ret = br_stub_mark_object_bad (this, local->u.context.inode);
- if (ret)
- gf_msg (this->name, GF_LOG_ERROR, 0, BRS_MSG_BAD_OBJ_MARK_FAIL,
- "failed to mark object %s as bad",
- uuid_utoa (local->u.context.inode->gfid));
-
- ret = br_stub_add (this, local->u.context.inode->gfid);
+br_stub_fsetxattr_bad_object_cbk(call_frame_t *frame, void *cookie,
+ xlator_t *this, int32_t op_ret,
+ int32_t op_errno, dict_t *xdata)
+{
+ br_stub_local_t *local = NULL;
+ int32_t ret = -1;
+
+ local = frame->local;
+ frame->local = NULL;
+
+ if (op_ret < 0)
+ goto unwind;
+
+ /*
+ * What to do if marking the object as bad fails? (i.e. in memory
+ * marking within the inode context. If we are here means fsetxattr
+ * fop has succeeded on disk and the bad object xattr has been set).
+ * We can return failure to scruber, but there is nothing the scrubber
+ * can do with it (it might assume that the on disk setxattr itself has
+ * failed). The main purpose of this operation is to help identify the
+ * bad object by checking the inode context itself (thus avoiding the
+ * necessity of doing a getxattr fop on the disk).
+ *
+ * So as of now, success itself is being returned even though inode
+ * context set operation fails.
+ * In future if there is any change in the policy which can handle this,
+ * then appropriate response should be sent (i.e. success or error).
+ */
+ ret = br_stub_mark_object_bad(this, local->u.context.inode);
+ if (ret)
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_BAD_OBJ_MARK_FAIL,
+ "failed to mark object %s as bad",
+ uuid_utoa(local->u.context.inode->gfid));
+
+ ret = br_stub_add(this, local->u.context.inode->gfid);
unwind:
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, xdata);
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
- return 0;
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, xdata);
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
+ return 0;
}
static int32_t
-br_stub_handle_bad_object_key (call_frame_t *frame, xlator_t *this, fd_t *fd,
- dict_t *dict, int flags, dict_t *xdata)
-{
- br_stub_local_t *local = NULL;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
-
- if (frame->root->pid != GF_CLIENT_PID_SCRUB) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_NON_SCRUB_BAD_OBJ_MARK, "bad object marking "
- "on %s is not from the scrubber",
- uuid_utoa (fd->inode->gfid));
- goto unwind;
- }
-
- local = br_stub_alloc_local (this);
- if (!local) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRS_MSG_NO_MEMORY,
- "failed to allocate memory for fsetxattr on %s",
- uuid_utoa (fd->inode->gfid));
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
+br_stub_handle_bad_object_key(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ dict_t *dict, int flags, dict_t *xdata)
+{
+ br_stub_local_t *local = NULL;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+
+ if (frame->root->pid != GF_CLIENT_PID_SCRUB) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_NON_SCRUB_BAD_OBJ_MARK,
+ "bad object marking "
+ "on %s is not from the scrubber",
+ uuid_utoa(fd->inode->gfid));
+ goto unwind;
+ }
+
+ local = br_stub_alloc_local(this);
+ if (!local) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_NO_MEMORY,
+ "failed to allocate memory for fsetxattr on %s",
+ uuid_utoa(fd->inode->gfid));
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
- br_stub_fill_local (local, NULL, fd, fd->inode,
- fd->inode->gfid, BR_STUB_NO_VERSIONING, 0);
- frame->local = local;
+ br_stub_fill_local(local, NULL, fd, fd->inode, fd->inode->gfid,
+ BR_STUB_NO_VERSIONING, 0);
+ frame->local = local;
- STACK_WIND (frame, br_stub_fsetxattr_bad_object_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->fsetxattr, fd, dict, flags,
- xdata);
- return 0;
+ STACK_WIND(frame, br_stub_fsetxattr_bad_object_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, NULL);
- return 0;
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, NULL);
+ return 0;
}
-
/**
* As of now, versioning is done by the stub (though as a setxattr
* operation) as part of inode modification operations such as writev,
@@ -1289,126 +1264,122 @@ unwind:
*
*/
static int32_t
-br_stub_handle_internal_xattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
- char *key)
+br_stub_handle_internal_xattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ char *key)
{
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_SET_INTERNAL_XATTR, "setxattr called"
- " on the internal xattr %s for inode %s", key,
- uuid_utoa (fd->inode->gfid));
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_SET_INTERNAL_XATTR,
+ "setxattr called"
+ " on the internal xattr %s for inode %s",
+ key, uuid_utoa(fd->inode->gfid));
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, NULL);
- return 0;
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, NULL);
+ return 0;
}
static void
-br_stub_dump_xattr (xlator_t *this, dict_t *dict, int *op_errno)
-{
- char *format = "(%s:%s)";
- char *dump = NULL;
-
- dump = GF_CALLOC (1, BR_STUB_DUMP_STR_SIZE, gf_br_stub_mt_misc);
- if (!dump) {
- *op_errno = ENOMEM;
- goto out;
- }
- dict_dump_to_str (dict, dump, BR_STUB_DUMP_STR_SIZE, format);
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_SET_INTERNAL_XATTR, "fsetxattr called on "
- "internal xattr %s", dump);
- out:
- if (dump) {
- GF_FREE (dump);
- }
- return;
+br_stub_dump_xattr(xlator_t *this, dict_t *dict, int *op_errno)
+{
+ char *format = "(%s:%s)";
+ char *dump = NULL;
+
+ dump = GF_CALLOC(1, BR_STUB_DUMP_STR_SIZE, gf_br_stub_mt_misc);
+ if (!dump) {
+ *op_errno = ENOMEM;
+ goto out;
+ }
+ dict_dump_to_str(dict, dump, BR_STUB_DUMP_STR_SIZE, format);
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_SET_INTERNAL_XATTR,
+ "fsetxattr called on "
+ "internal xattr %s",
+ dump);
+out:
+ if (dump) {
+ GF_FREE(dump);
+ }
+ return;
}
int
-br_stub_fsetxattr (call_frame_t *frame, xlator_t *this,
- fd_t *fd, dict_t *dict, int flags, dict_t *xdata)
-{
- int32_t ret = 0;
- uint32_t val = 0;
- br_isignature_t *sign = NULL;
- br_stub_private_t *priv = NULL;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
-
- priv = this->private;
-
- if ((frame->root->pid != GF_CLIENT_PID_BITD &&
- frame->root->pid != GF_CLIENT_PID_SCRUB) &&
- br_stub_internal_xattr (dict)) {
- br_stub_dump_xattr (this, dict, &op_errno);
- goto unwind;
- }
-
- if (!priv->do_versioning)
- goto wind;
-
- if (!IA_ISREG (fd->inode->ia_type))
- goto wind;
-
- /* object signature request */
- ret = dict_get_bin (dict, GLUSTERFS_SET_OBJECT_SIGNATURE,
- (void **) &sign);
- if (!ret) {
- br_stub_handle_object_signature (frame, this,
- fd, dict, sign, xdata);
- goto done;
- }
-
- /* signing xattr */
- if (dict_get(dict, BITROT_SIGNING_VERSION_KEY)) {
- br_stub_handle_internal_xattr (frame, this, fd,
- BITROT_SIGNING_VERSION_KEY);
- goto done;
- }
-
- /* version xattr */
- if (dict_get(dict, BITROT_CURRENT_VERSION_KEY)) {
- br_stub_handle_internal_xattr (frame, this, fd,
- BITROT_CURRENT_VERSION_KEY);
- goto done;
- }
-
- if (dict_get (dict, GLUSTERFS_GET_OBJECT_SIGNATURE)) {
- br_stub_handle_internal_xattr (frame, this, fd,
- GLUSTERFS_GET_OBJECT_SIGNATURE);
- goto done;
- }
-
- /* object reopen request */
- ret = dict_get_uint32 (dict, BR_REOPEN_SIGN_HINT_KEY, &val);
- if (!ret) {
- br_stub_handle_object_reopen (frame, this, fd, val);
- goto done;
- }
-
- /* handle bad object */
- if (dict_get (dict, BITROT_OBJECT_BAD_KEY)) {
- br_stub_handle_bad_object_key (frame, this, fd,
- dict, flags, xdata);
- goto done;
- }
+br_stub_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
+ int flags, dict_t *xdata)
+{
+ int32_t ret = 0;
+ uint32_t val = 0;
+ br_isignature_t *sign = NULL;
+ br_stub_private_t *priv = NULL;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+
+ priv = this->private;
+
+ if ((frame->root->pid != GF_CLIENT_PID_BITD &&
+ frame->root->pid != GF_CLIENT_PID_SCRUB) &&
+ br_stub_internal_xattr(dict)) {
+ br_stub_dump_xattr(this, dict, &op_errno);
+ goto unwind;
+ }
+
+ if (!priv->do_versioning)
+ goto wind;
+
+ if (!IA_ISREG(fd->inode->ia_type))
+ goto wind;
+
+ /* object signature request */
+ ret = dict_get_bin(dict, GLUSTERFS_SET_OBJECT_SIGNATURE, (void **)&sign);
+ if (!ret) {
+ br_stub_handle_object_signature(frame, this, fd, dict, sign, xdata);
+ goto done;
+ }
+
+ /* signing xattr */
+ if (dict_get(dict, BITROT_SIGNING_VERSION_KEY)) {
+ br_stub_handle_internal_xattr(frame, this, fd,
+ BITROT_SIGNING_VERSION_KEY);
+ goto done;
+ }
+
+ /* version xattr */
+ if (dict_get(dict, BITROT_CURRENT_VERSION_KEY)) {
+ br_stub_handle_internal_xattr(frame, this, fd,
+ BITROT_CURRENT_VERSION_KEY);
+ goto done;
+ }
+
+ if (dict_get(dict, GLUSTERFS_GET_OBJECT_SIGNATURE)) {
+ br_stub_handle_internal_xattr(frame, this, fd,
+ GLUSTERFS_GET_OBJECT_SIGNATURE);
+ goto done;
+ }
+
+ /* object reopen request */
+ ret = dict_get_uint32(dict, BR_REOPEN_SIGN_HINT_KEY, &val);
+ if (!ret) {
+ br_stub_handle_object_reopen(frame, this, fd, val);
+ goto done;
+ }
+
+ /* handle bad object */
+ if (dict_get(dict, BITROT_OBJECT_BAD_KEY)) {
+ br_stub_handle_bad_object_key(frame, this, fd, dict, flags, xdata);
+ goto done;
+ }
wind:
- STACK_WIND (frame, default_fsetxattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->fsetxattr, fd, dict, flags,
- xdata);
- return 0;
+ STACK_WIND(frame, default_fsetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, NULL);
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, NULL);
done:
- return 0;
+ return 0;
}
-
/**
* Currently BitD and scrubber are doing fsetxattr to either sign the object
* or to mark it as bad. Hence setxattr on any of those keys is denied directly
@@ -1417,82 +1388,79 @@ done:
* check has to be added below.
*/
int
-br_stub_setxattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc, dict_t *dict, int flags, dict_t *xdata)
+br_stub_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
+ int flags, dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
- if (br_stub_internal_xattr (dict)) {
- br_stub_dump_xattr (this, dict, &op_errno);
- goto unwind;
- }
+ if (br_stub_internal_xattr(dict)) {
+ br_stub_dump_xattr(this, dict, &op_errno);
+ goto unwind;
+ }
- STACK_WIND_TAIL (frame, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->setxattr, loc, dict, flags,
- xdata);
- return 0;
+ STACK_WIND_TAIL(frame, FIRST_CHILD(this), FIRST_CHILD(this)->fops->setxattr,
+ loc, dict, flags, xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, NULL);
- return 0;
+ STACK_UNWIND_STRICT(setxattr, frame, op_ret, op_errno, NULL);
+ return 0;
}
/** }}} */
-
/** {{{ */
/* {f}removexattr() */
int32_t
-br_stub_removexattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc, const char *name, dict_t *xdata)
-{
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
-
- if (!strcmp (BITROT_OBJECT_BAD_KEY, name) ||
- !strcmp (BITROT_SIGNING_VERSION_KEY, name) ||
- !strcmp (BITROT_CURRENT_VERSION_KEY, name)) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRS_MSG_REMOVE_INTERNAL_XATTR, "removexattr called"
- " on internal xattr %s for file %s", name, loc->path);
- goto unwind;
- }
-
- STACK_WIND_TAIL (frame, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->removexattr,
- loc, name, xdata);
- return 0;
+br_stub_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
+{
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+
+ if (!strcmp(BITROT_OBJECT_BAD_KEY, name) ||
+ !strcmp(BITROT_SIGNING_VERSION_KEY, name) ||
+ !strcmp(BITROT_CURRENT_VERSION_KEY, name)) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_REMOVE_INTERNAL_XATTR,
+ "removexattr called"
+ " on internal xattr %s for file %s",
+ name, loc->path);
+ goto unwind;
+ }
+
+ STACK_WIND_TAIL(frame, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr, loc, name, xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno, NULL);
- return 0;
+ STACK_UNWIND_STRICT(removexattr, frame, op_ret, op_errno, NULL);
+ return 0;
}
int32_t
-br_stub_fremovexattr (call_frame_t *frame, xlator_t *this,
- fd_t *fd, const char *name, dict_t *xdata)
-{
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
-
- if (!strcmp (BITROT_OBJECT_BAD_KEY, name) ||
- !strcmp (BITROT_SIGNING_VERSION_KEY, name) ||
- !strcmp (BITROT_CURRENT_VERSION_KEY, name)) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRS_MSG_REMOVE_INTERNAL_XATTR, "removexattr called"
- " on internal xattr %s for inode %s", name,
- uuid_utoa (fd->inode->gfid));
- goto unwind;
- }
-
- STACK_WIND_TAIL (frame, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fremovexattr,
- fd, name, xdata);
- return 0;
+br_stub_fremovexattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ const char *name, dict_t *xdata)
+{
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+
+ if (!strcmp(BITROT_OBJECT_BAD_KEY, name) ||
+ !strcmp(BITROT_SIGNING_VERSION_KEY, name) ||
+ !strcmp(BITROT_CURRENT_VERSION_KEY, name)) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_REMOVE_INTERNAL_XATTR,
+ "removexattr called"
+ " on internal xattr %s for inode %s",
+ name, uuid_utoa(fd->inode->gfid));
+ goto unwind;
+ }
+
+ STACK_WIND_TAIL(frame, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fremovexattr, fd, name, xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (fremovexattr, frame, op_ret, op_errno, NULL);
- return 0;
+ STACK_UNWIND_STRICT(fremovexattr, frame, op_ret, op_errno, NULL);
+ return 0;
}
/** }}} */
@@ -1502,17 +1470,17 @@ unwind:
/* {f}getxattr() */
int
-br_stub_listxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xattr, dict_t *xdata)
+br_stub_listxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, dict_t *xattr, dict_t *xdata)
{
- if (op_ret < 0)
- goto unwind;
+ if (op_ret < 0)
+ goto unwind;
- br_stub_remove_vxattrs (xattr);
+ br_stub_remove_vxattrs(xattr);
- unwind:
- STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, xattr, xdata);
- return 0;
+unwind:
+ STACK_UNWIND_STRICT(getxattr, frame, op_ret, op_errno, xattr, xdata);
+ return 0;
}
/**
@@ -1551,383 +1519,386 @@ br_stub_listxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
* then treat the object as stale.
*/
char
-br_stub_is_object_stale (xlator_t *this, call_frame_t *frame, inode_t *inode,
- br_version_t *obuf, br_signature_t *sbuf)
-{
- uint64_t ctx_addr = 0;
- br_stub_inode_ctx_t *ctx = NULL;
- int32_t ret = -1;
- char stale = 0;
-
- if (obuf->ongoingversion == sbuf->signedversion)
- goto out;
-
- if (frame->root->pid == GF_CLIENT_PID_SCRUB) {
- stale = 1;
- goto out;
- }
-
- ret = br_stub_get_inode_ctx (this, inode, &ctx_addr);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_GET_INODE_CONTEXT_FAILED, "failed to get the "
- "inode context for %s", uuid_utoa (inode->gfid));
- goto out;
- }
-
- ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
-
- LOCK (&inode->lock);
- {
- if ((!__br_stub_is_inode_dirty (ctx) &&
- ctx->info_sign != BR_SIGN_NORMAL) ||
- __br_stub_is_inode_dirty (ctx))
- stale = 1;
- }
- UNLOCK (&inode->lock);
+br_stub_is_object_stale(xlator_t *this, call_frame_t *frame, inode_t *inode,
+ br_version_t *obuf, br_signature_t *sbuf)
+{
+ uint64_t ctx_addr = 0;
+ br_stub_inode_ctx_t *ctx = NULL;
+ int32_t ret = -1;
+ char stale = 0;
+
+ if (obuf->ongoingversion == sbuf->signedversion)
+ goto out;
+
+ if (frame->root->pid == GF_CLIENT_PID_SCRUB) {
+ stale = 1;
+ goto out;
+ }
+
+ ret = br_stub_get_inode_ctx(this, inode, &ctx_addr);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_GET_INODE_CONTEXT_FAILED,
+ "failed to get the "
+ "inode context for %s",
+ uuid_utoa(inode->gfid));
+ goto out;
+ }
+
+ ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
+
+ LOCK(&inode->lock);
+ {
+ if ((!__br_stub_is_inode_dirty(ctx) &&
+ ctx->info_sign != BR_SIGN_NORMAL) ||
+ __br_stub_is_inode_dirty(ctx))
+ stale = 1;
+ }
+ UNLOCK(&inode->lock);
out:
- return stale;
+ return stale;
}
int
-br_stub_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xattr, dict_t *xdata)
-{
- int32_t ret = 0;
- size_t totallen = 0;
- size_t signaturelen = 0;
- br_stub_private_t *priv = NULL;
- br_version_t *obuf = NULL;
- br_signature_t *sbuf = NULL;
- br_isignature_out_t *sign = NULL;
- br_vxattr_status_t status;
- br_stub_local_t *local = NULL;
- inode_t *inode = NULL;
- gf_boolean_t bad_object = _gf_false;
- gf_boolean_t ver_enabled = _gf_false;
-
- BR_STUB_VER_ENABLED_IN_CALLPATH(frame, ver_enabled);
- priv = this->private;
-
- if (op_ret < 0)
- goto unwind;
- BR_STUB_VER_COND_GOTO (priv, (!ver_enabled), delkeys);
-
- if (cookie != (void *) BR_STUB_REQUEST_COOKIE)
- goto unwind;
-
- local = frame->local;
- frame->local = NULL;
- inode = local->u.context.inode;
-
- op_ret = -1;
- status = br_version_xattr_state (xattr, &obuf, &sbuf, &bad_object);
+br_stub_getxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, dict_t *xattr, dict_t *xdata)
+{
+ int32_t ret = 0;
+ size_t totallen = 0;
+ size_t signaturelen = 0;
+ br_stub_private_t *priv = NULL;
+ br_version_t *obuf = NULL;
+ br_signature_t *sbuf = NULL;
+ br_isignature_out_t *sign = NULL;
+ br_vxattr_status_t status;
+ br_stub_local_t *local = NULL;
+ inode_t *inode = NULL;
+ gf_boolean_t bad_object = _gf_false;
+ gf_boolean_t ver_enabled = _gf_false;
+
+ BR_STUB_VER_ENABLED_IN_CALLPATH(frame, ver_enabled);
+ priv = this->private;
+
+ if (op_ret < 0)
+ goto unwind;
+ BR_STUB_VER_COND_GOTO(priv, (!ver_enabled), delkeys);
+
+ if (cookie != (void *)BR_STUB_REQUEST_COOKIE)
+ goto unwind;
+
+ local = frame->local;
+ frame->local = NULL;
+ inode = local->u.context.inode;
+
+ op_ret = -1;
+ status = br_version_xattr_state(xattr, &obuf, &sbuf, &bad_object);
+
+ op_errno = EIO;
+ if (bad_object)
+ goto delkeys;
+
+ op_errno = EINVAL;
+ if (status == BR_VXATTR_STATUS_INVALID)
+ goto delkeys;
+
+ op_errno = ENODATA;
+ if ((status == BR_VXATTR_STATUS_MISSING) ||
+ (status == BR_VXATTR_STATUS_UNSIGNED))
+ goto delkeys;
+
+ /**
+ * okay.. we have enough information to satisfy the request,
+ * namely: version and signing extended attribute. what's
+ * pending is the signature length -- that's figured out
+ * indirectly via the size of the _whole_ xattr and the
+ * on-disk signing xattr header size.
+ */
+ op_errno = EINVAL;
+ ret = dict_get_uint32(xattr, BITROT_SIGNING_XATTR_SIZE_KEY,
+ (uint32_t *)&signaturelen);
+ if (ret)
+ goto delkeys;
+
+ signaturelen -= sizeof(br_signature_t);
+ totallen = sizeof(br_isignature_out_t) + signaturelen;
+
+ op_errno = ENOMEM;
+ sign = GF_CALLOC(1, totallen, gf_br_stub_mt_signature_t);
+ if (!sign)
+ goto delkeys;
+
+ sign->time[0] = obuf->timebuf[0];
+ sign->time[1] = obuf->timebuf[1];
+
+ /* Object's dirty state & current signed version */
+ sign->version = sbuf->signedversion;
+ sign->stale = br_stub_is_object_stale(this, frame, inode, obuf, sbuf);
+
+ /* Object's signature */
+ sign->signaturelen = signaturelen;
+ sign->signaturetype = sbuf->signaturetype;
+ (void)memcpy(sign->signature, sbuf->signature, signaturelen);
+
+ op_errno = EINVAL;
+ ret = dict_set_bin(xattr, GLUSTERFS_GET_OBJECT_SIGNATURE, (void *)sign,
+ totallen);
+ if (ret < 0) {
+ GF_FREE(sign);
+ goto delkeys;
+ }
+ op_errno = 0;
+ op_ret = totallen;
+
+delkeys:
+ br_stub_remove_vxattrs(xattr);
- op_errno = EIO;
- if (bad_object)
- goto delkeys;
-
- op_errno = EINVAL;
- if (status == BR_VXATTR_STATUS_INVALID)
- goto delkeys;
-
- op_errno = ENODATA;
- if ((status == BR_VXATTR_STATUS_MISSING)
- || (status == BR_VXATTR_STATUS_UNSIGNED))
- goto delkeys;
-
- /**
- * okay.. we have enough information to satisfy the request,
- * namely: version and signing extended attribute. what's
- * pending is the signature length -- that's figured out
- * indirectly via the size of the _whole_ xattr and the
- * on-disk signing xattr header size.
- */
- op_errno = EINVAL;
- ret = dict_get_uint32 (xattr, BITROT_SIGNING_XATTR_SIZE_KEY,
- (uint32_t *)&signaturelen);
- if (ret)
- goto delkeys;
-
- signaturelen -= sizeof (br_signature_t);
- totallen = sizeof (br_isignature_out_t) + signaturelen;
-
- op_errno = ENOMEM;
- sign = GF_CALLOC (1, totallen, gf_br_stub_mt_signature_t);
- if (!sign)
- goto delkeys;
-
- sign->time[0] = obuf->timebuf[0];
- sign->time[1] = obuf->timebuf[1];
-
- /* Object's dirty state & current signed version */
- sign->version = sbuf->signedversion;
- sign->stale = br_stub_is_object_stale (this, frame, inode, obuf, sbuf);
-
- /* Object's signature */
- sign->signaturelen = signaturelen;
- sign->signaturetype = sbuf->signaturetype;
- (void) memcpy (sign->signature, sbuf->signature, signaturelen);
-
- op_errno = EINVAL;
- ret = dict_set_bin (xattr, GLUSTERFS_GET_OBJECT_SIGNATURE,
- (void *)sign, totallen);
- if (ret < 0) {
- GF_FREE (sign);
- goto delkeys;
- }
- op_errno = 0;
- op_ret = totallen;
-
- delkeys:
- br_stub_remove_vxattrs (xattr);
-
- unwind:
- STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, xattr, xdata);
- if (local) {
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
- }
- return 0;
+unwind:
+ STACK_UNWIND_STRICT(getxattr, frame, op_ret, op_errno, xattr, xdata);
+ if (local) {
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
+ }
+ return 0;
}
static void
-br_stub_send_stub_init_time (call_frame_t *frame, xlator_t *this)
+br_stub_send_stub_init_time(call_frame_t *frame, xlator_t *this)
{
- int op_ret = 0;
- int op_errno = 0;
- dict_t *xattr = NULL;
- br_stub_init_t stub = {{0,},};
- br_stub_private_t *priv = NULL;
+ int op_ret = 0;
+ int op_errno = 0;
+ dict_t *xattr = NULL;
+ br_stub_init_t stub = {
+ {
+ 0,
+ },
+ };
+ br_stub_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- xattr = dict_new ();
- if (!xattr) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
+ xattr = dict_new();
+ if (!xattr) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
- stub.timebuf[0] = priv->boot[0];
- stub.timebuf[1] = priv->boot[1];
- memcpy (stub.export, priv->export, strlen (priv->export) + 1);
+ stub.timebuf[0] = priv->boot[0];
+ stub.timebuf[1] = priv->boot[1];
+ memcpy(stub.export, priv->export, strlen(priv->export) + 1);
- op_ret = dict_set_static_bin (xattr, GLUSTERFS_GET_BR_STUB_INIT_TIME,
- (void *) &stub, sizeof (br_stub_init_t));
- if (op_ret < 0) {
- op_errno = EINVAL;
- goto unwind;
- }
+ op_ret = dict_set_static_bin(xattr, GLUSTERFS_GET_BR_STUB_INIT_TIME,
+ (void *)&stub, sizeof(br_stub_init_t));
+ if (op_ret < 0) {
+ op_errno = EINVAL;
+ goto unwind;
+ }
- op_ret = sizeof (br_stub_init_t);
+ op_ret = sizeof(br_stub_init_t);
- unwind:
- STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, xattr, NULL);
+unwind:
+ STACK_UNWIND_STRICT(getxattr, frame, op_ret, op_errno, xattr, NULL);
- if (xattr)
- dict_unref (xattr);
+ if (xattr)
+ dict_unref(xattr);
}
int
-br_stub_getxattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc, const char *name, dict_t *xdata)
-{
- void *cookie = NULL;
- uuid_t rootgfid = {0, };
- fop_getxattr_cbk_t cbk = br_stub_getxattr_cbk;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- br_stub_local_t *local = NULL;
- br_stub_private_t *priv = NULL;
-
-
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc, unwind);
- GF_VALIDATE_OR_GOTO (this->name, this->private, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc->inode, unwind);
-
- rootgfid[15] = 1;
-
- if (!name) {
- cbk = br_stub_listxattr_cbk;
- goto wind;
- }
-
- if (br_stub_is_internal_xattr (name))
- goto unwind;
-
- priv = this->private;
- BR_STUB_VER_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
-
- /**
- * If xattr is node-uuid and the inode is marked bad, return EIO.
- * Returning EIO would result in AFR to choose correct node-uuid
- * corresponding to the subvolume * where the good copy of the
- * file resides.
- */
- if (IA_ISREG (loc->inode->ia_type) && XATTR_IS_NODE_UUID (name) &&
- br_stub_check_bad_object (this, loc->inode, &op_ret, &op_errno)) {
- goto unwind;
- }
-
- /**
- * this special extended attribute is allowed only on root
- */
- if (name
- && (strncmp (name, GLUSTERFS_GET_BR_STUB_INIT_TIME,
- sizeof (GLUSTERFS_GET_BR_STUB_INIT_TIME) - 1) == 0)
- && ((gf_uuid_compare (loc->gfid, rootgfid) == 0)
- || (gf_uuid_compare (loc->inode->gfid, rootgfid) == 0))) {
- BR_STUB_RESET_LOCAL_NULL (frame);
- br_stub_send_stub_init_time (frame, this);
- return 0;
+br_stub_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
+{
+ void *cookie = NULL;
+ uuid_t rootgfid = {
+ 0,
+ };
+ fop_getxattr_cbk_t cbk = br_stub_getxattr_cbk;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ br_stub_local_t *local = NULL;
+ br_stub_private_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc->inode, unwind);
+
+ rootgfid[15] = 1;
+
+ if (!name) {
+ cbk = br_stub_listxattr_cbk;
+ goto wind;
+ }
+
+ if (br_stub_is_internal_xattr(name))
+ goto unwind;
+
+ priv = this->private;
+ BR_STUB_VER_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+
+ /**
+ * If xattr is node-uuid and the inode is marked bad, return EIO.
+ * Returning EIO would result in AFR to choose correct node-uuid
+ * corresponding to the subvolume * where the good copy of the
+ * file resides.
+ */
+ if (IA_ISREG(loc->inode->ia_type) && XATTR_IS_NODE_UUID(name) &&
+ br_stub_check_bad_object(this, loc->inode, &op_ret, &op_errno)) {
+ goto unwind;
+ }
+
+ /**
+ * this special extended attribute is allowed only on root
+ */
+ if (name &&
+ (strncmp(name, GLUSTERFS_GET_BR_STUB_INIT_TIME,
+ sizeof(GLUSTERFS_GET_BR_STUB_INIT_TIME) - 1) == 0) &&
+ ((gf_uuid_compare(loc->gfid, rootgfid) == 0) ||
+ (gf_uuid_compare(loc->inode->gfid, rootgfid) == 0))) {
+ BR_STUB_RESET_LOCAL_NULL(frame);
+ br_stub_send_stub_init_time(frame, this);
+ return 0;
+ }
+
+ if (!IA_ISREG(loc->inode->ia_type))
+ goto wind;
+
+ if (name && (strncmp(name, GLUSTERFS_GET_OBJECT_SIGNATURE,
+ sizeof(GLUSTERFS_GET_OBJECT_SIGNATURE) - 1) == 0)) {
+ cookie = (void *)BR_STUB_REQUEST_COOKIE;
+
+ local = br_stub_alloc_local(this);
+ if (!local) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
}
- if (!IA_ISREG (loc->inode->ia_type))
- goto wind;
-
- if (name && (strncmp (name, GLUSTERFS_GET_OBJECT_SIGNATURE,
- sizeof (GLUSTERFS_GET_OBJECT_SIGNATURE) - 1) == 0)) {
- cookie = (void *) BR_STUB_REQUEST_COOKIE;
-
- local = br_stub_alloc_local (this);
- if (!local) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
-
- br_stub_fill_local (local, NULL, NULL, loc->inode,
- loc->inode->gfid,
- BR_STUB_NO_VERSIONING, 0);
- frame->local = local;
- }
+ br_stub_fill_local(local, NULL, NULL, loc->inode, loc->inode->gfid,
+ BR_STUB_NO_VERSIONING, 0);
+ frame->local = local;
+ }
- wind:
- STACK_WIND_COOKIE
- (frame, cbk, cookie, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->getxattr, loc, name, xdata);
- return 0;
+wind:
+ STACK_WIND_COOKIE(frame, cbk, cookie, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->getxattr, loc, name, xdata);
+ return 0;
unwind:
- BR_STUB_RESET_LOCAL_NULL (frame);
- STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, NULL, NULL);
- return 0;
+ BR_STUB_RESET_LOCAL_NULL(frame);
+ STACK_UNWIND_STRICT(getxattr, frame, op_ret, op_errno, NULL, NULL);
+ return 0;
}
int
-br_stub_fgetxattr (call_frame_t *frame, xlator_t *this,
- fd_t *fd, const char *name, dict_t *xdata)
-{
- void *cookie = NULL;
- uuid_t rootgfid = {0, };
- fop_fgetxattr_cbk_t cbk = br_stub_getxattr_cbk;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- br_stub_local_t *local = NULL;
- br_stub_private_t *priv = NULL;
-
- rootgfid[15] = 1;
- priv = this->private;
-
- if (!name) {
- cbk = br_stub_listxattr_cbk;
- goto wind;
- }
-
- if (br_stub_is_internal_xattr (name))
- goto unwind;
-
- BR_STUB_VER_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
-
- /**
- * If xattr is node-uuid and the inode is marked bad, return EIO.
- * Returning EIO would result in AFR to choose correct node-uuid
- * corresponding to the subvolume * where the good copy of the
- * file resides.
- */
- if (IA_ISREG (fd->inode->ia_type) && XATTR_IS_NODE_UUID (name) &&
- br_stub_check_bad_object (this, fd->inode, &op_ret, &op_errno)) {
- goto unwind;
- }
-
- /**
- * this special extended attribute is allowed only on root
- */
- if (name
- && (strncmp (name, GLUSTERFS_GET_BR_STUB_INIT_TIME,
- sizeof (GLUSTERFS_GET_BR_STUB_INIT_TIME) - 1) == 0)
- && (gf_uuid_compare (fd->inode->gfid, rootgfid) == 0)) {
- BR_STUB_RESET_LOCAL_NULL (frame);
- br_stub_send_stub_init_time (frame, this);
- return 0;
+br_stub_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ const char *name, dict_t *xdata)
+{
+ void *cookie = NULL;
+ uuid_t rootgfid = {
+ 0,
+ };
+ fop_fgetxattr_cbk_t cbk = br_stub_getxattr_cbk;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ br_stub_local_t *local = NULL;
+ br_stub_private_t *priv = NULL;
+
+ rootgfid[15] = 1;
+ priv = this->private;
+
+ if (!name) {
+ cbk = br_stub_listxattr_cbk;
+ goto wind;
+ }
+
+ if (br_stub_is_internal_xattr(name))
+ goto unwind;
+
+ BR_STUB_VER_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+
+ /**
+ * If xattr is node-uuid and the inode is marked bad, return EIO.
+ * Returning EIO would result in AFR to choose correct node-uuid
+ * corresponding to the subvolume * where the good copy of the
+ * file resides.
+ */
+ if (IA_ISREG(fd->inode->ia_type) && XATTR_IS_NODE_UUID(name) &&
+ br_stub_check_bad_object(this, fd->inode, &op_ret, &op_errno)) {
+ goto unwind;
+ }
+
+ /**
+ * this special extended attribute is allowed only on root
+ */
+ if (name &&
+ (strncmp(name, GLUSTERFS_GET_BR_STUB_INIT_TIME,
+ sizeof(GLUSTERFS_GET_BR_STUB_INIT_TIME) - 1) == 0) &&
+ (gf_uuid_compare(fd->inode->gfid, rootgfid) == 0)) {
+ BR_STUB_RESET_LOCAL_NULL(frame);
+ br_stub_send_stub_init_time(frame, this);
+ return 0;
+ }
+
+ if (!IA_ISREG(fd->inode->ia_type))
+ goto wind;
+
+ if (name && (strncmp(name, GLUSTERFS_GET_OBJECT_SIGNATURE,
+ sizeof(GLUSTERFS_GET_OBJECT_SIGNATURE) - 1) == 0)) {
+ cookie = (void *)BR_STUB_REQUEST_COOKIE;
+
+ local = br_stub_alloc_local(this);
+ if (!local) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
}
- if (!IA_ISREG (fd->inode->ia_type))
- goto wind;
-
- if (name && (strncmp (name, GLUSTERFS_GET_OBJECT_SIGNATURE,
- sizeof (GLUSTERFS_GET_OBJECT_SIGNATURE) - 1) == 0)) {
- cookie = (void *) BR_STUB_REQUEST_COOKIE;
-
- local = br_stub_alloc_local (this);
- if (!local) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
-
- br_stub_fill_local (local, NULL, fd, fd->inode,
- fd->inode->gfid,
- BR_STUB_NO_VERSIONING, 0);
- frame->local = local;
- }
+ br_stub_fill_local(local, NULL, fd, fd->inode, fd->inode->gfid,
+ BR_STUB_NO_VERSIONING, 0);
+ frame->local = local;
+ }
- wind:
- STACK_WIND_COOKIE
- (frame, cbk, cookie, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->fgetxattr, fd, name, xdata);
- return 0;
+wind:
+ STACK_WIND_COOKIE(frame, cbk, cookie, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fgetxattr, fd, name, xdata);
+ return 0;
unwind:
- BR_STUB_RESET_LOCAL_NULL (frame);
- STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, NULL, NULL);
- return 0;
+ BR_STUB_RESET_LOCAL_NULL(frame);
+ STACK_UNWIND_STRICT(fgetxattr, frame, op_ret, op_errno, NULL, NULL);
+ return 0;
}
int32_t
-br_stub_readv (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t offset, uint32_t flags, dict_t *xdata)
+br_stub_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset, uint32_t flags, dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- int32_t ret = -1;
- br_stub_private_t *priv = NULL;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ int32_t ret = -1;
+ br_stub_private_t *priv = NULL;
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, unwind);
- GF_VALIDATE_OR_GOTO (this->name, frame, unwind);
- GF_VALIDATE_OR_GOTO (this->name, this->private, unwind);
- GF_VALIDATE_OR_GOTO (this->name, fd, unwind);
- GF_VALIDATE_OR_GOTO (this->name, fd->inode, unwind);
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, frame, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, fd, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, fd->inode, unwind);
- priv = this->private;
- if (!priv->do_versioning)
- goto wind;
+ priv = this->private;
+ if (!priv->do_versioning)
+ goto wind;
- ret = br_stub_check_bad_object (this, fd->inode, &op_ret, &op_errno);
- if (ret)
- goto unwind;
+ ret = br_stub_check_bad_object(this, fd->inode, &op_ret, &op_errno);
+ if (ret)
+ goto unwind;
wind:
- STACK_WIND_TAIL (frame, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->readv, fd, size, offset,
- flags, xdata);
- return 0;
+ STACK_WIND_TAIL(frame, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readv,
+ fd, size, offset, flags, xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, NULL, 0, NULL,
- NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, NULL, 0, NULL, NULL,
+ NULL);
+ return 0;
}
/**
@@ -1938,44 +1909,44 @@ unwind:
* fds.
*/
int32_t
-br_stub_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+br_stub_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- int32_t ret = 0;
- br_stub_local_t *local = NULL;
+ int32_t ret = 0;
+ br_stub_local_t *local = NULL;
- local = frame->local;
- frame->local = NULL;
+ local = frame->local;
+ frame->local = NULL;
- if (op_ret < 0)
- goto unwind;
+ if (op_ret < 0)
+ goto unwind;
- ret = br_stub_mark_inode_modified (this, local);
- if (ret) {
- op_ret = -1;
- op_errno = EINVAL;
- }
+ ret = br_stub_mark_inode_modified(this, local);
+ if (ret) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ }
unwind:
- STACK_UNWIND_STRICT (writev, frame,
- op_ret, op_errno, prebuf, postbuf, xdata);
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
- return 0;
+ return 0;
}
int32_t
-br_stub_writev_resume (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *vector, int32_t count, off_t offset,
- uint32_t flags, struct iobref *iobref, dict_t *xdata)
+br_stub_writev_resume(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *vector, int32_t count, off_t offset,
+ uint32_t flags, struct iobref *iobref, dict_t *xdata)
{
- STACK_WIND (frame, br_stub_writev_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->writev, fd, vector, count,
- offset, flags, iobref, xdata);
- return 0;
+ STACK_WIND(frame, br_stub_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, vector, count, offset,
+ flags, iobref, xdata);
+ return 0;
}
/**
@@ -1989,248 +1960,247 @@ br_stub_writev_resume (call_frame_t *frame, xlator_t *this, fd_t *fd,
* This prevents signing of objects that have not been modified.
*/
int32_t
-br_stub_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *vector, int32_t count, off_t offset,
- uint32_t flags, struct iobref *iobref, dict_t *xdata)
-{
- call_stub_t *stub = NULL;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- gf_boolean_t inc_version = _gf_false;
- gf_boolean_t modified = _gf_false;
- br_stub_inode_ctx_t *ctx = NULL;
- int32_t ret = -1;
- fop_writev_cbk_t cbk = default_writev_cbk;
- br_stub_local_t *local = NULL;
- br_stub_private_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, unwind);
- GF_VALIDATE_OR_GOTO (this->name, this->private, unwind);
- GF_VALIDATE_OR_GOTO (this->name, frame, unwind);
- GF_VALIDATE_OR_GOTO (this->name, fd, unwind);
-
- priv = this->private;
- if (!priv->do_versioning)
- goto wind;
-
- ret = br_stub_need_versioning (this, fd, &inc_version, &modified, &ctx);
- if (ret)
- goto unwind;
-
- ret = br_stub_check_bad_object (this, fd->inode, &op_ret, &op_errno);
- if (ret)
- goto unwind;
+br_stub_writev(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *vector, int32_t count, off_t offset,
+ uint32_t flags, struct iobref *iobref, dict_t *xdata)
+{
+ call_stub_t *stub = NULL;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ gf_boolean_t inc_version = _gf_false;
+ gf_boolean_t modified = _gf_false;
+ br_stub_inode_ctx_t *ctx = NULL;
+ int32_t ret = -1;
+ fop_writev_cbk_t cbk = default_writev_cbk;
+ br_stub_local_t *local = NULL;
+ br_stub_private_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, frame, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, fd, unwind);
+
+ priv = this->private;
+ if (!priv->do_versioning)
+ goto wind;
+
+ ret = br_stub_need_versioning(this, fd, &inc_version, &modified, &ctx);
+ if (ret)
+ goto unwind;
+
+ ret = br_stub_check_bad_object(this, fd->inode, &op_ret, &op_errno);
+ if (ret)
+ goto unwind;
+
+ /**
+ * The inode is not dirty and also witnessed at least one successful
+ * modification operation. Therefore, subsequent operations need not
+ * perform any special tracking.
+ */
+ if (!inc_version && modified)
+ goto wind;
+
+ /**
+ * okay.. so, either the inode needs versioning or the modification
+ * needs to be tracked. ->cbk is set to the appropriate callback
+ * routine for this.
+ * NOTE: ->local needs to be deallocated on failures from here on.
+ */
+ ret = br_stub_versioning_prep(frame, this, fd, ctx);
+ if (ret)
+ goto unwind;
+
+ local = frame->local;
+ if (!inc_version) {
+ br_stub_fill_local(local, NULL, fd, fd->inode, fd->inode->gfid,
+ BR_STUB_NO_VERSIONING, 0);
+ cbk = br_stub_writev_cbk;
+ goto wind;
+ }
+
+ stub = fop_writev_stub(frame, br_stub_writev_resume, fd, vector, count,
+ offset, flags, iobref, xdata);
+
+ if (!stub) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_STUB_ALLOC_FAILED,
+ "failed to allocate stub for write fop (gfid: %s), "
+ "unwinding",
+ uuid_utoa(fd->inode->gfid));
+ goto cleanup_local;
+ }
+
+ /* Perform Versioning */
+ return br_stub_perform_incversioning(this, frame, stub, fd, ctx);
- /**
- * The inode is not dirty and also witnessed at least one successful
- * modification operation. Therefore, subsequent operations need not
- * perform any special tracking.
- */
- if (!inc_version && modified)
- goto wind;
-
- /**
- * okay.. so, either the inode needs versioning or the modification
- * needs to be tracked. ->cbk is set to the appropriate callback
- * routine for this.
- * NOTE: ->local needs to be deallocated on failures from here on.
- */
- ret = br_stub_versioning_prep (frame, this, fd, ctx);
- if (ret)
- goto unwind;
-
- local = frame->local;
- if (!inc_version) {
- br_stub_fill_local (local, NULL, fd, fd->inode,
- fd->inode->gfid, BR_STUB_NO_VERSIONING, 0);
- cbk = br_stub_writev_cbk;
- goto wind;
- }
-
- stub = fop_writev_stub (frame, br_stub_writev_resume, fd, vector, count,
- offset, flags, iobref, xdata);
-
- if (!stub) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRS_MSG_STUB_ALLOC_FAILED,
- "failed to allocate stub for write fop (gfid: %s), "
- "unwinding", uuid_utoa (fd->inode->gfid));
- goto cleanup_local;
- }
-
- /* Perform Versioning */
- return br_stub_perform_incversioning (this, frame, stub, fd, ctx);
-
- wind:
- STACK_WIND (frame, cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->writev,
- fd, vector, count, offset, flags, iobref, xdata);
- return 0;
+wind:
+ STACK_WIND(frame, cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->writev,
+ fd, vector, count, offset, flags, iobref, xdata);
+ return 0;
- cleanup_local:
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
+cleanup_local:
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
- unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, NULL, NULL,
- NULL);
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, NULL, NULL, NULL);
- return 0;
+ return 0;
}
int32_t
-br_stub_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+br_stub_ftruncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- int32_t ret = -1;
- br_stub_local_t *local = NULL;
+ int32_t ret = -1;
+ br_stub_local_t *local = NULL;
- local = frame->local;
- frame->local = NULL;
+ local = frame->local;
+ frame->local = NULL;
- if (op_ret < 0)
- goto unwind;
+ if (op_ret < 0)
+ goto unwind;
- ret = br_stub_mark_inode_modified (this, local);
- if (ret) {
- op_ret = -1;
- op_errno = EINVAL;
- }
+ ret = br_stub_mark_inode_modified(this, local);
+ if (ret) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ }
unwind:
- STACK_UNWIND_STRICT (ftruncate, frame,
- op_ret, op_errno, prebuf, postbuf, xdata);
+ STACK_UNWIND_STRICT(ftruncate, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
- return 0;
+ return 0;
}
int32_t
-br_stub_ftruncate_resume (call_frame_t *frame, xlator_t *this, fd_t *fd,
- off_t offset, dict_t *xdata)
+br_stub_ftruncate_resume(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ off_t offset, dict_t *xdata)
{
- STACK_WIND (frame, br_stub_ftruncate_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
- return 0;
+ STACK_WIND(frame, br_stub_ftruncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
+ return 0;
}
/* c.f. br_stub_writev() for explanation */
int32_t
-br_stub_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd,
- off_t offset, dict_t *xdata)
-{
- br_stub_local_t *local = NULL;
- call_stub_t *stub = NULL;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- gf_boolean_t inc_version = _gf_false;
- gf_boolean_t modified = _gf_false;
- br_stub_inode_ctx_t *ctx = NULL;
- int32_t ret = -1;
- fop_ftruncate_cbk_t cbk = default_ftruncate_cbk;
- br_stub_private_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, unwind);
- GF_VALIDATE_OR_GOTO (this->name, this->private, unwind);
- GF_VALIDATE_OR_GOTO (this->name, frame, unwind);
- GF_VALIDATE_OR_GOTO (this->name, fd, unwind);
-
- priv = this->private;
- if (!priv->do_versioning)
- goto wind;
-
- ret = br_stub_need_versioning (this, fd, &inc_version, &modified, &ctx);
- if (ret)
- goto unwind;
-
- ret = br_stub_check_bad_object (this, fd->inode, &op_ret, &op_errno);
- if (ret)
- goto unwind;
-
- if (!inc_version && modified)
- goto wind;
-
- ret = br_stub_versioning_prep (frame, this, fd, ctx);
- if (ret)
- goto unwind;
-
- local = frame->local;
- if (!inc_version) {
- br_stub_fill_local (local, NULL, fd, fd->inode,
- fd->inode->gfid, BR_STUB_NO_VERSIONING, 0);
- cbk = br_stub_ftruncate_cbk;
- goto wind;
- }
+br_stub_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ dict_t *xdata)
+{
+ br_stub_local_t *local = NULL;
+ call_stub_t *stub = NULL;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ gf_boolean_t inc_version = _gf_false;
+ gf_boolean_t modified = _gf_false;
+ br_stub_inode_ctx_t *ctx = NULL;
+ int32_t ret = -1;
+ fop_ftruncate_cbk_t cbk = default_ftruncate_cbk;
+ br_stub_private_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, frame, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, fd, unwind);
+
+ priv = this->private;
+ if (!priv->do_versioning)
+ goto wind;
+
+ ret = br_stub_need_versioning(this, fd, &inc_version, &modified, &ctx);
+ if (ret)
+ goto unwind;
+
+ ret = br_stub_check_bad_object(this, fd->inode, &op_ret, &op_errno);
+ if (ret)
+ goto unwind;
+
+ if (!inc_version && modified)
+ goto wind;
+
+ ret = br_stub_versioning_prep(frame, this, fd, ctx);
+ if (ret)
+ goto unwind;
+
+ local = frame->local;
+ if (!inc_version) {
+ br_stub_fill_local(local, NULL, fd, fd->inode, fd->inode->gfid,
+ BR_STUB_NO_VERSIONING, 0);
+ cbk = br_stub_ftruncate_cbk;
+ goto wind;
+ }
+
+ stub = fop_ftruncate_stub(frame, br_stub_ftruncate_resume, fd, offset,
+ xdata);
+ if (!stub) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_STUB_ALLOC_FAILED,
+ "failed to allocate stub for ftruncate fop (gfid: %s),"
+ " unwinding",
+ uuid_utoa(fd->inode->gfid));
+ goto cleanup_local;
+ }
+
+ return br_stub_perform_incversioning(this, frame, stub, fd, ctx);
- stub = fop_ftruncate_stub (frame, br_stub_ftruncate_resume, fd, offset,
- xdata);
- if (!stub) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRS_MSG_STUB_ALLOC_FAILED,
- "failed to allocate stub for ftruncate fop (gfid: %s),"
- " unwinding", uuid_utoa (fd->inode->gfid));
- goto cleanup_local;
- }
-
- return br_stub_perform_incversioning (this, frame, stub, fd, ctx);
-
- wind:
- STACK_WIND (frame, cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
- return 0;
+wind:
+ STACK_WIND(frame, cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
+ return 0;
- cleanup_local:
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
+cleanup_local:
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
- unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, NULL, NULL,
- NULL);
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(ftruncate, frame, op_ret, op_errno, NULL, NULL, NULL);
- return 0;
+ return 0;
}
int32_t
-br_stub_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+br_stub_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- int32_t ret = 0;
- br_stub_local_t *local = NULL;
+ int32_t ret = 0;
+ br_stub_local_t *local = NULL;
- local = frame->local;
- frame->local = NULL;
+ local = frame->local;
+ frame->local = NULL;
- if (op_ret < 0)
- goto unwind;
+ if (op_ret < 0)
+ goto unwind;
- ret = br_stub_mark_inode_modified (this, local);
- if (ret) {
- op_ret = -1;
- op_errno = EINVAL;
- }
+ ret = br_stub_mark_inode_modified(this, local);
+ if (ret) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ }
unwind:
- STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, prebuf, postbuf,
- xdata);
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
- return 0;
+ STACK_UNWIND_STRICT(truncate, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
+ return 0;
}
int32_t
-br_stub_truncate_resume (call_frame_t *frame, xlator_t *this, loc_t *loc,
- off_t offset, dict_t *xdata)
+br_stub_truncate_resume(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ off_t offset, dict_t *xdata)
{
- br_stub_local_t *local = frame->local;
+ br_stub_local_t *local = frame->local;
- fd_unref (local->u.context.fd);
- STACK_WIND (frame, br_stub_ftruncate_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
- return 0;
+ fd_unref(local->u.context.fd);
+ STACK_WIND(frame, br_stub_ftruncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
+ return 0;
}
/**
@@ -2248,97 +2218,96 @@ br_stub_truncate_resume (call_frame_t *frame, xlator_t *this, loc_t *loc,
* c.f. br_writev_cbk() for explanation
*/
int32_t
-br_stub_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc,
- off_t offset, dict_t *xdata)
-{
- br_stub_local_t *local = NULL;
- call_stub_t *stub = NULL;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- gf_boolean_t inc_version = _gf_false;
- gf_boolean_t modified = _gf_false;
- br_stub_inode_ctx_t *ctx = NULL;
- int32_t ret = -1;
- fd_t *fd = NULL;
- fop_truncate_cbk_t cbk = default_truncate_cbk;
- br_stub_private_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, unwind);
- GF_VALIDATE_OR_GOTO (this->name, this->private, unwind);
- GF_VALIDATE_OR_GOTO (this->name, frame, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc->inode, unwind);
-
- priv = this->private;
- if (!priv->do_versioning)
- goto wind;
-
- fd = fd_anonymous (loc->inode);
- if (!fd) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_CREATE_ANONYMOUS_FD_FAILED, "failed to create "
- "anonymous fd for the inode %s",
- uuid_utoa (loc->inode->gfid));
- goto unwind;
- }
-
- ret = br_stub_need_versioning (this, fd, &inc_version, &modified, &ctx);
- if (ret)
- goto cleanup_fd;
-
- ret = br_stub_check_bad_object (this, fd->inode, &op_ret, &op_errno);
- if (ret)
- goto unwind;
-
- if (!inc_version && modified)
- goto wind;
-
- ret = br_stub_versioning_prep (frame, this, fd, ctx);
- if (ret)
- goto cleanup_fd;
-
- local = frame->local;
- if (!inc_version) {
- br_stub_fill_local (local, NULL, fd, fd->inode,
- fd->inode->gfid, BR_STUB_NO_VERSIONING, 0);
- cbk = br_stub_truncate_cbk;
- goto wind;
- }
-
- stub = fop_truncate_stub (frame, br_stub_truncate_resume, loc, offset,
- xdata);
- if (!stub) {
- gf_msg (this->name, GF_LOG_ERROR, 0, BRS_MSG_STUB_ALLOC_FAILED,
- "failed to allocate stub for truncate fop (gfid: %s), "
- "unwinding", uuid_utoa (fd->inode->gfid));
- goto cleanup_local;
- }
+br_stub_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
+ dict_t *xdata)
+{
+ br_stub_local_t *local = NULL;
+ call_stub_t *stub = NULL;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ gf_boolean_t inc_version = _gf_false;
+ gf_boolean_t modified = _gf_false;
+ br_stub_inode_ctx_t *ctx = NULL;
+ int32_t ret = -1;
+ fd_t *fd = NULL;
+ fop_truncate_cbk_t cbk = default_truncate_cbk;
+ br_stub_private_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, frame, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc->inode, unwind);
+
+ priv = this->private;
+ if (!priv->do_versioning)
+ goto wind;
+
+ fd = fd_anonymous(loc->inode);
+ if (!fd) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_CREATE_ANONYMOUS_FD_FAILED,
+ "failed to create "
+ "anonymous fd for the inode %s",
+ uuid_utoa(loc->inode->gfid));
+ goto unwind;
+ }
+
+ ret = br_stub_need_versioning(this, fd, &inc_version, &modified, &ctx);
+ if (ret)
+ goto cleanup_fd;
+
+ ret = br_stub_check_bad_object(this, fd->inode, &op_ret, &op_errno);
+ if (ret)
+ goto unwind;
+
+ if (!inc_version && modified)
+ goto wind;
+
+ ret = br_stub_versioning_prep(frame, this, fd, ctx);
+ if (ret)
+ goto cleanup_fd;
+
+ local = frame->local;
+ if (!inc_version) {
+ br_stub_fill_local(local, NULL, fd, fd->inode, fd->inode->gfid,
+ BR_STUB_NO_VERSIONING, 0);
+ cbk = br_stub_truncate_cbk;
+ goto wind;
+ }
+
+ stub = fop_truncate_stub(frame, br_stub_truncate_resume, loc, offset,
+ xdata);
+ if (!stub) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_STUB_ALLOC_FAILED,
+ "failed to allocate stub for truncate fop (gfid: %s), "
+ "unwinding",
+ uuid_utoa(fd->inode->gfid));
+ goto cleanup_local;
+ }
- return br_stub_perform_incversioning (this, frame, stub, fd, ctx);
+ return br_stub_perform_incversioning(this, frame, stub, fd, ctx);
- wind:
- STACK_WIND (frame, cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
- if (fd)
- fd_unref (fd);
- return 0;
-
- cleanup_local:
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
- cleanup_fd:
- fd_unref (fd);
- unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, NULL, NULL,
- NULL);
+wind:
+ STACK_WIND(frame, cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->truncate,
+ loc, offset, xdata);
+ if (fd)
+ fd_unref(fd);
+ return 0;
+
+cleanup_local:
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
+cleanup_fd:
+ fd_unref(fd);
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(truncate, frame, op_ret, op_errno, NULL, NULL, NULL);
- return 0;
+ return 0;
}
/** }}} */
-
/** {{{ */
/* open() */
@@ -2358,76 +2327,73 @@ br_stub_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc,
*/
int
-br_stub_open (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int32_t flags, fd_t *fd, dict_t *xdata)
-{
- int32_t ret = -1;
- br_stub_inode_ctx_t *ctx = NULL;
- uint64_t ctx_addr = 0;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- br_stub_private_t *priv = NULL;
- unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
-
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, unwind);
- GF_VALIDATE_OR_GOTO (this->name, this->private, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc, unwind);
- GF_VALIDATE_OR_GOTO (this->name, fd, unwind);
- GF_VALIDATE_OR_GOTO (this->name, fd->inode, unwind);
-
- priv = this->private;
-
- if (!priv->do_versioning)
- goto wind;
-
- ret = br_stub_get_inode_ctx (this, fd->inode, &ctx_addr);
+br_stub_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ fd_t *fd, dict_t *xdata)
+{
+ int32_t ret = -1;
+ br_stub_inode_ctx_t *ctx = NULL;
+ uint64_t ctx_addr = 0;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ br_stub_private_t *priv = NULL;
+ unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
+
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, fd, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, fd->inode, unwind);
+
+ priv = this->private;
+
+ if (!priv->do_versioning)
+ goto wind;
+
+ ret = br_stub_get_inode_ctx(this, fd->inode, &ctx_addr);
+ if (ret) {
+ ret = br_stub_init_inode_versions(this, fd, fd->inode, version,
+ _gf_true, _gf_false, &ctx_addr);
if (ret) {
- ret = br_stub_init_inode_versions (this, fd, fd->inode, version,
- _gf_true, _gf_false,
- &ctx_addr);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_GET_INODE_CONTEXT_FAILED,
- "failed to init the inode context for "
- "the file %s (gfid: %s)", loc->path,
- uuid_utoa (fd->inode->gfid));
- goto unwind;
- }
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ BRS_MSG_GET_INODE_CONTEXT_FAILED,
+ "failed to init the inode context for "
+ "the file %s (gfid: %s)",
+ loc->path, uuid_utoa(fd->inode->gfid));
+ goto unwind;
}
+ }
- ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
+ ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
- ret = br_stub_check_bad_object (this, fd->inode, &op_ret, &op_errno);
- if (ret)
- goto unwind;
+ ret = br_stub_check_bad_object(this, fd->inode, &op_ret, &op_errno);
+ if (ret)
+ goto unwind;
- if (frame->root->pid == GF_CLIENT_PID_SCRUB)
- goto wind;
+ if (frame->root->pid == GF_CLIENT_PID_SCRUB)
+ goto wind;
- if (flags == O_RDONLY)
- goto wind;
+ if (flags == O_RDONLY)
+ goto wind;
- ret = br_stub_add_fd_to_inode (this, fd, ctx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_ADD_FD_TO_LIST_FAILED,
- "failed add fd to the list (gfid: %s)",
- uuid_utoa (fd->inode->gfid));
- goto unwind;
- }
+ ret = br_stub_add_fd_to_inode(this, fd, ctx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_ADD_FD_TO_LIST_FAILED,
+ "failed add fd to the list (gfid: %s)",
+ uuid_utoa(fd->inode->gfid));
+ goto unwind;
+ }
wind:
- STACK_WIND (frame, default_open_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->open, loc, flags, fd, xdata);
- return 0;
+ STACK_WIND(frame, default_open_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(open, frame, op_ret, op_errno, NULL, NULL);
+ return 0;
}
/** }}} */
-
/** {{{ */
/* creat() */
@@ -2437,143 +2403,139 @@ unwind:
* fd to the inode context fd tracking list.
*/
int32_t
-br_stub_add_fd_to_inode (xlator_t *this, fd_t *fd, br_stub_inode_ctx_t *ctx)
+br_stub_add_fd_to_inode(xlator_t *this, fd_t *fd, br_stub_inode_ctx_t *ctx)
{
- int32_t ret = -1;
- br_stub_fd_t *br_stub_fd = NULL;
+ int32_t ret = -1;
+ br_stub_fd_t *br_stub_fd = NULL;
- ret = br_stub_require_release_call (this, fd, &br_stub_fd);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_SET_FD_CONTEXT_FAILED, "failed to set the fd "
- "context for the file (gfid: %s)",
- uuid_utoa (fd->inode->gfid));
- goto out;
- }
+ ret = br_stub_require_release_call(this, fd, &br_stub_fd);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_SET_FD_CONTEXT_FAILED,
+ "failed to set the fd "
+ "context for the file (gfid: %s)",
+ uuid_utoa(fd->inode->gfid));
+ goto out;
+ }
- LOCK (&fd->inode->lock);
- {
- list_add_tail (&ctx->fd_list, &br_stub_fd->list);
- }
- UNLOCK (&fd->inode->lock);
+ LOCK(&fd->inode->lock);
+ {
+ list_add_tail(&ctx->fd_list, &br_stub_fd->list);
+ }
+ UNLOCK(&fd->inode->lock);
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
int
-br_stub_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, fd_t *fd, inode_t *inode,
- struct iatt *stbuf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
-{
- int32_t ret = 0;
- uint64_t ctx_addr = 0;
- br_stub_inode_ctx_t *ctx = NULL;
- unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
- br_stub_private_t *priv = NULL;
-
- priv = this->private;
-
- if (op_ret < 0)
- goto unwind;
-
- if (!priv->do_versioning)
- goto unwind;
-
- ret = br_stub_get_inode_ctx (this, fd->inode, &ctx_addr);
- if (ret < 0) {
- ret = br_stub_init_inode_versions (this, fd, inode, version,
- _gf_true, _gf_false,
- &ctx_addr);
- if (ret) {
- op_ret = -1;
- op_errno = EINVAL;
- }
- } else {
- ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
- ret = br_stub_add_fd_to_inode (this, fd, ctx);
+br_stub_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, fd_t *fd, inode_t *inode,
+ struct iatt *stbuf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
+{
+ int32_t ret = 0;
+ uint64_t ctx_addr = 0;
+ br_stub_inode_ctx_t *ctx = NULL;
+ unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
+ br_stub_private_t *priv = NULL;
+
+ priv = this->private;
+
+ if (op_ret < 0)
+ goto unwind;
+
+ if (!priv->do_versioning)
+ goto unwind;
+
+ ret = br_stub_get_inode_ctx(this, fd->inode, &ctx_addr);
+ if (ret < 0) {
+ ret = br_stub_init_inode_versions(this, fd, inode, version, _gf_true,
+ _gf_false, &ctx_addr);
+ if (ret) {
+ op_ret = -1;
+ op_errno = EINVAL;
}
+ } else {
+ ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
+ ret = br_stub_add_fd_to_inode(this, fd, ctx);
+ }
unwind:
- STACK_UNWIND_STRICT (create, frame, op_ret, op_errno,
- fd, inode, stbuf, preparent, postparent, xdata);
- return 0;
+ STACK_UNWIND_STRICT(create, frame, op_ret, op_errno, fd, inode, stbuf,
+ preparent, postparent, xdata);
+ return 0;
}
int
-br_stub_create (call_frame_t *frame,
- xlator_t *this, loc_t *loc, int32_t flags,
- mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
-{
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc->inode, unwind);
- GF_VALIDATE_OR_GOTO (this->name, fd, unwind);
- GF_VALIDATE_OR_GOTO (this->name, fd->inode, unwind);
-
- STACK_WIND (frame, br_stub_create_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->create,
- loc, flags, mode, umask, fd, xdata);
- return 0;
+br_stub_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
+{
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc->inode, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, fd, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, fd->inode, unwind);
+
+ STACK_WIND(frame, br_stub_create_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->create, loc, flags, mode, umask, fd,
+ xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (create, frame, -1, EINVAL, NULL, NULL, NULL, NULL,
- NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(create, frame, -1, EINVAL, NULL, NULL, NULL, NULL, NULL,
+ NULL);
+ return 0;
}
int
-br_stub_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, inode_t *inode,
- struct iatt *stbuf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
-{
- int32_t ret = -1;
- unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
- br_stub_private_t *priv = NULL;
-
- priv = this->private;
-
- if (op_ret < 0)
- goto unwind;
-
- if (!priv->do_versioning)
- goto unwind;
-
- ret = br_stub_init_inode_versions (this, NULL, inode, version,
- _gf_true, _gf_false, NULL);
- /**
- * Like lookup, if init_inode_versions fail, return EINVAL
- */
- if (ret) {
- op_ret = -1;
- op_errno = EINVAL;
- }
+br_stub_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, inode_t *inode, struct iatt *stbuf,
+ struct iatt *preparent, struct iatt *postparent,
+ dict_t *xdata)
+{
+ int32_t ret = -1;
+ unsigned long version = BITROT_DEFAULT_CURRENT_VERSION;
+ br_stub_private_t *priv = NULL;
+
+ priv = this->private;
+
+ if (op_ret < 0)
+ goto unwind;
+
+ if (!priv->do_versioning)
+ goto unwind;
+
+ ret = br_stub_init_inode_versions(this, NULL, inode, version, _gf_true,
+ _gf_false, NULL);
+ /**
+ * Like lookup, if init_inode_versions fail, return EINVAL
+ */
+ if (ret) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ }
unwind:
- STACK_UNWIND_STRICT (mknod, frame, op_ret, op_errno,
- inode, stbuf, preparent, postparent, xdata);
- return 0;
+ STACK_UNWIND_STRICT(mknod, frame, op_ret, op_errno, inode, stbuf, preparent,
+ postparent, xdata);
+ return 0;
}
int
-br_stub_mknod (call_frame_t *frame, xlator_t *this,
- loc_t *loc, mode_t mode, dev_t dev, mode_t umask, dict_t *xdata)
+br_stub_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ dev_t dev, mode_t umask, dict_t *xdata)
{
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc->inode, unwind);
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc->inode, unwind);
- STACK_WIND (frame, br_stub_mknod_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->mknod,
- loc, mode, dev, umask, xdata);
- return 0;
+ STACK_WIND(frame, br_stub_mknod_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mknod, loc, mode, dev, umask, xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (mknod, frame, -1, EINVAL, NULL, NULL, NULL,
- NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(mknod, frame, -1, EINVAL, NULL, NULL, NULL, NULL, NULL);
+ return 0;
}
/** }}} */
@@ -2603,226 +2565,225 @@ unwind:
* creattion failure as the lookup failure.
*/
static int32_t
-br_stub_lookup_version (xlator_t *this,
- uuid_t gfid, inode_t *inode, dict_t *xattr)
-{
- unsigned long version = 0;
- br_version_t *obuf = NULL;
- br_signature_t *sbuf = NULL;
- br_vxattr_status_t status;
- gf_boolean_t bad_object = _gf_false;
-
- /**
- * versioning xattrs were requested from POSIX. if available, figure
- * out the correct version to use in the inode context (start with
- * the default version if unavailable). As of now versions are not
- * persisted on-disk. The inode is marked dirty, so that the first
- * operation (such as write(), etc..) triggers synchronization to
- * disk.
- */
- status = br_version_xattr_state (xattr, &obuf, &sbuf, &bad_object);
- version = ((status == BR_VXATTR_STATUS_FULL)
- || (status == BR_VXATTR_STATUS_UNSIGNED))
- ? obuf->ongoingversion : BITROT_DEFAULT_CURRENT_VERSION;
-
- /**
- * If signature is there, but version is not there then that status is
- * is treated as INVALID. So in that case, we should not initialize the
- * inode context with wrong version names etc.
- */
- if (status == BR_VXATTR_STATUS_INVALID)
- return -1;
+br_stub_lookup_version(xlator_t *this, uuid_t gfid, inode_t *inode,
+ dict_t *xattr)
+{
+ unsigned long version = 0;
+ br_version_t *obuf = NULL;
+ br_signature_t *sbuf = NULL;
+ br_vxattr_status_t status;
+ gf_boolean_t bad_object = _gf_false;
+
+ /**
+ * versioning xattrs were requested from POSIX. if available, figure
+ * out the correct version to use in the inode context (start with
+ * the default version if unavailable). As of now versions are not
+ * persisted on-disk. The inode is marked dirty, so that the first
+ * operation (such as write(), etc..) triggers synchronization to
+ * disk.
+ */
+ status = br_version_xattr_state(xattr, &obuf, &sbuf, &bad_object);
+ version = ((status == BR_VXATTR_STATUS_FULL) ||
+ (status == BR_VXATTR_STATUS_UNSIGNED))
+ ? obuf->ongoingversion
+ : BITROT_DEFAULT_CURRENT_VERSION;
+
+ /**
+ * If signature is there, but version is not there then that status is
+ * is treated as INVALID. So in that case, we should not initialize the
+ * inode context with wrong version names etc.
+ */
+ if (status == BR_VXATTR_STATUS_INVALID)
+ return -1;
- return br_stub_init_inode_versions (this, NULL, inode, version,
- _gf_true, bad_object, NULL);
+ return br_stub_init_inode_versions(this, NULL, inode, version, _gf_true,
+ bad_object, NULL);
}
-
/** {{{ */
int32_t
-br_stub_opendir (call_frame_t *frame, xlator_t *this,
- loc_t *loc, fd_t *fd, dict_t *xdata)
-{
- br_stub_private_t *priv = NULL;
- br_stub_fd_t *fd_ctx = NULL;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
-
- priv = this->private;
- if (gf_uuid_compare (fd->inode->gfid, priv->bad_object_dir_gfid))
- goto normal;
-
- fd_ctx = br_stub_fd_new ();
- if (!fd_ctx) {
- op_errno = ENOMEM;
- goto unwind;
- }
+br_stub_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
+ dict_t *xdata)
+{
+ br_stub_private_t *priv = NULL;
+ br_stub_fd_t *fd_ctx = NULL;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
- fd_ctx->bad_object.dir_eof = -1;
- fd_ctx->bad_object.dir = sys_opendir (priv->stub_basepath);
- if (!fd_ctx->bad_object.dir) {
- op_errno = errno;
- goto err_freectx;
- }
+ priv = this->private;
+ if (gf_uuid_compare(fd->inode->gfid, priv->bad_object_dir_gfid))
+ goto normal;
+
+ fd_ctx = br_stub_fd_new();
+ if (!fd_ctx) {
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+
+ fd_ctx->bad_object.dir_eof = -1;
+ fd_ctx->bad_object.dir = sys_opendir(priv->stub_basepath);
+ if (!fd_ctx->bad_object.dir) {
+ op_errno = errno;
+ goto err_freectx;
+ }
- op_ret = br_stub_fd_ctx_set (this, fd, fd_ctx);
- if (!op_ret)
- goto unwind;
+ op_ret = br_stub_fd_ctx_set(this, fd, fd_ctx);
+ if (!op_ret)
+ goto unwind;
- sys_closedir (fd_ctx->bad_object.dir);
+ sys_closedir(fd_ctx->bad_object.dir);
err_freectx:
- GF_FREE (fd_ctx);
+ GF_FREE(fd_ctx);
unwind:
- STACK_UNWIND_STRICT (opendir, frame, op_ret, op_errno, fd, NULL);
- return 0;
+ STACK_UNWIND_STRICT(opendir, frame, op_ret, op_errno, fd, NULL);
+ return 0;
normal:
- STACK_WIND (frame, default_opendir_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->opendir, loc, fd, xdata);
- return 0;
+ STACK_WIND(frame, default_opendir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->opendir, loc, fd, xdata);
+ return 0;
}
int32_t
-br_stub_readdir (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t off, dict_t *xdata)
-{
- call_stub_t *stub = NULL;
- br_stub_private_t *priv = NULL;
-
- priv = this->private;
- if (!priv->do_versioning)
- goto out;
-
- if (gf_uuid_compare (fd->inode->gfid, priv->bad_object_dir_gfid))
- goto out;
- stub = fop_readdir_stub (frame, br_stub_readdir_wrapper, fd, size, off,
- xdata);
- if (!stub) {
- STACK_UNWIND_STRICT (readdir, frame, -1, ENOMEM, NULL, NULL);
- return 0;
- }
- br_stub_worker_enqueue (this, stub);
- return 0;
+br_stub_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t off, dict_t *xdata)
+{
+ call_stub_t *stub = NULL;
+ br_stub_private_t *priv = NULL;
+
+ priv = this->private;
+ if (!priv->do_versioning)
+ goto out;
+
+ if (gf_uuid_compare(fd->inode->gfid, priv->bad_object_dir_gfid))
+ goto out;
+ stub = fop_readdir_stub(frame, br_stub_readdir_wrapper, fd, size, off,
+ xdata);
+ if (!stub) {
+ STACK_UNWIND_STRICT(readdir, frame, -1, ENOMEM, NULL, NULL);
+ return 0;
+ }
+ br_stub_worker_enqueue(this, stub);
+ return 0;
out:
- STACK_WIND (frame, default_readdir_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->readdir, fd, size, off, xdata);
- return 0;
+ STACK_WIND(frame, default_readdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readdir, fd, size, off, xdata);
+ return 0;
}
int
-br_stub_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, gf_dirent_t *entries,
- dict_t *dict)
-{
- int32_t ret = 0;
- uint64_t ctxaddr = 0;
- gf_dirent_t *entry = NULL;
- br_stub_private_t *priv = NULL;
- gf_boolean_t ver_enabled = _gf_false;
-
- BR_STUB_VER_ENABLED_IN_CALLPATH (frame, ver_enabled);
- priv = this->private;
- BR_STUB_VER_COND_GOTO (priv, (!ver_enabled), unwind);
-
- if (op_ret < 0)
- goto unwind;
-
- list_for_each_entry (entry, &entries->list, list) {
- if ((strcmp (entry->d_name, ".") == 0)
- || (strcmp (entry->d_name, "..") == 0))
- continue;
-
- if (!IA_ISREG (entry->d_stat.ia_type))
- continue;
-
- ret = br_stub_get_inode_ctx (this, entry->inode, &ctxaddr);
- if (ret < 0)
- ctxaddr = 0;
- if (ctxaddr) { /* already has the context */
- br_stub_remove_vxattrs (entry->dict);
- continue;
- }
-
- ret = br_stub_lookup_version
- (this, entry->inode->gfid, entry->inode, entry->dict);
- br_stub_remove_vxattrs (entry->dict);
- if (ret) {
- /**
- * there's no per-file granularity support in case of
- * failure. let's fail the entire request for now..
- */
- break;
- }
+br_stub_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, gf_dirent_t *entries,
+ dict_t *dict)
+{
+ int32_t ret = 0;
+ uint64_t ctxaddr = 0;
+ gf_dirent_t *entry = NULL;
+ br_stub_private_t *priv = NULL;
+ gf_boolean_t ver_enabled = _gf_false;
+
+ BR_STUB_VER_ENABLED_IN_CALLPATH(frame, ver_enabled);
+ priv = this->private;
+ BR_STUB_VER_COND_GOTO(priv, (!ver_enabled), unwind);
+
+ if (op_ret < 0)
+ goto unwind;
+
+ list_for_each_entry(entry, &entries->list, list)
+ {
+ if ((strcmp(entry->d_name, ".") == 0) ||
+ (strcmp(entry->d_name, "..") == 0))
+ continue;
+
+ if (!IA_ISREG(entry->d_stat.ia_type))
+ continue;
+
+ ret = br_stub_get_inode_ctx(this, entry->inode, &ctxaddr);
+ if (ret < 0)
+ ctxaddr = 0;
+ if (ctxaddr) { /* already has the context */
+ br_stub_remove_vxattrs(entry->dict);
+ continue;
}
+ ret = br_stub_lookup_version(this, entry->inode->gfid, entry->inode,
+ entry->dict);
+ br_stub_remove_vxattrs(entry->dict);
if (ret) {
- op_ret = -1;
- op_errno = EINVAL;
+ /**
+ * there's no per-file granularity support in case of
+ * failure. let's fail the entire request for now..
+ */
+ break;
}
+ }
- unwind:
- STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno, entries, dict);
+ if (ret) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ }
- return 0;
+unwind:
+ STACK_UNWIND_STRICT(readdirp, frame, op_ret, op_errno, entries, dict);
+
+ return 0;
}
int
-br_stub_readdirp (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t offset, dict_t *dict)
+br_stub_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset, dict_t *dict)
{
- int32_t ret = -1;
- int op_errno = 0;
- gf_boolean_t xref = _gf_false;
- br_stub_private_t *priv = NULL;
+ int32_t ret = -1;
+ int op_errno = 0;
+ gf_boolean_t xref = _gf_false;
+ br_stub_private_t *priv = NULL;
- priv = this->private;
- BR_STUB_VER_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ priv = this->private;
+ BR_STUB_VER_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- op_errno = ENOMEM;
- if (!dict) {
- dict = dict_new ();
- if (!dict)
- goto unwind;
- } else {
- dict = dict_ref (dict);
- }
-
- xref = _gf_true;
-
- op_errno = EINVAL;
- ret = dict_set_uint32 (dict, BITROT_CURRENT_VERSION_KEY, 0);
- if (ret)
- goto unwind;
- ret = dict_set_uint32 (dict, BITROT_SIGNING_VERSION_KEY, 0);
- if (ret)
- goto unwind;
- ret = dict_set_uint32 (dict, BITROT_OBJECT_BAD_KEY, 0);
- if (ret)
- goto unwind;
+ op_errno = ENOMEM;
+ if (!dict) {
+ dict = dict_new();
+ if (!dict)
+ goto unwind;
+ } else {
+ dict = dict_ref(dict);
+ }
+
+ xref = _gf_true;
+
+ op_errno = EINVAL;
+ ret = dict_set_uint32(dict, BITROT_CURRENT_VERSION_KEY, 0);
+ if (ret)
+ goto unwind;
+ ret = dict_set_uint32(dict, BITROT_SIGNING_VERSION_KEY, 0);
+ if (ret)
+ goto unwind;
+ ret = dict_set_uint32(dict, BITROT_OBJECT_BAD_KEY, 0);
+ if (ret)
+ goto unwind;
wind:
- STACK_WIND (frame, br_stub_readdirp_cbk, FIRST_CHILD (this),
- FIRST_CHILD(this)->fops->readdirp, fd, size,
- offset, dict);
- goto unref_dict;
+ STACK_WIND(frame, br_stub_readdirp_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readdirp, fd, size, offset, dict);
+ goto unref_dict;
unwind:
- if (frame->local == (void *)0x1)
- frame->local = NULL;
- STACK_UNWIND_STRICT (readdirp, frame, -1, op_errno, NULL, NULL);
- return 0;
+ if (frame->local == (void *)0x1)
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(readdirp, frame, -1, op_errno, NULL, NULL);
+ return 0;
unref_dict:
- if (xref)
- dict_unref (dict);
- return 0;
+ if (xref)
+ dict_unref(dict);
+ return 0;
}
/** }}} */
-
/** {{{ */
/* lookup() */
@@ -2836,203 +2797,198 @@ unref_dict:
* either forget () or lookup () will take care of removing the link.
*/
void
-br_stub_handle_lookup_error (xlator_t *this, inode_t *inode, int32_t op_errno)
+br_stub_handle_lookup_error(xlator_t *this, inode_t *inode, int32_t op_errno)
{
- int32_t ret = -1;
- uint64_t ctx_addr = 0;
- br_stub_inode_ctx_t *ctx = NULL;
+ int32_t ret = -1;
+ uint64_t ctx_addr = 0;
+ br_stub_inode_ctx_t *ctx = NULL;
- if (op_errno != ENOENT)
- goto out;
+ if (op_errno != ENOENT)
+ goto out;
- if (!inode_is_linked (inode))
- goto out;
+ if (!inode_is_linked(inode))
+ goto out;
- ret = br_stub_get_inode_ctx (this, inode, &ctx_addr);
- if (ret)
- goto out;
+ ret = br_stub_get_inode_ctx(this, inode, &ctx_addr);
+ if (ret)
+ goto out;
- ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
+ ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
- LOCK (&inode->lock);
- {
- if (__br_stub_is_bad_object (ctx))
- (void) br_stub_del (this, inode->gfid);
- }
- UNLOCK (&inode->lock);
-
- if (__br_stub_is_bad_object (ctx)) {
- /* File is not present, might be deleted for recovery,
- * del the bitrot inode context
- */
- ctx_addr = 0;
- inode_ctx_del (inode, this, &ctx_addr);
- if (ctx_addr) {
- ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
- GF_FREE (ctx);
- }
+ LOCK(&inode->lock);
+ {
+ if (__br_stub_is_bad_object(ctx))
+ (void)br_stub_del(this, inode->gfid);
+ }
+ UNLOCK(&inode->lock);
+
+ if (__br_stub_is_bad_object(ctx)) {
+ /* File is not present, might be deleted for recovery,
+ * del the bitrot inode context
+ */
+ ctx_addr = 0;
+ inode_ctx_del(inode, this, &ctx_addr);
+ if (ctx_addr) {
+ ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
+ GF_FREE(ctx);
}
+ }
out:
- return;
+ return;
}
int
-br_stub_lookup_cbk (call_frame_t *frame, void *cookie,
- xlator_t *this, int op_ret, int op_errno, inode_t *inode,
- struct iatt *stbuf, dict_t *xattr, struct iatt *postparent)
-{
- int32_t ret = 0;
- br_stub_private_t *priv = NULL;
- gf_boolean_t ver_enabled = _gf_false;
-
- BR_STUB_VER_ENABLED_IN_CALLPATH(frame, ver_enabled);
- priv = this->private;
-
- if (op_ret < 0) {
- (void) br_stub_handle_lookup_error (this, inode, op_errno);
- goto unwind;
- }
-
- BR_STUB_VER_COND_GOTO (priv, (!ver_enabled), delkey);
-
- if (!IA_ISREG (stbuf->ia_type))
- goto unwind;
-
- /**
- * If the object is bad, then "bad inode" marker has to be sent back
- * in resoinse, for revalidated lookups as well. Some xlators such as
- * quick-read might cache the data in revalidated lookup as fresh
- * lookup would anyway have sent "bad inode" marker.
- * In general send bad inode marker for every lookup operation on the
- * bad object.
- */
- if (cookie != (void *) BR_STUB_REQUEST_COOKIE) {
- ret = br_stub_mark_xdata_bad_object (this, inode, xattr);
- if (ret) {
- op_ret = -1;
- op_errno = EIO;
- goto unwind;
- }
- goto delkey;
- }
-
- ret = br_stub_lookup_version (this, stbuf->ia_gfid, inode, xattr);
- if (ret < 0) {
- op_ret = -1;
- op_errno = EINVAL;
- goto delkey;
+br_stub_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, inode_t *inode, struct iatt *stbuf,
+ dict_t *xattr, struct iatt *postparent)
+{
+ int32_t ret = 0;
+ br_stub_private_t *priv = NULL;
+ gf_boolean_t ver_enabled = _gf_false;
+
+ BR_STUB_VER_ENABLED_IN_CALLPATH(frame, ver_enabled);
+ priv = this->private;
+
+ if (op_ret < 0) {
+ (void)br_stub_handle_lookup_error(this, inode, op_errno);
+ goto unwind;
+ }
+
+ BR_STUB_VER_COND_GOTO(priv, (!ver_enabled), delkey);
+
+ if (!IA_ISREG(stbuf->ia_type))
+ goto unwind;
+
+ /**
+ * If the object is bad, then "bad inode" marker has to be sent back
+ * in resoinse, for revalidated lookups as well. Some xlators such as
+ * quick-read might cache the data in revalidated lookup as fresh
+ * lookup would anyway have sent "bad inode" marker.
+ * In general send bad inode marker for every lookup operation on the
+ * bad object.
+ */
+ if (cookie != (void *)BR_STUB_REQUEST_COOKIE) {
+ ret = br_stub_mark_xdata_bad_object(this, inode, xattr);
+ if (ret) {
+ op_ret = -1;
+ op_errno = EIO;
+ goto unwind;
}
+ goto delkey;
+ }
+ ret = br_stub_lookup_version(this, stbuf->ia_gfid, inode, xattr);
+ if (ret < 0) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto delkey;
+ }
+
+ /**
+ * If the object is bad, send "bad inode" marker back in response
+ * for xlator(s) to act accordingly (such as quick-read, etc..)
+ */
+ ret = br_stub_mark_xdata_bad_object(this, inode, xattr);
+ if (ret) {
/**
- * If the object is bad, send "bad inode" marker back in response
- * for xlator(s) to act accordingly (such as quick-read, etc..)
+ * aaha! bad object, but sorry we would not
+ * satisfy the request on allocation failures.
*/
- ret = br_stub_mark_xdata_bad_object (this, inode, xattr);
- if (ret) {
- /**
- * aaha! bad object, but sorry we would not
- * satisfy the request on allocation failures.
- */
- op_ret = -1;
- op_errno = EIO;
- goto unwind;
- }
+ op_ret = -1;
+ op_errno = EIO;
+ goto unwind;
+ }
delkey:
- br_stub_remove_vxattrs (xattr);
+ br_stub_remove_vxattrs(xattr);
unwind:
- STACK_UNWIND_STRICT (lookup, frame,
- op_ret, op_errno, inode, stbuf, xattr, postparent);
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, stbuf, xattr,
+ postparent);
- return 0;
+ return 0;
}
int
-br_stub_lookup (call_frame_t *frame,
- xlator_t *this, loc_t *loc, dict_t *xdata)
-{
- int32_t ret = 0;
- int op_errno = 0;
- void *cookie = NULL;
- uint64_t ctx_addr = 0;
- gf_boolean_t xref = _gf_false;
- br_stub_private_t *priv = NULL;
- call_stub_t *stub = NULL;
-
- GF_VALIDATE_OR_GOTO ("bit-rot-stub", this, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc, unwind);
- GF_VALIDATE_OR_GOTO (this->name, loc->inode, unwind);
-
- priv = this->private;
-
- BR_STUB_VER_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
-
- if (!gf_uuid_compare (loc->gfid, priv->bad_object_dir_gfid) ||
- !gf_uuid_compare (loc->pargfid, priv->bad_object_dir_gfid)) {
-
- stub = fop_lookup_stub (frame, br_stub_lookup_wrapper, loc,
- xdata);
- if (!stub) {
- op_errno = ENOMEM;
- goto unwind;
- }
- br_stub_worker_enqueue (this, stub);
- return 0;
- }
+br_stub_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
+{
+ int32_t ret = 0;
+ int op_errno = 0;
+ void *cookie = NULL;
+ uint64_t ctx_addr = 0;
+ gf_boolean_t xref = _gf_false;
+ br_stub_private_t *priv = NULL;
+ call_stub_t *stub = NULL;
- ret = br_stub_get_inode_ctx (this, loc->inode, &ctx_addr);
- if (ret < 0)
- ctx_addr = 0;
- if (ctx_addr != 0)
- goto wind;
+ GF_VALIDATE_OR_GOTO("bit-rot-stub", this, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc, unwind);
+ GF_VALIDATE_OR_GOTO(this->name, loc->inode, unwind);
- /**
- * fresh lookup: request version keys from POSIX
- */
- op_errno = ENOMEM;
- if (!xdata) {
- xdata = dict_new ();
- if (!xdata)
- goto unwind;
- } else {
- xdata = dict_ref (xdata);
+ priv = this->private;
+
+ BR_STUB_VER_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+
+ if (!gf_uuid_compare(loc->gfid, priv->bad_object_dir_gfid) ||
+ !gf_uuid_compare(loc->pargfid, priv->bad_object_dir_gfid)) {
+ stub = fop_lookup_stub(frame, br_stub_lookup_wrapper, loc, xdata);
+ if (!stub) {
+ op_errno = ENOMEM;
+ goto unwind;
}
+ br_stub_worker_enqueue(this, stub);
+ return 0;
+ }
- xref = _gf_true;
+ ret = br_stub_get_inode_ctx(this, loc->inode, &ctx_addr);
+ if (ret < 0)
+ ctx_addr = 0;
+ if (ctx_addr != 0)
+ goto wind;
- /**
- * Requesting both xattrs provides a way of sanity checking the
- * object. Anomaly checking is done in cbk by examining absence
- * of either or both xattrs.
- */
- op_errno = EINVAL;
- ret = dict_set_uint32 (xdata, BITROT_CURRENT_VERSION_KEY, 0);
- if (ret)
- goto unwind;
- ret = dict_set_uint32 (xdata, BITROT_SIGNING_VERSION_KEY, 0);
- if (ret)
- goto unwind;
- ret = dict_set_uint32 (xdata, BITROT_OBJECT_BAD_KEY, 0);
- if (ret)
- goto unwind;
- cookie = (void *) BR_STUB_REQUEST_COOKIE;
+ /**
+ * fresh lookup: request version keys from POSIX
+ */
+ op_errno = ENOMEM;
+ if (!xdata) {
+ xdata = dict_new();
+ if (!xdata)
+ goto unwind;
+ } else {
+ xdata = dict_ref(xdata);
+ }
+
+ xref = _gf_true;
+
+ /**
+ * Requesting both xattrs provides a way of sanity checking the
+ * object. Anomaly checking is done in cbk by examining absence
+ * of either or both xattrs.
+ */
+ op_errno = EINVAL;
+ ret = dict_set_uint32(xdata, BITROT_CURRENT_VERSION_KEY, 0);
+ if (ret)
+ goto unwind;
+ ret = dict_set_uint32(xdata, BITROT_SIGNING_VERSION_KEY, 0);
+ if (ret)
+ goto unwind;
+ ret = dict_set_uint32(xdata, BITROT_OBJECT_BAD_KEY, 0);
+ if (ret)
+ goto unwind;
+ cookie = (void *)BR_STUB_REQUEST_COOKIE;
- wind:
- STACK_WIND_COOKIE (frame, br_stub_lookup_cbk, cookie,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->lookup,
- loc, xdata);
- goto dealloc_dict;
+wind:
+ STACK_WIND_COOKIE(frame, br_stub_lookup_cbk, cookie, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, loc, xdata);
+ goto dealloc_dict;
- unwind:
- if (frame->local == (void *) 0x1)
- frame->local = NULL;
- STACK_UNWIND_STRICT (lookup, frame,
- -1, op_errno, NULL, NULL, NULL, NULL);
- dealloc_dict:
- if (xref)
- dict_unref (xdata);
- return 0;
+unwind:
+ if (frame->local == (void *)0x1)
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(lookup, frame, -1, op_errno, NULL, NULL, NULL, NULL);
+dealloc_dict:
+ if (xref)
+ dict_unref(xdata);
+ return 0;
}
/** }}} */
@@ -3041,64 +2997,64 @@ br_stub_lookup (call_frame_t *frame,
/* stat */
int
-br_stub_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
+br_stub_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- int32_t ret = 0;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- br_stub_private_t *priv = NULL;
+ int32_t ret = 0;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ br_stub_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- if (!priv->do_versioning)
- goto wind;
+ if (!priv->do_versioning)
+ goto wind;
- if (!IA_ISREG (loc->inode->ia_type))
- goto wind;
+ if (!IA_ISREG(loc->inode->ia_type))
+ goto wind;
- ret = br_stub_check_bad_object (this, loc->inode, &op_ret, &op_errno);
- if (ret)
- goto unwind;
+ ret = br_stub_check_bad_object(this, loc->inode, &op_ret, &op_errno);
+ if (ret)
+ goto unwind;
- wind:
- STACK_WIND_TAIL (frame, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->stat, loc, xdata);
- return 0;
+wind:
+ STACK_WIND_TAIL(frame, FIRST_CHILD(this), FIRST_CHILD(this)->fops->stat,
+ loc, xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(stat, frame, op_ret, op_errno, NULL, NULL);
+ return 0;
}
/* fstat */
int
-br_stub_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
+br_stub_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
{
- int32_t ret = 0;
- int32_t op_ret = -1;
- int32_t op_errno = EINVAL;
- br_stub_private_t *priv = NULL;
+ int32_t ret = 0;
+ int32_t op_ret = -1;
+ int32_t op_errno = EINVAL;
+ br_stub_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- if (!priv->do_versioning)
- goto wind;
+ if (!priv->do_versioning)
+ goto wind;
- if (!IA_ISREG (fd->inode->ia_type))
- goto wind;
+ if (!IA_ISREG(fd->inode->ia_type))
+ goto wind;
- ret = br_stub_check_bad_object (this, fd->inode, &op_ret, &op_errno);
- if (ret)
- goto unwind;
+ ret = br_stub_check_bad_object(this, fd->inode, &op_ret, &op_errno);
+ if (ret)
+ goto unwind;
- wind:
- STACK_WIND_TAIL (frame, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fstat, fd, xdata);
- return 0;
+wind:
+ STACK_WIND_TAIL(frame, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fstat,
+ fd, xdata);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(fstat, frame, op_ret, op_errno, NULL, NULL);
+ return 0;
}
/** }}} */
@@ -3108,114 +3064,111 @@ unwind:
/* unlink() */
int
-br_stub_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+br_stub_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, struct iatt *preparent,
struct iatt *postparent, dict_t *xdata)
{
- br_stub_local_t *local = NULL;
- inode_t *inode = NULL;
- uint64_t ctx_addr = 0;
- br_stub_inode_ctx_t *ctx = NULL;
- int32_t ret = -1;
- br_stub_private_t *priv = NULL;
- gf_boolean_t ver_enabled = _gf_false;
+ br_stub_local_t *local = NULL;
+ inode_t *inode = NULL;
+ uint64_t ctx_addr = 0;
+ br_stub_inode_ctx_t *ctx = NULL;
+ int32_t ret = -1;
+ br_stub_private_t *priv = NULL;
+ gf_boolean_t ver_enabled = _gf_false;
- BR_STUB_VER_ENABLED_IN_CALLPATH (frame, ver_enabled);
- priv = this->private;
- BR_STUB_VER_COND_GOTO (priv, (!ver_enabled), unwind);
+ BR_STUB_VER_ENABLED_IN_CALLPATH(frame, ver_enabled);
+ priv = this->private;
+ BR_STUB_VER_COND_GOTO(priv, (!ver_enabled), unwind);
- local = frame->local;
- frame->local = NULL;
+ local = frame->local;
+ frame->local = NULL;
- if (op_ret < 0)
- goto unwind;
+ if (op_ret < 0)
+ goto unwind;
- inode = local->u.context.inode;
- if (!IA_ISREG (inode->ia_type))
- goto unwind;
+ inode = local->u.context.inode;
+ if (!IA_ISREG(inode->ia_type))
+ goto unwind;
- ret = br_stub_get_inode_ctx (this, inode, &ctx_addr);
- if (ret) {
- /**
- * If the inode is bad AND context is not there, then there
- * is a possibility of the gfid of the object being listed
- * in the quarantine directory and will be shown in the
- * bad objects list. So continuing with the fop with a
- * warning log. The entry from the quarantine directory
- * has to be removed manually. Its not a good idea to fail
- * the fop, as the object has already been deleted.
- */
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRS_MSG_GET_INODE_CONTEXT_FAILED,
- "failed to get the context for the inode %s",
- uuid_utoa (inode->gfid));
- goto unwind;
- }
+ ret = br_stub_get_inode_ctx(this, inode, &ctx_addr);
+ if (ret) {
+ /**
+ * If the inode is bad AND context is not there, then there
+ * is a possibility of the gfid of the object being listed
+ * in the quarantine directory and will be shown in the
+ * bad objects list. So continuing with the fop with a
+ * warning log. The entry from the quarantine directory
+ * has to be removed manually. Its not a good idea to fail
+ * the fop, as the object has already been deleted.
+ */
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_GET_INODE_CONTEXT_FAILED,
+ "failed to get the context for the inode %s",
+ uuid_utoa(inode->gfid));
+ goto unwind;
+ }
- ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
+ ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
- LOCK (&inode->lock);
- {
- /**
- * Ignoring the return value of br_stub_del ().
- * There is not much that can be done if unlinking
- * of the entry in the quarantine directory fails.
- * The failure is logged.
- */
- if (__br_stub_is_bad_object (ctx))
- (void) br_stub_del (this, inode->gfid);
- }
- UNLOCK (&inode->lock);
+ LOCK(&inode->lock);
+ {
+ /**
+ * Ignoring the return value of br_stub_del ().
+ * There is not much that can be done if unlinking
+ * of the entry in the quarantine directory fails.
+ * The failure is logged.
+ */
+ if (__br_stub_is_bad_object(ctx))
+ (void)br_stub_del(this, inode->gfid);
+ }
+ UNLOCK(&inode->lock);
unwind:
- STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, preparent,
- postparent, xdata);
- br_stub_cleanup_local (local);
- br_stub_dealloc_local (local);
- return 0;
+ STACK_UNWIND_STRICT(unlink, frame, op_ret, op_errno, preparent, postparent,
+ xdata);
+ br_stub_cleanup_local(local);
+ br_stub_dealloc_local(local);
+ return 0;
}
int
-br_stub_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int flag,
- dict_t *xdata)
+br_stub_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int flag,
+ dict_t *xdata)
{
- br_stub_local_t *local = NULL;
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- br_stub_private_t *priv = NULL;
+ br_stub_local_t *local = NULL;
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ br_stub_private_t *priv = NULL;
- priv = this->private;
- BR_STUB_VER_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ priv = this->private;
+ BR_STUB_VER_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- local = br_stub_alloc_local (this);
- if (!local) {
- op_ret = -1;
- op_errno = ENOMEM;
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, BRS_MSG_NO_MEMORY,
- "failed to allocate memory for local (path: %s, gfid: %s)",
- loc->path, uuid_utoa (loc->inode->gfid));
- goto unwind;
- }
+ local = br_stub_alloc_local(this);
+ if (!local) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, BRS_MSG_NO_MEMORY,
+ "failed to allocate memory for local (path: %s, gfid: %s)",
+ loc->path, uuid_utoa(loc->inode->gfid));
+ goto unwind;
+ }
- br_stub_fill_local (local, NULL, NULL, loc->inode,
- loc->inode->gfid,
- BR_STUB_NO_VERSIONING, 0);
+ br_stub_fill_local(local, NULL, NULL, loc->inode, loc->inode->gfid,
+ BR_STUB_NO_VERSIONING, 0);
- frame->local = local;
+ frame->local = local;
wind:
- STACK_WIND (frame, br_stub_unlink_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->unlink, loc, flag, xdata);
- return 0;
+ STACK_WIND(frame, br_stub_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, loc, flag, xdata);
+ return 0;
unwind:
- if (frame->local == (void *)0x1)
- frame->local = NULL;
- STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, NULL, NULL, NULL);
- return 0;
+ if (frame->local == (void *)0x1)
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(unlink, frame, op_ret, op_errno, NULL, NULL, NULL);
+ return 0;
}
-
/** }}} */
/** {{{ */
@@ -3223,20 +3176,20 @@ unwind:
/* forget() */
int
-br_stub_forget (xlator_t *this, inode_t *inode)
+br_stub_forget(xlator_t *this, inode_t *inode)
{
- uint64_t ctx_addr = 0;
- br_stub_inode_ctx_t *ctx = NULL;
+ uint64_t ctx_addr = 0;
+ br_stub_inode_ctx_t *ctx = NULL;
- inode_ctx_del (inode, this, &ctx_addr);
- if (!ctx_addr)
- return 0;
+ inode_ctx_del(inode, this, &ctx_addr);
+ if (!ctx_addr)
+ return 0;
- ctx = (br_stub_inode_ctx_t *) (long) ctx_addr;
+ ctx = (br_stub_inode_ctx_t *)(long)ctx_addr;
- GF_FREE (ctx);
+ GF_FREE(ctx);
- return 0;
+ return 0;
}
/** }}} */
@@ -3244,60 +3197,60 @@ br_stub_forget (xlator_t *this, inode_t *inode)
/** {{{ */
int32_t
-br_stub_noop (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+br_stub_noop(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, dict_t *xdata)
{
- STACK_DESTROY (frame->root);
- return 0;
+ STACK_DESTROY(frame->root);
+ return 0;
}
static void
-br_stub_send_ipc_fop (xlator_t *this, fd_t *fd, unsigned long releaseversion,
- int sign_info)
-{
- int32_t op = 0;
- int32_t ret = 0;
- dict_t *xdata = NULL;
- call_frame_t *frame = NULL;
- changelog_event_t ev = {0,};
-
- ev.ev_type = CHANGELOG_OP_TYPE_BR_RELEASE;
- ev.u.releasebr.version = releaseversion;
- ev.u.releasebr.sign_info = sign_info;
- gf_uuid_copy (ev.u.releasebr.gfid, fd->inode->gfid);
-
- xdata = dict_new ();
- if (!xdata) {
- gf_msg (this->name, GF_LOG_WARNING, ENOMEM, BRS_MSG_NO_MEMORY,
- "dict allocation failed: cannot send IPC FOP "
- "to changelog");
- goto out;
- }
-
- ret = dict_set_static_bin (xdata,
- "RELEASE-EVENT", &ev, CHANGELOG_EV_SIZE);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, 0, BRS_MSG_SET_EVENT_FAILED,
- "cannot set release event in dict");
- goto dealloc_dict;
- }
+br_stub_send_ipc_fop(xlator_t *this, fd_t *fd, unsigned long releaseversion,
+ int sign_info)
+{
+ int32_t op = 0;
+ int32_t ret = 0;
+ dict_t *xdata = NULL;
+ call_frame_t *frame = NULL;
+ changelog_event_t ev = {
+ 0,
+ };
+
+ ev.ev_type = CHANGELOG_OP_TYPE_BR_RELEASE;
+ ev.u.releasebr.version = releaseversion;
+ ev.u.releasebr.sign_info = sign_info;
+ gf_uuid_copy(ev.u.releasebr.gfid, fd->inode->gfid);
+
+ xdata = dict_new();
+ if (!xdata) {
+ gf_msg(this->name, GF_LOG_WARNING, ENOMEM, BRS_MSG_NO_MEMORY,
+ "dict allocation failed: cannot send IPC FOP "
+ "to changelog");
+ goto out;
+ }
+
+ ret = dict_set_static_bin(xdata, "RELEASE-EVENT", &ev, CHANGELOG_EV_SIZE);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_SET_EVENT_FAILED,
+ "cannot set release event in dict");
+ goto dealloc_dict;
+ }
- frame = create_frame (this, this->ctx->pool);
- if (!frame) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- BRS_MSG_CREATE_FRAME_FAILED,
- "create_frame() failure");
- goto dealloc_dict;
- }
+ frame = create_frame(this, this->ctx->pool);
+ if (!frame) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, BRS_MSG_CREATE_FRAME_FAILED,
+ "create_frame() failure");
+ goto dealloc_dict;
+ }
- op = GF_IPC_TARGET_CHANGELOG;
- STACK_WIND (frame, br_stub_noop, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->ipc, op, xdata);
+ op = GF_IPC_TARGET_CHANGELOG;
+ STACK_WIND(frame, br_stub_noop, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ipc, op, xdata);
- dealloc_dict:
- dict_unref (xdata);
- out:
- return;
+dealloc_dict:
+ dict_unref(xdata);
+out:
+ return;
}
/**
@@ -3321,115 +3274,113 @@ br_stub_send_ipc_fop (xlator_t *this, fd_t *fd, unsigned long releaseversion,
* set state = BR_SIGN_QUICK;
*/
br_sign_state_t
-__br_stub_inode_sign_state (br_stub_inode_ctx_t *ctx,
- glusterfs_fop_t fop, fd_t *fd)
+__br_stub_inode_sign_state(br_stub_inode_ctx_t *ctx, glusterfs_fop_t fop,
+ fd_t *fd)
{
- br_sign_state_t sign_info = BR_SIGN_INVALID;
-
- switch (fop) {
+ br_sign_state_t sign_info = BR_SIGN_INVALID;
+ switch (fop) {
case GF_FOP_FSETXATTR:
- sign_info = ctx->info_sign = BR_SIGN_QUICK;
- break;
+ sign_info = ctx->info_sign = BR_SIGN_QUICK;
+ break;
case GF_FOP_RELEASE:
- GF_ASSERT (ctx->info_sign != BR_SIGN_REOPEN_WAIT);
+ GF_ASSERT(ctx->info_sign != BR_SIGN_REOPEN_WAIT);
- if (ctx->info_sign == BR_SIGN_NORMAL) {
- sign_info = ctx->info_sign = BR_SIGN_REOPEN_WAIT;
- } else {
- sign_info = ctx->info_sign;
- ctx->info_sign = BR_SIGN_NORMAL;
- }
+ if (ctx->info_sign == BR_SIGN_NORMAL) {
+ sign_info = ctx->info_sign = BR_SIGN_REOPEN_WAIT;
+ } else {
+ sign_info = ctx->info_sign;
+ ctx->info_sign = BR_SIGN_NORMAL;
+ }
- break;
+ break;
default:
- break;
- }
+ break;
+ }
- return sign_info;
+ return sign_info;
}
int32_t
-br_stub_release (xlator_t *this, fd_t *fd)
-{
- int32_t ret = 0;
- int32_t flags = 0;
- inode_t *inode = NULL;
- unsigned long releaseversion = 0;
- br_stub_inode_ctx_t *ctx = NULL;
- uint64_t tmp = 0;
- br_stub_fd_t *br_stub_fd = NULL;
- int32_t signinfo = 0;
-
- inode = fd->inode;
-
- LOCK (&inode->lock);
- {
- ctx = __br_stub_get_ongoing_version_ctx (this, inode, NULL);
- if (ctx == NULL)
- goto unblock;
- br_stub_fd = br_stub_fd_ctx_get (this, fd);
- if (br_stub_fd) {
- list_del_init (&br_stub_fd->list);
- }
-
- ret = __br_stub_can_trigger_release
- (inode, ctx, &releaseversion);
- if (!ret)
- goto unblock;
-
- signinfo = __br_stub_inode_sign_state (ctx, GF_FOP_RELEASE, fd);
- signinfo = htonl (signinfo);
-
- /* inode back to initital state: mark dirty */
- if (ctx->info_sign == BR_SIGN_NORMAL) {
- __br_stub_mark_inode_dirty (ctx);
- __br_stub_unset_inode_modified (ctx);
- }
- }
- unblock:
- UNLOCK (&inode->lock);
+br_stub_release(xlator_t *this, fd_t *fd)
+{
+ int32_t ret = 0;
+ int32_t flags = 0;
+ inode_t *inode = NULL;
+ unsigned long releaseversion = 0;
+ br_stub_inode_ctx_t *ctx = NULL;
+ uint64_t tmp = 0;
+ br_stub_fd_t *br_stub_fd = NULL;
+ int32_t signinfo = 0;
+
+ inode = fd->inode;
+
+ LOCK(&inode->lock);
+ {
+ ctx = __br_stub_get_ongoing_version_ctx(this, inode, NULL);
+ if (ctx == NULL)
+ goto unblock;
+ br_stub_fd = br_stub_fd_ctx_get(this, fd);
+ if (br_stub_fd) {
+ list_del_init(&br_stub_fd->list);
+ }
+
+ ret = __br_stub_can_trigger_release(inode, ctx, &releaseversion);
+ if (!ret)
+ goto unblock;
+
+ signinfo = __br_stub_inode_sign_state(ctx, GF_FOP_RELEASE, fd);
+ signinfo = htonl(signinfo);
+
+ /* inode back to initital state: mark dirty */
+ if (ctx->info_sign == BR_SIGN_NORMAL) {
+ __br_stub_mark_inode_dirty(ctx);
+ __br_stub_unset_inode_modified(ctx);
+ }
+ }
+unblock:
+ UNLOCK(&inode->lock);
- if (ret) {
- gf_msg_debug (this->name, 0, "releaseversion: %lu | flags: %d "
- "| signinfo: %d",
- (unsigned long) ntohl (releaseversion), flags,
- ntohl(signinfo));
- br_stub_send_ipc_fop (this, fd, releaseversion, signinfo);
- }
+ if (ret) {
+ gf_msg_debug(this->name, 0,
+ "releaseversion: %lu | flags: %d "
+ "| signinfo: %d",
+ (unsigned long)ntohl(releaseversion), flags,
+ ntohl(signinfo));
+ br_stub_send_ipc_fop(this, fd, releaseversion, signinfo);
+ }
- ret = fd_ctx_del (fd, this, &tmp);
- br_stub_fd = (br_stub_fd_t *)(long)tmp;
+ ret = fd_ctx_del(fd, this, &tmp);
+ br_stub_fd = (br_stub_fd_t *)(long)tmp;
- GF_FREE (br_stub_fd);
+ GF_FREE(br_stub_fd);
- return 0;
+ return 0;
}
int32_t
-br_stub_releasedir (xlator_t *this, fd_t *fd)
+br_stub_releasedir(xlator_t *this, fd_t *fd)
{
- br_stub_fd_t *fctx = NULL;
- uint64_t ctx = 0;
- int ret = 0;
+ br_stub_fd_t *fctx = NULL;
+ uint64_t ctx = 0;
+ int ret = 0;
- ret = fd_ctx_del (fd, this, &ctx);
- if (ret < 0)
- goto out;
-
- fctx = (br_stub_fd_t *) (long) ctx;
- if (fctx->bad_object.dir) {
- ret = sys_closedir (fctx->bad_object.dir);
- if (ret)
- gf_msg (this->name, GF_LOG_ERROR, 0,
- BRS_MSG_BAD_OBJ_DIR_CLOSE_FAIL,
- "closedir error: %s", strerror (errno));
- }
+ ret = fd_ctx_del(fd, this, &ctx);
+ if (ret < 0)
+ goto out;
+
+ fctx = (br_stub_fd_t *)(long)ctx;
+ if (fctx->bad_object.dir) {
+ ret = sys_closedir(fctx->bad_object.dir);
+ if (ret)
+ gf_msg(this->name, GF_LOG_ERROR, 0, BRS_MSG_BAD_OBJ_DIR_CLOSE_FAIL,
+ "closedir error: %s", strerror(errno));
+ }
- GF_FREE (fctx);
+ GF_FREE(fctx);
out:
- return 0;
+ return 0;
}
/** }}} */
@@ -3439,90 +3390,86 @@ out:
/* ictxmerge */
void
-br_stub_ictxmerge (xlator_t *this, fd_t *fd,
- inode_t *inode, inode_t *linked_inode)
-{
- int32_t ret = 0;
- uint64_t ctxaddr = 0;
- uint64_t lctxaddr = 0;
- br_stub_inode_ctx_t *ctx = NULL;
- br_stub_inode_ctx_t *lctx = NULL;
- br_stub_fd_t *br_stub_fd = NULL;
-
- ret = br_stub_get_inode_ctx (this, inode, &ctxaddr);
+br_stub_ictxmerge(xlator_t *this, fd_t *fd, inode_t *inode,
+ inode_t *linked_inode)
+{
+ int32_t ret = 0;
+ uint64_t ctxaddr = 0;
+ uint64_t lctxaddr = 0;
+ br_stub_inode_ctx_t *ctx = NULL;
+ br_stub_inode_ctx_t *lctx = NULL;
+ br_stub_fd_t *br_stub_fd = NULL;
+
+ ret = br_stub_get_inode_ctx(this, inode, &ctxaddr);
+ if (ret < 0)
+ goto done;
+ ctx = (br_stub_inode_ctx_t *)ctxaddr;
+
+ LOCK(&linked_inode->lock);
+ {
+ ret = __br_stub_get_inode_ctx(this, linked_inode, &lctxaddr);
if (ret < 0)
- goto done;
- ctx = (br_stub_inode_ctx_t *) ctxaddr;
+ goto unblock;
+ lctx = (br_stub_inode_ctx_t *)lctxaddr;
- LOCK (&linked_inode->lock);
- {
- ret = __br_stub_get_inode_ctx (this, linked_inode, &lctxaddr);
- if (ret < 0)
- goto unblock;
- lctx = (br_stub_inode_ctx_t *) lctxaddr;
-
- GF_ASSERT (list_is_singular (&ctx->fd_list));
- br_stub_fd = list_first_entry (&ctx->fd_list, br_stub_fd_t,
- list);
- if (br_stub_fd) {
- GF_ASSERT (br_stub_fd->fd == fd);
- list_move_tail (&br_stub_fd->list, &lctx->fd_list);
- }
+ GF_ASSERT(list_is_singular(&ctx->fd_list));
+ br_stub_fd = list_first_entry(&ctx->fd_list, br_stub_fd_t, list);
+ if (br_stub_fd) {
+ GF_ASSERT(br_stub_fd->fd == fd);
+ list_move_tail(&br_stub_fd->list, &lctx->fd_list);
}
+ }
unblock:
- UNLOCK (&linked_inode->lock);
+ UNLOCK(&linked_inode->lock);
- done:
- return;
+done:
+ return;
}
/** }}} */
-
struct xlator_fops fops = {
- .lookup = br_stub_lookup,
- .stat = br_stub_stat,
- .fstat = br_stub_fstat,
- .open = br_stub_open,
- .create = br_stub_create,
- .readdirp = br_stub_readdirp,
- .getxattr = br_stub_getxattr,
- .fgetxattr = br_stub_fgetxattr,
- .fsetxattr = br_stub_fsetxattr,
- .writev = br_stub_writev,
- .truncate = br_stub_truncate,
- .ftruncate = br_stub_ftruncate,
- .mknod = br_stub_mknod,
- .readv = br_stub_readv,
- .removexattr = br_stub_removexattr,
- .fremovexattr = br_stub_fremovexattr,
- .setxattr = br_stub_setxattr,
- .opendir = br_stub_opendir,
- .readdir = br_stub_readdir,
- .unlink = br_stub_unlink,
+ .lookup = br_stub_lookup,
+ .stat = br_stub_stat,
+ .fstat = br_stub_fstat,
+ .open = br_stub_open,
+ .create = br_stub_create,
+ .readdirp = br_stub_readdirp,
+ .getxattr = br_stub_getxattr,
+ .fgetxattr = br_stub_fgetxattr,
+ .fsetxattr = br_stub_fsetxattr,
+ .writev = br_stub_writev,
+ .truncate = br_stub_truncate,
+ .ftruncate = br_stub_ftruncate,
+ .mknod = br_stub_mknod,
+ .readv = br_stub_readv,
+ .removexattr = br_stub_removexattr,
+ .fremovexattr = br_stub_fremovexattr,
+ .setxattr = br_stub_setxattr,
+ .opendir = br_stub_opendir,
+ .readdir = br_stub_readdir,
+ .unlink = br_stub_unlink,
};
struct xlator_cbks cbks = {
- .forget = br_stub_forget,
- .release = br_stub_release,
- .ictxmerge = br_stub_ictxmerge,
+ .forget = br_stub_forget,
+ .release = br_stub_release,
+ .ictxmerge = br_stub_ictxmerge,
};
struct volume_options options[] = {
- { .key = {"bitrot"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .op_version = {GD_OP_VERSION_3_7_0},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_FORCE,
- .tags = {"bitrot"},
- .description = "enable/disable bitrot stub"
- },
- { .key = {"export"},
- .type = GF_OPTION_TYPE_PATH,
- .op_version = {GD_OP_VERSION_3_7_0},
- .tags = {"bitrot"},
- .description = "brick path for versioning",
- .default_value = "{{ brick.path }}"
- },
- { .key = {NULL} },
+ {.key = {"bitrot"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_FORCE,
+ .tags = {"bitrot"},
+ .description = "enable/disable bitrot stub"},
+ {.key = {"export"},
+ .type = GF_OPTION_TYPE_PATH,
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .tags = {"bitrot"},
+ .description = "brick path for versioning",
+ .default_value = "{{ brick.path }}"},
+ {.key = {NULL}},
};
diff --git a/xlators/features/changelog/lib/examples/c/get-changes-multi.c b/xlators/features/changelog/lib/examples/c/get-changes-multi.c
index 3741bdf6edc..5ea5bbb6630 100644
--- a/xlators/features/changelog/lib/examples/c/get-changes-multi.c
+++ b/xlators/features/changelog/lib/examples/c/get-changes-multi.c
@@ -25,64 +25,66 @@
#include "changelog.h"
-void *brick_init (void *xl, struct gf_brick_spec *brick)
+void *
+brick_init(void *xl, struct gf_brick_spec *brick)
{
- return brick;
+ return brick;
}
-void brick_fini (void *xl, char *brick, void *data)
+void
+brick_fini(void *xl, char *brick, void *data)
{
- return;
+ return;
}
-void brick_callback (void *xl, char *brick,
- void *data, changelog_event_t *ev)
+void
+brick_callback(void *xl, char *brick, void *data, changelog_event_t *ev)
{
- printf ("->callback: (brick,type) [%s:%d]\n", brick, ev->ev_type);
+ printf("->callback: (brick,type) [%s:%d]\n", brick, ev->ev_type);
}
-void fill_brick_spec (struct gf_brick_spec *brick, char *path)
+void
+fill_brick_spec(struct gf_brick_spec *brick, char *path)
{
- brick->brick_path = strdup (path);
- brick->filter = CHANGELOG_OP_TYPE_BR_RELEASE;
-
- brick->init = brick_init;
- brick->fini = brick_fini;
- brick->callback = brick_callback;
- brick->connected = NULL;
- brick->disconnected = NULL;
+ brick->brick_path = strdup(path);
+ brick->filter = CHANGELOG_OP_TYPE_BR_RELEASE;
+
+ brick->init = brick_init;
+ brick->fini = brick_fini;
+ brick->callback = brick_callback;
+ brick->connected = NULL;
+ brick->disconnected = NULL;
}
int
-main (int argc, char **argv)
+main(int argc, char **argv)
{
- int ret = 0;
- void *bricks = NULL;
- struct gf_brick_spec *brick = NULL;
+ int ret = 0;
+ void *bricks = NULL;
+ struct gf_brick_spec *brick = NULL;
- bricks = calloc (2, sizeof (struct gf_brick_spec));
- if (!bricks)
- goto error_return;
+ bricks = calloc(2, sizeof(struct gf_brick_spec));
+ if (!bricks)
+ goto error_return;
- brick = (struct gf_brick_spec *)bricks;
- fill_brick_spec (brick, "/export/z1/zwoop");
+ brick = (struct gf_brick_spec *)bricks;
+ fill_brick_spec(brick, "/export/z1/zwoop");
- brick++;
- fill_brick_spec (brick, "/export/z2/zwoop");
+ brick++;
+ fill_brick_spec(brick, "/export/z2/zwoop");
- ret = gf_changelog_init (NULL);
- if (ret)
- goto error_return;
+ ret = gf_changelog_init(NULL);
+ if (ret)
+ goto error_return;
- ret = gf_changelog_register_generic ((struct gf_brick_spec *)bricks, 2,
- 0, "/tmp/multi-changes.log", 9,
- NULL);
- if (ret)
- goto error_return;
+ ret = gf_changelog_register_generic((struct gf_brick_spec *)bricks, 2, 0,
+ "/tmp/multi-changes.log", 9, NULL);
+ if (ret)
+ goto error_return;
- /* let callbacks do the job */
- select (0, NULL, NULL, NULL, NULL);
+ /* let callbacks do the job */
+ select(0, NULL, NULL, NULL, NULL);
- error_return:
- return -1;
+error_return:
+ return -1;
}
diff --git a/xlators/features/changelog/lib/examples/c/get-changes.c b/xlators/features/changelog/lib/examples/c/get-changes.c
index ef766c566b6..8bc651c24a4 100644
--- a/xlators/features/changelog/lib/examples/c/get-changes.c
+++ b/xlators/features/changelog/lib/examples/c/get-changes.c
@@ -27,67 +27,67 @@
#include "changelog.h"
-#define handle_error(fn) \
- printf ("%s (reason: %s)\n", fn, strerror (errno))
+#define handle_error(fn) printf("%s (reason: %s)\n", fn, strerror(errno))
int
-main (int argc, char ** argv)
+main(int argc, char **argv)
{
- int i = 0;
- int ret = 0;
- ssize_t nr_changes = 0;
- ssize_t changes = 0;
- char fbuf[PATH_MAX] = {0,};
-
- ret = gf_changelog_init (NULL);
- if (ret) {
- handle_error ("Init failed");
- goto out;
+ int i = 0;
+ int ret = 0;
+ ssize_t nr_changes = 0;
+ ssize_t changes = 0;
+ char fbuf[PATH_MAX] = {
+ 0,
+ };
+
+ ret = gf_changelog_init(NULL);
+ if (ret) {
+ handle_error("Init failed");
+ goto out;
+ }
+
+ /* get changes for brick "/home/vshankar/export/yow/yow-1" */
+ ret = gf_changelog_register("/export/z1/zwoop", "/tmp/scratch",
+ "/tmp/change.log", 9, 5);
+ if (ret) {
+ handle_error("register failed");
+ goto out;
+ }
+
+ while (1) {
+ i = 0;
+ nr_changes = gf_changelog_scan();
+ if (nr_changes < 0) {
+ handle_error("scan(): ");
+ break;
}
- /* get changes for brick "/home/vshankar/export/yow/yow-1" */
- ret = gf_changelog_register ("/export/z1/zwoop",
- "/tmp/scratch", "/tmp/change.log", 9, 5);
- if (ret) {
- handle_error ("register failed");
- goto out;
- }
-
- while (1) {
- i = 0;
- nr_changes = gf_changelog_scan ();
- if (nr_changes < 0) {
- handle_error ("scan(): ");
- break;
- }
-
- if (nr_changes == 0)
- goto next;
+ if (nr_changes == 0)
+ goto next;
- printf ("Got %ld changelog files\n", nr_changes);
+ printf("Got %ld changelog files\n", nr_changes);
- while ( (changes =
- gf_changelog_next_change (fbuf, PATH_MAX)) > 0) {
- printf ("changelog file [%d]: %s\n", ++i, fbuf);
+ while ((changes = gf_changelog_next_change(fbuf, PATH_MAX)) > 0) {
+ printf("changelog file [%d]: %s\n", ++i, fbuf);
- /* process changelog */
- /* ... */
- /* ... */
- /* ... */
- /* done processing */
+ /* process changelog */
+ /* ... */
+ /* ... */
+ /* ... */
+ /* done processing */
- ret = gf_changelog_done (fbuf);
- if (ret)
- handle_error ("gf_changelog_done");
- }
+ ret = gf_changelog_done(fbuf);
+ if (ret)
+ handle_error("gf_changelog_done");
+ }
- if (changes == -1)
- handle_error ("gf_changelog_next_change");
+ if (changes == -1)
+ handle_error("gf_changelog_next_change");
- next:
- sleep (10);
- }
+ next:
+ sleep(10);
+ }
- out:
- return ret;
+out:
+ return ret;
}
diff --git a/xlators/features/changelog/lib/examples/c/get-history.c b/xlators/features/changelog/lib/examples/c/get-history.c
index ee3ec0ad100..3e888d75ca6 100644
--- a/xlators/features/changelog/lib/examples/c/get-history.c
+++ b/xlators/features/changelog/lib/examples/c/get-history.c
@@ -27,90 +27,90 @@
#include "changelog.h"
-#define handle_error(fn) \
- printf ("%s (reason: %s)\n", fn, strerror (errno))
+#define handle_error(fn) printf("%s (reason: %s)\n", fn, strerror(errno))
int
-main (int argc, char ** argv)
+main(int argc, char **argv)
{
- int i = 0;
- int ret = 0;
- ssize_t nr_changes = 0;
- ssize_t changes = 0;
- char fbuf[PATH_MAX] = {0,};
- unsigned long end_ts = 0;
-
- ret = gf_changelog_init (NULL);
- if (ret) {
- handle_error ("init failed");
- goto out;
+ int i = 0;
+ int ret = 0;
+ ssize_t nr_changes = 0;
+ ssize_t changes = 0;
+ char fbuf[PATH_MAX] = {
+ 0,
+ };
+ unsigned long end_ts = 0;
+
+ ret = gf_changelog_init(NULL);
+ if (ret) {
+ handle_error("init failed");
+ goto out;
+ }
+
+ ret = gf_changelog_register("/export/z1/zwoop", "/tmp/scratch_v1",
+ "/tmp/changes.log", 9, 5);
+ if (ret) {
+ handle_error("register failed");
+ goto out;
+ }
+
+ int a, b;
+ printf("give the two numbers start and end\t");
+ scanf("%d%d", &a, &b);
+ ret = gf_history_changelog("/export/z1/zwoop/.glusterfs/changelogs", a, b,
+ 3, &end_ts);
+ if (ret == -1) {
+ printf("history failed");
+ goto out;
+ }
+
+ printf("end time till when changelog available : %d , ret(%d) \t", end_ts,
+ ret);
+ fflush(stdout);
+
+ while (1) {
+ nr_changes = gf_history_changelog_scan();
+ printf("scanned, nr_changes : %d\n", nr_changes);
+ if (nr_changes < 0) {
+ handle_error("scan(): ");
+ break;
}
- ret = gf_changelog_register ("/export/z1/zwoop",
- "/tmp/scratch_v1", "/tmp/changes.log",
- 9, 5);
- if (ret) {
- handle_error ("register failed");
- goto out;
+ if (nr_changes == 0) {
+ printf("done scanning \n");
+ goto out;
}
- int a, b;
- printf ("give the two numbers start and end\t");
- scanf ("%d%d", &a, &b);
- ret = gf_history_changelog ("/export/z1/zwoop/.glusterfs/changelogs",
- a, b, 3, &end_ts);
- if (ret == -1) {
- printf ("history failed");
- goto out;
- }
+ printf("Got %ld changelog files\n", nr_changes);
+
+ while ((changes = gf_history_changelog_next_change(fbuf, PATH_MAX)) >
+ 0) {
+ printf("changelog file [%d]: %s\n", ++i, fbuf);
- printf ("end time till when changelog available : %d , ret(%d) \t", end_ts, ret);
- fflush(stdout);
-
- while (1) {
- nr_changes = gf_history_changelog_scan ();
- printf ("scanned, nr_changes : %d\n",nr_changes);
- if (nr_changes < 0) {
- handle_error ("scan(): ");
- break;
- }
-
- if (nr_changes == 0) {
- printf ("done scanning \n");
- goto out;
- }
-
- printf ("Got %ld changelog files\n", nr_changes);
-
- while ( (changes =
- gf_history_changelog_next_change (fbuf, PATH_MAX)) > 0) {
- printf ("changelog file [%d]: %s\n", ++i, fbuf);
-
- /* process changelog */
- /* ... */
- /* ... */
- /* ... */
- /* done processing */
-
- ret = gf_history_changelog_done (fbuf);
- if (ret)
- handle_error ("gf_changelog_done");
- }
- /*
- if (changes == -1)
- handle_error ("gf_changelog_next_change");
- if (nr_changes ==1){
- printf("continue scanning\n");
- }
-
- if(nr_changes == 0){
- printf("done scanning \n");
- goto out;
- }
- */
+ /* process changelog */
+ /* ... */
+ /* ... */
+ /* ... */
+ /* done processing */
+
+ ret = gf_history_changelog_done(fbuf);
+ if (ret)
+ handle_error("gf_changelog_done");
+ }
+ /*
+ if (changes == -1)
+ handle_error ("gf_changelog_next_change");
+ if (nr_changes ==1){
+ printf("continue scanning\n");
}
+ if(nr_changes == 0){
+ printf("done scanning \n");
+ goto out;
+ }
+ */
+ }
out:
- return ret;
+ return ret;
}
diff --git a/xlators/features/changelog/lib/src/gf-changelog-api.c b/xlators/features/changelog/lib/src/gf-changelog-api.c
index 372550c7acf..1b6e932596d 100644
--- a/xlators/features/changelog/lib/src/gf-changelog-api.c
+++ b/xlators/features/changelog/lib/src/gf-changelog-api.c
@@ -19,57 +19,54 @@
#include "changelog-lib-messages.h"
int
-gf_changelog_done (char *file)
+gf_changelog_done(char *file)
{
- int ret = -1;
- char *buffer = NULL;
- xlator_t *this = NULL;
- gf_changelog_journal_t *jnl = NULL;
- char to_path[PATH_MAX] = {0,};
-
- errno = EINVAL;
-
- this = THIS;
- if (!this)
- goto out;
-
- jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this);
- if (!jnl)
- goto out;
-
- if (!file || !strlen (file))
- goto out;
-
- /* make sure 'file' is inside ->jnl_working_dir */
- buffer = realpath (file, NULL);
- if (!buffer)
- goto out;
-
- if (strncmp (jnl->jnl_working_dir,
- buffer, strlen (jnl->jnl_working_dir)))
- goto out;
-
- (void) snprintf (to_path, PATH_MAX, "%s%s",
- jnl->jnl_processed_dir, basename (buffer));
- gf_msg_debug (this->name, 0,
- "moving %s to processed directory", file);
- ret = sys_rename (buffer, to_path);
- if (ret) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_RENAME_FAILED,
- "cannot move changelog file",
- "from=%s", file,
- "to=%s", to_path,
- NULL);
- goto out;
- }
-
- ret = 0;
+ int ret = -1;
+ char *buffer = NULL;
+ xlator_t *this = NULL;
+ gf_changelog_journal_t *jnl = NULL;
+ char to_path[PATH_MAX] = {
+ 0,
+ };
+
+ errno = EINVAL;
+
+ this = THIS;
+ if (!this)
+ goto out;
+
+ jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this);
+ if (!jnl)
+ goto out;
+
+ if (!file || !strlen(file))
+ goto out;
+
+ /* make sure 'file' is inside ->jnl_working_dir */
+ buffer = realpath(file, NULL);
+ if (!buffer)
+ goto out;
+
+ if (strncmp(jnl->jnl_working_dir, buffer, strlen(jnl->jnl_working_dir)))
+ goto out;
+
+ (void)snprintf(to_path, PATH_MAX, "%s%s", jnl->jnl_processed_dir,
+ basename(buffer));
+ gf_msg_debug(this->name, 0, "moving %s to processed directory", file);
+ ret = sys_rename(buffer, to_path);
+ if (ret) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_RENAME_FAILED, "cannot move changelog file",
+ "from=%s", file, "to=%s", to_path, NULL);
+ goto out;
+ }
+
+ ret = 0;
- out:
- if (buffer)
- free (buffer); /* allocated by realpath() */
- return ret;
+out:
+ if (buffer)
+ free(buffer); /* allocated by realpath() */
+ return ret;
}
/**
@@ -77,28 +74,28 @@ gf_changelog_done (char *file)
* for a set of changelogs, start from the beginning
*/
int
-gf_changelog_start_fresh ()
+gf_changelog_start_fresh()
{
- xlator_t *this = NULL;
- gf_changelog_journal_t *jnl = NULL;
+ xlator_t *this = NULL;
+ gf_changelog_journal_t *jnl = NULL;
- this = THIS;
- if (!this)
- goto out;
+ this = THIS;
+ if (!this)
+ goto out;
- errno = EINVAL;
+ errno = EINVAL;
- jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this);
- if (!jnl)
- goto out;
+ jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this);
+ if (!jnl)
+ goto out;
- if (gf_ftruncate (jnl->jnl_fd, 0))
- goto out;
+ if (gf_ftruncate(jnl->jnl_fd, 0))
+ goto out;
- return 0;
+ return 0;
- out:
- return -1;
+out:
+ return -1;
}
/**
@@ -107,40 +104,42 @@ gf_changelog_start_fresh ()
* consumed.
*/
ssize_t
-gf_changelog_next_change (char *bufptr, size_t maxlen)
+gf_changelog_next_change(char *bufptr, size_t maxlen)
{
- ssize_t size = -1;
- int tracker_fd = 0;
- xlator_t *this = NULL;
- gf_changelog_journal_t *jnl = NULL;
- char buffer[PATH_MAX] = {0,};
+ ssize_t size = -1;
+ int tracker_fd = 0;
+ xlator_t *this = NULL;
+ gf_changelog_journal_t *jnl = NULL;
+ char buffer[PATH_MAX] = {
+ 0,
+ };
- errno = EINVAL;
+ errno = EINVAL;
- this = THIS;
- if (!this)
- goto out;
+ this = THIS;
+ if (!this)
+ goto out;
- jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this);
- if (!jnl)
- goto out;
+ jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this);
+ if (!jnl)
+ goto out;
- tracker_fd = jnl->jnl_fd;
+ tracker_fd = jnl->jnl_fd;
- size = gf_readline (tracker_fd, buffer, maxlen);
- if (size < 0) {
- size = -1;
- goto out;
- }
+ size = gf_readline(tracker_fd, buffer, maxlen);
+ if (size < 0) {
+ size = -1;
+ goto out;
+ }
- if (size == 0)
- goto out;
+ if (size == 0)
+ goto out;
- memcpy (bufptr, buffer, size - 1);
- bufptr[size - 1] = '\0';
+ memcpy(bufptr, buffer, size - 1);
+ bufptr[size - 1] = '\0';
out:
- return size;
+ return size;
}
/**
@@ -152,70 +151,74 @@ out:
* This call also acts as a cancellation point for the consumer.
*/
ssize_t
-gf_changelog_scan ()
+gf_changelog_scan()
{
- int tracker_fd = 0;
- size_t off = 0;
- xlator_t *this = NULL;
- size_t nr_entries = 0;
- gf_changelog_journal_t *jnl = NULL;
- struct dirent *entry = NULL;
- struct dirent scratch[2] = {{0,},};
- char buffer[PATH_MAX] = {0,};
-
- this = THIS;
- if (!this)
- goto out;
-
- jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this);
- if (!jnl)
- goto out;
- if (JNL_IS_API_DISCONNECTED (jnl)) {
- errno = ENOTCONN;
- goto out;
+ int tracker_fd = 0;
+ size_t off = 0;
+ xlator_t *this = NULL;
+ size_t nr_entries = 0;
+ gf_changelog_journal_t *jnl = NULL;
+ struct dirent *entry = NULL;
+ struct dirent scratch[2] = {
+ {
+ 0,
+ },
+ };
+ char buffer[PATH_MAX] = {
+ 0,
+ };
+
+ this = THIS;
+ if (!this)
+ goto out;
+
+ jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this);
+ if (!jnl)
+ goto out;
+ if (JNL_IS_API_DISCONNECTED(jnl)) {
+ errno = ENOTCONN;
+ goto out;
+ }
+
+ errno = EINVAL;
+
+ tracker_fd = jnl->jnl_fd;
+ if (gf_ftruncate(tracker_fd, 0))
+ goto out;
+
+ rewinddir(jnl->jnl_dir);
+
+ for (;;) {
+ errno = 0;
+ entry = sys_readdir(jnl->jnl_dir, scratch);
+ if (!entry || errno != 0)
+ break;
+
+ if (!strcmp(basename(entry->d_name), ".") ||
+ !strcmp(basename(entry->d_name), ".."))
+ continue;
+
+ nr_entries++;
+
+ GF_CHANGELOG_FILL_BUFFER(jnl->jnl_processing_dir, buffer, off,
+ strlen(jnl->jnl_processing_dir));
+ GF_CHANGELOG_FILL_BUFFER(entry->d_name, buffer, off,
+ strlen(entry->d_name));
+ GF_CHANGELOG_FILL_BUFFER("\n", buffer, off, 1);
+
+ if (gf_changelog_write(tracker_fd, buffer, off) != off) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_WRITE_FAILED,
+ "error writing changelog filename"
+ " to tracker file");
+ break;
}
+ off = 0;
+ }
- errno = EINVAL;
-
- tracker_fd = jnl->jnl_fd;
- if (gf_ftruncate (tracker_fd, 0))
- goto out;
-
- rewinddir (jnl->jnl_dir);
-
- for (;;) {
- errno = 0;
- entry = sys_readdir (jnl->jnl_dir, scratch);
- if (!entry || errno != 0)
- break;
-
- if (!strcmp (basename (entry->d_name), ".")
- || !strcmp (basename (entry->d_name), ".."))
- continue;
-
- nr_entries++;
-
- GF_CHANGELOG_FILL_BUFFER (jnl->jnl_processing_dir,
- buffer, off,
- strlen (jnl->jnl_processing_dir));
- GF_CHANGELOG_FILL_BUFFER (entry->d_name, buffer,
- off, strlen (entry->d_name));
- GF_CHANGELOG_FILL_BUFFER ("\n", buffer, off, 1);
-
- if (gf_changelog_write (tracker_fd, buffer, off) != off) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_WRITE_FAILED,
- "error writing changelog filename"
- " to tracker file");
- break;
- }
- off = 0;
- }
-
- if (!entry) {
- if (gf_lseek (tracker_fd, 0, SEEK_SET) != -1)
- return nr_entries;
- }
- out:
- return -1;
+ if (!entry) {
+ if (gf_lseek(tracker_fd, 0, SEEK_SET) != -1)
+ return nr_entries;
+ }
+out:
+ return -1;
}
diff --git a/xlators/features/changelog/lib/src/gf-changelog-helpers.c b/xlators/features/changelog/lib/src/gf-changelog-helpers.c
index 9ff1d135933..fd15ec68ab8 100644
--- a/xlators/features/changelog/lib/src/gf-changelog-helpers.c
+++ b/xlators/features/changelog/lib/src/gf-changelog-helpers.c
@@ -13,38 +13,40 @@
#include "changelog-lib-messages.h"
#include "syscall.h"
-ssize_t gf_changelog_read_path (int fd, char *buffer, size_t bufsize)
+ssize_t
+gf_changelog_read_path(int fd, char *buffer, size_t bufsize)
{
- return sys_read (fd, buffer, bufsize);
+ return sys_read(fd, buffer, bufsize);
}
size_t
-gf_changelog_write (int fd, char *buffer, size_t len)
+gf_changelog_write(int fd, char *buffer, size_t len)
{
- ssize_t size = 0;
- size_t written = 0;
+ ssize_t size = 0;
+ size_t written = 0;
- while (written < len) {
- size = sys_write (fd, buffer + written, len - written);
- if (size <= 0)
- break;
+ while (written < len) {
+ size = sys_write(fd, buffer + written, len - written);
+ if (size <= 0)
+ break;
- written += size;
- }
+ written += size;
+ }
- return written;
+ return written;
}
void
-gf_rfc3986_encode_space_newline (unsigned char *s, char *enc, char *estr)
+gf_rfc3986_encode_space_newline(unsigned char *s, char *enc, char *estr)
{
- for (; *s; s++) {
- if (estr[*s])
- sprintf(enc, "%c", estr[*s]);
- else
- sprintf(enc, "%%%02X", *s);
- while (*++enc);
- }
+ for (; *s; s++) {
+ if (estr[*s])
+ sprintf(enc, "%c", estr[*s]);
+ else
+ sprintf(enc, "%%%02X", *s);
+ while (*++enc)
+ ;
+ }
}
/**
@@ -66,154 +68,152 @@ static pthread_key_t rl_key;
static pthread_once_t rl_once = PTHREAD_ONCE_INIT;
static void
-readline_destructor (void *ptr)
+readline_destructor(void *ptr)
{
- GF_FREE (ptr);
+ GF_FREE(ptr);
}
static void
-readline_once (void)
+readline_once(void)
{
- pthread_key_create (&rl_key, readline_destructor);
+ pthread_key_create(&rl_key, readline_destructor);
}
static ssize_t
-my_read (read_line_t *tsd, int fd, char *ptr)
+my_read(read_line_t *tsd, int fd, char *ptr)
{
- if (tsd->rl_cnt <= 0) {
- tsd->rl_cnt = sys_read (fd, tsd->rl_buf, MAXLINE);
-
- if (tsd->rl_cnt < 0)
- return -1;
- else if (tsd->rl_cnt == 0)
- return 0;
- tsd->rl_bufptr = tsd->rl_buf;
- }
-
- tsd->rl_cnt--;
- *ptr = *tsd->rl_bufptr++;
- return 1;
+ if (tsd->rl_cnt <= 0) {
+ tsd->rl_cnt = sys_read(fd, tsd->rl_buf, MAXLINE);
+
+ if (tsd->rl_cnt < 0)
+ return -1;
+ else if (tsd->rl_cnt == 0)
+ return 0;
+ tsd->rl_bufptr = tsd->rl_buf;
+ }
+
+ tsd->rl_cnt--;
+ *ptr = *tsd->rl_bufptr++;
+ return 1;
}
static int
-gf_readline_init_once (read_line_t **tsd)
+gf_readline_init_once(read_line_t **tsd)
{
- if (pthread_once (&rl_once, readline_once) != 0)
- return -1;
+ if (pthread_once(&rl_once, readline_once) != 0)
+ return -1;
- *tsd = pthread_getspecific (rl_key);
- if (*tsd)
- goto out;
+ *tsd = pthread_getspecific(rl_key);
+ if (*tsd)
+ goto out;
- *tsd = GF_CALLOC (1, sizeof (**tsd),
- gf_changelog_mt_libgfchangelog_rl_t);
- if (!*tsd)
- return -1;
+ *tsd = GF_CALLOC(1, sizeof(**tsd), gf_changelog_mt_libgfchangelog_rl_t);
+ if (!*tsd)
+ return -1;
- if (pthread_setspecific (rl_key, *tsd) != 0)
- return -1;
+ if (pthread_setspecific(rl_key, *tsd) != 0)
+ return -1;
- out:
- return 0;
+out:
+ return 0;
}
ssize_t
-gf_readline (int fd, void *vptr, size_t maxlen)
+gf_readline(int fd, void *vptr, size_t maxlen)
{
- size_t n = 0;
- size_t rc = 0;
- char c = ' ';
- char *ptr = NULL;
- read_line_t *tsd = NULL;
-
- if (gf_readline_init_once (&tsd))
- return -1;
-
- ptr = vptr;
- for (n = 1; n < maxlen; n++) {
- if ( (rc = my_read (tsd, fd, &c)) == 1 ) {
- *ptr++ = c;
- if (c == '\n')
- break;
- } else if (rc == 0) {
- *ptr = '\0';
- return (n - 1);
- } else
- return -1;
- }
-
- *ptr = '\0';
- return n;
+ size_t n = 0;
+ size_t rc = 0;
+ char c = ' ';
+ char *ptr = NULL;
+ read_line_t *tsd = NULL;
+
+ if (gf_readline_init_once(&tsd))
+ return -1;
+ ptr = vptr;
+ for (n = 1; n < maxlen; n++) {
+ if ((rc = my_read(tsd, fd, &c)) == 1) {
+ *ptr++ = c;
+ if (c == '\n')
+ break;
+ } else if (rc == 0) {
+ *ptr = '\0';
+ return (n - 1);
+ } else
+ return -1;
+ }
+
+ *ptr = '\0';
+ return n;
}
off_t
-gf_lseek (int fd, off_t offset, int whence)
+gf_lseek(int fd, off_t offset, int whence)
{
- off_t off = 0;
- read_line_t *tsd = NULL;
+ off_t off = 0;
+ read_line_t *tsd = NULL;
- if (gf_readline_init_once (&tsd))
- return -1;
+ if (gf_readline_init_once(&tsd))
+ return -1;
- off = sys_lseek (fd, offset, whence);
- if (off == -1)
- return -1;
+ off = sys_lseek(fd, offset, whence);
+ if (off == -1)
+ return -1;
- tsd->rl_cnt = 0;
- tsd->rl_bufptr = tsd->rl_buf;
+ tsd->rl_cnt = 0;
+ tsd->rl_bufptr = tsd->rl_buf;
- return off;
+ return off;
}
int
-gf_ftruncate (int fd, off_t length)
+gf_ftruncate(int fd, off_t length)
{
- read_line_t *tsd = NULL;
+ read_line_t *tsd = NULL;
- if (gf_readline_init_once (&tsd))
- return -1;
+ if (gf_readline_init_once(&tsd))
+ return -1;
- if (sys_ftruncate (fd, 0))
- return -1;
+ if (sys_ftruncate(fd, 0))
+ return -1;
- tsd->rl_cnt = 0;
- tsd->rl_bufptr = tsd->rl_buf;
+ tsd->rl_cnt = 0;
+ tsd->rl_bufptr = tsd->rl_buf;
- return 0;
+ return 0;
}
int
-gf_thread_cleanup (xlator_t *this, pthread_t thread)
+gf_thread_cleanup(xlator_t *this, pthread_t thread)
{
- int ret = 0;
- void *res = NULL;
-
- ret = pthread_cancel (thread);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING,
- "Failed to send cancellation to thread");
- goto error_return;
- }
-
- ret = pthread_join (thread, &res);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING,
- "failed to join thread");
- goto error_return;
- }
-
- if (res != PTHREAD_CANCELED) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING,
- "Thread could not be cleaned up");
- goto error_return;
- }
-
- return 0;
-
- error_return:
- return -1;
+ int ret = 0;
+ void *res = NULL;
+
+ ret = pthread_cancel(thread);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0,
+ CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING,
+ "Failed to send cancellation to thread");
+ goto error_return;
+ }
+
+ ret = pthread_join(thread, &res);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0,
+ CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING,
+ "failed to join thread");
+ goto error_return;
+ }
+
+ if (res != PTHREAD_CANCELED) {
+ gf_msg(this->name, GF_LOG_WARNING, 0,
+ CHANGELOG_LIB_MSG_THREAD_CLEANUP_WARNING,
+ "Thread could not be cleaned up");
+ goto error_return;
+ }
+
+ return 0;
+
+error_return:
+ return -1;
}
diff --git a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c
index bdb410030f6..ef46bf50c97 100644
--- a/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c
+++ b/xlators/features/changelog/lib/src/gf-changelog-journal-handler.c
@@ -25,112 +25,107 @@
extern int byebye;
-enum changelog_versions {
- VERSION_1_1 = 0,
- VERSION_1_2 = 1
-};
+enum changelog_versions { VERSION_1_1 = 0, VERSION_1_2 = 1 };
/**
* number of gfid records after fop number
*/
-int nr_gfids[2][GF_FOP_MAXVALUE] = {
- {
- [GF_FOP_MKNOD] = 1,
- [GF_FOP_MKDIR] = 1,
- [GF_FOP_UNLINK] = 1,
- [GF_FOP_RMDIR] = 1,
- [GF_FOP_SYMLINK] = 1,
- [GF_FOP_RENAME] = 2,
- [GF_FOP_LINK] = 1,
- [GF_FOP_CREATE] = 1,
- },
- {
- [GF_FOP_MKNOD] = 1,
- [GF_FOP_MKDIR] = 1,
- [GF_FOP_UNLINK] = 2,
- [GF_FOP_RMDIR] = 2,
- [GF_FOP_SYMLINK] = 1,
- [GF_FOP_RENAME] = 2,
- [GF_FOP_LINK] = 1,
- [GF_FOP_CREATE] = 1,
- }
-};
-
-int nr_extra_recs[2][GF_FOP_MAXVALUE] = {
- {
- [GF_FOP_MKNOD] = 3,
- [GF_FOP_MKDIR] = 3,
- [GF_FOP_UNLINK] = 0,
- [GF_FOP_RMDIR] = 0,
- [GF_FOP_SYMLINK] = 0,
- [GF_FOP_RENAME] = 0,
- [GF_FOP_LINK] = 0,
- [GF_FOP_CREATE] = 3,
- },
- {
- [GF_FOP_MKNOD] = 3,
- [GF_FOP_MKDIR] = 3,
- [GF_FOP_UNLINK] = 0,
- [GF_FOP_RMDIR] = 0,
- [GF_FOP_SYMLINK] = 0,
- [GF_FOP_RENAME] = 0,
- [GF_FOP_LINK] = 0,
- [GF_FOP_CREATE] = 3,
- }
-};
+int nr_gfids[2][GF_FOP_MAXVALUE] = {{
+ [GF_FOP_MKNOD] = 1,
+ [GF_FOP_MKDIR] = 1,
+ [GF_FOP_UNLINK] = 1,
+ [GF_FOP_RMDIR] = 1,
+ [GF_FOP_SYMLINK] = 1,
+ [GF_FOP_RENAME] = 2,
+ [GF_FOP_LINK] = 1,
+ [GF_FOP_CREATE] = 1,
+ },
+ {
+ [GF_FOP_MKNOD] = 1,
+ [GF_FOP_MKDIR] = 1,
+ [GF_FOP_UNLINK] = 2,
+ [GF_FOP_RMDIR] = 2,
+ [GF_FOP_SYMLINK] = 1,
+ [GF_FOP_RENAME] = 2,
+ [GF_FOP_LINK] = 1,
+ [GF_FOP_CREATE] = 1,
+ }};
+
+int nr_extra_recs[2][GF_FOP_MAXVALUE] = {{
+ [GF_FOP_MKNOD] = 3,
+ [GF_FOP_MKDIR] = 3,
+ [GF_FOP_UNLINK] = 0,
+ [GF_FOP_RMDIR] = 0,
+ [GF_FOP_SYMLINK] = 0,
+ [GF_FOP_RENAME] = 0,
+ [GF_FOP_LINK] = 0,
+ [GF_FOP_CREATE] = 3,
+ },
+ {
+ [GF_FOP_MKNOD] = 3,
+ [GF_FOP_MKDIR] = 3,
+ [GF_FOP_UNLINK] = 0,
+ [GF_FOP_RMDIR] = 0,
+ [GF_FOP_SYMLINK] = 0,
+ [GF_FOP_RENAME] = 0,
+ [GF_FOP_LINK] = 0,
+ [GF_FOP_CREATE] = 3,
+ }};
static char *
-binary_to_ascii (uuid_t uuid)
+binary_to_ascii(uuid_t uuid)
{
- return uuid_utoa (uuid);
+ return uuid_utoa(uuid);
}
static char *
-conv_noop (char *ptr) { return ptr; }
-
-#define VERIFY_SEPARATOR(ptr, plen, perr) \
- { \
- if (*(ptr + plen) != '\0') { \
- perr = 1; \
- break; \
- } \
- }
+conv_noop(char *ptr)
+{
+ return ptr;
+}
-#define MOVER_MOVE(mover, nleft, bytes) \
- { \
- mover += bytes; \
- nleft -= bytes; \
- } \
-
-#define PARSE_GFID(mov, ptr, le, fn, perr) \
- { \
- VERIFY_SEPARATOR (mov, le, perr); \
- ptr = fn (mov); \
- if (!ptr) { \
- perr = 1; \
- break; \
- } \
- }
+#define VERIFY_SEPARATOR(ptr, plen, perr) \
+ { \
+ if (*(ptr + plen) != '\0') { \
+ perr = 1; \
+ break; \
+ } \
+ }
-#define FILL_AND_MOVE(pt, buf, of, mo, nl, le) \
- { \
- GF_CHANGELOG_FILL_BUFFER (pt, buf, of, strlen (pt)); \
- MOVER_MOVE (mo, nl, le); \
- }
+#define MOVER_MOVE(mover, nleft, bytes) \
+ { \
+ mover += bytes; \
+ nleft -= bytes; \
+ }
+
+#define PARSE_GFID(mov, ptr, le, fn, perr) \
+ { \
+ VERIFY_SEPARATOR(mov, le, perr); \
+ ptr = fn(mov); \
+ if (!ptr) { \
+ perr = 1; \
+ break; \
+ } \
+ }
+#define FILL_AND_MOVE(pt, buf, of, mo, nl, le) \
+ { \
+ GF_CHANGELOG_FILL_BUFFER(pt, buf, of, strlen(pt)); \
+ MOVER_MOVE(mo, nl, le); \
+ }
-#define PARSE_GFID_MOVE(ptr, uuid, mover, nleft, perr) \
- { \
- memcpy (uuid, mover, sizeof (uuid_t)); \
- ptr = binary_to_ascii (uuid); \
- if (!ptr) { \
- perr = 1; \
- break; \
- } \
- MOVER_MOVE (mover, nleft, sizeof (uuid_t)); \
- } \
+#define PARSE_GFID_MOVE(ptr, uuid, mover, nleft, perr) \
+ { \
+ memcpy(uuid, mover, sizeof(uuid_t)); \
+ ptr = binary_to_ascii(uuid); \
+ if (!ptr) { \
+ perr = 1; \
+ break; \
+ } \
+ MOVER_MOVE(mover, nleft, sizeof(uuid_t)); \
+ }
-#define LINE_BUFSIZE (3*PATH_MAX) /* enough buffer for extra chars too */
+#define LINE_BUFSIZE (3 * PATH_MAX) /* enough buffer for extra chars too */
/**
* using mmap() makes parsing easy. fgets() cannot be used here as
@@ -145,111 +140,107 @@ conv_noop (char *ptr) { return ptr; }
*/
static int
-gf_changelog_parse_binary (xlator_t *this,
- gf_changelog_journal_t *jnl,
- int from_fd, int to_fd,
- size_t start_offset, struct stat *stbuf,
- int version_idx)
+gf_changelog_parse_binary(xlator_t *this, gf_changelog_journal_t *jnl,
+ int from_fd, int to_fd, size_t start_offset,
+ struct stat *stbuf, int version_idx)
{
- int ret = -1;
- off_t off = 0;
- off_t nleft = 0;
- uuid_t uuid = {0,};
- char *ptr = NULL;
- char *bname_start = NULL;
- char *bname_end = NULL;
- char *mover = NULL;
- void *start = NULL;
- char current_mover = ' ';
- size_t blen = 0;
- int parse_err = 0;
- char *ascii = NULL;
-
- ascii = GF_CALLOC (LINE_BUFSIZE, sizeof(char), gf_common_mt_char);
-
- nleft = stbuf->st_size;
-
- start = mmap (NULL, nleft, PROT_READ, MAP_PRIVATE, from_fd, 0);
- if (start == MAP_FAILED) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_MMAP_FAILED,
- "mmap() error");
- goto out;
- }
-
- mover = start;
+ int ret = -1;
+ off_t off = 0;
+ off_t nleft = 0;
+ uuid_t uuid = {
+ 0,
+ };
+ char *ptr = NULL;
+ char *bname_start = NULL;
+ char *bname_end = NULL;
+ char *mover = NULL;
+ void *start = NULL;
+ char current_mover = ' ';
+ size_t blen = 0;
+ int parse_err = 0;
+ char *ascii = NULL;
+
+ ascii = GF_CALLOC(LINE_BUFSIZE, sizeof(char), gf_common_mt_char);
+
+ nleft = stbuf->st_size;
+
+ start = mmap(NULL, nleft, PROT_READ, MAP_PRIVATE, from_fd, 0);
+ if (start == MAP_FAILED) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_MMAP_FAILED,
+ "mmap() error");
+ goto out;
+ }
- MOVER_MOVE (mover, nleft, start_offset);
+ mover = start;
- while (nleft > 0) {
+ MOVER_MOVE(mover, nleft, start_offset);
- off = blen = 0;
- ptr = bname_start = bname_end = NULL;
+ while (nleft > 0) {
+ off = blen = 0;
+ ptr = bname_start = bname_end = NULL;
- current_mover = *mover;
+ current_mover = *mover;
- switch (current_mover) {
- case 'D':
- case 'M':
- MOVER_MOVE (mover, nleft, 1);
- PARSE_GFID_MOVE (ptr, uuid, mover, nleft, parse_err);
+ switch (current_mover) {
+ case 'D':
+ case 'M':
+ MOVER_MOVE(mover, nleft, 1);
+ PARSE_GFID_MOVE(ptr, uuid, mover, nleft, parse_err);
- break;
+ break;
- case 'E':
- MOVER_MOVE (mover, nleft, 1);
- PARSE_GFID_MOVE (ptr, uuid, mover, nleft, parse_err);
+ case 'E':
+ MOVER_MOVE(mover, nleft, 1);
+ PARSE_GFID_MOVE(ptr, uuid, mover, nleft, parse_err);
- bname_start = mover;
- bname_end = strchr (mover, '\n');
- if (bname_end == NULL) {
- parse_err = 1;
- break;
- }
+ bname_start = mover;
+ bname_end = strchr(mover, '\n');
+ if (bname_end == NULL) {
+ parse_err = 1;
+ break;
+ }
- blen = bname_end - bname_start;
- MOVER_MOVE (mover, nleft, blen);
+ blen = bname_end - bname_start;
+ MOVER_MOVE(mover, nleft, blen);
- break;
+ break;
- default:
- parse_err = 1;
- }
+ default:
+ parse_err = 1;
+ }
- if (parse_err)
- break;
+ if (parse_err)
+ break;
+
+ GF_CHANGELOG_FILL_BUFFER(&current_mover, ascii, off, 1);
+ GF_CHANGELOG_FILL_BUFFER(" ", ascii, off, 1);
+ GF_CHANGELOG_FILL_BUFFER(ptr, ascii, off, strlen(ptr));
+ if (blen)
+ GF_CHANGELOG_FILL_BUFFER(bname_start, ascii, off, blen);
+ GF_CHANGELOG_FILL_BUFFER("\n", ascii, off, 1);
+
+ if (gf_changelog_write(to_fd, ascii, off) != off) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_ASCII_ERROR,
+ "processing binary changelog failed due to "
+ " error in writing ascii change");
+ break;
+ }
- GF_CHANGELOG_FILL_BUFFER (&current_mover, ascii, off, 1);
- GF_CHANGELOG_FILL_BUFFER (" ", ascii, off, 1);
- GF_CHANGELOG_FILL_BUFFER (ptr, ascii, off, strlen (ptr));
- if (blen)
- GF_CHANGELOG_FILL_BUFFER (bname_start,
- ascii, off, blen);
- GF_CHANGELOG_FILL_BUFFER ("\n", ascii, off, 1);
-
- if (gf_changelog_write (to_fd, ascii, off) != off) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_ASCII_ERROR,
- "processing binary changelog failed due to "
- " error in writing ascii change");
- break;
- }
+ MOVER_MOVE(mover, nleft, 1);
+ }
- MOVER_MOVE (mover, nleft, 1);
- }
+ if ((nleft == 0) && (!parse_err))
+ ret = 0;
- if ((nleft == 0) && (!parse_err))
- ret = 0;
-
- if (munmap (start, stbuf->st_size))
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_MUNMAP_FAILED,
- "munmap() error");
- out:
- if (ascii)
- GF_FREE (ascii);
- return ret;
+ if (munmap(start, stbuf->st_size))
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_MUNMAP_FAILED,
+ "munmap() error");
+out:
+ if (ascii)
+ GF_FREE(ascii);
+ return ret;
}
/**
@@ -258,804 +249,784 @@ gf_changelog_parse_binary (xlator_t *this,
* - use fop name rather than fop number
*/
static int
-gf_changelog_parse_ascii (xlator_t *this,
- gf_changelog_journal_t *jnl,
- int from_fd, int to_fd,
- size_t start_offset, struct stat *stbuf,
- int version_idx)
+gf_changelog_parse_ascii(xlator_t *this, gf_changelog_journal_t *jnl,
+ int from_fd, int to_fd, size_t start_offset,
+ struct stat *stbuf, int version_idx)
{
- int ng = 0;
- int ret = -1;
- int fop = 0;
- int len = 0;
- off_t off = 0;
- off_t nleft = 0;
- char *ptr = NULL;
- char *eptr = NULL;
- void *start = NULL;
- char *mover = NULL;
- int parse_err = 0;
- char current_mover = ' ';
- char *ascii = NULL;
- const char *fopname = NULL;
-
- ascii = GF_CALLOC (LINE_BUFSIZE, sizeof(char), gf_common_mt_char);
-
- nleft = stbuf->st_size;
-
- start = mmap (NULL, nleft, PROT_READ, MAP_PRIVATE, from_fd, 0);
- if (start == MAP_FAILED) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_MMAP_FAILED,
- "mmap() error");
- goto out;
- }
+ int ng = 0;
+ int ret = -1;
+ int fop = 0;
+ int len = 0;
+ off_t off = 0;
+ off_t nleft = 0;
+ char *ptr = NULL;
+ char *eptr = NULL;
+ void *start = NULL;
+ char *mover = NULL;
+ int parse_err = 0;
+ char current_mover = ' ';
+ char *ascii = NULL;
+ const char *fopname = NULL;
+
+ ascii = GF_CALLOC(LINE_BUFSIZE, sizeof(char), gf_common_mt_char);
+
+ nleft = stbuf->st_size;
+
+ start = mmap(NULL, nleft, PROT_READ, MAP_PRIVATE, from_fd, 0);
+ if (start == MAP_FAILED) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_MMAP_FAILED,
+ "mmap() error");
+ goto out;
+ }
- mover = start;
+ mover = start;
- MOVER_MOVE (mover, nleft, start_offset);
+ MOVER_MOVE(mover, nleft, start_offset);
- while (nleft > 0) {
- off = 0;
- current_mover = *mover;
+ while (nleft > 0) {
+ off = 0;
+ current_mover = *mover;
- GF_CHANGELOG_FILL_BUFFER (&current_mover, ascii, off, 1);
- GF_CHANGELOG_FILL_BUFFER (" ", ascii, off, 1);
+ GF_CHANGELOG_FILL_BUFFER(&current_mover, ascii, off, 1);
+ GF_CHANGELOG_FILL_BUFFER(" ", ascii, off, 1);
- switch (current_mover) {
- case 'D':
- MOVER_MOVE (mover, nleft, 1);
+ switch (current_mover) {
+ case 'D':
+ MOVER_MOVE(mover, nleft, 1);
- /* target gfid */
- PARSE_GFID (mover, ptr, UUID_CANONICAL_FORM_LEN,
- conv_noop, parse_err);
- FILL_AND_MOVE(ptr, ascii, off,
- mover, nleft, UUID_CANONICAL_FORM_LEN);
- break;
- case 'M':
- MOVER_MOVE (mover, nleft, 1);
+ /* target gfid */
+ PARSE_GFID(mover, ptr, UUID_CANONICAL_FORM_LEN, conv_noop,
+ parse_err);
+ FILL_AND_MOVE(ptr, ascii, off, mover, nleft,
+ UUID_CANONICAL_FORM_LEN);
+ break;
+ case 'M':
+ MOVER_MOVE(mover, nleft, 1);
+
+ /* target gfid */
+ PARSE_GFID(mover, ptr, UUID_CANONICAL_FORM_LEN, conv_noop,
+ parse_err);
+ FILL_AND_MOVE(ptr, ascii, off, mover, nleft,
+ UUID_CANONICAL_FORM_LEN);
+ FILL_AND_MOVE(" ", ascii, off, mover, nleft, 1);
+
+ /* fop */
+ len = strlen(mover);
+ VERIFY_SEPARATOR(mover, len, parse_err);
+
+ fop = atoi(mover);
+ fopname = gf_fop_list[fop];
+ if (fopname == NULL) {
+ parse_err = 1;
+ break;
+ }
- /* target gfid */
- PARSE_GFID (mover, ptr, UUID_CANONICAL_FORM_LEN,
- conv_noop, parse_err);
- FILL_AND_MOVE (ptr, ascii, off,
- mover, nleft, UUID_CANONICAL_FORM_LEN);
- FILL_AND_MOVE (" ", ascii, off, mover, nleft, 1);
+ MOVER_MOVE(mover, nleft, len);
- /* fop */
- len = strlen (mover);
- VERIFY_SEPARATOR (mover, len, parse_err);
+ len = strlen(fopname);
+ GF_CHANGELOG_FILL_BUFFER(fopname, ascii, off, len);
- fop = atoi (mover);
- fopname = gf_fop_list[fop];
- if (fopname == NULL) {
- parse_err = 1;
- break;
- }
+ break;
- MOVER_MOVE (mover, nleft, len);
+ case 'E':
+ MOVER_MOVE(mover, nleft, 1);
+
+ /* target gfid */
+ PARSE_GFID(mover, ptr, UUID_CANONICAL_FORM_LEN, conv_noop,
+ parse_err);
+ FILL_AND_MOVE(ptr, ascii, off, mover, nleft,
+ UUID_CANONICAL_FORM_LEN);
+ FILL_AND_MOVE(" ", ascii, off, mover, nleft, 1);
+
+ /* fop */
+ len = strlen(mover);
+ VERIFY_SEPARATOR(mover, len, parse_err);
+
+ fop = atoi(mover);
+ fopname = gf_fop_list[fop];
+ if (fopname == NULL) {
+ parse_err = 1;
+ break;
+ }
- len = strlen (fopname);
- GF_CHANGELOG_FILL_BUFFER (fopname, ascii, off, len);
+ MOVER_MOVE(mover, nleft, len);
- break;
+ len = strlen(fopname);
+ GF_CHANGELOG_FILL_BUFFER(fopname, ascii, off, len);
- case 'E':
- MOVER_MOVE (mover, nleft, 1);
-
- /* target gfid */
- PARSE_GFID (mover, ptr, UUID_CANONICAL_FORM_LEN,
- conv_noop, parse_err);
- FILL_AND_MOVE (ptr, ascii, off,
- mover, nleft, UUID_CANONICAL_FORM_LEN);
- FILL_AND_MOVE (" ", ascii, off,
- mover, nleft, 1);
-
- /* fop */
- len = strlen (mover);
- VERIFY_SEPARATOR (mover, len, parse_err);
-
- fop = atoi (mover);
- fopname = gf_fop_list[fop];
- if (fopname == NULL) {
- parse_err = 1;
- break;
- }
-
- MOVER_MOVE (mover, nleft, len);
-
- len = strlen (fopname);
- GF_CHANGELOG_FILL_BUFFER (fopname, ascii, off, len);
-
- ng = nr_extra_recs[version_idx][fop];
- for (; ng > 0; ng--) {
- MOVER_MOVE (mover, nleft, 1);
- len = strlen (mover);
- VERIFY_SEPARATOR (mover, len, parse_err);
-
- GF_CHANGELOG_FILL_BUFFER (" ", ascii, off, 1);
- FILL_AND_MOVE (mover, ascii,
- off, mover, nleft, len);
- }
-
- /* pargfid + bname */
- ng = nr_gfids[version_idx][fop];
- while (ng-- > 0) {
- MOVER_MOVE (mover, nleft, 1);
- len = strlen (mover);
- if (!len) {
- MOVER_MOVE (mover, nleft, 1);
- continue;
- }
-
- GF_CHANGELOG_FILL_BUFFER (" ", ascii, off, 1);
-
- PARSE_GFID (mover, ptr, len,
- conv_noop, parse_err);
- eptr = calloc (3, strlen (ptr));
- if (!eptr) {
- parse_err = 1;
- break;
- }
-
- gf_rfc3986_encode_space_newline (
- (unsigned char *) ptr,
- eptr,
- jnl->rfc3986_space_newline);
- FILL_AND_MOVE (eptr, ascii, off,
- mover, nleft, len);
- free (eptr);
- }
+ ng = nr_extra_recs[version_idx][fop];
+ for (; ng > 0; ng--) {
+ MOVER_MOVE(mover, nleft, 1);
+ len = strlen(mover);
+ VERIFY_SEPARATOR(mover, len, parse_err);
- break;
- default:
- parse_err = 1;
+ GF_CHANGELOG_FILL_BUFFER(" ", ascii, off, 1);
+ FILL_AND_MOVE(mover, ascii, off, mover, nleft, len);
}
- if (parse_err)
+ /* pargfid + bname */
+ ng = nr_gfids[version_idx][fop];
+ while (ng-- > 0) {
+ MOVER_MOVE(mover, nleft, 1);
+ len = strlen(mover);
+ if (!len) {
+ MOVER_MOVE(mover, nleft, 1);
+ continue;
+ }
+
+ GF_CHANGELOG_FILL_BUFFER(" ", ascii, off, 1);
+
+ PARSE_GFID(mover, ptr, len, conv_noop, parse_err);
+ eptr = calloc(3, strlen(ptr));
+ if (!eptr) {
+ parse_err = 1;
break;
+ }
- GF_CHANGELOG_FILL_BUFFER ("\n", ascii, off, 1);
-
- if (gf_changelog_write (to_fd, ascii, off) != off) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_ASCII_ERROR,
- "processing ascii changelog failed due to "
- " error in writing change");
- break;
+ gf_rfc3986_encode_space_newline((unsigned char *)ptr, eptr,
+ jnl->rfc3986_space_newline);
+ FILL_AND_MOVE(eptr, ascii, off, mover, nleft, len);
+ free(eptr);
}
- MOVER_MOVE (mover, nleft, 1);
+ break;
+ default:
+ parse_err = 1;
+ }
+
+ if (parse_err)
+ break;
+
+ GF_CHANGELOG_FILL_BUFFER("\n", ascii, off, 1);
+ if (gf_changelog_write(to_fd, ascii, off) != off) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_ASCII_ERROR,
+ "processing ascii changelog failed due to "
+ " error in writing change");
+ break;
}
- if ((nleft == 0) && (!parse_err))
- ret = 0;
+ MOVER_MOVE(mover, nleft, 1);
+ }
+
+ if ((nleft == 0) && (!parse_err))
+ ret = 0;
- if (munmap (start, stbuf->st_size))
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_MUNMAP_FAILED,
- "munmap() error");
+ if (munmap(start, stbuf->st_size))
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_MUNMAP_FAILED,
+ "munmap() error");
- out:
- if (ascii)
- GF_FREE (ascii);
+out:
+ if (ascii)
+ GF_FREE(ascii);
- return ret;
+ return ret;
}
static int
-gf_changelog_decode (xlator_t *this, gf_changelog_journal_t *jnl,
- int from_fd, int to_fd, struct stat *stbuf, int *zerob)
+gf_changelog_decode(xlator_t *this, gf_changelog_journal_t *jnl, int from_fd,
+ int to_fd, struct stat *stbuf, int *zerob)
{
- int ret = -1;
- int encoding = -1;
- int major_version = -1;
- int minor_version = -1;
- int version_idx = -1;
- size_t elen = 0;
- char buffer[1024] = {0,};
-
- CHANGELOG_GET_HEADER_INFO (from_fd, buffer, sizeof (buffer), encoding,
- major_version, minor_version, elen);
- if (encoding == -1) /* unknown encoding */
- goto out;
-
- if (major_version == -1) /* unknown major version */
- goto out;
-
- if (minor_version == -1) /* unknown minor version */
- goto out;
-
- if (!CHANGELOG_VALID_ENCODING (encoding))
- goto out;
-
- if (elen == stbuf->st_size) {
- *zerob = 1;
- goto out;
- }
+ int ret = -1;
+ int encoding = -1;
+ int major_version = -1;
+ int minor_version = -1;
+ int version_idx = -1;
+ size_t elen = 0;
+ char buffer[1024] = {
+ 0,
+ };
+
+ CHANGELOG_GET_HEADER_INFO(from_fd, buffer, sizeof(buffer), encoding,
+ major_version, minor_version, elen);
+ if (encoding == -1) /* unknown encoding */
+ goto out;
+
+ if (major_version == -1) /* unknown major version */
+ goto out;
+
+ if (minor_version == -1) /* unknown minor version */
+ goto out;
+
+ if (!CHANGELOG_VALID_ENCODING(encoding))
+ goto out;
+
+ if (elen == stbuf->st_size) {
+ *zerob = 1;
+ goto out;
+ }
- if (major_version == 1 && minor_version == 1) {
- version_idx = VERSION_1_1;
- } else if (major_version == 1 && minor_version == 2) {
- version_idx = VERSION_1_2;
- }
+ if (major_version == 1 && minor_version == 1) {
+ version_idx = VERSION_1_1;
+ } else if (major_version == 1 && minor_version == 2) {
+ version_idx = VERSION_1_2;
+ }
- if (version_idx == -1) /* unknown version number */
- goto out;
+ if (version_idx == -1) /* unknown version number */
+ goto out;
- /**
- * start processing after the header
- */
- if (sys_lseek (from_fd, elen, SEEK_SET) < 0) {
- goto out;
- }
- switch (encoding) {
+ /**
+ * start processing after the header
+ */
+ if (sys_lseek(from_fd, elen, SEEK_SET) < 0) {
+ goto out;
+ }
+ switch (encoding) {
case CHANGELOG_ENCODE_BINARY:
- /**
- * this ideally should have been a part of changelog-encoders.c
- * (ie. part of the changelog translator).
- */
- ret = gf_changelog_parse_binary (this, jnl, from_fd,
- to_fd, elen, stbuf,
- version_idx);
- break;
+ /**
+ * this ideally should have been a part of changelog-encoders.c
+ * (ie. part of the changelog translator).
+ */
+ ret = gf_changelog_parse_binary(this, jnl, from_fd, to_fd, elen,
+ stbuf, version_idx);
+ break;
case CHANGELOG_ENCODE_ASCII:
- ret = gf_changelog_parse_ascii (this, jnl, from_fd,
- to_fd, elen, stbuf,
- version_idx);
- break;
- }
+ ret = gf_changelog_parse_ascii(this, jnl, from_fd, to_fd, elen,
+ stbuf, version_idx);
+ break;
+ }
out:
- return ret;
+ return ret;
}
int
-gf_changelog_publish (xlator_t *this,
- gf_changelog_journal_t *jnl, char *from_path)
+gf_changelog_publish(xlator_t *this, gf_changelog_journal_t *jnl,
+ char *from_path)
{
- int ret = 0;
- char dest[PATH_MAX] = {0,};
- char to_path[PATH_MAX] = {0,};
- struct stat stbuf = {0,};
-
- if (snprintf (to_path, PATH_MAX, "%s%s", jnl->jnl_current_dir,
- basename (from_path)) >= PATH_MAX)
- return -1;
-
- /* handle zerob file that won't exist in current */
- ret = sys_stat (to_path, &stbuf);
- if (ret) {
- if (errno == ENOENT)
- ret = 0;
- goto out;
- }
+ int ret = 0;
+ char dest[PATH_MAX] = {
+ 0,
+ };
+ char to_path[PATH_MAX] = {
+ 0,
+ };
+ struct stat stbuf = {
+ 0,
+ };
+
+ if (snprintf(to_path, PATH_MAX, "%s%s", jnl->jnl_current_dir,
+ basename(from_path)) >= PATH_MAX)
+ return -1;
- if (snprintf (dest, PATH_MAX, "%s%s", jnl->jnl_processing_dir,
- basename (from_path)) >= PATH_MAX)
- return -1;
-
- ret = sys_rename (to_path, dest);
- if (ret) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_RENAME_FAILED,
- "error moving changelog to processing dir",
- "path=%s", to_path,
- NULL);
- }
+ /* handle zerob file that won't exist in current */
+ ret = sys_stat(to_path, &stbuf);
+ if (ret) {
+ if (errno == ENOENT)
+ ret = 0;
+ goto out;
+ }
+
+ if (snprintf(dest, PATH_MAX, "%s%s", jnl->jnl_processing_dir,
+ basename(from_path)) >= PATH_MAX)
+ return -1;
+
+ ret = sys_rename(to_path, dest);
+ if (ret) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_RENAME_FAILED,
+ "error moving changelog to processing dir", "path=%s", to_path,
+ NULL);
+ }
out:
- return ret;
+ return ret;
}
int
-gf_changelog_consume (xlator_t *this,
- gf_changelog_journal_t *jnl,
- char *from_path, gf_boolean_t no_publish)
+gf_changelog_consume(xlator_t *this, gf_changelog_journal_t *jnl,
+ char *from_path, gf_boolean_t no_publish)
{
- int ret = -1;
- int fd1 = 0;
- int fd2 = 0;
- int zerob = 0;
- struct stat stbuf = {0,};
- char dest[PATH_MAX] = {0,};
- char to_path[PATH_MAX] = {0,};
-
- if (snprintf (to_path, PATH_MAX, "%s%s", jnl->jnl_current_dir,
- basename (from_path)) >= PATH_MAX)
- goto out;
- if (snprintf (dest, PATH_MAX, "%s%s", jnl->jnl_processing_dir,
- basename (from_path)) >= PATH_MAX)
- goto out;
-
- ret = sys_stat (from_path, &stbuf);
- if (ret || !S_ISREG(stbuf.st_mode)) {
- ret = -1;
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_STAT_FAILED,
- "stat failed on changelog file",
- "path=%s", from_path,
- NULL);
- goto out;
- }
+ int ret = -1;
+ int fd1 = 0;
+ int fd2 = 0;
+ int zerob = 0;
+ struct stat stbuf = {
+ 0,
+ };
+ char dest[PATH_MAX] = {
+ 0,
+ };
+ char to_path[PATH_MAX] = {
+ 0,
+ };
+
+ if (snprintf(to_path, PATH_MAX, "%s%s", jnl->jnl_current_dir,
+ basename(from_path)) >= PATH_MAX)
+ goto out;
+ if (snprintf(dest, PATH_MAX, "%s%s", jnl->jnl_processing_dir,
+ basename(from_path)) >= PATH_MAX)
+ goto out;
+
+ ret = sys_stat(from_path, &stbuf);
+ if (ret || !S_ISREG(stbuf.st_mode)) {
+ ret = -1;
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_STAT_FAILED,
+ "stat failed on changelog file", "path=%s", from_path, NULL);
+ goto out;
+ }
- fd1 = open (from_path, O_RDONLY);
- if (fd1 < 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_OPEN_FAILED,
- "cannot open changelog file",
- "path=%s", from_path,
- NULL);
- goto out;
- }
+ fd1 = open(from_path, O_RDONLY);
+ if (fd1 < 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_OPEN_FAILED,
+ "cannot open changelog file", "path=%s", from_path, NULL);
+ goto out;
+ }
- fd2 = open (to_path, O_CREAT | O_TRUNC | O_RDWR,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (fd2 < 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_OPEN_FAILED,
- "cannot create ascii changelog file",
- "path=%s", to_path,
- NULL);
+ fd2 = open(to_path, O_CREAT | O_TRUNC | O_RDWR,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (fd2 < 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_OPEN_FAILED,
+ "cannot create ascii changelog file", "path=%s", to_path, NULL);
+ goto close_fd;
+ } else {
+ ret = gf_changelog_decode(this, jnl, fd1, fd2, &stbuf, &zerob);
+
+ sys_close(fd2);
+
+ if (!ret) {
+ /* move it to processing on a successful
+ decode */
+ if (no_publish == _gf_true)
goto close_fd;
- } else {
- ret = gf_changelog_decode (this, jnl, fd1,
- fd2, &stbuf, &zerob);
-
- sys_close (fd2);
-
- if (!ret) {
- /* move it to processing on a successful
- decode */
- if (no_publish == _gf_true)
- goto close_fd;
- ret = sys_rename (to_path, dest);
- if (ret)
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_RENAME_FAILED,
- "error moving changelog to processing dir",
- "path=%s", to_path,
- NULL);
- }
+ ret = sys_rename(to_path, dest);
+ if (ret)
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_RENAME_FAILED,
+ "error moving changelog to processing dir", "path=%s",
+ to_path, NULL);
+ }
- /* remove it from .current if it's an empty file */
- if (zerob) {
- /* zerob changelogs must be unlinked */
- ret = sys_unlink (to_path);
- if (ret)
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_UNLINK_FAILED,
- "could not unlink empty changelog",
- "path=%s", to_path,
- NULL);
- }
+ /* remove it from .current if it's an empty file */
+ if (zerob) {
+ /* zerob changelogs must be unlinked */
+ ret = sys_unlink(to_path);
+ if (ret)
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_UNLINK_FAILED,
+ "could not unlink empty changelog", "path=%s", to_path,
+ NULL);
}
+ }
- close_fd:
- sys_close (fd1);
+close_fd:
+ sys_close(fd1);
- out:
- return ret;
+out:
+ return ret;
}
void *
-gf_changelog_process (void *data)
+gf_changelog_process(void *data)
{
- xlator_t *this = NULL;
- gf_changelog_journal_t *jnl = NULL;
- gf_changelog_entry_t *entry = NULL;
- gf_changelog_processor_t *jnl_proc = NULL;
-
- jnl = data;
- jnl_proc = jnl->jnl_proc;
- THIS = jnl->this;
- this = jnl->this;
-
- while (1) {
- pthread_mutex_lock (&jnl_proc->lock);
- {
- while (list_empty (&jnl_proc->entries)) {
- jnl_proc->waiting = _gf_true;
- pthread_cond_wait
- (&jnl_proc->cond, &jnl_proc->lock);
- }
-
- entry = list_first_entry (&jnl_proc->entries,
- gf_changelog_entry_t, list);
- if (entry)
- list_del (&entry->list);
-
- jnl_proc->waiting = _gf_false;
- }
- pthread_mutex_unlock (&jnl_proc->lock);
+ xlator_t *this = NULL;
+ gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_entry_t *entry = NULL;
+ gf_changelog_processor_t *jnl_proc = NULL;
+
+ jnl = data;
+ jnl_proc = jnl->jnl_proc;
+ THIS = jnl->this;
+ this = jnl->this;
+
+ while (1) {
+ pthread_mutex_lock(&jnl_proc->lock);
+ {
+ while (list_empty(&jnl_proc->entries)) {
+ jnl_proc->waiting = _gf_true;
+ pthread_cond_wait(&jnl_proc->cond, &jnl_proc->lock);
+ }
- if (entry) {
- (void) gf_changelog_consume (this, jnl,
- entry->path, _gf_false);
- GF_FREE (entry);
- }
+ entry = list_first_entry(&jnl_proc->entries, gf_changelog_entry_t,
+ list);
+ if (entry)
+ list_del(&entry->list);
+
+ jnl_proc->waiting = _gf_false;
}
+ pthread_mutex_unlock(&jnl_proc->lock);
+
+ if (entry) {
+ (void)gf_changelog_consume(this, jnl, entry->path, _gf_false);
+ GF_FREE(entry);
+ }
+ }
- return NULL;
+ return NULL;
}
void
-gf_changelog_queue_journal (gf_changelog_processor_t *jnl_proc,
- changelog_event_t *event)
+gf_changelog_queue_journal(gf_changelog_processor_t *jnl_proc,
+ changelog_event_t *event)
{
- size_t len = 0;
- gf_changelog_entry_t *entry = NULL;
+ size_t len = 0;
+ gf_changelog_entry_t *entry = NULL;
- entry = GF_CALLOC (1, sizeof (gf_changelog_entry_t),
- gf_changelog_mt_libgfchangelog_entry_t);
- if (!entry)
- return;
- INIT_LIST_HEAD (&entry->list);
+ entry = GF_CALLOC(1, sizeof(gf_changelog_entry_t),
+ gf_changelog_mt_libgfchangelog_entry_t);
+ if (!entry)
+ return;
+ INIT_LIST_HEAD(&entry->list);
- len = strlen (event->u.journal.path);
- (void)memcpy (entry->path, event->u.journal.path, len+1);
- entry->path[len] = '\0';
+ len = strlen(event->u.journal.path);
+ (void)memcpy(entry->path, event->u.journal.path, len + 1);
+ entry->path[len] = '\0';
- pthread_mutex_lock (&jnl_proc->lock);
- {
- list_add_tail (&entry->list, &jnl_proc->entries);
- if (jnl_proc->waiting)
- pthread_cond_signal (&jnl_proc->cond);
- }
- pthread_mutex_unlock (&jnl_proc->lock);
+ pthread_mutex_lock(&jnl_proc->lock);
+ {
+ list_add_tail(&entry->list, &jnl_proc->entries);
+ if (jnl_proc->waiting)
+ pthread_cond_signal(&jnl_proc->cond);
+ }
+ pthread_mutex_unlock(&jnl_proc->lock);
- return;
+ return;
}
void
-gf_changelog_handle_journal (void *xl, char *brick,
- void *cbkdata, changelog_event_t *event)
+gf_changelog_handle_journal(void *xl, char *brick, void *cbkdata,
+ changelog_event_t *event)
{
- gf_changelog_journal_t *jnl = NULL;
- gf_changelog_processor_t *jnl_proc = NULL;
+ gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_processor_t *jnl_proc = NULL;
- jnl = cbkdata;
- jnl_proc = jnl->jnl_proc;
+ jnl = cbkdata;
+ jnl_proc = jnl->jnl_proc;
- gf_changelog_queue_journal (jnl_proc, event);
+ gf_changelog_queue_journal(jnl_proc, event);
}
void
-gf_changelog_journal_disconnect (void *xl, char *brick, void *data)
+gf_changelog_journal_disconnect(void *xl, char *brick, void *data)
{
- gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_journal_t *jnl = NULL;
- jnl = data;
+ jnl = data;
- pthread_spin_lock (&jnl->lock);
- {
- JNL_SET_API_STATE (jnl, JNL_API_DISCONNECTED);
- };
- pthread_spin_unlock (&jnl->lock);
+ pthread_spin_lock(&jnl->lock);
+ {
+ JNL_SET_API_STATE(jnl, JNL_API_DISCONNECTED);
+ };
+ pthread_spin_unlock(&jnl->lock);
}
void
-gf_changelog_journal_connect (void *xl, char *brick, void *data)
+gf_changelog_journal_connect(void *xl, char *brick, void *data)
{
- gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_journal_t *jnl = NULL;
- jnl = data;
+ jnl = data;
- pthread_spin_lock (&jnl->lock);
- {
- JNL_SET_API_STATE (jnl, JNL_API_CONNECTED);
- };
- pthread_spin_unlock (&jnl->lock);
+ pthread_spin_lock(&jnl->lock);
+ {
+ JNL_SET_API_STATE(jnl, JNL_API_CONNECTED);
+ };
+ pthread_spin_unlock(&jnl->lock);
- return;
+ return;
}
void
-gf_changelog_cleanup_processor (gf_changelog_journal_t *jnl)
+gf_changelog_cleanup_processor(gf_changelog_journal_t *jnl)
{
- int ret = 0;
- xlator_t *this = NULL;
- gf_changelog_processor_t *jnl_proc = NULL;
-
- this = THIS;
- if (!this || !jnl || !jnl->jnl_proc)
- goto error_return;
-
- jnl_proc = jnl->jnl_proc;
-
- ret = gf_thread_cleanup (this, jnl_proc->processor);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_CLEANUP_ERROR,
- "failed to cleanup processor thread");
- goto error_return;
- }
+ int ret = 0;
+ xlator_t *this = NULL;
+ gf_changelog_processor_t *jnl_proc = NULL;
- (void)pthread_mutex_destroy (&jnl_proc->lock);
- (void)pthread_cond_destroy (&jnl_proc->cond);
+ this = THIS;
+ if (!this || !jnl || !jnl->jnl_proc)
+ goto error_return;
- GF_FREE (jnl_proc);
+ jnl_proc = jnl->jnl_proc;
- error_return:
- return;
+ ret = gf_thread_cleanup(this, jnl_proc->processor);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_CLEANUP_ERROR,
+ "failed to cleanup processor thread");
+ goto error_return;
+ }
+
+ (void)pthread_mutex_destroy(&jnl_proc->lock);
+ (void)pthread_cond_destroy(&jnl_proc->cond);
+
+ GF_FREE(jnl_proc);
+
+error_return:
+ return;
}
int
-gf_changelog_init_processor (gf_changelog_journal_t *jnl)
+gf_changelog_init_processor(gf_changelog_journal_t *jnl)
{
- int ret = -1;
- gf_changelog_processor_t *jnl_proc = NULL;
+ int ret = -1;
+ gf_changelog_processor_t *jnl_proc = NULL;
- jnl_proc = GF_CALLOC (1, sizeof (gf_changelog_processor_t),
- gf_changelog_mt_libgfchangelog_t);
- if (!jnl_proc)
- goto error_return;
-
- ret = pthread_mutex_init (&jnl_proc->lock, NULL);
- if (ret != 0)
- goto free_jnl_proc;
- ret = pthread_cond_init (&jnl_proc->cond, NULL);
- if (ret != 0)
- goto cleanup_mutex;
-
- INIT_LIST_HEAD (&jnl_proc->entries);
- jnl_proc->waiting = _gf_false;
- jnl->jnl_proc = jnl_proc;
-
- ret = gf_thread_create (&jnl_proc->processor,
- NULL, gf_changelog_process, jnl, "clogproc");
- if (ret != 0) {
- jnl->jnl_proc = NULL;
- goto cleanup_cond;
- }
+ jnl_proc = GF_CALLOC(1, sizeof(gf_changelog_processor_t),
+ gf_changelog_mt_libgfchangelog_t);
+ if (!jnl_proc)
+ goto error_return;
+
+ ret = pthread_mutex_init(&jnl_proc->lock, NULL);
+ if (ret != 0)
+ goto free_jnl_proc;
+ ret = pthread_cond_init(&jnl_proc->cond, NULL);
+ if (ret != 0)
+ goto cleanup_mutex;
+
+ INIT_LIST_HEAD(&jnl_proc->entries);
+ jnl_proc->waiting = _gf_false;
+ jnl->jnl_proc = jnl_proc;
+
+ ret = gf_thread_create(&jnl_proc->processor, NULL, gf_changelog_process,
+ jnl, "clogproc");
+ if (ret != 0) {
+ jnl->jnl_proc = NULL;
+ goto cleanup_cond;
+ }
- return 0;
+ return 0;
- cleanup_cond:
- (void) pthread_cond_destroy (&jnl_proc->cond);
- cleanup_mutex:
- (void) pthread_mutex_destroy (&jnl_proc->lock);
- free_jnl_proc:
- GF_FREE (jnl_proc);
- error_return:
- return -1;
+cleanup_cond:
+ (void)pthread_cond_destroy(&jnl_proc->cond);
+cleanup_mutex:
+ (void)pthread_mutex_destroy(&jnl_proc->lock);
+free_jnl_proc:
+ GF_FREE(jnl_proc);
+error_return:
+ return -1;
}
static void
-gf_changelog_cleanup_fds (gf_changelog_journal_t *jnl)
+gf_changelog_cleanup_fds(gf_changelog_journal_t *jnl)
{
- /* tracker fd */
- if (jnl->jnl_fd != -1)
- sys_close (jnl->jnl_fd);
- /* processing dir */
- if (jnl->jnl_dir)
- sys_closedir (jnl->jnl_dir);
-
- if (jnl->jnl_working_dir)
- free (jnl->jnl_working_dir); /* allocated by realpath */
+ /* tracker fd */
+ if (jnl->jnl_fd != -1)
+ sys_close(jnl->jnl_fd);
+ /* processing dir */
+ if (jnl->jnl_dir)
+ sys_closedir(jnl->jnl_dir);
+
+ if (jnl->jnl_working_dir)
+ free(jnl->jnl_working_dir); /* allocated by realpath */
}
static int
-gf_changelog_open_dirs (xlator_t *this, gf_changelog_journal_t *jnl)
+gf_changelog_open_dirs(xlator_t *this, gf_changelog_journal_t *jnl)
{
- int ret = -1;
- DIR *dir = NULL;
- int tracker_fd = 0;
- char tracker_path[PATH_MAX] = {0,};
-
- /* .current */
- (void) snprintf (jnl->jnl_current_dir, PATH_MAX,
- "%s/"GF_CHANGELOG_CURRENT_DIR"/",
- jnl->jnl_working_dir);
- ret = recursive_rmdir (jnl->jnl_current_dir);
- if (ret) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_FAILED_TO_RMDIR,
- "Failed to rmdir",
- "path=%s", jnl->jnl_current_dir,
- NULL);
- goto out;
- }
- ret = mkdir_p (jnl->jnl_current_dir, 0600, _gf_false);
- if (ret)
- goto out;
+ int ret = -1;
+ DIR *dir = NULL;
+ int tracker_fd = 0;
+ char tracker_path[PATH_MAX] = {
+ 0,
+ };
+
+ /* .current */
+ (void)snprintf(jnl->jnl_current_dir, PATH_MAX,
+ "%s/" GF_CHANGELOG_CURRENT_DIR "/", jnl->jnl_working_dir);
+ ret = recursive_rmdir(jnl->jnl_current_dir);
+ if (ret) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_FAILED_TO_RMDIR, "Failed to rmdir", "path=%s",
+ jnl->jnl_current_dir, NULL);
+ goto out;
+ }
+ ret = mkdir_p(jnl->jnl_current_dir, 0600, _gf_false);
+ if (ret)
+ goto out;
+
+ /* .processed */
+ (void)snprintf(jnl->jnl_processed_dir, PATH_MAX,
+ "%s/" GF_CHANGELOG_PROCESSED_DIR "/", jnl->jnl_working_dir);
+ ret = mkdir_p(jnl->jnl_processed_dir, 0600, _gf_false);
+ if (ret)
+ goto out;
+
+ /* .processing */
+ (void)snprintf(jnl->jnl_processing_dir, PATH_MAX,
+ "%s/" GF_CHANGELOG_PROCESSING_DIR "/", jnl->jnl_working_dir);
+ ret = recursive_rmdir(jnl->jnl_processing_dir);
+ if (ret) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_FAILED_TO_RMDIR, "Failed to rmdir", "path=%s",
+ jnl->jnl_processing_dir, NULL);
+ goto out;
+ }
- /* .processed */
- (void) snprintf (jnl->jnl_processed_dir, PATH_MAX,
- "%s/"GF_CHANGELOG_PROCESSED_DIR"/",
- jnl->jnl_working_dir);
- ret = mkdir_p (jnl->jnl_processed_dir, 0600, _gf_false);
- if (ret)
- goto out;
-
- /* .processing */
- (void) snprintf (jnl->jnl_processing_dir, PATH_MAX,
- "%s/"GF_CHANGELOG_PROCESSING_DIR"/",
- jnl->jnl_working_dir);
- ret = recursive_rmdir (jnl->jnl_processing_dir);
- if (ret) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_FAILED_TO_RMDIR,
- "Failed to rmdir",
- "path=%s", jnl->jnl_processing_dir,
- NULL);
- goto out;
- }
+ ret = mkdir_p(jnl->jnl_processing_dir, 0600, _gf_false);
+ if (ret)
+ goto out;
- ret = mkdir_p (jnl->jnl_processing_dir, 0600, _gf_false);
- if (ret)
- goto out;
-
- dir = sys_opendir (jnl->jnl_processing_dir);
- if (!dir) {
- gf_msg ("", GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_OPENDIR_ERROR,
- "opendir() error");
- goto out;
- }
+ dir = sys_opendir(jnl->jnl_processing_dir);
+ if (!dir) {
+ gf_msg("", GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_OPENDIR_ERROR,
+ "opendir() error");
+ goto out;
+ }
- jnl->jnl_dir = dir;
+ jnl->jnl_dir = dir;
- (void) snprintf (tracker_path, PATH_MAX,
- "%s/"GF_CHANGELOG_TRACKER, jnl->jnl_working_dir);
+ (void)snprintf(tracker_path, PATH_MAX, "%s/" GF_CHANGELOG_TRACKER,
+ jnl->jnl_working_dir);
- tracker_fd = open (tracker_path, O_CREAT | O_APPEND | O_RDWR,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (tracker_fd < 0) {
- sys_closedir (jnl->jnl_dir);
- ret = -1;
- goto out;
- }
+ tracker_fd = open(tracker_path, O_CREAT | O_APPEND | O_RDWR,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (tracker_fd < 0) {
+ sys_closedir(jnl->jnl_dir);
+ ret = -1;
+ goto out;
+ }
- jnl->jnl_fd = tracker_fd;
- ret = 0;
- out:
- return ret;
+ jnl->jnl_fd = tracker_fd;
+ ret = 0;
+out:
+ return ret;
}
int
-gf_changelog_init_history (xlator_t *this,
- gf_changelog_journal_t *jnl,
- char *brick_path)
+gf_changelog_init_history(xlator_t *this, gf_changelog_journal_t *jnl,
+ char *brick_path)
{
- int i = 0;
- int ret = 0;
- char hist_scratch_dir[PATH_MAX] = {0,};
+ int i = 0;
+ int ret = 0;
+ char hist_scratch_dir[PATH_MAX] = {
+ 0,
+ };
- jnl->hist_jnl = GF_CALLOC (1, sizeof (*jnl),
- gf_changelog_mt_libgfchangelog_t);
- if (!jnl->hist_jnl)
- goto error_return;
+ jnl->hist_jnl = GF_CALLOC(1, sizeof(*jnl),
+ gf_changelog_mt_libgfchangelog_t);
+ if (!jnl->hist_jnl)
+ goto error_return;
- jnl->hist_jnl->jnl_dir = NULL;
- jnl->hist_jnl->jnl_fd = -1;
+ jnl->hist_jnl->jnl_dir = NULL;
+ jnl->hist_jnl->jnl_fd = -1;
- (void) snprintf (hist_scratch_dir, PATH_MAX,
- "%s/"GF_CHANGELOG_HISTORY_DIR"/",
- jnl->jnl_working_dir);
+ (void)snprintf(hist_scratch_dir, PATH_MAX,
+ "%s/" GF_CHANGELOG_HISTORY_DIR "/", jnl->jnl_working_dir);
- ret = mkdir_p (hist_scratch_dir, 0600, _gf_false);
- if (ret)
- goto dealloc_hist;
-
- jnl->hist_jnl->jnl_working_dir = realpath (hist_scratch_dir, NULL);
- if (!jnl->hist_jnl->jnl_working_dir)
- goto dealloc_hist;
-
- ret = gf_changelog_open_dirs (this, jnl->hist_jnl);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_OPENDIR_ERROR,
- "could not create entries in history scratch dir");
- goto dealloc_hist;
- }
+ ret = mkdir_p(hist_scratch_dir, 0600, _gf_false);
+ if (ret)
+ goto dealloc_hist;
- if (snprintf (jnl->hist_jnl->jnl_brickpath, PATH_MAX, "%s",
- brick_path) >= PATH_MAX)
- goto dealloc_hist;
+ jnl->hist_jnl->jnl_working_dir = realpath(hist_scratch_dir, NULL);
+ if (!jnl->hist_jnl->jnl_working_dir)
+ goto dealloc_hist;
- for (i = 0; i < 256; i++) {
- jnl->hist_jnl->rfc3986_space_newline[i] =
- (i == ' ' || i == '\n' || i == '%') ? 0 : i;
- }
+ ret = gf_changelog_open_dirs(this, jnl->hist_jnl);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_OPENDIR_ERROR,
+ "could not create entries in history scratch dir");
+ goto dealloc_hist;
+ }
- return 0;
+ if (snprintf(jnl->hist_jnl->jnl_brickpath, PATH_MAX, "%s", brick_path) >=
+ PATH_MAX)
+ goto dealloc_hist;
- dealloc_hist:
- GF_FREE (jnl->hist_jnl);
- jnl->hist_jnl = NULL;
- error_return:
- return -1;
+ for (i = 0; i < 256; i++) {
+ jnl->hist_jnl->rfc3986_space_newline[i] = (i == ' ' || i == '\n' ||
+ i == '%')
+ ? 0
+ : i;
+ }
+
+ return 0;
+
+dealloc_hist:
+ GF_FREE(jnl->hist_jnl);
+ jnl->hist_jnl = NULL;
+error_return:
+ return -1;
}
void
-gf_changelog_journal_fini (void *xl, char *brick, void *data)
+gf_changelog_journal_fini(void *xl, char *brick, void *data)
{
- gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_journal_t *jnl = NULL;
- jnl = data;
+ jnl = data;
- gf_changelog_cleanup_processor (jnl);
+ gf_changelog_cleanup_processor(jnl);
- gf_changelog_cleanup_fds (jnl);
- if (jnl->hist_jnl)
- gf_changelog_cleanup_fds (jnl->hist_jnl);
+ gf_changelog_cleanup_fds(jnl);
+ if (jnl->hist_jnl)
+ gf_changelog_cleanup_fds(jnl->hist_jnl);
- GF_FREE (jnl);
+ GF_FREE(jnl);
}
void *
-gf_changelog_journal_init (void *xl, struct gf_brick_spec *brick)
+gf_changelog_journal_init(void *xl, struct gf_brick_spec *brick)
{
- int i = 0;
- int ret = 0;
- xlator_t *this = NULL;
- struct stat buf = {0,};
- char *scratch_dir = NULL;
- gf_changelog_journal_t *jnl = NULL;
-
- this = xl;
- scratch_dir = (char *) brick->ptr;
-
- jnl = GF_CALLOC (1, sizeof (gf_changelog_journal_t),
- gf_changelog_mt_libgfchangelog_t);
- if (!jnl)
- goto error_return;
-
- if (snprintf (jnl->jnl_brickpath, PATH_MAX, "%s",
- brick->brick_path) >= PATH_MAX)
- goto dealloc_private;
-
- if (sys_stat (scratch_dir, &buf) && errno == ENOENT) {
- ret = mkdir_p (scratch_dir, 0600, _gf_true);
- if (ret)
- goto dealloc_private;
- }
+ int i = 0;
+ int ret = 0;
+ xlator_t *this = NULL;
+ struct stat buf = {
+ 0,
+ };
+ char *scratch_dir = NULL;
+ gf_changelog_journal_t *jnl = NULL;
+
+ this = xl;
+ scratch_dir = (char *)brick->ptr;
+
+ jnl = GF_CALLOC(1, sizeof(gf_changelog_journal_t),
+ gf_changelog_mt_libgfchangelog_t);
+ if (!jnl)
+ goto error_return;
+
+ if (snprintf(jnl->jnl_brickpath, PATH_MAX, "%s", brick->brick_path) >=
+ PATH_MAX)
+ goto dealloc_private;
+
+ if (sys_stat(scratch_dir, &buf) && errno == ENOENT) {
+ ret = mkdir_p(scratch_dir, 0600, _gf_true);
+ if (ret)
+ goto dealloc_private;
+ }
- jnl->jnl_working_dir = realpath (scratch_dir, NULL);
- if (!jnl->jnl_working_dir)
- goto dealloc_private;
+ jnl->jnl_working_dir = realpath(scratch_dir, NULL);
+ if (!jnl->jnl_working_dir)
+ goto dealloc_private;
- ret = gf_changelog_open_dirs (this, jnl);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_OPENDIR_ERROR,
- "could not create entries in scratch dir");
- goto dealloc_private;
- }
-
- /* RFC 3986 {de,en}coding */
- for (i = 0; i < 256; i++) {
- jnl->rfc3986_space_newline[i] =
- (i == ' ' || i == '\n' || i == '%') ? 0 : i;
- }
+ ret = gf_changelog_open_dirs(this, jnl);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_OPENDIR_ERROR,
+ "could not create entries in scratch dir");
+ goto dealloc_private;
+ }
- ret = gf_changelog_init_history (this, jnl, brick->brick_path);
- if (ret)
- goto cleanup_fds;
+ /* RFC 3986 {de,en}coding */
+ for (i = 0; i < 256; i++) {
+ jnl->rfc3986_space_newline[i] = (i == ' ' || i == '\n' || i == '%') ? 0
+ : i;
+ }
- /* initialize journal processor */
- jnl->this = this;
- ret = gf_changelog_init_processor (jnl);
- if (ret)
- goto cleanup_fds;
-
- JNL_SET_API_STATE (jnl, JNL_API_CONN_INPROGESS);
- ret = pthread_spin_init (&jnl->lock, 0);
- if (ret != 0)
- goto cleanup_processor;
- return jnl;
-
- cleanup_processor:
- gf_changelog_cleanup_processor (jnl);
- cleanup_fds:
- gf_changelog_cleanup_fds (jnl);
- if (jnl->hist_jnl)
- gf_changelog_cleanup_fds (jnl->hist_jnl);
- dealloc_private:
- GF_FREE (jnl);
- error_return:
- return NULL;
+ ret = gf_changelog_init_history(this, jnl, brick->brick_path);
+ if (ret)
+ goto cleanup_fds;
+
+ /* initialize journal processor */
+ jnl->this = this;
+ ret = gf_changelog_init_processor(jnl);
+ if (ret)
+ goto cleanup_fds;
+
+ JNL_SET_API_STATE(jnl, JNL_API_CONN_INPROGESS);
+ ret = pthread_spin_init(&jnl->lock, 0);
+ if (ret != 0)
+ goto cleanup_processor;
+ return jnl;
+
+cleanup_processor:
+ gf_changelog_cleanup_processor(jnl);
+cleanup_fds:
+ gf_changelog_cleanup_fds(jnl);
+ if (jnl->hist_jnl)
+ gf_changelog_cleanup_fds(jnl->hist_jnl);
+dealloc_private:
+ GF_FREE(jnl);
+error_return:
+ return NULL;
}
diff --git a/xlators/features/changelog/lib/src/gf-changelog-reborp.c b/xlators/features/changelog/lib/src/gf-changelog-reborp.c
index f9fb8fcf01a..8dfda4c79c5 100644
--- a/xlators/features/changelog/lib/src/gf-changelog-reborp.c
+++ b/xlators/features/changelog/lib/src/gf-changelog-reborp.c
@@ -25,133 +25,121 @@
struct rpcsvc_program *gf_changelog_reborp_programs[];
void *
-gf_changelog_connection_janitor (void *arg)
+gf_changelog_connection_janitor(void *arg)
{
- int32_t ret = 0;
- xlator_t *this = NULL;
- gf_private_t *priv = NULL;
- gf_changelog_t *entry = NULL;
- struct gf_event *event = NULL;
- struct gf_event_list *ev = NULL;
- unsigned long drained = 0;
-
- this = arg;
- THIS = this;
-
- priv = this->private;
-
- while (1) {
- pthread_mutex_lock (&priv->lock);
- {
- while (list_empty (&priv->cleanups))
- pthread_cond_wait (&priv->cond, &priv->lock);
-
- entry = list_first_entry (&priv->cleanups,
- gf_changelog_t, list);
- list_del_init (&entry->list);
- }
- pthread_mutex_unlock (&priv->lock);
-
- drained = 0;
- ev = &entry->event;
-
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_LIB_MSG_CLEANING_BRICK_ENTRY_INFO,
- "Cleaning brick entry for brick",
- "brick=%s", entry->brick,
- NULL);
-
- /* 0x0: disable rpc-clnt */
- rpc_clnt_disable (RPC_PROBER (entry));
-
- /* 0x1: cleanup callback invoker thread */
- ret = gf_cleanup_event (this, ev);
- if (ret)
- continue;
-
- /* 0x2: drain pending events */
- while (!list_empty (&ev->events)) {
- event = list_first_entry (&ev->events,
- struct gf_event, list);
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_LIB_MSG_DRAINING_EVENT_INFO,
- "Draining event",
- "seq=%lu", event->seq,
- "payload=%d", event->count,
- NULL);
-
- GF_FREE (event);
- drained++;
- }
-
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_LIB_MSG_DRAINING_EVENT_INFO,
- "Drained events",
- "num=%lu", drained,
- NULL);
-
- /* 0x3: freeup brick entry */
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_LIB_MSG_FREEING_ENTRY_INFO,
- "freeing entry",
- "entry=%p", entry,
- NULL);
- LOCK_DESTROY (&entry->statelock);
- GF_FREE (entry);
+ int32_t ret = 0;
+ xlator_t *this = NULL;
+ gf_private_t *priv = NULL;
+ gf_changelog_t *entry = NULL;
+ struct gf_event *event = NULL;
+ struct gf_event_list *ev = NULL;
+ unsigned long drained = 0;
+
+ this = arg;
+ THIS = this;
+
+ priv = this->private;
+
+ while (1) {
+ pthread_mutex_lock(&priv->lock);
+ {
+ while (list_empty(&priv->cleanups))
+ pthread_cond_wait(&priv->cond, &priv->lock);
+
+ entry = list_first_entry(&priv->cleanups, gf_changelog_t, list);
+ list_del_init(&entry->list);
+ }
+ pthread_mutex_unlock(&priv->lock);
+
+ drained = 0;
+ ev = &entry->event;
+
+ gf_smsg(this->name, GF_LOG_INFO, 0,
+ CHANGELOG_LIB_MSG_CLEANING_BRICK_ENTRY_INFO,
+ "Cleaning brick entry for brick", "brick=%s", entry->brick,
+ NULL);
+
+ /* 0x0: disable rpc-clnt */
+ rpc_clnt_disable(RPC_PROBER(entry));
+
+ /* 0x1: cleanup callback invoker thread */
+ ret = gf_cleanup_event(this, ev);
+ if (ret)
+ continue;
+
+ /* 0x2: drain pending events */
+ while (!list_empty(&ev->events)) {
+ event = list_first_entry(&ev->events, struct gf_event, list);
+ gf_smsg(this->name, GF_LOG_INFO, 0,
+ CHANGELOG_LIB_MSG_DRAINING_EVENT_INFO, "Draining event",
+ "seq=%lu", event->seq, "payload=%d", event->count, NULL);
+
+ GF_FREE(event);
+ drained++;
}
- return NULL;
+ gf_smsg(this->name, GF_LOG_INFO, 0,
+ CHANGELOG_LIB_MSG_DRAINING_EVENT_INFO, "Drained events",
+ "num=%lu", drained, NULL);
+
+ /* 0x3: freeup brick entry */
+ gf_smsg(this->name, GF_LOG_INFO, 0,
+ CHANGELOG_LIB_MSG_FREEING_ENTRY_INFO, "freeing entry",
+ "entry=%p", entry, NULL);
+ LOCK_DESTROY(&entry->statelock);
+ GF_FREE(entry);
+ }
+
+ return NULL;
}
int
-gf_changelog_reborp_rpcsvc_notify (rpcsvc_t *rpc, void *mydata,
- rpcsvc_event_t event, void *data)
+gf_changelog_reborp_rpcsvc_notify(rpcsvc_t *rpc, void *mydata,
+ rpcsvc_event_t event, void *data)
{
- int ret = 0;
- xlator_t *this = NULL;
- gf_changelog_t *entry = NULL;
+ int ret = 0;
+ xlator_t *this = NULL;
+ gf_changelog_t *entry = NULL;
- if (!(event == RPCSVC_EVENT_ACCEPT ||
- event == RPCSVC_EVENT_DISCONNECT))
- return 0;
+ if (!(event == RPCSVC_EVENT_ACCEPT || event == RPCSVC_EVENT_DISCONNECT))
+ return 0;
- entry = mydata;
- this = entry->this;
+ entry = mydata;
+ this = entry->this;
- switch (event) {
+ switch (event) {
case RPCSVC_EVENT_ACCEPT:
- ret = sys_unlink (RPC_SOCK(entry));
- if (ret != 0)
- gf_smsg (this->name, GF_LOG_WARNING, errno,
- CHANGELOG_LIB_MSG_UNLINK_FAILED,
- "failed to unlink "
- "reverse socket",
- "path=%s", RPC_SOCK (entry),
- NULL);
- if (entry->connected)
- GF_CHANGELOG_INVOKE_CBK (this, entry->connected,
- entry->brick, entry->ptr);
- break;
+ ret = sys_unlink(RPC_SOCK(entry));
+ if (ret != 0)
+ gf_smsg(this->name, GF_LOG_WARNING, errno,
+ CHANGELOG_LIB_MSG_UNLINK_FAILED,
+ "failed to unlink "
+ "reverse socket",
+ "path=%s", RPC_SOCK(entry), NULL);
+ if (entry->connected)
+ GF_CHANGELOG_INVOKE_CBK(this, entry->connected, entry->brick,
+ entry->ptr);
+ break;
case RPCSVC_EVENT_DISCONNECT:
- if (entry->disconnected)
- GF_CHANGELOG_INVOKE_CBK (this, entry->disconnected,
- entry->brick, entry->ptr);
- /* passthrough */
+ if (entry->disconnected)
+ GF_CHANGELOG_INVOKE_CBK(this, entry->disconnected, entry->brick,
+ entry->ptr);
+ /* passthrough */
default:
- break;
- }
+ break;
+ }
- return 0;
+ return 0;
}
rpcsvc_t *
-gf_changelog_reborp_init_rpc_listner (xlator_t *this,
- char *path, char *sock, void *cbkdata)
+gf_changelog_reborp_init_rpc_listner(xlator_t *this, char *path, char *sock,
+ void *cbkdata)
{
- CHANGELOG_MAKE_TMP_SOCKET_PATH (path, sock, UNIX_PATH_MAX);
- return changelog_rpc_server_init (this, sock, cbkdata,
- gf_changelog_reborp_rpcsvc_notify,
- gf_changelog_reborp_programs);
+ CHANGELOG_MAKE_TMP_SOCKET_PATH(path, sock, UNIX_PATH_MAX);
+ return changelog_rpc_server_init(this, sock, cbkdata,
+ gf_changelog_reborp_rpcsvc_notify,
+ gf_changelog_reborp_programs);
}
/**
@@ -164,29 +152,27 @@ gf_changelog_reborp_init_rpc_listner (xlator_t *this,
* @FIXME: cleanup this bugger once server filters events.
*/
void
-gf_changelog_invoke_callback (gf_changelog_t *entry,
- struct iovec **vec, int payloadcnt)
+gf_changelog_invoke_callback(gf_changelog_t *entry, struct iovec **vec,
+ int payloadcnt)
{
- int i = 0;
- int evsize = 0;
- xlator_t *this = NULL;
- changelog_event_t *event = NULL;
-
- this = entry->this;
-
- for (; i < payloadcnt; i++) {
- event = (changelog_event_t *)vec[i]->iov_base;
- evsize = vec[i]->iov_len / CHANGELOG_EV_SIZE;
-
- for (; evsize > 0; evsize--, event++) {
- if (gf_changelog_filter_check (entry, event)) {
- GF_CHANGELOG_INVOKE_CBK (this,
- entry->callback,
- entry->brick,
- entry->ptr, event);
- }
- }
+ int i = 0;
+ int evsize = 0;
+ xlator_t *this = NULL;
+ changelog_event_t *event = NULL;
+
+ this = entry->this;
+
+ for (; i < payloadcnt; i++) {
+ event = (changelog_event_t *)vec[i]->iov_base;
+ evsize = vec[i]->iov_len / CHANGELOG_EV_SIZE;
+
+ for (; evsize > 0; evsize--, event++) {
+ if (gf_changelog_filter_check(entry, event)) {
+ GF_CHANGELOG_INVOKE_CBK(this, entry->callback, entry->brick,
+ entry->ptr, event);
+ }
}
+ }
}
/**
@@ -197,218 +183,217 @@ gf_changelog_invoke_callback (gf_changelog_t *entry,
*/
int
-__is_expected_sequence (struct gf_event_list *ev, struct gf_event *event)
+__is_expected_sequence(struct gf_event_list *ev, struct gf_event *event)
{
- return (ev->next_seq == event->seq);
+ return (ev->next_seq == event->seq);
}
int
-__can_process_event (struct gf_event_list *ev, struct gf_event **event)
+__can_process_event(struct gf_event_list *ev, struct gf_event **event)
{
- *event = list_first_entry (&ev->events, struct gf_event, list);
+ *event = list_first_entry(&ev->events, struct gf_event, list);
- if (__is_expected_sequence (ev, *event)) {
- list_del (&(*event)->list);
- ev->next_seq++;
- return 1;
- }
+ if (__is_expected_sequence(ev, *event)) {
+ list_del(&(*event)->list);
+ ev->next_seq++;
+ return 1;
+ }
- return 0;
+ return 0;
}
void
-pick_event_ordered (struct gf_event_list *ev, struct gf_event **event)
+pick_event_ordered(struct gf_event_list *ev, struct gf_event **event)
{
- pthread_mutex_lock (&ev->lock);
- {
- while (list_empty (&ev->events)
- || !__can_process_event (ev, event))
- pthread_cond_wait (&ev->cond, &ev->lock);
- }
- pthread_mutex_unlock (&ev->lock);
+ pthread_mutex_lock(&ev->lock);
+ {
+ while (list_empty(&ev->events) || !__can_process_event(ev, event))
+ pthread_cond_wait(&ev->cond, &ev->lock);
+ }
+ pthread_mutex_unlock(&ev->lock);
}
void
-pick_event_unordered (struct gf_event_list *ev, struct gf_event **event)
+pick_event_unordered(struct gf_event_list *ev, struct gf_event **event)
{
- pthread_mutex_lock (&ev->lock);
- {
- while (list_empty (&ev->events))
- pthread_cond_wait (&ev->cond, &ev->lock);
- *event = list_first_entry (&ev->events, struct gf_event, list);
- list_del (&(*event)->list);
- }
- pthread_mutex_unlock (&ev->lock);
+ pthread_mutex_lock(&ev->lock);
+ {
+ while (list_empty(&ev->events))
+ pthread_cond_wait(&ev->cond, &ev->lock);
+ *event = list_first_entry(&ev->events, struct gf_event, list);
+ list_del(&(*event)->list);
+ }
+ pthread_mutex_unlock(&ev->lock);
}
void *
-gf_changelog_callback_invoker (void *arg)
+gf_changelog_callback_invoker(void *arg)
{
- xlator_t *this = NULL;
- gf_changelog_t *entry = NULL;
- struct iovec *vec = NULL;
- struct gf_event *event = NULL;
- struct gf_event_list *ev = NULL;
+ xlator_t *this = NULL;
+ gf_changelog_t *entry = NULL;
+ struct iovec *vec = NULL;
+ struct gf_event *event = NULL;
+ struct gf_event_list *ev = NULL;
- ev = arg;
- entry = ev->entry;
- THIS = this = entry->this;
+ ev = arg;
+ entry = ev->entry;
+ THIS = this = entry->this;
- while (1) {
- entry->pickevent (ev, &event);
+ while (1) {
+ entry->pickevent(ev, &event);
- vec = (struct iovec *) &event->iov;
- gf_changelog_invoke_callback (entry, &vec, event->count);
+ vec = (struct iovec *)&event->iov;
+ gf_changelog_invoke_callback(entry, &vec, event->count);
- GF_FREE (event);
- }
+ GF_FREE(event);
+ }
- return NULL;
+ return NULL;
}
static int
-orderfn (struct list_head *pos1, struct list_head *pos2)
+orderfn(struct list_head *pos1, struct list_head *pos2)
{
- struct gf_event *event1 = NULL;
- struct gf_event *event2 = NULL;
+ struct gf_event *event1 = NULL;
+ struct gf_event *event2 = NULL;
- event1 = list_entry (pos1, struct gf_event, list);
- event2 = list_entry (pos2, struct gf_event, list);
+ event1 = list_entry(pos1, struct gf_event, list);
+ event2 = list_entry(pos2, struct gf_event, list);
- if (event1->seq > event2->seq)
- return 1;
- return -1;
+ if (event1->seq > event2->seq)
+ return 1;
+ return -1;
}
void
-queue_ordered_event (struct gf_event_list *ev, struct gf_event *event)
+queue_ordered_event(struct gf_event_list *ev, struct gf_event *event)
{
- /* add event to the ordered event list and wake up listener(s) */
- pthread_mutex_lock (&ev->lock);
- {
- list_add_order (&event->list, &ev->events, orderfn);
- if (!ev->next_seq)
- ev->next_seq = event->seq;
- if (ev->next_seq == event->seq)
- pthread_cond_signal (&ev->cond);
- }
- pthread_mutex_unlock (&ev->lock);
+ /* add event to the ordered event list and wake up listener(s) */
+ pthread_mutex_lock(&ev->lock);
+ {
+ list_add_order(&event->list, &ev->events, orderfn);
+ if (!ev->next_seq)
+ ev->next_seq = event->seq;
+ if (ev->next_seq == event->seq)
+ pthread_cond_signal(&ev->cond);
+ }
+ pthread_mutex_unlock(&ev->lock);
}
void
-queue_unordered_event (struct gf_event_list *ev, struct gf_event *event)
+queue_unordered_event(struct gf_event_list *ev, struct gf_event *event)
{
- /* add event to the tail of the queue and wake up listener(s) */
- pthread_mutex_lock (&ev->lock);
- {
- list_add_tail (&event->list, &ev->events);
- pthread_cond_signal (&ev->cond);
- }
- pthread_mutex_unlock (&ev->lock);
+ /* add event to the tail of the queue and wake up listener(s) */
+ pthread_mutex_lock(&ev->lock);
+ {
+ list_add_tail(&event->list, &ev->events);
+ pthread_cond_signal(&ev->cond);
+ }
+ pthread_mutex_unlock(&ev->lock);
}
int
-gf_changelog_event_handler (rpcsvc_request_t *req,
- xlator_t *this, gf_changelog_t *entry)
+gf_changelog_event_handler(rpcsvc_request_t *req, xlator_t *this,
+ gf_changelog_t *entry)
{
- int i = 0;
- size_t payloadlen = 0;
- ssize_t len = 0;
- int payloadcnt = 0;
- changelog_event_req rpc_req = {0,};
- changelog_event_rsp rpc_rsp = {0,};
- struct iovec *vec = NULL;
- struct gf_event *event = NULL;
- struct gf_event_list *ev = NULL;
-
- ev = &entry->event;
-
- len = xdr_to_generic (req->msg[0],
- &rpc_req, (xdrproc_t)xdr_changelog_event_req);
- if (len < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_XDR_DECODING_FAILED,
- "xdr decoding failed");
- req->rpc_err = GARBAGE_ARGS;
- goto handle_xdr_error;
- }
-
- if (len < req->msg[0].iov_len) {
- payloadcnt = 1;
- payloadlen = (req->msg[0].iov_len - len);
- }
- for (i = 1; i < req->count; i++) {
- payloadcnt++;
- payloadlen += req->msg[i].iov_len;
- }
-
- event = GF_CALLOC (1, GF_EVENT_CALLOC_SIZE (payloadcnt, payloadlen),
- gf_changelog_mt_libgfchangelog_event_t);
- if (!event)
- goto handle_xdr_error;
- INIT_LIST_HEAD (&event->list);
-
- payloadlen = 0;
- event->seq = rpc_req.seq;
- event->count = payloadcnt;
-
- /* deep copy IO vectors */
- vec = &event->iov[0];
- GF_EVENT_ASSIGN_IOVEC (vec, event,
- (req->msg[0].iov_len - len), payloadlen);
- (void) memcpy (vec->iov_base,
- req->msg[0].iov_base + len, vec->iov_len);
-
- for (i = 1; i < req->count; i++) {
- vec = &event->iov[i];
- GF_EVENT_ASSIGN_IOVEC (vec, event,
- req->msg[i].iov_len, payloadlen);
- (void) memcpy (event->iov[i].iov_base,
- req->msg[i].iov_base, req->msg[i].iov_len);
- }
-
- gf_msg_debug (this->name, 0,
- "seq: %lu [%s] (time: %lu.%lu), (vec: %d, len: %zd)",
- rpc_req.seq, entry->brick, rpc_req.tv_sec,
- rpc_req.tv_usec, payloadcnt, payloadlen);
-
- /* dispatch event */
- entry->queueevent (ev, event);
-
- /* ack sequence number */
- rpc_rsp.op_ret = 0;
- rpc_rsp.seq = rpc_req.seq;
-
- goto submit_rpc;
-
- handle_xdr_error:
- rpc_rsp.op_ret = -1;
- rpc_rsp.seq = 0; /* invalid */
- submit_rpc:
- return changelog_rpc_sumbit_reply (req, &rpc_rsp, NULL, 0, NULL,
- (xdrproc_t)xdr_changelog_event_rsp);
+ int i = 0;
+ size_t payloadlen = 0;
+ ssize_t len = 0;
+ int payloadcnt = 0;
+ changelog_event_req rpc_req = {
+ 0,
+ };
+ changelog_event_rsp rpc_rsp = {
+ 0,
+ };
+ struct iovec *vec = NULL;
+ struct gf_event *event = NULL;
+ struct gf_event_list *ev = NULL;
+
+ ev = &entry->event;
+
+ len = xdr_to_generic(req->msg[0], &rpc_req,
+ (xdrproc_t)xdr_changelog_event_req);
+ if (len < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_LIB_MSG_XDR_DECODING_FAILED, "xdr decoding failed");
+ req->rpc_err = GARBAGE_ARGS;
+ goto handle_xdr_error;
+ }
+
+ if (len < req->msg[0].iov_len) {
+ payloadcnt = 1;
+ payloadlen = (req->msg[0].iov_len - len);
+ }
+ for (i = 1; i < req->count; i++) {
+ payloadcnt++;
+ payloadlen += req->msg[i].iov_len;
+ }
+
+ event = GF_CALLOC(1, GF_EVENT_CALLOC_SIZE(payloadcnt, payloadlen),
+ gf_changelog_mt_libgfchangelog_event_t);
+ if (!event)
+ goto handle_xdr_error;
+ INIT_LIST_HEAD(&event->list);
+
+ payloadlen = 0;
+ event->seq = rpc_req.seq;
+ event->count = payloadcnt;
+
+ /* deep copy IO vectors */
+ vec = &event->iov[0];
+ GF_EVENT_ASSIGN_IOVEC(vec, event, (req->msg[0].iov_len - len), payloadlen);
+ (void)memcpy(vec->iov_base, req->msg[0].iov_base + len, vec->iov_len);
+
+ for (i = 1; i < req->count; i++) {
+ vec = &event->iov[i];
+ GF_EVENT_ASSIGN_IOVEC(vec, event, req->msg[i].iov_len, payloadlen);
+ (void)memcpy(event->iov[i].iov_base, req->msg[i].iov_base,
+ req->msg[i].iov_len);
+ }
+
+ gf_msg_debug(this->name, 0,
+ "seq: %lu [%s] (time: %lu.%lu), (vec: %d, len: %zd)",
+ rpc_req.seq, entry->brick, rpc_req.tv_sec, rpc_req.tv_usec,
+ payloadcnt, payloadlen);
+
+ /* dispatch event */
+ entry->queueevent(ev, event);
+
+ /* ack sequence number */
+ rpc_rsp.op_ret = 0;
+ rpc_rsp.seq = rpc_req.seq;
+
+ goto submit_rpc;
+
+handle_xdr_error:
+ rpc_rsp.op_ret = -1;
+ rpc_rsp.seq = 0; /* invalid */
+submit_rpc:
+ return changelog_rpc_sumbit_reply(req, &rpc_rsp, NULL, 0, NULL,
+ (xdrproc_t)xdr_changelog_event_rsp);
}
int
-gf_changelog_reborp_handle_event (rpcsvc_request_t *req)
+gf_changelog_reborp_handle_event(rpcsvc_request_t *req)
{
- xlator_t *this = NULL;
- rpcsvc_t *svc = NULL;
- gf_changelog_t *entry = NULL;
+ xlator_t *this = NULL;
+ rpcsvc_t *svc = NULL;
+ gf_changelog_t *entry = NULL;
- svc = rpcsvc_request_service (req);
- entry = svc->mydata;
+ svc = rpcsvc_request_service(req);
+ entry = svc->mydata;
- this = THIS = entry->this;
+ this = THIS = entry->this;
- return gf_changelog_event_handler (req, this, entry);
+ return gf_changelog_event_handler(req, this, entry);
}
rpcsvc_actor_t gf_changelog_reborp_actors[CHANGELOG_REV_PROC_MAX] = {
- [CHANGELOG_REV_PROC_EVENT] = {
- "CHANGELOG EVENT HANDLER", CHANGELOG_REV_PROC_EVENT,
- gf_changelog_reborp_handle_event, NULL, 0, DRC_NA
- },
+ [CHANGELOG_REV_PROC_EVENT] = {"CHANGELOG EVENT HANDLER",
+ CHANGELOG_REV_PROC_EVENT,
+ gf_changelog_reborp_handle_event, NULL, 0,
+ DRC_NA},
};
/**
@@ -418,15 +403,15 @@ rpcsvc_actor_t gf_changelog_reborp_actors[CHANGELOG_REV_PROC_MAX] = {
* brick path and it's private data.
*/
struct rpcsvc_program gf_changelog_reborp_prog = {
- .progname = "LIBGFCHANGELOG REBORP",
- .prognum = CHANGELOG_REV_RPC_PROCNUM,
- .progver = CHANGELOG_REV_RPC_PROCVER,
- .numactors = CHANGELOG_REV_PROC_MAX,
- .actors = gf_changelog_reborp_actors,
- .synctask = _gf_false,
+ .progname = "LIBGFCHANGELOG REBORP",
+ .prognum = CHANGELOG_REV_RPC_PROCNUM,
+ .progver = CHANGELOG_REV_RPC_PROCVER,
+ .numactors = CHANGELOG_REV_PROC_MAX,
+ .actors = gf_changelog_reborp_actors,
+ .synctask = _gf_false,
};
struct rpcsvc_program *gf_changelog_reborp_programs[] = {
- &gf_changelog_reborp_prog,
- NULL,
+ &gf_changelog_reborp_prog,
+ NULL,
};
diff --git a/xlators/features/changelog/lib/src/gf-changelog-rpc.c b/xlators/features/changelog/lib/src/gf-changelog-rpc.c
index 7eb5416ae98..8ec6ffbcebc 100644
--- a/xlators/features/changelog/lib/src/gf-changelog-rpc.c
+++ b/xlators/features/changelog/lib/src/gf-changelog-rpc.c
@@ -16,31 +16,32 @@ struct rpc_clnt_program gf_changelog_clnt;
/* TODO: piggyback reconnect to called (upcall) */
int
-gf_changelog_rpc_notify (struct rpc_clnt *rpc,
- void *mydata, rpc_clnt_event_t event, void *data)
+gf_changelog_rpc_notify(struct rpc_clnt *rpc, void *mydata,
+ rpc_clnt_event_t event, void *data)
{
- switch (event) {
+ switch (event) {
case RPC_CLNT_CONNECT:
- break;
+ break;
case RPC_CLNT_DISCONNECT:
case RPC_CLNT_MSG:
case RPC_CLNT_DESTROY:
case RPC_CLNT_PING:
- break;
- }
+ break;
+ }
- return 0;
+ return 0;
}
struct rpc_clnt *
-gf_changelog_rpc_init (xlator_t *this, gf_changelog_t *entry)
+gf_changelog_rpc_init(xlator_t *this, gf_changelog_t *entry)
{
- char sockfile[UNIX_PATH_MAX] = {0,};
+ char sockfile[UNIX_PATH_MAX] = {
+ 0,
+ };
- CHANGELOG_MAKE_SOCKET_PATH (entry->brick,
- sockfile, UNIX_PATH_MAX);
- return changelog_rpc_client_init (this, entry,
- sockfile, gf_changelog_rpc_notify);
+ CHANGELOG_MAKE_SOCKET_PATH(entry->brick, sockfile, UNIX_PATH_MAX);
+ return changelog_rpc_client_init(this, entry, sockfile,
+ gf_changelog_rpc_notify);
}
/**
@@ -48,51 +49,50 @@ gf_changelog_rpc_init (xlator_t *this, gf_changelog_t *entry)
*/
int
-gf_probe_changelog_cbk (struct rpc_req *req,
- struct iovec *iovec, int count, void *myframe)
+gf_probe_changelog_cbk(struct rpc_req *req, struct iovec *iovec, int count,
+ void *myframe)
{
- return 0;
+ return 0;
}
int
-gf_probe_changelog_filter (call_frame_t *frame, xlator_t *this, void *data)
+gf_probe_changelog_filter(call_frame_t *frame, xlator_t *this, void *data)
{
- char *sock = NULL;
- gf_changelog_t *entry = NULL;
- changelog_probe_req req = {0,};
-
- entry = data;
- sock = RPC_SOCK (entry);
-
- (void) memcpy (&req.sock, sock, strlen (sock));
- req.filter = entry->notify;
-
- /* invoke RPC */
- return changelog_rpc_sumbit_req (RPC_PROBER (entry), (void *) &req,
- frame, &gf_changelog_clnt,
- CHANGELOG_RPC_PROBE_FILTER, NULL, 0,
- NULL, this, gf_probe_changelog_cbk,
- (xdrproc_t) xdr_changelog_probe_req);
+ char *sock = NULL;
+ gf_changelog_t *entry = NULL;
+ changelog_probe_req req = {
+ 0,
+ };
+
+ entry = data;
+ sock = RPC_SOCK(entry);
+
+ (void)memcpy(&req.sock, sock, strlen(sock));
+ req.filter = entry->notify;
+
+ /* invoke RPC */
+ return changelog_rpc_sumbit_req(
+ RPC_PROBER(entry), (void *)&req, frame, &gf_changelog_clnt,
+ CHANGELOG_RPC_PROBE_FILTER, NULL, 0, NULL, this, gf_probe_changelog_cbk,
+ (xdrproc_t)xdr_changelog_probe_req);
}
int
-gf_changelog_invoke_rpc (xlator_t *this, gf_changelog_t *entry, int procidx)
+gf_changelog_invoke_rpc(xlator_t *this, gf_changelog_t *entry, int procidx)
{
- return changelog_invoke_rpc (this, RPC_PROBER (entry),
- &gf_changelog_clnt, procidx, entry);
+ return changelog_invoke_rpc(this, RPC_PROBER(entry), &gf_changelog_clnt,
+ procidx, entry);
}
struct rpc_clnt_procedure gf_changelog_procs[CHANGELOG_RPC_PROC_MAX] = {
- [CHANGELOG_RPC_PROC_NULL] = {"NULL", NULL},
- [CHANGELOG_RPC_PROBE_FILTER] = {
- "PROBE FILTER", gf_probe_changelog_filter
- },
+ [CHANGELOG_RPC_PROC_NULL] = {"NULL", NULL},
+ [CHANGELOG_RPC_PROBE_FILTER] = {"PROBE FILTER", gf_probe_changelog_filter},
};
struct rpc_clnt_program gf_changelog_clnt = {
- .progname = "LIBGFCHANGELOG",
- .prognum = CHANGELOG_RPC_PROGNUM,
- .progver = CHANGELOG_RPC_PROGVER,
- .numproc = CHANGELOG_RPC_PROC_MAX,
- .proctable = gf_changelog_procs,
+ .progname = "LIBGFCHANGELOG",
+ .prognum = CHANGELOG_RPC_PROGNUM,
+ .progver = CHANGELOG_RPC_PROGVER,
+ .numproc = CHANGELOG_RPC_PROC_MAX,
+ .proctable = gf_changelog_procs,
};
diff --git a/xlators/features/changelog/lib/src/gf-changelog.c b/xlators/features/changelog/lib/src/gf-changelog.c
index 8198560e736..c7791c62950 100644
--- a/xlators/features/changelog/lib/src/gf-changelog.c
+++ b/xlators/features/changelog/lib/src/gf-changelog.c
@@ -45,291 +45,291 @@
*/
xlator_t *master = NULL;
-static inline
-gf_private_t *gf_changelog_alloc_priv ()
+static inline gf_private_t *
+gf_changelog_alloc_priv()
{
- int ret = 0;
- gf_private_t *priv = NULL;
-
- priv = GF_CALLOC (1, sizeof (*priv), gf_changelog_mt_priv_t);
- if (!priv)
- goto error_return;
- INIT_LIST_HEAD (&priv->connections);
- INIT_LIST_HEAD (&priv->cleanups);
-
- ret = pthread_mutex_init (&priv->lock, NULL);
- if (ret != 0)
- goto free_priv;
- ret = pthread_cond_init (&priv->cond, NULL);
- if (ret != 0)
- goto cleanup_mutex;
-
- priv->api = NULL;
- return priv;
-
- cleanup_mutex:
- (void) pthread_mutex_destroy (&priv->lock);
- free_priv:
- GF_FREE (priv);
- error_return:
- return NULL;
+ int ret = 0;
+ gf_private_t *priv = NULL;
+
+ priv = GF_CALLOC(1, sizeof(*priv), gf_changelog_mt_priv_t);
+ if (!priv)
+ goto error_return;
+ INIT_LIST_HEAD(&priv->connections);
+ INIT_LIST_HEAD(&priv->cleanups);
+
+ ret = pthread_mutex_init(&priv->lock, NULL);
+ if (ret != 0)
+ goto free_priv;
+ ret = pthread_cond_init(&priv->cond, NULL);
+ if (ret != 0)
+ goto cleanup_mutex;
+
+ priv->api = NULL;
+ return priv;
+
+cleanup_mutex:
+ (void)pthread_mutex_destroy(&priv->lock);
+free_priv:
+ GF_FREE(priv);
+error_return:
+ return NULL;
}
-#define GF_CHANGELOG_EVENT_POOL_SIZE 16384
+#define GF_CHANGELOG_EVENT_POOL_SIZE 16384
#define GF_CHANGELOG_EVENT_THREAD_COUNT 4
static int
-gf_changelog_ctx_defaults_init (glusterfs_ctx_t *ctx)
+gf_changelog_ctx_defaults_init(glusterfs_ctx_t *ctx)
{
- cmd_args_t *cmd_args = NULL;
- struct rlimit lim = {0, };
- call_pool_t *pool = NULL;
- int ret = -1;
-
- ret = xlator_mem_acct_init (THIS, gf_changelog_mt_end);
- if (ret != 0)
- return -1;
+ cmd_args_t *cmd_args = NULL;
+ struct rlimit lim = {
+ 0,
+ };
+ call_pool_t *pool = NULL;
+ int ret = -1;
+
+ ret = xlator_mem_acct_init(THIS, gf_changelog_mt_end);
+ if (ret != 0)
+ return -1;
- ctx->process_uuid = generate_glusterfs_ctx_id ();
- if (!ctx->process_uuid)
- return -1;
+ ctx->process_uuid = generate_glusterfs_ctx_id();
+ if (!ctx->process_uuid)
+ return -1;
- ctx->page_size = 128 * GF_UNIT_KB;
+ ctx->page_size = 128 * GF_UNIT_KB;
- ctx->iobuf_pool = iobuf_pool_new ();
- if (!ctx->iobuf_pool)
- return -1;
+ ctx->iobuf_pool = iobuf_pool_new();
+ if (!ctx->iobuf_pool)
+ return -1;
- ctx->event_pool = event_pool_new (GF_CHANGELOG_EVENT_POOL_SIZE,
- GF_CHANGELOG_EVENT_THREAD_COUNT);
- if (!ctx->event_pool)
- return -1;
+ ctx->event_pool = event_pool_new(GF_CHANGELOG_EVENT_POOL_SIZE,
+ GF_CHANGELOG_EVENT_THREAD_COUNT);
+ if (!ctx->event_pool)
+ return -1;
- pool = GF_CALLOC (1, sizeof (call_pool_t),
- gf_changelog_mt_libgfchangelog_call_pool_t);
- if (!pool)
- return -1;
+ pool = GF_CALLOC(1, sizeof(call_pool_t),
+ gf_changelog_mt_libgfchangelog_call_pool_t);
+ if (!pool)
+ return -1;
- /* frame_mem_pool size 112 * 64 */
- pool->frame_mem_pool = mem_pool_new (call_frame_t, 32);
- if (!pool->frame_mem_pool)
- return -1;
+ /* frame_mem_pool size 112 * 64 */
+ pool->frame_mem_pool = mem_pool_new(call_frame_t, 32);
+ if (!pool->frame_mem_pool)
+ return -1;
- /* stack_mem_pool size 256 * 128 */
- pool->stack_mem_pool = mem_pool_new (call_stack_t, 16);
+ /* stack_mem_pool size 256 * 128 */
+ pool->stack_mem_pool = mem_pool_new(call_stack_t, 16);
- if (!pool->stack_mem_pool)
- return -1;
+ if (!pool->stack_mem_pool)
+ return -1;
- ctx->stub_mem_pool = mem_pool_new (call_stub_t, 16);
- if (!ctx->stub_mem_pool)
- return -1;
+ ctx->stub_mem_pool = mem_pool_new(call_stub_t, 16);
+ if (!ctx->stub_mem_pool)
+ return -1;
- ctx->dict_pool = mem_pool_new (dict_t, 32);
- if (!ctx->dict_pool)
- return -1;
+ ctx->dict_pool = mem_pool_new(dict_t, 32);
+ if (!ctx->dict_pool)
+ return -1;
- ctx->dict_pair_pool = mem_pool_new (data_pair_t, 512);
- if (!ctx->dict_pair_pool)
- return -1;
+ ctx->dict_pair_pool = mem_pool_new(data_pair_t, 512);
+ if (!ctx->dict_pair_pool)
+ return -1;
- ctx->dict_data_pool = mem_pool_new (data_t, 512);
- if (!ctx->dict_data_pool)
- return -1;
+ ctx->dict_data_pool = mem_pool_new(data_t, 512);
+ if (!ctx->dict_data_pool)
+ return -1;
- ctx->logbuf_pool = mem_pool_new (log_buf_t, 256);
- if (!ctx->logbuf_pool)
- return -1;
+ ctx->logbuf_pool = mem_pool_new(log_buf_t, 256);
+ if (!ctx->logbuf_pool)
+ return -1;
- INIT_LIST_HEAD (&pool->all_frames);
- LOCK_INIT (&pool->lock);
- ctx->pool = pool;
+ INIT_LIST_HEAD(&pool->all_frames);
+ LOCK_INIT(&pool->lock);
+ ctx->pool = pool;
- LOCK_INIT (&ctx->lock);
+ LOCK_INIT(&ctx->lock);
- cmd_args = &ctx->cmd_args;
+ cmd_args = &ctx->cmd_args;
- INIT_LIST_HEAD (&cmd_args->xlator_options);
+ INIT_LIST_HEAD(&cmd_args->xlator_options);
- lim.rlim_cur = RLIM_INFINITY;
- lim.rlim_max = RLIM_INFINITY;
- setrlimit (RLIMIT_CORE, &lim);
+ lim.rlim_cur = RLIM_INFINITY;
+ lim.rlim_max = RLIM_INFINITY;
+ setrlimit(RLIMIT_CORE, &lim);
- return 0;
+ return 0;
}
/* TODO: cleanup ctx defaults */
void
-gf_changelog_cleanup_this (xlator_t *this)
+gf_changelog_cleanup_this(xlator_t *this)
{
- glusterfs_ctx_t *ctx = NULL;
+ glusterfs_ctx_t *ctx = NULL;
- if (!this)
- return;
+ if (!this)
+ return;
- ctx = this->ctx;
- syncenv_destroy (ctx->env);
- free (ctx);
+ ctx = this->ctx;
+ syncenv_destroy(ctx->env);
+ free(ctx);
- this->private = NULL;
- this->ctx = NULL;
+ this->private = NULL;
+ this->ctx = NULL;
- mem_pools_fini ();
+ mem_pools_fini();
}
static int
-gf_changelog_init_context ()
+gf_changelog_init_context()
{
- glusterfs_ctx_t *ctx = NULL;
+ glusterfs_ctx_t *ctx = NULL;
- ctx = glusterfs_ctx_new ();
- if (!ctx)
- goto error_return;
+ ctx = glusterfs_ctx_new();
+ if (!ctx)
+ goto error_return;
- if (glusterfs_globals_init (ctx))
- goto free_ctx;
+ if (glusterfs_globals_init(ctx))
+ goto free_ctx;
- THIS->ctx = ctx;
- if (gf_changelog_ctx_defaults_init (ctx))
- goto free_ctx;
+ THIS->ctx = ctx;
+ if (gf_changelog_ctx_defaults_init(ctx))
+ goto free_ctx;
- ctx->env = syncenv_new (0, 0, 0);
- if (!ctx->env)
- goto free_ctx;
- return 0;
+ ctx->env = syncenv_new(0, 0, 0);
+ if (!ctx->env)
+ goto free_ctx;
+ return 0;
- free_ctx:
- free (ctx);
- THIS->ctx = NULL;
- error_return:
- return -1;
+free_ctx:
+ free(ctx);
+ THIS->ctx = NULL;
+error_return:
+ return -1;
}
static int
-gf_changelog_init_master ()
+gf_changelog_init_master()
{
- int ret = 0;
+ int ret = 0;
- mem_pools_init_early ();
- ret = gf_changelog_init_context ();
- mem_pools_init_late ();
+ mem_pools_init_early();
+ ret = gf_changelog_init_context();
+ mem_pools_init_late();
- return ret;
+ return ret;
}
/* TODO: cleanup clnt/svc on failure */
int
-gf_changelog_setup_rpc (xlator_t *this,
- gf_changelog_t *entry, int proc)
+gf_changelog_setup_rpc(xlator_t *this, gf_changelog_t *entry, int proc)
{
- int ret = 0;
- rpcsvc_t *svc = NULL;
- struct rpc_clnt *rpc = NULL;
-
- /**
- * Initialize a connect back socket. A probe() RPC call to the server
- * triggers a reverse connect.
- */
- svc = gf_changelog_reborp_init_rpc_listner (this, entry->brick,
- RPC_SOCK (entry), entry);
- if (!svc)
- goto error_return;
- RPC_REBORP (entry) = svc;
-
- /* Initialize an RPC client */
- rpc = gf_changelog_rpc_init (this, entry);
- if (!rpc)
- goto error_return;
- RPC_PROBER (entry) = rpc;
-
- /**
- * @FIXME
- * till we have connection state machine, let's delay the RPC call
- * for now..
- */
- sleep (2);
-
- /**
- * Probe changelog translator for reverse connection. After a successful
- * call, there's less use of the client and can be disconnected, but
- * let's leave the connection active for any future RPC calls.
- */
- ret = gf_changelog_invoke_rpc (this, entry, proc);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_INVOKE_RPC_FAILED,
- "Could not initiate probe RPC, bailing out!!!");
- goto error_return;
- }
-
- return 0;
-
- error_return:
- return -1;
+ int ret = 0;
+ rpcsvc_t *svc = NULL;
+ struct rpc_clnt *rpc = NULL;
+
+ /**
+ * Initialize a connect back socket. A probe() RPC call to the server
+ * triggers a reverse connect.
+ */
+ svc = gf_changelog_reborp_init_rpc_listner(this, entry->brick,
+ RPC_SOCK(entry), entry);
+ if (!svc)
+ goto error_return;
+ RPC_REBORP(entry) = svc;
+
+ /* Initialize an RPC client */
+ rpc = gf_changelog_rpc_init(this, entry);
+ if (!rpc)
+ goto error_return;
+ RPC_PROBER(entry) = rpc;
+
+ /**
+ * @FIXME
+ * till we have connection state machine, let's delay the RPC call
+ * for now..
+ */
+ sleep(2);
+
+ /**
+ * Probe changelog translator for reverse connection. After a successful
+ * call, there's less use of the client and can be disconnected, but
+ * let's leave the connection active for any future RPC calls.
+ */
+ ret = gf_changelog_invoke_rpc(this, entry, proc);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_INVOKE_RPC_FAILED,
+ "Could not initiate probe RPC, bailing out!!!");
+ goto error_return;
+ }
+
+ return 0;
+
+error_return:
+ return -1;
}
int
-gf_cleanup_event (xlator_t *this, struct gf_event_list *ev)
+gf_cleanup_event(xlator_t *this, struct gf_event_list *ev)
{
- int ret = 0;
-
- ret = gf_thread_cleanup (this, ev->invoker);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, -ret,
- CHANGELOG_LIB_MSG_CLEANUP_ERROR,
- "cannot cleanup callback invoker thread."
- " Not freeing resources");
- return -1;
- }
+ int ret = 0;
+
+ ret = gf_thread_cleanup(this, ev->invoker);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, -ret,
+ CHANGELOG_LIB_MSG_CLEANUP_ERROR,
+ "cannot cleanup callback invoker thread."
+ " Not freeing resources");
+ return -1;
+ }
- ev->entry = NULL;
+ ev->entry = NULL;
- return 0;
+ return 0;
}
static int
-gf_init_event (gf_changelog_t *entry)
+gf_init_event(gf_changelog_t *entry)
{
- int ret = 0;
- struct gf_event_list *ev = NULL;
-
- ev = &entry->event;
- ev->entry = entry;
-
- ret = pthread_mutex_init (&ev->lock, NULL);
- if (ret != 0)
- goto error_return;
- ret = pthread_cond_init (&ev->cond, NULL);
- if (ret != 0)
- goto cleanup_mutex;
- INIT_LIST_HEAD (&ev->events);
-
- ev->next_seq = 0; /* bootstrap sequencing */
-
- if (GF_NEED_ORDERED_EVENTS (entry)) {
- entry->pickevent = pick_event_ordered;
- entry->queueevent = queue_ordered_event;
- } else {
- entry->pickevent = pick_event_unordered;
- entry->queueevent = queue_unordered_event;
- }
-
- ret = gf_thread_create (&ev->invoker, NULL,
- gf_changelog_callback_invoker, ev, "clogcbki");
- if (ret != 0) {
- entry->pickevent = NULL;
- entry->queueevent = NULL;
- goto cleanup_cond;
- }
-
- return 0;
-
- cleanup_cond:
- (void) pthread_cond_destroy (&ev->cond);
- cleanup_mutex:
- (void) pthread_mutex_destroy (&ev->lock);
- error_return:
- return -1;
+ int ret = 0;
+ struct gf_event_list *ev = NULL;
+
+ ev = &entry->event;
+ ev->entry = entry;
+
+ ret = pthread_mutex_init(&ev->lock, NULL);
+ if (ret != 0)
+ goto error_return;
+ ret = pthread_cond_init(&ev->cond, NULL);
+ if (ret != 0)
+ goto cleanup_mutex;
+ INIT_LIST_HEAD(&ev->events);
+
+ ev->next_seq = 0; /* bootstrap sequencing */
+
+ if (GF_NEED_ORDERED_EVENTS(entry)) {
+ entry->pickevent = pick_event_ordered;
+ entry->queueevent = queue_ordered_event;
+ } else {
+ entry->pickevent = pick_event_unordered;
+ entry->queueevent = queue_unordered_event;
+ }
+
+ ret = gf_thread_create(&ev->invoker, NULL, gf_changelog_callback_invoker,
+ ev, "clogcbki");
+ if (ret != 0) {
+ entry->pickevent = NULL;
+ entry->queueevent = NULL;
+ goto cleanup_cond;
+ }
+
+ return 0;
+
+cleanup_cond:
+ (void)pthread_cond_destroy(&ev->cond);
+cleanup_mutex:
+ (void)pthread_mutex_destroy(&ev->lock);
+error_return:
+ return -1;
}
/**
@@ -339,251 +339,242 @@ gf_init_event (gf_changelog_t *entry)
* - destroy rpc{-clnt, svc}
*/
int
-gf_cleanup_brick_connection (xlator_t *this, gf_changelog_t *entry)
+gf_cleanup_brick_connection(xlator_t *this, gf_changelog_t *entry)
{
- return 0;
+ return 0;
}
int
-gf_cleanup_connections (xlator_t *this)
+gf_cleanup_connections(xlator_t *this)
{
- return 0;
+ return 0;
}
static int
-gf_setup_brick_connection (xlator_t *this,
- struct gf_brick_spec *brick,
- gf_boolean_t ordered, void *xl)
+gf_setup_brick_connection(xlator_t *this, struct gf_brick_spec *brick,
+ gf_boolean_t ordered, void *xl)
{
- int ret = 0;
- gf_private_t *priv = NULL;
- gf_changelog_t *entry = NULL;
-
- priv = this->private;
-
- if (!brick->callback || !brick->init || !brick->fini)
- goto error_return;
-
- entry = GF_CALLOC (1, sizeof (*entry),
- gf_changelog_mt_libgfchangelog_t);
- if (!entry)
- goto error_return;
- INIT_LIST_HEAD (&entry->list);
-
- LOCK_INIT (&entry->statelock);
- entry->connstate = GF_CHANGELOG_CONN_STATE_PENDING;
-
- entry->notify = brick->filter;
- if (snprintf (entry->brick, PATH_MAX, "%s", brick->brick_path)
- >= PATH_MAX)
- goto free_entry;
-
- entry->this = this;
- entry->invokerxl = xl;
-
- entry->ordered = ordered;
- ret = gf_init_event (entry);
- if (ret)
- goto free_entry;
-
- entry->fini = brick->fini;
- entry->callback = brick->callback;
- entry->connected = brick->connected;
- entry->disconnected = brick->disconnected;
-
- entry->ptr = brick->init (this, brick);
- if (!entry->ptr)
- goto cleanup_event;
- priv->api = entry->ptr; /* pointer to API, if required */
-
- pthread_mutex_lock (&priv->lock);
- {
- list_add_tail (&entry->list, &priv->connections);
- }
- pthread_mutex_unlock (&priv->lock);
-
- ret = gf_changelog_setup_rpc (this, entry, CHANGELOG_RPC_PROBE_FILTER);
- if (ret)
- goto cleanup_event;
- return 0;
-
- cleanup_event:
- (void) gf_cleanup_event (this, &entry->event);
- free_entry:
- gf_msg_debug (this->name, 0, "freeing entry %p", entry);
- list_del (&entry->list); /* FIXME: kludge for now */
- GF_FREE (entry);
- error_return:
- return -1;
+ int ret = 0;
+ gf_private_t *priv = NULL;
+ gf_changelog_t *entry = NULL;
+
+ priv = this->private;
+
+ if (!brick->callback || !brick->init || !brick->fini)
+ goto error_return;
+
+ entry = GF_CALLOC(1, sizeof(*entry), gf_changelog_mt_libgfchangelog_t);
+ if (!entry)
+ goto error_return;
+ INIT_LIST_HEAD(&entry->list);
+
+ LOCK_INIT(&entry->statelock);
+ entry->connstate = GF_CHANGELOG_CONN_STATE_PENDING;
+
+ entry->notify = brick->filter;
+ if (snprintf(entry->brick, PATH_MAX, "%s", brick->brick_path) >= PATH_MAX)
+ goto free_entry;
+
+ entry->this = this;
+ entry->invokerxl = xl;
+
+ entry->ordered = ordered;
+ ret = gf_init_event(entry);
+ if (ret)
+ goto free_entry;
+
+ entry->fini = brick->fini;
+ entry->callback = brick->callback;
+ entry->connected = brick->connected;
+ entry->disconnected = brick->disconnected;
+
+ entry->ptr = brick->init(this, brick);
+ if (!entry->ptr)
+ goto cleanup_event;
+ priv->api = entry->ptr; /* pointer to API, if required */
+
+ pthread_mutex_lock(&priv->lock);
+ {
+ list_add_tail(&entry->list, &priv->connections);
+ }
+ pthread_mutex_unlock(&priv->lock);
+
+ ret = gf_changelog_setup_rpc(this, entry, CHANGELOG_RPC_PROBE_FILTER);
+ if (ret)
+ goto cleanup_event;
+ return 0;
+
+cleanup_event:
+ (void)gf_cleanup_event(this, &entry->event);
+free_entry:
+ gf_msg_debug(this->name, 0, "freeing entry %p", entry);
+ list_del(&entry->list); /* FIXME: kludge for now */
+ GF_FREE(entry);
+error_return:
+ return -1;
}
int
-gf_changelog_register_brick (xlator_t *this,
- struct gf_brick_spec *brick,
- gf_boolean_t ordered, void *xl)
+gf_changelog_register_brick(xlator_t *this, struct gf_brick_spec *brick,
+ gf_boolean_t ordered, void *xl)
{
- return gf_setup_brick_connection (this, brick, ordered, xl);
+ return gf_setup_brick_connection(this, brick, ordered, xl);
}
static int
-gf_changelog_setup_logging (xlator_t *this, char *logfile, int loglevel)
+gf_changelog_setup_logging(xlator_t *this, char *logfile, int loglevel)
{
- /* passing ident as NULL means to use default ident for syslog */
- if (gf_log_init (this->ctx, logfile, NULL))
- return -1;
+ /* passing ident as NULL means to use default ident for syslog */
+ if (gf_log_init(this->ctx, logfile, NULL))
+ return -1;
- gf_log_set_loglevel (this->ctx, (loglevel == -1) ? GF_LOG_INFO :
- loglevel);
- return 0;
+ gf_log_set_loglevel(this->ctx, (loglevel == -1) ? GF_LOG_INFO : loglevel);
+ return 0;
}
static int
-gf_changelog_set_master (xlator_t *master, void *xl)
+gf_changelog_set_master(xlator_t *master, void *xl)
{
- int32_t ret = 0;
- xlator_t *this = NULL;
- xlator_t *old_this = NULL;
- gf_private_t *priv = NULL;
-
- this = xl;
- if (!this || !this->ctx) {
- ret = gf_changelog_init_master ();
- if (ret)
- return -1;
- this = THIS;
- }
+ int32_t ret = 0;
+ xlator_t *this = NULL;
+ xlator_t *old_this = NULL;
+ gf_private_t *priv = NULL;
+
+ this = xl;
+ if (!this || !this->ctx) {
+ ret = gf_changelog_init_master();
+ if (ret)
+ return -1;
+ this = THIS;
+ }
- master->ctx = this->ctx;
+ master->ctx = this->ctx;
- INIT_LIST_HEAD (&master->volume_options);
- SAVE_THIS (THIS);
+ INIT_LIST_HEAD(&master->volume_options);
+ SAVE_THIS(THIS);
- ret = xlator_mem_acct_init (THIS, gf_changelog_mt_end);
- if (ret != 0)
- goto restore_this;
+ ret = xlator_mem_acct_init(THIS, gf_changelog_mt_end);
+ if (ret != 0)
+ goto restore_this;
- priv = gf_changelog_alloc_priv ();
- if (!priv) {
- ret = -1;
- goto restore_this;
- }
+ priv = gf_changelog_alloc_priv();
+ if (!priv) {
+ ret = -1;
+ goto restore_this;
+ }
- if (!xl) {
- /* poller thread */
- ret = gf_thread_create (&priv->poller,
- NULL, changelog_rpc_poller, THIS,
- "clogpoll");
- if (ret != 0) {
- GF_FREE (priv);
- gf_msg (master->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED,
- "failed to spawn poller thread");
- goto restore_this;
- }
+ if (!xl) {
+ /* poller thread */
+ ret = gf_thread_create(&priv->poller, NULL, changelog_rpc_poller, THIS,
+ "clogpoll");
+ if (ret != 0) {
+ GF_FREE(priv);
+ gf_msg(master->name, GF_LOG_ERROR, 0,
+ CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED,
+ "failed to spawn poller thread");
+ goto restore_this;
}
+ }
- master->private = priv;
+ master->private = priv;
- restore_this:
- RESTORE_THIS ();
+restore_this:
+ RESTORE_THIS();
- return ret;
+ return ret;
}
int
-gf_changelog_init (void *xl)
+gf_changelog_init(void *xl)
{
- int ret = 0;
- gf_private_t *priv = NULL;
-
- if (master)
- return 0;
-
- master = calloc (1, sizeof (*master));
- if (!master)
- goto error_return;
-
- master->name = strdup ("gfchangelog");
- if (!master->name)
- goto dealloc_master;
-
- ret = gf_changelog_set_master (master, xl);
- if (ret)
- goto dealloc_name;
-
- priv = master->private;
- ret = gf_thread_create (&priv->connectionjanitor, NULL,
- gf_changelog_connection_janitor, master,
- "clogjan");
- if (ret != 0) {
- /* TODO: cleanup priv, mutex (poller thread for !xl) */
- goto dealloc_name;
- }
+ int ret = 0;
+ gf_private_t *priv = NULL;
+ if (master)
return 0;
- dealloc_name:
- free (master->name);
- dealloc_master:
- free (master);
- master = NULL;
- error_return:
- return -1;
+ master = calloc(1, sizeof(*master));
+ if (!master)
+ goto error_return;
+
+ master->name = strdup("gfchangelog");
+ if (!master->name)
+ goto dealloc_master;
+
+ ret = gf_changelog_set_master(master, xl);
+ if (ret)
+ goto dealloc_name;
+
+ priv = master->private;
+ ret = gf_thread_create(&priv->connectionjanitor, NULL,
+ gf_changelog_connection_janitor, master, "clogjan");
+ if (ret != 0) {
+ /* TODO: cleanup priv, mutex (poller thread for !xl) */
+ goto dealloc_name;
+ }
+
+ return 0;
+
+dealloc_name:
+ free(master->name);
+dealloc_master:
+ free(master);
+ master = NULL;
+error_return:
+ return -1;
}
int
-gf_changelog_register_generic (struct gf_brick_spec *bricks, int count,
- int ordered, char *logfile, int lvl, void *xl)
+gf_changelog_register_generic(struct gf_brick_spec *bricks, int count,
+ int ordered, char *logfile, int lvl, void *xl)
{
- int ret = 0;
- xlator_t *this = NULL;
- xlator_t *old_this = NULL;
- struct gf_brick_spec *brick = NULL;
- gf_boolean_t need_order = _gf_false;
+ int ret = 0;
+ xlator_t *this = NULL;
+ xlator_t *old_this = NULL;
+ struct gf_brick_spec *brick = NULL;
+ gf_boolean_t need_order = _gf_false;
- SAVE_THIS (xl);
+ SAVE_THIS(xl);
- this = THIS;
- if (!this)
- goto error_return;
+ this = THIS;
+ if (!this)
+ goto error_return;
- ret = gf_changelog_setup_logging (this, logfile, lvl);
- if (ret)
- goto error_return;
-
- need_order = (ordered) ? _gf_true : _gf_false;
-
- brick = bricks;
- while (count--) {
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_LIB_MSG_NOTIFY_REGISTER_INFO,
- "Registering brick",
- "brick=%s", brick->brick_path,
- "notify_filter=%d", brick->filter,
- NULL);
-
- ret = gf_changelog_register_brick (this, brick, need_order, xl);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_NOTIFY_REGISTER_FAILED,
- "Error registering with changelog xlator");
- break;
- }
-
- brick++;
+ ret = gf_changelog_setup_logging(this, logfile, lvl);
+ if (ret)
+ goto error_return;
+
+ need_order = (ordered) ? _gf_true : _gf_false;
+
+ brick = bricks;
+ while (count--) {
+ gf_smsg(this->name, GF_LOG_INFO, 0,
+ CHANGELOG_LIB_MSG_NOTIFY_REGISTER_INFO, "Registering brick",
+ "brick=%s", brick->brick_path, "notify_filter=%d",
+ brick->filter, NULL);
+
+ ret = gf_changelog_register_brick(this, brick, need_order, xl);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_LIB_MSG_NOTIFY_REGISTER_FAILED,
+ "Error registering with changelog xlator");
+ break;
}
- if (ret != 0)
- goto cleanup_inited_bricks;
+ brick++;
+ }
- RESTORE_THIS();
- return 0;
+ if (ret != 0)
+ goto cleanup_inited_bricks;
- cleanup_inited_bricks:
- gf_cleanup_connections (this);
- error_return:
- RESTORE_THIS();
- return -1;
+ RESTORE_THIS();
+ return 0;
+
+cleanup_inited_bricks:
+ gf_cleanup_connections(this);
+error_return:
+ RESTORE_THIS();
+ return -1;
}
/**
@@ -610,27 +601,29 @@ gf_changelog_register_generic (struct gf_brick_spec *bricks, int count,
* For generic API, refer gf_changelog_register_generic().
*/
int
-gf_changelog_register (char *brick_path, char *scratch_dir,
- char *log_file, int log_level, int max_reconnects)
+gf_changelog_register(char *brick_path, char *scratch_dir, char *log_file,
+ int log_level, int max_reconnects)
{
- struct gf_brick_spec brick = {0,};
+ struct gf_brick_spec brick = {
+ 0,
+ };
- if (master)
- THIS = master;
- else
- return -1;
+ if (master)
+ THIS = master;
+ else
+ return -1;
- brick.brick_path = brick_path;
- brick.filter = CHANGELOG_OP_TYPE_JOURNAL;
+ brick.brick_path = brick_path;
+ brick.filter = CHANGELOG_OP_TYPE_JOURNAL;
- brick.init = gf_changelog_journal_init;
- brick.fini = gf_changelog_journal_fini;
- brick.callback = gf_changelog_handle_journal;
- brick.connected = gf_changelog_journal_connect;
- brick.disconnected = gf_changelog_journal_disconnect;
+ brick.init = gf_changelog_journal_init;
+ brick.fini = gf_changelog_journal_fini;
+ brick.callback = gf_changelog_handle_journal;
+ brick.connected = gf_changelog_journal_connect;
+ brick.disconnected = gf_changelog_journal_disconnect;
- brick.ptr = scratch_dir;
+ brick.ptr = scratch_dir;
- return gf_changelog_register_generic (&brick, 1, 1,
- log_file, log_level, NULL);
+ return gf_changelog_register_generic(&brick, 1, 1, log_file, log_level,
+ NULL);
}
diff --git a/xlators/features/changelog/lib/src/gf-history-changelog.c b/xlators/features/changelog/lib/src/gf-history-changelog.c
index 5259ae3893b..c8a31ebbd73 100644
--- a/xlators/features/changelog/lib/src/gf-history-changelog.c
+++ b/xlators/features/changelog/lib/src/gf-history-changelog.c
@@ -36,62 +36,60 @@
* -1: On error.
*/
int
-gf_history_changelog_done (char *file)
+gf_history_changelog_done(char *file)
{
- int ret = -1;
- char *buffer = NULL;
- xlator_t *this = NULL;
- gf_changelog_journal_t *jnl = NULL;
- gf_changelog_journal_t *hist_jnl = NULL;
- char to_path[PATH_MAX] = {0,};
+ int ret = -1;
+ char *buffer = NULL;
+ xlator_t *this = NULL;
+ gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_journal_t *hist_jnl = NULL;
+ char to_path[PATH_MAX] = {
+ 0,
+ };
+
+ errno = EINVAL;
+
+ this = THIS;
+ if (!this)
+ goto out;
+
+ jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this);
+ if (!jnl)
+ goto out;
+
+ hist_jnl = jnl->hist_jnl;
+ if (!hist_jnl)
+ goto out;
+
+ if (!file || !strlen(file))
+ goto out;
+
+ /* make sure 'file' is inside ->jnl_working_dir */
+ buffer = realpath(file, NULL);
+ if (!buffer)
+ goto out;
+
+ if (strncmp(hist_jnl->jnl_working_dir, buffer,
+ strlen(hist_jnl->jnl_working_dir)))
+ goto out;
+
+ (void)snprintf(to_path, PATH_MAX, "%s%s", hist_jnl->jnl_processed_dir,
+ basename(buffer));
+ gf_msg_debug(this->name, 0, "moving %s to processed directory", file);
+ ret = sys_rename(buffer, to_path);
+ if (ret) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_RENAME_FAILED, "cannot move changelog file",
+ "from=%s", file, "to=%s", to_path, NULL);
+ goto out;
+ }
+
+ ret = 0;
- errno = EINVAL;
-
- this = THIS;
- if (!this)
- goto out;
-
- jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this);
- if (!jnl)
- goto out;
-
- hist_jnl = jnl->hist_jnl;
- if (!hist_jnl)
- goto out;
-
- if (!file || !strlen (file))
- goto out;
-
- /* make sure 'file' is inside ->jnl_working_dir */
- buffer = realpath (file, NULL);
- if (!buffer)
- goto out;
-
- if (strncmp (hist_jnl->jnl_working_dir,
- buffer, strlen (hist_jnl->jnl_working_dir)))
- goto out;
-
- (void) snprintf (to_path, PATH_MAX, "%s%s",
- hist_jnl->jnl_processed_dir, basename (buffer));
- gf_msg_debug (this->name, 0,
- "moving %s to processed directory", file);
- ret = sys_rename (buffer, to_path);
- if (ret) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_RENAME_FAILED,
- "cannot move changelog file",
- "from=%s", file,
- "to=%s", to_path,
- NULL);
- goto out;
- }
-
- ret = 0;
-
- out:
- if (buffer)
- free (buffer); /* allocated by realpath() */
- return ret;
+out:
+ if (buffer)
+ free(buffer); /* allocated by realpath() */
+ return ret;
}
/**
@@ -105,33 +103,33 @@ gf_history_changelog_done (char *file)
* -1: On error.
*/
int
-gf_history_changelog_start_fresh ()
+gf_history_changelog_start_fresh()
{
- xlator_t *this = NULL;
- gf_changelog_journal_t *jnl = NULL;
- gf_changelog_journal_t *hist_jnl = NULL;
+ xlator_t *this = NULL;
+ gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_journal_t *hist_jnl = NULL;
- this = THIS;
- if (!this)
- goto out;
+ this = THIS;
+ if (!this)
+ goto out;
- errno = EINVAL;
+ errno = EINVAL;
- jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this);
- if (!jnl)
- goto out;
+ jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this);
+ if (!jnl)
+ goto out;
- hist_jnl = jnl->hist_jnl;
- if (!hist_jnl)
- goto out;
+ hist_jnl = jnl->hist_jnl;
+ if (!hist_jnl)
+ goto out;
- if (gf_ftruncate (hist_jnl->jnl_fd, 0))
- goto out;
+ if (gf_ftruncate(hist_jnl->jnl_fd, 0))
+ goto out;
- return 0;
+ return 0;
- out:
- return -1;
+out:
+ return -1;
}
/**
@@ -150,50 +148,52 @@ gf_history_changelog_start_fresh ()
* -1 : On error.
*/
ssize_t
-gf_history_changelog_next_change (char *bufptr, size_t maxlen)
+gf_history_changelog_next_change(char *bufptr, size_t maxlen)
{
- ssize_t size = -1;
- int tracker_fd = 0;
- xlator_t *this = NULL;
- gf_changelog_journal_t *jnl = NULL;
- gf_changelog_journal_t *hist_jnl = NULL;
- char buffer[PATH_MAX] = {0,};
-
- if (maxlen > PATH_MAX) {
- errno = ENAMETOOLONG;
- goto out;
- }
+ ssize_t size = -1;
+ int tracker_fd = 0;
+ xlator_t *this = NULL;
+ gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_journal_t *hist_jnl = NULL;
+ char buffer[PATH_MAX] = {
+ 0,
+ };
- errno = EINVAL;
+ if (maxlen > PATH_MAX) {
+ errno = ENAMETOOLONG;
+ goto out;
+ }
- this = THIS;
- if (!this)
- goto out;
+ errno = EINVAL;
- jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this);
- if (!jnl)
- goto out;
+ this = THIS;
+ if (!this)
+ goto out;
- hist_jnl = jnl->hist_jnl;
- if (!hist_jnl)
- goto out;
+ jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this);
+ if (!jnl)
+ goto out;
- tracker_fd = hist_jnl->jnl_fd;
+ hist_jnl = jnl->hist_jnl;
+ if (!hist_jnl)
+ goto out;
- size = gf_readline (tracker_fd, buffer, maxlen);
- if (size < 0) {
- size = -1;
- goto out;
- }
+ tracker_fd = hist_jnl->jnl_fd;
- if (size == 0)
- goto out;
+ size = gf_readline(tracker_fd, buffer, maxlen);
+ if (size < 0) {
+ size = -1;
+ goto out;
+ }
- memcpy (bufptr, buffer, size - 1);
- bufptr[size - 1] = '\0';
+ if (size == 0)
+ goto out;
+
+ memcpy(bufptr, buffer, size - 1);
+ bufptr[size - 1] = '\0';
out:
- return size;
+ return size;
}
/**
@@ -214,97 +214,100 @@ out:
*
*/
ssize_t
-gf_history_changelog_scan ()
+gf_history_changelog_scan()
{
- int tracker_fd = 0;
- size_t off = 0;
- xlator_t *this = NULL;
- size_t nr_entries = 0;
- gf_changelog_journal_t *jnl = NULL;
- gf_changelog_journal_t *hist_jnl = NULL;
- struct dirent *entry = NULL;
- struct dirent scratch[2] = {{0,},};
- char buffer[PATH_MAX] = {0,};
- static int is_last_scan;
-
- this = THIS;
- if (!this)
- goto out;
+ int tracker_fd = 0;
+ size_t off = 0;
+ xlator_t *this = NULL;
+ size_t nr_entries = 0;
+ gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_journal_t *hist_jnl = NULL;
+ struct dirent *entry = NULL;
+ struct dirent scratch[2] = {
+ {
+ 0,
+ },
+ };
+ char buffer[PATH_MAX] = {
+ 0,
+ };
+ static int is_last_scan;
+
+ this = THIS;
+ if (!this)
+ goto out;
+
+ jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this);
+ if (!jnl)
+ goto out;
+ if (JNL_IS_API_DISCONNECTED(jnl)) {
+ errno = ENOTCONN;
+ goto out;
+ }
+
+ hist_jnl = jnl->hist_jnl;
+ if (!hist_jnl)
+ goto out;
+
+retry:
+ if (is_last_scan == 1)
+ return 0;
+ if (hist_jnl->hist_done == 0)
+ is_last_scan = 1;
- jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this);
- if (!jnl)
- goto out;
- if (JNL_IS_API_DISCONNECTED (jnl)) {
- errno = ENOTCONN;
- goto out;
- }
+ errno = EINVAL;
+ if (hist_jnl->hist_done == -1)
+ goto out;
- hist_jnl = jnl->hist_jnl;
- if (!hist_jnl)
- goto out;
+ tracker_fd = hist_jnl->jnl_fd;
- retry:
- if (is_last_scan == 1)
- return 0;
- if (hist_jnl->hist_done == 0)
- is_last_scan = 1;
+ if (gf_ftruncate(tracker_fd, 0))
+ goto out;
- errno = EINVAL;
- if (hist_jnl->hist_done == -1)
- goto out;
+ rewinddir(hist_jnl->jnl_dir);
- tracker_fd = hist_jnl->jnl_fd;
+ for (;;) {
+ errno = 0;
+ entry = sys_readdir(hist_jnl->jnl_dir, scratch);
+ if (!entry || errno != 0)
+ break;
- if (gf_ftruncate (tracker_fd, 0))
- goto out;
+ if (strcmp(basename(entry->d_name), ".") == 0 ||
+ strcmp(basename(entry->d_name), "..") == 0)
+ continue;
- rewinddir (hist_jnl->jnl_dir);
-
- for (;;) {
- errno = 0;
- entry = sys_readdir (hist_jnl->jnl_dir, scratch);
- if (!entry || errno != 0)
- break;
-
- if (strcmp (basename (entry->d_name), ".") == 0 ||
- strcmp (basename (entry->d_name), "..") == 0)
- continue;
-
- nr_entries++;
-
- GF_CHANGELOG_FILL_BUFFER (hist_jnl->jnl_processing_dir,
- buffer, off,
- strlen (hist_jnl->jnl_processing_dir));
- GF_CHANGELOG_FILL_BUFFER (entry->d_name, buffer,
- off, strlen (entry->d_name));
- GF_CHANGELOG_FILL_BUFFER ("\n", buffer, off, 1);
-
- if (gf_changelog_write (tracker_fd, buffer, off) != off) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_WRITE_FAILED,
- "error writing changelog filename"
- " to tracker file");
- break;
- }
- off = 0;
- }
+ nr_entries++;
- gf_msg_debug (this->name, 0,
- "hist_done %d, is_last_scan: %d",
- hist_jnl->hist_done, is_last_scan);
-
- if (!entry) {
- if (gf_lseek (tracker_fd, 0, SEEK_SET) != -1) {
- if (nr_entries > 0)
- return nr_entries;
- else {
- sleep(1);
- goto retry;
- }
- }
+ GF_CHANGELOG_FILL_BUFFER(hist_jnl->jnl_processing_dir, buffer, off,
+ strlen(hist_jnl->jnl_processing_dir));
+ GF_CHANGELOG_FILL_BUFFER(entry->d_name, buffer, off,
+ strlen(entry->d_name));
+ GF_CHANGELOG_FILL_BUFFER("\n", buffer, off, 1);
+
+ if (gf_changelog_write(tracker_fd, buffer, off) != off) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_WRITE_FAILED,
+ "error writing changelog filename"
+ " to tracker file");
+ break;
}
- out:
- return -1;
+ off = 0;
+ }
+
+ gf_msg_debug(this->name, 0, "hist_done %d, is_last_scan: %d",
+ hist_jnl->hist_done, is_last_scan);
+
+ if (!entry) {
+ if (gf_lseek(tracker_fd, 0, SEEK_SET) != -1) {
+ if (nr_entries > 0)
+ return nr_entries;
+ else {
+ sleep(1);
+ goto retry;
+ }
+ }
+ }
+out:
+ return -1;
}
/*
@@ -312,36 +315,36 @@ gf_history_changelog_scan ()
* Returns 0 on success(updates given time-stamp), -1 on failure.
*/
int
-gf_history_get_timestamp (int fd, int index, int len,
- unsigned long *ts)
+gf_history_get_timestamp(int fd, int index, int len, unsigned long *ts)
{
- xlator_t *this = NULL;
- int n_read = -1;
- char path_buf[PATH_MAX]= {0,};
- char *iter = path_buf;
- size_t offset = index * (len+1);
- unsigned long value = 0;
- int ret = 0;
-
- this = THIS;
- if (!this) {
- return -1;
- }
-
- n_read = sys_pread (fd, path_buf, len, offset);
- if (n_read < 0 ) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_READ_ERROR,
- "could not read from htime file");
- goto out;
- }
- iter+= len - TIMESTAMP_LENGTH;
- sscanf (iter, "%lu",&value);
+ xlator_t *this = NULL;
+ int n_read = -1;
+ char path_buf[PATH_MAX] = {
+ 0,
+ };
+ char *iter = path_buf;
+ size_t offset = index * (len + 1);
+ unsigned long value = 0;
+ int ret = 0;
+
+ this = THIS;
+ if (!this) {
+ return -1;
+ }
+
+ n_read = sys_pread(fd, path_buf, len, offset);
+ if (n_read < 0) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_READ_ERROR,
+ "could not read from htime file");
+ goto out;
+ }
+ iter += len - TIMESTAMP_LENGTH;
+ sscanf(iter, "%lu", &value);
out:
- if(ret == 0)
- *ts = value;
- return ret;
+ if (ret == 0)
+ *ts = value;
+ return ret;
}
/*
@@ -349,38 +352,37 @@ out:
* Checks whether @value is there next to @target_index or not
*/
int
-gf_history_check ( int fd, int target_index, unsigned long value, int len)
+gf_history_check(int fd, int target_index, unsigned long value, int len)
{
- int ret = 0;
- unsigned long ts1 = 0;
- unsigned long ts2 = 0;
-
- if (target_index == 0) {
- ret = gf_history_get_timestamp (fd, target_index, len, &ts1);
- if (ret == -1)
- goto out;
- if (value <= ts1)
- goto out;
- else {
- ret = -1;
- goto out;
- }
- }
+ int ret = 0;
+ unsigned long ts1 = 0;
+ unsigned long ts2 = 0;
- ret = gf_history_get_timestamp (fd, target_index, len, &ts1);
- if (ret ==-1)
- goto out;
- ret = gf_history_get_timestamp (fd, target_index -1, len, &ts2);
- if (ret ==-1)
- goto out;
-
- if ( (value <= ts1) && (value > ts2) ) {
- goto out;
+ if (target_index == 0) {
+ ret = gf_history_get_timestamp(fd, target_index, len, &ts1);
+ if (ret == -1)
+ goto out;
+ if (value <= ts1)
+ goto out;
+ else {
+ ret = -1;
+ goto out;
}
- else
- ret = -1;
+ }
+
+ ret = gf_history_get_timestamp(fd, target_index, len, &ts1);
+ if (ret == -1)
+ goto out;
+ ret = gf_history_get_timestamp(fd, target_index - 1, len, &ts2);
+ if (ret == -1)
+ goto out;
+
+ if ((value <= ts1) && (value > ts2)) {
+ goto out;
+ } else
+ ret = -1;
out:
- return ret;
+ return ret;
}
/*
@@ -400,78 +402,69 @@ out:
*/
int
-gf_history_b_search (int fd, unsigned long value,
- unsigned long from, unsigned long to, int len)
+gf_history_b_search(int fd, unsigned long value, unsigned long from,
+ unsigned long to, int len)
{
- int m_index = -1;
- unsigned long cur_value = 0;
- unsigned long ts1 = 0;
- int ret = 0;
-
- m_index = (from + to)/2;
-
- if ( (to - from) <=1 ) {
- /* either one or 2 changelogs left */
- if ( to != from ) {
- /* check if value is less or greater than to
- * return accordingly
- */
- ret = gf_history_get_timestamp (fd, from, len, &ts1);
- if (ret ==-1)
- goto out;
- if ( ts1 >= value) {
- /* actually compatision should be
- * exactly == but considering
- *
- * case of only 2 changelogs in htime file
- */
- return from;
- }
- else
- return to;
- }
- else
- return to;
- }
-
- ret = gf_history_get_timestamp (fd, m_index, len, &cur_value);
+ int m_index = -1;
+ unsigned long cur_value = 0;
+ unsigned long ts1 = 0;
+ int ret = 0;
+
+ m_index = (from + to) / 2;
+
+ if ((to - from) <= 1) {
+ /* either one or 2 changelogs left */
+ if (to != from) {
+ /* check if value is less or greater than to
+ * return accordingly
+ */
+ ret = gf_history_get_timestamp(fd, from, len, &ts1);
+ if (ret == -1)
+ goto out;
+ if (ts1 >= value) {
+ /* actually compatision should be
+ * exactly == but considering
+ *
+ * case of only 2 changelogs in htime file
+ */
+ return from;
+ } else
+ return to;
+ } else
+ return to;
+ }
+
+ ret = gf_history_get_timestamp(fd, m_index, len, &cur_value);
+ if (ret == -1)
+ goto out;
+ if (cur_value == value) {
+ return m_index;
+ } else if (value > cur_value) {
+ ret = gf_history_get_timestamp(fd, m_index + 1, len, &cur_value);
if (ret == -1)
+ goto out;
+ if (value < cur_value)
+ return m_index + 1;
+ else
+ return gf_history_b_search(fd, value, m_index + 1, to, len);
+ } else {
+ if (m_index == 0) {
+ /* we are sure that values exists
+ * in this htime file
+ */
+ return 0;
+ } else {
+ ret = gf_history_get_timestamp(fd, m_index - 1, len, &cur_value);
+ if (ret == -1)
goto out;
- if (cur_value == value) {
+ if (value > cur_value) {
return m_index;
+ } else
+ return gf_history_b_search(fd, value, from, m_index - 1, len);
}
- else if (value > cur_value) {
- ret = gf_history_get_timestamp (fd, m_index+1, len, &cur_value);
- if (ret == -1)
- goto out;
- if (value < cur_value)
- return m_index + 1;
- else
- return gf_history_b_search (fd, value,
- m_index+1, to, len);
- }
- else {
- if (m_index ==0) {
- /* we are sure that values exists
- * in this htime file
- */
- return 0;
- }
- else {
- ret = gf_history_get_timestamp (fd, m_index-1, len,
- &cur_value);
- if (ret == -1)
- goto out;
- if (value > cur_value) {
- return m_index;
- }
- else
- return gf_history_b_search (fd, value, from,
- m_index-1, len);
- }
- }
+ }
out:
- return -1;
+ return -1;
}
/*
@@ -484,65 +477,60 @@ out:
* 0 : No, Not usable ( contains, "changelog")
*/
int
-gf_is_changelog_usable (char *cl_path)
+gf_is_changelog_usable(char *cl_path)
{
- int ret = -1;
- const char low_c[] = "changelog";
- char *str_ret = NULL;
- char *bname = NULL;
+ int ret = -1;
+ const char low_c[] = "changelog";
+ char *str_ret = NULL;
+ char *bname = NULL;
- bname = basename (cl_path);
+ bname = basename(cl_path);
- str_ret = strstr (bname, low_c);
+ str_ret = strstr(bname, low_c);
- if (str_ret != NULL)
- ret = 0;
- else
- ret = 1;
-
- return ret;
+ if (str_ret != NULL)
+ ret = 0;
+ else
+ ret = 1;
+ return ret;
}
void *
-gf_changelog_consume_wrap (void* data)
+gf_changelog_consume_wrap(void *data)
{
- int ret = -1;
- ssize_t nread = 0;
- xlator_t *this = NULL;
- gf_changelog_consume_data_t *ccd = NULL;
-
- ccd = (gf_changelog_consume_data_t *) data;
- this = ccd->this;
-
- ccd->retval = -1;
-
- nread = sys_pread (ccd->fd, ccd->changelog, PATH_MAX-1, ccd->offset);
- if (nread < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_READ_ERROR,
- "cannot read from history metadata file");
- goto out;
- }
-
- /* TODO: handle short reads and EOF. */
- if (gf_is_changelog_usable (ccd->changelog) == 1) {
-
- ret = gf_changelog_consume (ccd->this,
- ccd->jnl, ccd->changelog, _gf_true);
- if (ret) {
- gf_smsg (this->name, GF_LOG_ERROR,
- 0, CHANGELOG_LIB_MSG_PARSE_ERROR,
- "could not parse changelog",
- "name=%s", ccd->changelog,
- NULL);
- goto out;
- }
+ int ret = -1;
+ ssize_t nread = 0;
+ xlator_t *this = NULL;
+ gf_changelog_consume_data_t *ccd = NULL;
+
+ ccd = (gf_changelog_consume_data_t *)data;
+ this = ccd->this;
+
+ ccd->retval = -1;
+
+ nread = sys_pread(ccd->fd, ccd->changelog, PATH_MAX - 1, ccd->offset);
+ if (nread < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_READ_ERROR,
+ "cannot read from history metadata file");
+ goto out;
+ }
+
+ /* TODO: handle short reads and EOF. */
+ if (gf_is_changelog_usable(ccd->changelog) == 1) {
+ ret = gf_changelog_consume(ccd->this, ccd->jnl, ccd->changelog,
+ _gf_true);
+ if (ret) {
+ gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_LIB_MSG_PARSE_ERROR,
+ "could not parse changelog", "name=%s", ccd->changelog,
+ NULL);
+ goto out;
}
- ccd->retval = 0;
+ }
+ ccd->retval = 0;
- out:
- return NULL;
+out:
+ return NULL;
}
/**
@@ -551,133 +539,138 @@ gf_changelog_consume_wrap (void* data)
* to index "to" in open htime file whose fd is "fd".
*/
-#define MAX_PARALLELS 10
+#define MAX_PARALLELS 10
void *
-gf_history_consume (void * data)
+gf_history_consume(void *data)
{
- xlator_t *this = NULL;
- gf_changelog_journal_t *jnl = NULL;
- gf_changelog_journal_t *hist_jnl = NULL;
- int ret = 0;
- int iter = 0;
- int fd = -1;
- int from = -1;
- int to = -1;
- int len = -1;
- int n_parallel = 0;
- int n_envoked = 0;
- gf_boolean_t publish = _gf_true;
- pthread_t th_id[MAX_PARALLELS] = {0,};
- gf_changelog_history_data_t *hist_data = NULL;
- gf_changelog_consume_data_t ccd[MAX_PARALLELS] = {{0},};
- gf_changelog_consume_data_t *curr = NULL;
- char thread_name[GF_THREAD_NAMEMAX] = {0,};
-
- hist_data = (gf_changelog_history_data_t *) data;
- if (hist_data == NULL) {
- ret = -1;
- goto out;
+ xlator_t *this = NULL;
+ gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_journal_t *hist_jnl = NULL;
+ int ret = 0;
+ int iter = 0;
+ int fd = -1;
+ int from = -1;
+ int to = -1;
+ int len = -1;
+ int n_parallel = 0;
+ int n_envoked = 0;
+ gf_boolean_t publish = _gf_true;
+ pthread_t th_id[MAX_PARALLELS] = {
+ 0,
+ };
+ gf_changelog_history_data_t *hist_data = NULL;
+ gf_changelog_consume_data_t ccd[MAX_PARALLELS] = {
+ {0},
+ };
+ gf_changelog_consume_data_t *curr = NULL;
+ char thread_name[GF_THREAD_NAMEMAX] = {
+ 0,
+ };
+
+ hist_data = (gf_changelog_history_data_t *)data;
+ if (hist_data == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ fd = hist_data->htime_fd;
+ from = hist_data->from;
+ to = hist_data->to;
+ len = hist_data->len;
+ n_parallel = hist_data->n_parallel;
+
+ THIS = hist_data->this;
+ this = hist_data->this;
+ if (!this) {
+ ret = -1;
+ goto out;
+ }
+
+ jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this);
+ if (!jnl) {
+ ret = -1;
+ goto out;
+ }
+
+ hist_jnl = jnl->hist_jnl;
+ if (!hist_jnl) {
+ ret = -1;
+ goto out;
+ }
+
+ while (from <= to) {
+ n_envoked = 0;
+
+ for (iter = 0; (iter < n_parallel) && (from <= to); iter++) {
+ curr = &ccd[iter];
+
+ curr->this = this;
+ curr->jnl = hist_jnl;
+ curr->fd = fd;
+ curr->offset = from * (len + 1);
+
+ curr->retval = 0;
+ memset(curr->changelog, '\0', PATH_MAX);
+ snprintf(thread_name, sizeof(thread_name), "clogc%03hx",
+ ((iter + 1) & 0x3ff));
+
+ ret = gf_thread_create(&th_id[iter], NULL,
+ gf_changelog_consume_wrap, curr,
+ thread_name);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, ret,
+ CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED,
+ "could not create consume-thread");
+ goto sync;
+ } else
+ n_envoked++;
+
+ from++;
}
- fd = hist_data->htime_fd;
- from = hist_data->from;
- to = hist_data->to;
- len = hist_data->len;
- n_parallel = hist_data->n_parallel;
-
- THIS = hist_data->this;
- this = hist_data->this;
- if (!this) {
- ret = -1;
- goto out;
+ sync:
+ for (iter = 0; iter < n_envoked; iter++) {
+ ret = pthread_join(th_id[iter], NULL);
+ if (ret) {
+ publish = _gf_false;
+ gf_msg(this->name, GF_LOG_ERROR, ret,
+ CHANGELOG_LIB_MSG_PTHREAD_JOIN_FAILED,
+ "pthread_join() error");
+ /* try to join the rest */
+ continue;
+ }
+
+ if (publish == _gf_false)
+ continue;
+
+ curr = &ccd[iter];
+ if (ccd->retval) {
+ publish = _gf_false;
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_LIB_MSG_PARSE_ERROR,
+ "parsing error, ceased publishing...");
+ continue;
+ }
+
+ ret = gf_changelog_publish(curr->this, curr->jnl, curr->changelog);
+ if (ret) {
+ publish = _gf_false;
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_LIB_MSG_PUBLISH_ERROR,
+ "publish error, ceased publishing...");
+ }
}
+ }
- jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this);
- if (!jnl) {
- ret = -1;
- goto out;
- }
-
- hist_jnl = jnl->hist_jnl;
- if (!hist_jnl) {
- ret = -1;
- goto out;
- }
-
- while (from <= to) {
- n_envoked = 0;
-
- for (iter = 0 ; (iter < n_parallel) && (from <= to); iter++) {
- curr = &ccd[iter];
-
- curr->this = this;
- curr->jnl = hist_jnl;
- curr->fd = fd;
- curr->offset = from * (len + 1);
-
- curr->retval = 0;
- memset (curr->changelog, '\0', PATH_MAX);
- snprintf (thread_name, sizeof(thread_name),
- "clogc%03hx", ((iter + 1) & 0x3ff));
-
- ret = gf_thread_create (&th_id[iter], NULL,
- gf_changelog_consume_wrap, curr,
- thread_name);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, ret,
- CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED
- , "could not create consume-thread");
- goto sync;
- } else
- n_envoked++;
-
- from++;
- }
-
- sync:
- for (iter = 0; iter < n_envoked; iter++) {
- ret = pthread_join (th_id[iter], NULL);
- if (ret) {
- publish = _gf_false;
- gf_msg (this->name, GF_LOG_ERROR, ret,
- CHANGELOG_LIB_MSG_PTHREAD_JOIN_FAILED,
- "pthread_join() error");
- /* try to join the rest */
- continue;
- }
-
- if (publish == _gf_false)
- continue;
-
- curr = &ccd[iter];
- if (ccd->retval) {
- publish = _gf_false;
- gf_msg (this->name, GF_LOG_ERROR,
- 0, CHANGELOG_LIB_MSG_PARSE_ERROR,
- "parsing error, ceased publishing...");
- continue;
- }
-
- ret = gf_changelog_publish (curr->this,
- curr->jnl, curr->changelog);
- if (ret) {
- publish = _gf_false;
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_PUBLISH_ERROR,
- "publish error, ceased publishing...");
- }
- }
- }
-
- /* informing "parsing done". */
- hist_jnl->hist_done = (publish == _gf_true) ? 0 : -1;
+ /* informing "parsing done". */
+ hist_jnl->hist_done = (publish == _gf_true) ? 0 : -1;
out:
- if (fd != -1)
- (void) sys_close (fd);
- GF_FREE (hist_data);
- return NULL;
+ if (fd != -1)
+ (void)sys_close(fd);
+ GF_FREE(hist_data);
+ return NULL;
}
/**
@@ -707,77 +700,73 @@ out:
* -2 : Ignore this metadata file and process next
*/
int
-gf_changelog_extract_min_max (const char *dname, const char *htime_dir,
- int *fd, unsigned long *total,
- unsigned long *min_ts, unsigned long *max_ts)
+gf_changelog_extract_min_max(const char *dname, const char *htime_dir, int *fd,
+ unsigned long *total, unsigned long *min_ts,
+ unsigned long *max_ts)
{
- int ret = -1;
- xlator_t *this = NULL;
- char htime_file[PATH_MAX] = {0,};
- struct stat stbuf = {0,};
- char *iter = NULL;
- char x_value[30] = {0,};
-
- this = THIS;
-
- snprintf (htime_file, PATH_MAX, "%s/%s", htime_dir, dname);
-
- iter = (htime_file + strlen (htime_file) - TIMESTAMP_LENGTH);
- sscanf (iter ,"%lu",min_ts);
-
- ret = sys_stat (htime_file, &stbuf);
- if (ret) {
- ret = -1;
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_HTIME_ERROR,
- "stat() failed on htime file",
- "path=%s", htime_file,
- NULL);
- goto out;
- }
-
- /* ignore everything except regular files */
- if (!S_ISREG (stbuf.st_mode)) {
- ret = -2;
- goto out;
- }
-
- *fd = open (htime_file, O_RDONLY);
- if (*fd < 0) {
- ret = -1;
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_HTIME_ERROR,
- "open() failed for htime file",
- "path=%s", htime_file,
- NULL);
- goto out;
- }
-
- /* Looks good, extract max timestamp */
- ret = sys_fgetxattr (*fd, HTIME_KEY, x_value, sizeof (x_value));
- if (ret < 0) {
- ret = -1;
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_GET_XATTR_FAILED,
- "error extracting max timstamp from htime file"
- "path=%s", htime_file,
- NULL);
- goto out;
- }
+ int ret = -1;
+ xlator_t *this = NULL;
+ char htime_file[PATH_MAX] = {
+ 0,
+ };
+ struct stat stbuf = {
+ 0,
+ };
+ char *iter = NULL;
+ char x_value[30] = {
+ 0,
+ };
+
+ this = THIS;
+
+ snprintf(htime_file, PATH_MAX, "%s/%s", htime_dir, dname);
+
+ iter = (htime_file + strlen(htime_file) - TIMESTAMP_LENGTH);
+ sscanf(iter, "%lu", min_ts);
+
+ ret = sys_stat(htime_file, &stbuf);
+ if (ret) {
+ ret = -1;
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_HTIME_ERROR,
+ "stat() failed on htime file", "path=%s", htime_file, NULL);
+ goto out;
+ }
+
+ /* ignore everything except regular files */
+ if (!S_ISREG(stbuf.st_mode)) {
+ ret = -2;
+ goto out;
+ }
+
+ *fd = open(htime_file, O_RDONLY);
+ if (*fd < 0) {
+ ret = -1;
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_HTIME_ERROR,
+ "open() failed for htime file", "path=%s", htime_file, NULL);
+ goto out;
+ }
+
+ /* Looks good, extract max timestamp */
+ ret = sys_fgetxattr(*fd, HTIME_KEY, x_value, sizeof(x_value));
+ if (ret < 0) {
+ ret = -1;
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_GET_XATTR_FAILED,
+ "error extracting max timstamp from htime file"
+ "path=%s",
+ htime_file, NULL);
+ goto out;
+ }
+
+ sscanf(x_value, "%lu:%lu", max_ts, total);
+ gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_LIB_MSG_TOTAL_LOG_INFO,
+ "changelogs min max", "min=%lu", *min_ts, "max=%lu", *max_ts,
+ "total_changelogs=%lu", *total, NULL);
+
+ ret = 0;
- sscanf (x_value, "%lu:%lu", max_ts, total);
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_LIB_MSG_TOTAL_LOG_INFO,
- "changelogs min max",
- "min=%lu", *min_ts,
- "max=%lu", *max_ts,
- "total_changelogs=%lu", *total,
- NULL);
-
- ret = 0;
-
- out:
- return ret;
+out:
+ return ret;
}
/* gf_history_changelog returns actual_end and spawns threads to
@@ -790,275 +779,257 @@ gf_changelog_extract_min_max (const char *dname, const char *htime_dir,
* -1 : On any error
*/
int
-gf_history_changelog (char* changelog_dir, unsigned long start,
- unsigned long end, int n_parallel,
- unsigned long *actual_end)
+gf_history_changelog(char *changelog_dir, unsigned long start,
+ unsigned long end, int n_parallel,
+ unsigned long *actual_end)
{
- int ret = 0;
- int len = -1;
- int fd = -1;
- int n_read = -1;
- unsigned long min_ts = 0;
- unsigned long max_ts = 0;
- unsigned long end2 = 0;
- unsigned long ts1 = 0;
- unsigned long ts2 = 0;
- unsigned long to = 0;
- unsigned long from = 0;
- unsigned long total_changelog = 0;
- xlator_t *this = NULL;
- gf_changelog_journal_t *jnl = NULL;
- gf_changelog_journal_t *hist_jnl = NULL;
- gf_changelog_history_data_t *hist_data = NULL;
- DIR *dirp = NULL;
- struct dirent *entry = NULL;
- struct dirent scratch[2] = {{0,},};
- pthread_t consume_th = 0;
- char htime_dir[PATH_MAX] = {0,};
- char buffer[PATH_MAX] = {0,};
- gf_boolean_t partial_history = _gf_false;
-
- pthread_attr_t attr;
-
- this = THIS;
- if (!this) {
- ret = -1;
- goto out;
+ int ret = 0;
+ int len = -1;
+ int fd = -1;
+ int n_read = -1;
+ unsigned long min_ts = 0;
+ unsigned long max_ts = 0;
+ unsigned long end2 = 0;
+ unsigned long ts1 = 0;
+ unsigned long ts2 = 0;
+ unsigned long to = 0;
+ unsigned long from = 0;
+ unsigned long total_changelog = 0;
+ xlator_t *this = NULL;
+ gf_changelog_journal_t *jnl = NULL;
+ gf_changelog_journal_t *hist_jnl = NULL;
+ gf_changelog_history_data_t *hist_data = NULL;
+ DIR *dirp = NULL;
+ struct dirent *entry = NULL;
+ struct dirent scratch[2] = {
+ {
+ 0,
+ },
+ };
+ pthread_t consume_th = 0;
+ char htime_dir[PATH_MAX] = {
+ 0,
+ };
+ char buffer[PATH_MAX] = {
+ 0,
+ };
+ gf_boolean_t partial_history = _gf_false;
+
+ pthread_attr_t attr;
+
+ this = THIS;
+ if (!this) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = pthread_attr_init(&attr);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_PTHREAD_ERROR,
+ "Pthread init failed");
+ return -1;
+ }
+
+ jnl = (gf_changelog_journal_t *)GF_CHANGELOG_GET_API_PTR(this);
+ if (!jnl) {
+ ret = -1;
+ goto out;
+ }
+
+ hist_jnl = (gf_changelog_journal_t *)jnl->hist_jnl;
+ if (!hist_jnl) {
+ ret = -1;
+ goto out;
+ }
+
+ gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_LIB_MSG_TOTAL_LOG_INFO,
+ "Requesting historical changelogs", "start=%lu", start, "end=%lu",
+ end, NULL);
+
+ /* basic sanity check */
+ if (start > end || n_parallel <= 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_HIST_FAILED,
+ "Sanity check failed", "start=%lu", start, "end=%lu", end,
+ "thread_count=%d", n_parallel, NULL);
+ ret = -1;
+ goto out;
+ }
+
+ /* cap parallelism count */
+ if (n_parallel > MAX_PARALLELS)
+ n_parallel = MAX_PARALLELS;
+
+ CHANGELOG_FILL_HTIME_DIR(changelog_dir, htime_dir);
+
+ dirp = sys_opendir(htime_dir);
+ if (dirp == NULL) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_LIB_MSG_HTIME_ERROR,
+ "open dir on htime failed", "path=%s", htime_dir, NULL);
+ ret = -1;
+ goto out;
+ }
+
+ for (;;) {
+ errno = 0;
+
+ entry = sys_readdir(dirp, scratch);
+
+ if (!entry || errno != 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_HIST_FAILED,
+ "Requested changelog range is not availbale", "start=%lu",
+ start, "end=%lu", end, NULL);
+ ret = -2;
+ break;
}
- ret = pthread_attr_init (&attr);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_PTHREAD_ERROR,
- "Pthread init failed");
- return -1;
+ ret = gf_changelog_extract_min_max(entry->d_name, htime_dir, &fd,
+ &total_changelog, &min_ts, &max_ts);
+ if (ret) {
+ if (-2 == ret)
+ continue;
+ goto out;
}
- jnl = (gf_changelog_journal_t *) GF_CHANGELOG_GET_API_PTR (this);
- if (!jnl) {
+ if (start >= min_ts && start < max_ts) {
+ /**
+ * TODO: handle short reads later...
+ */
+ n_read = sys_read(fd, buffer, PATH_MAX);
+ if (n_read < 0) {
ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_READ_ERROR,
+ "unable to read htime file");
goto out;
- }
+ }
+
+ len = strlen(buffer);
+
+ /**
+ * search @start in the htime file returning it's index
+ * (@from)
+ */
+ from = gf_history_b_search(fd, start, 0, total_changelog - 1, len);
- hist_jnl = (gf_changelog_journal_t *) jnl->hist_jnl;
- if (!hist_jnl) {
+ /* ensuring correctness of gf_b_search */
+ if (gf_history_check(fd, from, start, len) != 0) {
ret = -1;
+ gf_smsg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_LIB_MSG_GET_TIME_ERROR,
+ "wrong result for start", "start=%lu", start, "idx=%lu",
+ from, NULL);
goto out;
- }
-
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_LIB_MSG_TOTAL_LOG_INFO,
- "Requesting historical changelogs",
- "start=%lu", start, "end=%lu", end, NULL);
-
- /* basic sanity check */
- if (start > end || n_parallel <= 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_HIST_FAILED, "Sanity check failed",
- "start=%lu", start,
- "end=%lu", end,
- "thread_count=%d", n_parallel,
- NULL);
+ }
+
+ end2 = (end <= max_ts) ? end : max_ts;
+
+ /* Check if end falls out of same HTIME file. The end
+ * falling to a different htime file or changelog
+ * disable-enable is detected only after 20 seconds.
+ * This is required because, applications generally
+ * asks historical changelogs till current time and
+ * it is possible changelog is not rolled over yet.
+ * So, buffer time of default rollover time plus 5
+ * seconds is subtracted. If the application requests
+ * the end time with in half a minute of changelog
+ * disable, it's not detected as changelog disable and
+ * it's application's responsibility to retry after
+ * 20 seconds before confirming it as partial history.
+ */
+ if ((end - 20) > max_ts) {
+ partial_history = _gf_true;
+ }
+
+ /**
+ * search @end2 in htime file returning it's index (@to)
+ */
+ to = gf_history_b_search(fd, end2, 0, total_changelog - 1, len);
+
+ if (gf_history_check(fd, to, end2, len) != 0) {
ret = -1;
+ gf_smsg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_LIB_MSG_GET_TIME_ERROR,
+ "wrong result for end", "start=%lu", end2, "idx=%lu",
+ to, NULL);
goto out;
- }
+ }
- /* cap parallelism count */
- if (n_parallel > MAX_PARALLELS)
- n_parallel = MAX_PARALLELS;
+ ret = gf_history_get_timestamp(fd, from, len, &ts1);
+ if (ret == -1)
+ goto out;
- CHANGELOG_FILL_HTIME_DIR (changelog_dir, htime_dir);
+ ret = gf_history_get_timestamp(fd, to, len, &ts2);
+ if (ret == -1)
+ goto out;
- dirp = sys_opendir (htime_dir);
- if (dirp == NULL) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_HTIME_ERROR,
- "open dir on htime failed",
- "path=%s", htime_dir,
- NULL);
+ gf_smsg(this->name, GF_LOG_INFO, 0,
+ CHANGELOG_LIB_MSG_TOTAL_LOG_INFO, "FINAL", "from=%lu", ts1,
+ "to=%lu", ts2, "changes=%lu", (to - from + 1), NULL);
+
+ hist_data = GF_CALLOC(1, sizeof(gf_changelog_history_data_t),
+ gf_changelog_mt_history_data_t);
+
+ hist_data->htime_fd = fd;
+ hist_data->from = from;
+ hist_data->to = to;
+ hist_data->len = len;
+ hist_data->n_parallel = n_parallel;
+ hist_data->this = this;
+
+ ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, ret,
+ CHANGELOG_LIB_MSG_PTHREAD_ERROR,
+ "unable to sets the detach"
+ " state attribute");
ret = -1;
goto out;
- }
+ }
+
+ /* spawn a thread for background parsing & publishing */
+ ret = gf_thread_create(&consume_th, &attr, gf_history_consume,
+ hist_data, "cloghcon");
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, ret,
+ CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED,
+ "creation of consume parent-thread"
+ " failed.");
+ ret = -1;
+ goto out;
+ }
- for (;;) {
-
- errno = 0;
-
- entry = sys_readdir (dirp, scratch);
-
- if (!entry || errno != 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_HIST_FAILED,
- "Requested changelog range is not availbale",
- "start=%lu", start, "end=%lu", end, NULL);
- ret = -2;
- break;
- }
-
- ret = gf_changelog_extract_min_max (entry->d_name, htime_dir,
- &fd, &total_changelog,
- &min_ts, &max_ts);
- if (ret) {
- if (-2 == ret)
- continue;
- goto out;
- }
-
- if (start >= min_ts && start < max_ts) {
- /**
- * TODO: handle short reads later...
- */
- n_read = sys_read (fd, buffer, PATH_MAX);
- if (n_read < 0) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_READ_ERROR,
- "unable to read htime file");
- goto out;
- }
-
- len = strlen (buffer);
-
- /**
- * search @start in the htime file returning it's index
- * (@from)
- */
- from = gf_history_b_search (fd, start, 0,
- total_changelog - 1, len);
-
- /* ensuring correctness of gf_b_search */
- if (gf_history_check (fd, from, start, len) != 0) {
- ret = -1;
- gf_smsg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_GET_TIME_ERROR,
- "wrong result for start",
- "start=%lu", start,
- "idx=%lu", from,
- NULL);
- goto out;
- }
-
- end2 = (end <= max_ts) ? end : max_ts;
-
- /* Check if end falls out of same HTIME file. The end
- * falling to a different htime file or changelog
- * disable-enable is detected only after 20 seconds.
- * This is required because, applications generally
- * asks historical changelogs till current time and
- * it is possible changelog is not rolled over yet.
- * So, buffer time of default rollover time plus 5
- * seconds is subtracted. If the application requests
- * the end time with in half a minute of changelog
- * disable, it's not detected as changelog disable and
- * it's application's responsibility to retry after
- * 20 seconds before confirming it as partial history.
- */
- if ((end - 20) > max_ts) {
- partial_history = _gf_true;
- }
-
- /**
- * search @end2 in htime file returning it's index (@to)
- */
- to = gf_history_b_search (fd, end2,
- 0, total_changelog - 1, len);
-
- if (gf_history_check (fd, to, end2, len) != 0) {
- ret = -1;
- gf_smsg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_LIB_MSG_GET_TIME_ERROR,
- "wrong result for end",
- "start=%lu", end2,
- "idx=%lu", to,
- NULL);
- goto out;
- }
-
- ret = gf_history_get_timestamp (fd, from, len, &ts1);
- if (ret == -1)
- goto out;
-
- ret = gf_history_get_timestamp (fd, to, len, &ts2);
- if (ret == -1)
- goto out;
-
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_LIB_MSG_TOTAL_LOG_INFO,
- "FINAL",
- "from=%lu", ts1,
- "to=%lu", ts2,
- "changes=%lu", (to - from + 1),
- NULL);
-
- hist_data = GF_CALLOC (1,
- sizeof (gf_changelog_history_data_t),
- gf_changelog_mt_history_data_t);
-
- hist_data->htime_fd = fd;
- hist_data->from = from;
- hist_data->to = to;
- hist_data->len = len;
- hist_data->n_parallel = n_parallel;
- hist_data->this = this;
-
- ret = pthread_attr_setdetachstate
- (&attr, PTHREAD_CREATE_DETACHED);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, ret,
- CHANGELOG_LIB_MSG_PTHREAD_ERROR,
- "unable to sets the detach"
- " state attribute");
- ret = -1;
- goto out;
- }
-
- /* spawn a thread for background parsing & publishing */
- ret = gf_thread_create (&consume_th, &attr,
- gf_history_consume, hist_data,
- "cloghcon");
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, ret,
- CHANGELOG_LIB_MSG_THREAD_CREATION_FAILED
- , "creation of consume parent-thread"
- " failed.");
- ret = -1;
- goto out;
- }
-
- goto out;
-
- } else {/* end of range check */
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_LIB_MSG_HIST_FAILED,
- "Requested changelog range is not "
- "available. Retrying next HTIME",
- "start=%lu", start,
- "end=%lu", end,
- "chlog_min=%lu", min_ts,
- "chlog_max=%lu", max_ts,
- NULL);
- }
- } /* end of readdir() */
+ goto out;
+
+ } else { /* end of range check */
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_LIB_MSG_HIST_FAILED,
+ "Requested changelog range is not "
+ "available. Retrying next HTIME",
+ "start=%lu", start, "end=%lu", end, "chlog_min=%lu", min_ts,
+ "chlog_max=%lu", max_ts, NULL);
+ }
+ } /* end of readdir() */
out:
- if (dirp != NULL)
- (void) sys_closedir (dirp);
+ if (dirp != NULL)
+ (void)sys_closedir(dirp);
- if (ret < 0) {
- if (fd != -1)
- (void) sys_close (fd);
- GF_FREE (hist_data);
- (void) pthread_attr_destroy (&attr);
+ if (ret < 0) {
+ if (fd != -1)
+ (void)sys_close(fd);
+ GF_FREE(hist_data);
+ (void)pthread_attr_destroy(&attr);
- return ret;
- }
+ return ret;
+ }
- hist_jnl->hist_done = 1;
- *actual_end = ts2;
+ hist_jnl->hist_done = 1;
+ *actual_end = ts2;
- if (partial_history) {
- ret = 1;
- }
+ if (partial_history) {
+ ret = 1;
+ }
- return ret;
+ return ret;
}
diff --git a/xlators/features/changelog/src/changelog-barrier.c b/xlators/features/changelog/src/changelog-barrier.c
index ac1eb0e4397..e8d742404df 100644
--- a/xlators/features/changelog/src/changelog-barrier.c
+++ b/xlators/features/changelog/src/changelog-barrier.c
@@ -14,121 +14,119 @@
/* Enqueue a stub*/
void
-__chlog_barrier_enqueue (xlator_t *this, call_stub_t *stub)
+__chlog_barrier_enqueue(xlator_t *this, call_stub_t *stub)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
- GF_ASSERT (priv);
+ priv = this->private;
+ GF_ASSERT(priv);
- list_add_tail (&stub->list, &priv->queue);
- priv->queue_size++;
+ list_add_tail(&stub->list, &priv->queue);
+ priv->queue_size++;
- return;
+ return;
}
/* Dequeue a stub */
call_stub_t *
-__chlog_barrier_dequeue (xlator_t *this, struct list_head *queue)
+__chlog_barrier_dequeue(xlator_t *this, struct list_head *queue)
{
- call_stub_t *stub = NULL;
- changelog_priv_t *priv = NULL;
+ call_stub_t *stub = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
- GF_ASSERT (priv);
+ priv = this->private;
+ GF_ASSERT(priv);
- if (list_empty (queue))
- goto out;
+ if (list_empty(queue))
+ goto out;
- stub = list_entry (queue->next, call_stub_t, list);
- list_del_init (&stub->list);
+ stub = list_entry(queue->next, call_stub_t, list);
+ list_del_init(&stub->list);
out:
- return stub;
+ return stub;
}
/* Dequeue all the stubs and call corresponding resume functions */
void
-chlog_barrier_dequeue_all (xlator_t *this, struct list_head *queue)
+chlog_barrier_dequeue_all(xlator_t *this, struct list_head *queue)
{
- call_stub_t *stub = NULL;
+ call_stub_t *stub = NULL;
- gf_msg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_BARRIER_INFO,
- "Dequeuing all the changelog barriered fops");
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO,
+ "Dequeuing all the changelog barriered fops");
- while ((stub = __chlog_barrier_dequeue (this, queue)))
- call_resume (stub);
+ while ((stub = __chlog_barrier_dequeue(this, queue)))
+ call_resume(stub);
- gf_msg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_BARRIER_INFO,
- "Dequeuing changelog barriered fops is finished");
- return;
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO,
+ "Dequeuing changelog barriered fops is finished");
+ return;
}
/* Function called on changelog barrier timeout */
void
-chlog_barrier_timeout (void *data)
+chlog_barrier_timeout(void *data)
{
- xlator_t *this = NULL;
- changelog_priv_t *priv = NULL;
- struct list_head queue = {0,};
+ xlator_t *this = NULL;
+ changelog_priv_t *priv = NULL;
+ struct list_head queue = {
+ 0,
+ };
- this = data;
- THIS = this;
- priv = this->private;
+ this = data;
+ THIS = this;
+ priv = this->private;
- INIT_LIST_HEAD (&queue);
+ INIT_LIST_HEAD(&queue);
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_BARRIER_ERROR,
- "Disabling changelog barrier because of the timeout.");
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_BARRIER_ERROR,
+ "Disabling changelog barrier because of the timeout.");
- LOCK (&priv->lock);
- {
- __chlog_barrier_disable (this, &queue);
- }
- UNLOCK (&priv->lock);
+ LOCK(&priv->lock);
+ {
+ __chlog_barrier_disable(this, &queue);
+ }
+ UNLOCK(&priv->lock);
- chlog_barrier_dequeue_all (this, &queue);
+ chlog_barrier_dequeue_all(this, &queue);
- return;
+ return;
}
/* Disable changelog barrier enable flag */
void
-__chlog_barrier_disable (xlator_t *this, struct list_head *queue)
+__chlog_barrier_disable(xlator_t *this, struct list_head *queue)
{
- changelog_priv_t *priv = this->private;
- GF_ASSERT (priv);
+ changelog_priv_t *priv = this->private;
+ GF_ASSERT(priv);
- if (priv->timer) {
- gf_timer_call_cancel (this->ctx, priv->timer);
- priv->timer = NULL;
- }
+ if (priv->timer) {
+ gf_timer_call_cancel(this->ctx, priv->timer);
+ priv->timer = NULL;
+ }
- list_splice_init (&priv->queue, queue);
- priv->queue_size = 0;
- priv->barrier_enabled = _gf_false;
+ list_splice_init(&priv->queue, queue);
+ priv->queue_size = 0;
+ priv->barrier_enabled = _gf_false;
}
/* Enable chagelog barrier enable with timer */
int
-__chlog_barrier_enable (xlator_t *this, changelog_priv_t *priv)
+__chlog_barrier_enable(xlator_t *this, changelog_priv_t *priv)
{
- int ret = -1;
-
- priv->timer = gf_timer_call_after (this->ctx, priv->timeout,
- chlog_barrier_timeout, (void *)this);
- if (!priv->timer) {
- gf_msg (this->name, GF_LOG_CRITICAL, 0,
- CHANGELOG_MSG_BARRIER_ERROR,
- "Couldn't add changelog barrier timeout event.");
- goto out;
- }
-
- priv->barrier_enabled = _gf_true;
- ret = 0;
+ int ret = -1;
+
+ priv->timer = gf_timer_call_after(this->ctx, priv->timeout,
+ chlog_barrier_timeout, (void *)this);
+ if (!priv->timer) {
+ gf_msg(this->name, GF_LOG_CRITICAL, 0, CHANGELOG_MSG_BARRIER_ERROR,
+ "Couldn't add changelog barrier timeout event.");
+ goto out;
+ }
+
+ priv->barrier_enabled = _gf_true;
+ ret = 0;
out:
- return ret;
+ return ret;
}
diff --git a/xlators/features/changelog/src/changelog-encoders.c b/xlators/features/changelog/src/changelog-encoders.c
index 95030236636..63754516c2e 100644
--- a/xlators/features/changelog/src/changelog-encoders.c
+++ b/xlators/features/changelog/src/changelog-encoders.c
@@ -11,117 +11,117 @@
#include "changelog-encoders.h"
size_t
-entry_fn (void *data, char *buffer, gf_boolean_t encode)
+entry_fn(void *data, char *buffer, gf_boolean_t encode)
{
- char *tmpbuf = NULL;
- size_t bufsz = 0;
- struct changelog_entry_fields *ce = NULL;
-
- ce = (struct changelog_entry_fields *) data;
-
- if (encode) {
- tmpbuf = uuid_utoa (ce->cef_uuid);
- CHANGELOG_FILL_BUFFER (buffer, bufsz, tmpbuf, strlen (tmpbuf));
- } else {
- CHANGELOG_FILL_BUFFER (buffer, bufsz,
- ce->cef_uuid, sizeof (uuid_t));
- }
-
- CHANGELOG_FILL_BUFFER (buffer, bufsz, "/", 1);
- CHANGELOG_FILL_BUFFER (buffer, bufsz,
- ce->cef_bname, strlen (ce->cef_bname));
- return bufsz;
+ char *tmpbuf = NULL;
+ size_t bufsz = 0;
+ struct changelog_entry_fields *ce = NULL;
+
+ ce = (struct changelog_entry_fields *)data;
+
+ if (encode) {
+ tmpbuf = uuid_utoa(ce->cef_uuid);
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, tmpbuf, strlen(tmpbuf));
+ } else {
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, ce->cef_uuid, sizeof(uuid_t));
+ }
+
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, "/", 1);
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, ce->cef_bname, strlen(ce->cef_bname));
+ return bufsz;
}
size_t
-del_entry_fn (void *data, char *buffer, gf_boolean_t encode)
+del_entry_fn(void *data, char *buffer, gf_boolean_t encode)
{
- char *tmpbuf = NULL;
- size_t bufsz = 0;
- struct changelog_entry_fields *ce = NULL;
-
- ce = (struct changelog_entry_fields *) data;
-
- if (encode) {
- tmpbuf = uuid_utoa (ce->cef_uuid);
- CHANGELOG_FILL_BUFFER (buffer, bufsz, tmpbuf, strlen (tmpbuf));
- } else {
- CHANGELOG_FILL_BUFFER (buffer, bufsz,
- ce->cef_uuid, sizeof (uuid_t));
- }
-
- CHANGELOG_FILL_BUFFER (buffer, bufsz, "/", 1);
- CHANGELOG_FILL_BUFFER (buffer, bufsz,
- ce->cef_bname, strlen (ce->cef_bname));
- CHANGELOG_FILL_BUFFER (buffer, bufsz, "\0", 1);
-
- if (ce->cef_path[0] == '\0') {
- CHANGELOG_FILL_BUFFER (buffer, bufsz, "\0", 1);
- } else {
- CHANGELOG_FILL_BUFFER (buffer, bufsz,
- ce->cef_path, strlen (ce->cef_path));
- }
-
- return bufsz;
+ char *tmpbuf = NULL;
+ size_t bufsz = 0;
+ struct changelog_entry_fields *ce = NULL;
+
+ ce = (struct changelog_entry_fields *)data;
+
+ if (encode) {
+ tmpbuf = uuid_utoa(ce->cef_uuid);
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, tmpbuf, strlen(tmpbuf));
+ } else {
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, ce->cef_uuid, sizeof(uuid_t));
+ }
+
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, "/", 1);
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, ce->cef_bname, strlen(ce->cef_bname));
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, "\0", 1);
+
+ if (ce->cef_path[0] == '\0') {
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, "\0", 1);
+ } else {
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, ce->cef_path,
+ strlen(ce->cef_path));
+ }
+
+ return bufsz;
}
size_t
-fop_fn (void *data, char *buffer, gf_boolean_t encode)
+fop_fn(void *data, char *buffer, gf_boolean_t encode)
{
- char buf[10] = {0,};
- size_t bufsz = 0;
- glusterfs_fop_t fop = 0;
+ char buf[10] = {
+ 0,
+ };
+ size_t bufsz = 0;
+ glusterfs_fop_t fop = 0;
- fop = *(glusterfs_fop_t *) data;
+ fop = *(glusterfs_fop_t *)data;
- if (encode) {
- (void) snprintf (buf, sizeof (buf), "%d", fop);
- CHANGELOG_FILL_BUFFER (buffer, bufsz, buf, strlen (buf));
- } else
- CHANGELOG_FILL_BUFFER (buffer, bufsz, &fop, sizeof (fop));
+ if (encode) {
+ (void)snprintf(buf, sizeof(buf), "%d", fop);
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, buf, strlen(buf));
+ } else
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, &fop, sizeof(fop));
- return bufsz;
+ return bufsz;
}
size_t
-number_fn (void *data, char *buffer, gf_boolean_t encode)
+number_fn(void *data, char *buffer, gf_boolean_t encode)
{
- size_t bufsz = 0;
- unsigned int nr = 0;
- char buf[20] = {0,};
+ size_t bufsz = 0;
+ unsigned int nr = 0;
+ char buf[20] = {
+ 0,
+ };
- nr = *(unsigned int *) data;
+ nr = *(unsigned int *)data;
- if (encode) {
- (void) snprintf (buf, sizeof (buf), "%u", nr);
- CHANGELOG_FILL_BUFFER (buffer, bufsz, buf, strlen (buf));
- } else
- CHANGELOG_FILL_BUFFER (buffer, bufsz, &nr, sizeof (unsigned int));
+ if (encode) {
+ (void)snprintf(buf, sizeof(buf), "%u", nr);
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, buf, strlen(buf));
+ } else
+ CHANGELOG_FILL_BUFFER(buffer, bufsz, &nr, sizeof(unsigned int));
- return bufsz;
+ return bufsz;
}
void
-entry_free_fn (void *data)
+entry_free_fn(void *data)
{
- changelog_opt_t *co = data;
+ changelog_opt_t *co = data;
- if (!co)
- return;
+ if (!co)
+ return;
- GF_FREE (co->co_entry.cef_bname);
+ GF_FREE(co->co_entry.cef_bname);
}
void
-del_entry_free_fn (void *data)
+del_entry_free_fn(void *data)
{
- changelog_opt_t *co = data;
+ changelog_opt_t *co = data;
- if (!co)
- return;
+ if (!co)
+ return;
- GF_FREE (co->co_entry.cef_bname);
- GF_FREE (co->co_entry.cef_path);
+ GF_FREE(co->co_entry.cef_bname);
+ GF_FREE(co->co_entry.cef_path);
}
/**
@@ -129,108 +129,104 @@ del_entry_free_fn (void *data)
*/
static void
-changelog_encode_write_xtra (changelog_log_data_t *cld,
- char *buffer, size_t *off, gf_boolean_t encode)
+changelog_encode_write_xtra(changelog_log_data_t *cld, char *buffer,
+ size_t *off, gf_boolean_t encode)
{
- int i = 0;
- size_t offset = 0;
- void *data = NULL;
- changelog_opt_t *co = NULL;
-
- offset = *off;
-
- co = (changelog_opt_t *) cld->cld_ptr;
-
- for (; i < cld->cld_xtra_records; i++, co++) {
- CHANGELOG_FILL_BUFFER (buffer, offset, "\0", 1);
-
- switch (co->co_type) {
- case CHANGELOG_OPT_REC_FOP:
- data = &co->co_fop;
- break;
- case CHANGELOG_OPT_REC_ENTRY:
- data = &co->co_entry;
- break;
- case CHANGELOG_OPT_REC_UINT32:
- data = &co->co_uint32;
- break;
- }
-
- if (co->co_convert)
- offset += co->co_convert (data,
- buffer + offset, encode);
- else /* no coversion: write it out as it is */
- CHANGELOG_FILL_BUFFER (buffer, offset,
- data, co->co_len);
+ int i = 0;
+ size_t offset = 0;
+ void *data = NULL;
+ changelog_opt_t *co = NULL;
+
+ offset = *off;
+
+ co = (changelog_opt_t *)cld->cld_ptr;
+
+ for (; i < cld->cld_xtra_records; i++, co++) {
+ CHANGELOG_FILL_BUFFER(buffer, offset, "\0", 1);
+
+ switch (co->co_type) {
+ case CHANGELOG_OPT_REC_FOP:
+ data = &co->co_fop;
+ break;
+ case CHANGELOG_OPT_REC_ENTRY:
+ data = &co->co_entry;
+ break;
+ case CHANGELOG_OPT_REC_UINT32:
+ data = &co->co_uint32;
+ break;
}
- *off = offset;
+ if (co->co_convert)
+ offset += co->co_convert(data, buffer + offset, encode);
+ else /* no coversion: write it out as it is */
+ CHANGELOG_FILL_BUFFER(buffer, offset, data, co->co_len);
+ }
+
+ *off = offset;
}
int
-changelog_encode_ascii (xlator_t *this, changelog_log_data_t *cld)
+changelog_encode_ascii(xlator_t *this, changelog_log_data_t *cld)
{
- size_t off = 0;
- size_t gfid_len = 0;
- char *gfid_str = NULL;
- char *buffer = NULL;
- changelog_priv_t *priv = NULL;
+ size_t off = 0;
+ size_t gfid_len = 0;
+ char *gfid_str = NULL;
+ char *buffer = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- gfid_str = uuid_utoa (cld->cld_gfid);
- gfid_len = strlen (gfid_str);
+ gfid_str = uuid_utoa(cld->cld_gfid);
+ gfid_len = strlen(gfid_str);
- /* extra bytes for decorations */
- buffer = alloca (gfid_len + cld->cld_ptr_len + 10);
- CHANGELOG_STORE_ASCII (priv, buffer,
- off, gfid_str, gfid_len, cld);
+ /* extra bytes for decorations */
+ buffer = alloca(gfid_len + cld->cld_ptr_len + 10);
+ CHANGELOG_STORE_ASCII(priv, buffer, off, gfid_str, gfid_len, cld);
- if (cld->cld_xtra_records)
- changelog_encode_write_xtra (cld, buffer, &off, _gf_true);
+ if (cld->cld_xtra_records)
+ changelog_encode_write_xtra(cld, buffer, &off, _gf_true);
- CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1);
+ CHANGELOG_FILL_BUFFER(buffer, off, "\0", 1);
- return changelog_write_change (priv, buffer, off);
+ return changelog_write_change(priv, buffer, off);
}
int
-changelog_encode_binary (xlator_t *this, changelog_log_data_t *cld)
+changelog_encode_binary(xlator_t *this, changelog_log_data_t *cld)
{
- size_t off = 0;
- char *buffer = NULL;
- changelog_priv_t *priv = NULL;
+ size_t off = 0;
+ char *buffer = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- /* extra bytes for decorations */
- buffer = alloca (sizeof (uuid_t) + cld->cld_ptr_len + 10);
- CHANGELOG_STORE_BINARY (priv, buffer, off, cld->cld_gfid, cld);
+ /* extra bytes for decorations */
+ buffer = alloca(sizeof(uuid_t) + cld->cld_ptr_len + 10);
+ CHANGELOG_STORE_BINARY(priv, buffer, off, cld->cld_gfid, cld);
- if (cld->cld_xtra_records)
- changelog_encode_write_xtra (cld, buffer, &off, _gf_false);
+ if (cld->cld_xtra_records)
+ changelog_encode_write_xtra(cld, buffer, &off, _gf_false);
- CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1);
+ CHANGELOG_FILL_BUFFER(buffer, off, "\0", 1);
- return changelog_write_change (priv, buffer, off);
+ return changelog_write_change(priv, buffer, off);
}
-static struct changelog_encoder
-cb_encoder[] = {
- [CHANGELOG_ENCODE_BINARY] =
+static struct changelog_encoder cb_encoder[] = {
+ [CHANGELOG_ENCODE_BINARY] =
{
- .encoder = CHANGELOG_ENCODE_BINARY,
- .encode = changelog_encode_binary,
+ .encoder = CHANGELOG_ENCODE_BINARY,
+ .encode = changelog_encode_binary,
},
- [CHANGELOG_ENCODE_ASCII] =
+ [CHANGELOG_ENCODE_ASCII] =
{
- .encoder = CHANGELOG_ENCODE_ASCII,
- .encode = changelog_encode_ascii,
+ .encoder = CHANGELOG_ENCODE_ASCII,
+ .encode = changelog_encode_ascii,
},
};
void
changelog_encode_change(changelog_priv_t *priv)
{
- priv->ce = &cb_encoder[priv->encode_mode];
+ priv->ce = &cb_encoder[priv->encode_mode];
}
diff --git a/xlators/features/changelog/src/changelog-ev-handle.c b/xlators/features/changelog/src/changelog-ev-handle.c
index 46d45fbd778..3ed6ff821d9 100644
--- a/xlators/features/changelog/src/changelog-ev-handle.c
+++ b/xlators/features/changelog/src/changelog-ev-handle.c
@@ -14,19 +14,19 @@
struct rpc_clnt_program changelog_ev_program;
-#define NR_IOVEC (MAX_IOVEC - 3)
+#define NR_IOVEC (MAX_IOVEC - 3)
struct ev_rpc_vec {
- int count;
- struct iovec vector[NR_IOVEC];
+ int count;
+ struct iovec vector[NR_IOVEC];
- /* sequence number */
- unsigned long seq;
+ /* sequence number */
+ unsigned long seq;
};
struct ev_rpc {
- rbuf_list_t *rlist;
- struct rpc_clnt *rpc;
- struct ev_rpc_vec vec;
+ rbuf_list_t *rlist;
+ struct rpc_clnt *rpc;
+ struct ev_rpc_vec vec;
};
/**
@@ -35,216 +35,215 @@ struct ev_rpc {
* intelligence can be built into the server.
*/
int
-changelog_event_dispatch_cbk (struct rpc_req *req,
- struct iovec *iov, int count, void *myframe)
+changelog_event_dispatch_cbk(struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
{
- return 0;
+ return 0;
}
/* dispatcher RPC */
int
-changelog_dispatch_vec (call_frame_t *frame, xlator_t *this,
- struct rpc_clnt *rpc, struct ev_rpc_vec *vec)
+changelog_dispatch_vec(call_frame_t *frame, xlator_t *this,
+ struct rpc_clnt *rpc, struct ev_rpc_vec *vec)
{
- struct timeval tv = {0,};
- changelog_event_req req = {0,};
-
- (void) gettimeofday (&tv, NULL);
-
- /**
- * Event dispatch RPC header contains a sequence number for each
- * dispatch. This allows the receiver to order the request before
- * processing.
- */
- req.seq = vec->seq;
- req.tv_sec = tv.tv_sec;
- req.tv_usec = tv.tv_usec;
-
- return changelog_rpc_sumbit_req (rpc, (void *)&req,
- frame, &changelog_ev_program,
- CHANGELOG_REV_PROC_EVENT,
- vec->vector, vec->count, NULL,
- this, changelog_event_dispatch_cbk,
- (xdrproc_t) xdr_changelog_event_req);
- }
-
- int
- changelog_event_dispatch_rpc (call_frame_t *frame, xlator_t *this, void *data)
- {
- int idx = 0;
- int count = 0;
- int ret = 0;
- unsigned long sequence = 0;
- rbuf_iovec_t *rvec = NULL;
- struct ev_rpc *erpc = NULL;
- struct rlist_iter riter = {{0,},};
-
- /* dispatch NR_IOVEC IO vectors at a time. */
-
- erpc = data;
- sequence = erpc->rlist->seq[0];
-
- rlist_iter_init (&riter, erpc->rlist);
-
- rvec_for_each_entry (rvec, &riter) {
- idx = count % NR_IOVEC;
- if (++count == NR_IOVEC) {
- erpc->vec.vector[idx] = rvec->iov;
- erpc->vec.seq = sequence++;
- erpc->vec.count = NR_IOVEC;
-
- ret = changelog_dispatch_vec (frame, this,
- erpc->rpc, &erpc->vec);
- if (ret)
- break;
- count = 0;
- continue;
- }
-
- erpc->vec.vector[idx] = rvec->iov;
- }
-
- if (ret)
- goto error_return;
-
- idx = count % NR_IOVEC;
- if (idx) {
- erpc->vec.seq = sequence;
- erpc->vec.count = idx;
-
- ret = changelog_dispatch_vec (frame, this,
- erpc->rpc, &erpc->vec);
- }
-
- error_return:
- return ret;
+ struct timeval tv = {
+ 0,
+ };
+ changelog_event_req req = {
+ 0,
+ };
+
+ (void)gettimeofday(&tv, NULL);
+
+ /**
+ * Event dispatch RPC header contains a sequence number for each
+ * dispatch. This allows the receiver to order the request before
+ * processing.
+ */
+ req.seq = vec->seq;
+ req.tv_sec = tv.tv_sec;
+ req.tv_usec = tv.tv_usec;
+
+ return changelog_rpc_sumbit_req(
+ rpc, (void *)&req, frame, &changelog_ev_program,
+ CHANGELOG_REV_PROC_EVENT, vec->vector, vec->count, NULL, this,
+ changelog_event_dispatch_cbk, (xdrproc_t)xdr_changelog_event_req);
}
int
-changelog_rpc_notify (struct rpc_clnt *rpc,
- void *mydata, rpc_clnt_event_t event, void *data)
+changelog_event_dispatch_rpc(call_frame_t *frame, xlator_t *this, void *data)
{
- xlator_t *this = NULL;
- changelog_rpc_clnt_t *crpc = NULL;
- changelog_clnt_t *c_clnt = NULL;
- changelog_priv_t *priv = NULL;
- changelog_ev_selector_t *selection = NULL;
+ int idx = 0;
+ int count = 0;
+ int ret = 0;
+ unsigned long sequence = 0;
+ rbuf_iovec_t *rvec = NULL;
+ struct ev_rpc *erpc = NULL;
+ struct rlist_iter riter = {
+ {
+ 0,
+ },
+ };
+
+ /* dispatch NR_IOVEC IO vectors at a time. */
+
+ erpc = data;
+ sequence = erpc->rlist->seq[0];
+
+ rlist_iter_init(&riter, erpc->rlist);
+
+ rvec_for_each_entry(rvec, &riter)
+ {
+ idx = count % NR_IOVEC;
+ if (++count == NR_IOVEC) {
+ erpc->vec.vector[idx] = rvec->iov;
+ erpc->vec.seq = sequence++;
+ erpc->vec.count = NR_IOVEC;
- crpc = mydata;
- this = crpc->this;
- c_clnt = crpc->c_clnt;
+ ret = changelog_dispatch_vec(frame, this, erpc->rpc, &erpc->vec);
+ if (ret)
+ break;
+ count = 0;
+ continue;
+ }
+
+ erpc->vec.vector[idx] = rvec->iov;
+ }
- priv = this->private;
+ if (ret)
+ goto error_return;
- switch (event) {
+ idx = count % NR_IOVEC;
+ if (idx) {
+ erpc->vec.seq = sequence;
+ erpc->vec.count = idx;
+
+ ret = changelog_dispatch_vec(frame, this, erpc->rpc, &erpc->vec);
+ }
+
+error_return:
+ return ret;
+}
+
+int
+changelog_rpc_notify(struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
+ void *data)
+{
+ xlator_t *this = NULL;
+ changelog_rpc_clnt_t *crpc = NULL;
+ changelog_clnt_t *c_clnt = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_ev_selector_t *selection = NULL;
+
+ crpc = mydata;
+ this = crpc->this;
+ c_clnt = crpc->c_clnt;
+
+ priv = this->private;
+
+ switch (event) {
case RPC_CLNT_CONNECT:
- selection = &priv->ev_selection;
+ selection = &priv->ev_selection;
- LOCK (&c_clnt->wait_lock);
+ LOCK(&c_clnt->wait_lock);
+ {
+ LOCK(&c_clnt->active_lock);
{
- LOCK (&c_clnt->active_lock);
- {
- changelog_select_event (this, selection,
- crpc->filter);
- list_move_tail (&crpc->list, &c_clnt->active);
- }
- UNLOCK (&c_clnt->active_lock);
+ changelog_select_event(this, selection, crpc->filter);
+ list_move_tail(&crpc->list, &c_clnt->active);
}
- UNLOCK (&c_clnt->wait_lock);
+ UNLOCK(&c_clnt->active_lock);
+ }
+ UNLOCK(&c_clnt->wait_lock);
- break;
+ break;
case RPC_CLNT_DISCONNECT:
- rpc_clnt_disable (crpc->rpc);
+ rpc_clnt_disable(crpc->rpc);
- /* rpc_clnt_disable doesn't unref the rpc. It just marks
- * the rpc as disabled and cancels reconnection timer.
- * Hence unref the rpc object to free it.
- */
- rpc_clnt_unref (crpc->rpc);
+ /* rpc_clnt_disable doesn't unref the rpc. It just marks
+ * the rpc as disabled and cancels reconnection timer.
+ * Hence unref the rpc object to free it.
+ */
+ rpc_clnt_unref(crpc->rpc);
- if (priv)
- selection = &priv->ev_selection;
+ if (priv)
+ selection = &priv->ev_selection;
- LOCK (&crpc->lock);
- {
- if (selection)
- changelog_deselect_event (this, selection,
- crpc->filter);
- changelog_set_disconnect_flag (crpc, _gf_true);
- }
- UNLOCK (&crpc->lock);
+ LOCK(&crpc->lock);
+ {
+ if (selection)
+ changelog_deselect_event(this, selection, crpc->filter);
+ changelog_set_disconnect_flag(crpc, _gf_true);
+ }
+ UNLOCK(&crpc->lock);
- break;
+ break;
case RPC_CLNT_MSG:
case RPC_CLNT_DESTROY:
- /* Free up mydata */
- changelog_rpc_clnt_unref (crpc);
- break;
+ /* Free up mydata */
+ changelog_rpc_clnt_unref(crpc);
+ break;
case RPC_CLNT_PING:
- break;
- }
+ break;
+ }
- return 0;
+ return 0;
}
void *
-changelog_ev_connector (void *data)
+changelog_ev_connector(void *data)
{
- xlator_t *this = NULL;
- changelog_clnt_t *c_clnt = NULL;
- changelog_rpc_clnt_t *crpc = NULL;
+ xlator_t *this = NULL;
+ changelog_clnt_t *c_clnt = NULL;
+ changelog_rpc_clnt_t *crpc = NULL;
- c_clnt = data;
- this = c_clnt->this;
+ c_clnt = data;
+ this = c_clnt->this;
- while (1) {
- pthread_mutex_lock (&c_clnt->pending_lock);
- {
- while (list_empty (&c_clnt->pending))
- pthread_cond_wait (&c_clnt->pending_cond,
- &c_clnt->pending_lock);
- crpc = list_first_entry (&c_clnt->pending,
- changelog_rpc_clnt_t, list);
- crpc->rpc =
- changelog_rpc_client_init (this, crpc,
- crpc->sock,
- changelog_rpc_notify);
- if (!crpc->rpc) {
- gf_smsg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_RPC_CONNECT_ERROR,
- "failed to connect back",
- "path=%s", crpc->sock,
- NULL);
- crpc->cleanup (crpc);
- goto mutex_unlock;
- }
-
- LOCK (&c_clnt->wait_lock);
- {
- list_move_tail (&crpc->list, &c_clnt->waitq);
- }
- UNLOCK (&c_clnt->wait_lock);
- }
- mutex_unlock:
- pthread_mutex_unlock (&c_clnt->pending_lock);
+ while (1) {
+ pthread_mutex_lock(&c_clnt->pending_lock);
+ {
+ while (list_empty(&c_clnt->pending))
+ pthread_cond_wait(&c_clnt->pending_cond, &c_clnt->pending_lock);
+ crpc = list_first_entry(&c_clnt->pending, changelog_rpc_clnt_t,
+ list);
+ crpc->rpc = changelog_rpc_client_init(this, crpc, crpc->sock,
+ changelog_rpc_notify);
+ if (!crpc->rpc) {
+ gf_smsg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_RPC_CONNECT_ERROR,
+ "failed to connect back", "path=%s", crpc->sock, NULL);
+ crpc->cleanup(crpc);
+ goto mutex_unlock;
+ }
+
+ LOCK(&c_clnt->wait_lock);
+ {
+ list_move_tail(&crpc->list, &c_clnt->waitq);
+ }
+ UNLOCK(&c_clnt->wait_lock);
}
+ mutex_unlock:
+ pthread_mutex_unlock(&c_clnt->pending_lock);
+ }
- return NULL;
+ return NULL;
}
void
-changelog_ev_cleanup_connections (xlator_t *this, changelog_clnt_t *c_clnt)
+changelog_ev_cleanup_connections(xlator_t *this, changelog_clnt_t *c_clnt)
{
- changelog_rpc_clnt_t *crpc = NULL;
+ changelog_rpc_clnt_t *crpc = NULL;
- /* cleanup active connections */
- LOCK (&c_clnt->active_lock);
+ /* cleanup active connections */
+ LOCK(&c_clnt->active_lock);
+ {
+ list_for_each_entry(crpc, &c_clnt->active, list)
{
- list_for_each_entry (crpc, &c_clnt->active, list) {
- rpc_clnt_disable (crpc->rpc);
- }
+ rpc_clnt_disable(crpc->rpc);
}
- UNLOCK (&c_clnt->active_lock);
+ }
+ UNLOCK(&c_clnt->active_lock);
}
/**
@@ -255,147 +254,146 @@ changelog_ev_cleanup_connections (xlator_t *this, changelog_clnt_t *c_clnt)
*/
static changelog_rpc_clnt_t *
-get_client (changelog_clnt_t *c_clnt, struct list_head **next)
+get_client(changelog_clnt_t *c_clnt, struct list_head **next)
{
- changelog_rpc_clnt_t *crpc = NULL;
-
- LOCK (&c_clnt->active_lock);
- {
- if (*next == &c_clnt->active)
- goto unblock;
- crpc = list_entry (*next, changelog_rpc_clnt_t, list);
- /* ref rpc as DISCONNECT might unref the rpc asynchronously */
- changelog_rpc_clnt_ref (crpc);
- rpc_clnt_ref (crpc->rpc);
- *next = (*next)->next;
- }
- unblock:
- UNLOCK (&c_clnt->active_lock);
-
- return crpc;
+ changelog_rpc_clnt_t *crpc = NULL;
+
+ LOCK(&c_clnt->active_lock);
+ {
+ if (*next == &c_clnt->active)
+ goto unblock;
+ crpc = list_entry(*next, changelog_rpc_clnt_t, list);
+ /* ref rpc as DISCONNECT might unref the rpc asynchronously */
+ changelog_rpc_clnt_ref(crpc);
+ rpc_clnt_ref(crpc->rpc);
+ *next = (*next)->next;
+ }
+unblock:
+ UNLOCK(&c_clnt->active_lock);
+
+ return crpc;
}
static void
-put_client (changelog_clnt_t *c_clnt, changelog_rpc_clnt_t *crpc)
+put_client(changelog_clnt_t *c_clnt, changelog_rpc_clnt_t *crpc)
{
- LOCK (&c_clnt->active_lock);
- {
- rpc_clnt_unref (crpc->rpc);
- changelog_rpc_clnt_unref (crpc);
- }
- UNLOCK (&c_clnt->active_lock);
+ LOCK(&c_clnt->active_lock);
+ {
+ rpc_clnt_unref(crpc->rpc);
+ changelog_rpc_clnt_unref(crpc);
+ }
+ UNLOCK(&c_clnt->active_lock);
}
void
-_dispatcher (rbuf_list_t *rlist, void *arg)
+_dispatcher(rbuf_list_t *rlist, void *arg)
{
- xlator_t *this = NULL;
- changelog_clnt_t *c_clnt = NULL;
- changelog_rpc_clnt_t *crpc = NULL;
- struct ev_rpc erpc = {0,};
- struct list_head *next = NULL;
-
- c_clnt = arg;
- this = c_clnt->this;
-
- erpc.rlist = rlist;
- next = c_clnt->active.next;
-
- while (1) {
- crpc = get_client (c_clnt, &next);
- if (!crpc)
- break;
- erpc.rpc = crpc->rpc;
- (void) changelog_invoke_rpc (this, crpc->rpc,
- &changelog_ev_program,
- CHANGELOG_REV_PROC_EVENT, &erpc);
- put_client (c_clnt, crpc);
- }
+ xlator_t *this = NULL;
+ changelog_clnt_t *c_clnt = NULL;
+ changelog_rpc_clnt_t *crpc = NULL;
+ struct ev_rpc erpc = {
+ 0,
+ };
+ struct list_head *next = NULL;
+
+ c_clnt = arg;
+ this = c_clnt->this;
+
+ erpc.rlist = rlist;
+ next = c_clnt->active.next;
+
+ while (1) {
+ crpc = get_client(c_clnt, &next);
+ if (!crpc)
+ break;
+ erpc.rpc = crpc->rpc;
+ (void)changelog_invoke_rpc(this, crpc->rpc, &changelog_ev_program,
+ CHANGELOG_REV_PROC_EVENT, &erpc);
+ put_client(c_clnt, crpc);
+ }
}
/** this is called under rotbuff's lock */
void
-sequencer (rbuf_list_t *rlist, void *mydata)
+sequencer(rbuf_list_t *rlist, void *mydata)
{
- unsigned long range = 0;
- changelog_clnt_t *c_clnt = 0;
+ unsigned long range = 0;
+ changelog_clnt_t *c_clnt = 0;
- c_clnt = mydata;
+ c_clnt = mydata;
- range = (RLIST_ENTRY_COUNT (rlist)) / NR_IOVEC;
- if ((RLIST_ENTRY_COUNT (rlist)) % NR_IOVEC)
- range++;
- RLIST_STORE_SEQ (rlist, c_clnt->sequence, range);
+ range = (RLIST_ENTRY_COUNT(rlist)) / NR_IOVEC;
+ if ((RLIST_ENTRY_COUNT(rlist)) % NR_IOVEC)
+ range++;
+ RLIST_STORE_SEQ(rlist, c_clnt->sequence, range);
- c_clnt->sequence += range;
+ c_clnt->sequence += range;
}
void *
-changelog_ev_dispatch (void *data)
+changelog_ev_dispatch(void *data)
{
- int ret = 0;
- void *opaque = NULL;
- xlator_t *this = NULL;
- changelog_clnt_t *c_clnt = NULL;
- struct timeval tv = {0,};
-
- c_clnt = data;
- this = c_clnt->this;
-
- while (1) {
- /* TODO: change this to be pthread cond based.. later */
-
- tv.tv_sec = 1;
- tv.tv_usec = 0;
- select (0, NULL, NULL, NULL, &tv);
-
- ret = rbuf_get_buffer (c_clnt->rbuf,
- &opaque, sequencer, c_clnt);
- if (ret != RBUF_CONSUMABLE) {
- if (ret != RBUF_EMPTY)
- gf_smsg (this->name, GF_LOG_WARNING, 0,
- CHANGELOG_MSG_BUFFER_STARVATION_ERROR,
- "Failed to get buffer for RPC dispatch",
- "rbuf_retval=%d", ret,
- NULL);
- continue;
- }
-
- ret = rbuf_wait_for_completion (c_clnt->rbuf,
- opaque, _dispatcher, c_clnt);
- if (ret)
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CHANGELOG_MSG_PUT_BUFFER_FAILED,
- "failed to put buffer after consumption");
-
+ int ret = 0;
+ void *opaque = NULL;
+ xlator_t *this = NULL;
+ changelog_clnt_t *c_clnt = NULL;
+ struct timeval tv = {
+ 0,
+ };
+
+ c_clnt = data;
+ this = c_clnt->this;
+
+ while (1) {
+ /* TODO: change this to be pthread cond based.. later */
+
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ select(0, NULL, NULL, NULL, &tv);
+
+ ret = rbuf_get_buffer(c_clnt->rbuf, &opaque, sequencer, c_clnt);
+ if (ret != RBUF_CONSUMABLE) {
+ if (ret != RBUF_EMPTY)
+ gf_smsg(this->name, GF_LOG_WARNING, 0,
+ CHANGELOG_MSG_BUFFER_STARVATION_ERROR,
+ "Failed to get buffer for RPC dispatch",
+ "rbuf_retval=%d", ret, NULL);
+ continue;
}
- return NULL;
+ ret = rbuf_wait_for_completion(c_clnt->rbuf, opaque, _dispatcher,
+ c_clnt);
+ if (ret)
+ gf_msg(this->name, GF_LOG_WARNING, 0,
+ CHANGELOG_MSG_PUT_BUFFER_FAILED,
+ "failed to put buffer after consumption");
+ }
+
+ return NULL;
}
void
-changelog_ev_queue_connection (changelog_clnt_t *c_clnt,
- changelog_rpc_clnt_t *crpc)
+changelog_ev_queue_connection(changelog_clnt_t *c_clnt,
+ changelog_rpc_clnt_t *crpc)
{
- pthread_mutex_lock (&c_clnt->pending_lock);
- {
- list_add_tail (&crpc->list, &c_clnt->pending);
- pthread_cond_signal (&c_clnt->pending_cond);
- }
- pthread_mutex_unlock (&c_clnt->pending_lock);
+ pthread_mutex_lock(&c_clnt->pending_lock);
+ {
+ list_add_tail(&crpc->list, &c_clnt->pending);
+ pthread_cond_signal(&c_clnt->pending_cond);
+ }
+ pthread_mutex_unlock(&c_clnt->pending_lock);
}
struct rpc_clnt_procedure changelog_ev_procs[CHANGELOG_REV_PROC_MAX] = {
- [CHANGELOG_REV_PROC_NULL] = {"NULL", NULL},
- [CHANGELOG_REV_PROC_EVENT] = {
- "EVENT DISPATCH", changelog_event_dispatch_rpc
- },
+ [CHANGELOG_REV_PROC_NULL] = {"NULL", NULL},
+ [CHANGELOG_REV_PROC_EVENT] = {"EVENT DISPATCH",
+ changelog_event_dispatch_rpc},
};
struct rpc_clnt_program changelog_ev_program = {
- .progname = "CHANGELOG EVENT DISPATCHER",
- .prognum = CHANGELOG_REV_RPC_PROCNUM,
- .progver = CHANGELOG_REV_RPC_PROCVER,
- .numproc = CHANGELOG_REV_PROC_MAX,
- .proctable = changelog_ev_procs,
+ .progname = "CHANGELOG EVENT DISPATCHER",
+ .prognum = CHANGELOG_REV_RPC_PROCNUM,
+ .progver = CHANGELOG_REV_RPC_PROCVER,
+ .numproc = CHANGELOG_REV_PROC_MAX,
+ .proctable = changelog_ev_procs,
};
diff --git a/xlators/features/changelog/src/changelog-helpers.c b/xlators/features/changelog/src/changelog-helpers.c
index 28c72a8f9d4..53219bf2d78 100644
--- a/xlators/features/changelog/src/changelog-helpers.c
+++ b/xlators/features/changelog/src/changelog-helpers.c
@@ -24,316 +24,301 @@
#include <pthread.h>
static void
-changelog_cleanup_free_mutex (void *arg_mutex)
+changelog_cleanup_free_mutex(void *arg_mutex)
{
- pthread_mutex_t *p_mutex = (pthread_mutex_t*) arg_mutex;
+ pthread_mutex_t *p_mutex = (pthread_mutex_t *)arg_mutex;
if (p_mutex)
- pthread_mutex_unlock(p_mutex);
+ pthread_mutex_unlock(p_mutex);
}
int
-changelog_thread_cleanup (xlator_t *this, pthread_t thr_id)
+changelog_thread_cleanup(xlator_t *this, pthread_t thr_id)
{
- int ret = 0;
- void *retval = NULL;
-
- /* send a cancel request to the thread */
- ret = pthread_cancel (thr_id);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_CANCEL_FAILED,
- "could not cancel thread");
- goto out;
- }
-
- ret = pthread_join (thr_id, &retval);
- if ((ret != 0) || (retval != PTHREAD_CANCELED)) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_CANCEL_FAILED,
- "cancel request not adhered as expected");
- }
+ int ret = 0;
+ void *retval = NULL;
+
+ /* send a cancel request to the thread */
+ ret = pthread_cancel(thr_id);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_CANCEL_FAILED, "could not cancel thread");
+ goto out;
+ }
+
+ ret = pthread_join(thr_id, &retval);
+ if ((ret != 0) || (retval != PTHREAD_CANCELED)) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_CANCEL_FAILED,
+ "cancel request not adhered as expected");
+ }
- out:
- return ret;
+out:
+ return ret;
}
void *
-changelog_get_usable_buffer (changelog_local_t *local)
+changelog_get_usable_buffer(changelog_local_t *local)
{
- changelog_log_data_t *cld = NULL;
+ changelog_log_data_t *cld = NULL;
- if (!local)
- return NULL;
+ if (!local)
+ return NULL;
- cld = &local->cld;
- if (!cld->cld_iobuf)
- return NULL;
+ cld = &local->cld;
+ if (!cld->cld_iobuf)
+ return NULL;
- return cld->cld_iobuf->ptr;
+ return cld->cld_iobuf->ptr;
}
static int
-changelog_selector_index (unsigned int selector)
+changelog_selector_index(unsigned int selector)
{
- return (ffs (selector) - 1);
+ return (ffs(selector) - 1);
}
int
-changelog_ev_selected (xlator_t *this,
- changelog_ev_selector_t *selection,
- unsigned int selector)
+changelog_ev_selected(xlator_t *this, changelog_ev_selector_t *selection,
+ unsigned int selector)
{
- int idx = 0;
-
- idx = changelog_selector_index (selector);
- gf_msg_debug (this->name, 0,
- "selector ref count for %d (idx: %d): %d",
- selector, idx, selection->ref[idx]);
- /* this can be lockless */
- return (idx < CHANGELOG_EV_SELECTION_RANGE
- && (selection->ref[idx] > 0));
+ int idx = 0;
+
+ idx = changelog_selector_index(selector);
+ gf_msg_debug(this->name, 0, "selector ref count for %d (idx: %d): %d",
+ selector, idx, selection->ref[idx]);
+ /* this can be lockless */
+ return (idx < CHANGELOG_EV_SELECTION_RANGE && (selection->ref[idx] > 0));
}
void
-changelog_select_event (xlator_t *this,
- changelog_ev_selector_t *selection,
- unsigned int selector)
+changelog_select_event(xlator_t *this, changelog_ev_selector_t *selection,
+ unsigned int selector)
{
- int idx = 0;
-
- LOCK (&selection->reflock);
- {
- while (selector) {
- idx = changelog_selector_index (selector);
- if (idx < CHANGELOG_EV_SELECTION_RANGE) {
- selection->ref[idx]++;
- gf_msg_debug (this->name, 0,
- "selecting event %d", idx);
- }
- selector &= ~(1 << idx);
- }
- }
- UNLOCK (&selection->reflock);
+ int idx = 0;
+
+ LOCK(&selection->reflock);
+ {
+ while (selector) {
+ idx = changelog_selector_index(selector);
+ if (idx < CHANGELOG_EV_SELECTION_RANGE) {
+ selection->ref[idx]++;
+ gf_msg_debug(this->name, 0, "selecting event %d", idx);
+ }
+ selector &= ~(1 << idx);
+ }
+ }
+ UNLOCK(&selection->reflock);
}
void
-changelog_deselect_event (xlator_t *this,
- changelog_ev_selector_t *selection,
- unsigned int selector)
+changelog_deselect_event(xlator_t *this, changelog_ev_selector_t *selection,
+ unsigned int selector)
{
- int idx = 0;
-
- LOCK (&selection->reflock);
- {
- while (selector) {
- idx = changelog_selector_index (selector);
- if (idx < CHANGELOG_EV_SELECTION_RANGE) {
- selection->ref[idx]--;
- gf_msg_debug (this->name, 0,
- "de-selecting event %d", idx);
- }
- selector &= ~(1 << idx);
- }
- }
- UNLOCK (&selection->reflock);
+ int idx = 0;
+
+ LOCK(&selection->reflock);
+ {
+ while (selector) {
+ idx = changelog_selector_index(selector);
+ if (idx < CHANGELOG_EV_SELECTION_RANGE) {
+ selection->ref[idx]--;
+ gf_msg_debug(this->name, 0, "de-selecting event %d", idx);
+ }
+ selector &= ~(1 << idx);
+ }
+ }
+ UNLOCK(&selection->reflock);
}
int
-changelog_init_event_selection (xlator_t *this,
- changelog_ev_selector_t *selection)
+changelog_init_event_selection(xlator_t *this,
+ changelog_ev_selector_t *selection)
{
- int ret = 0;
- int j = CHANGELOG_EV_SELECTION_RANGE;
+ int ret = 0;
+ int j = CHANGELOG_EV_SELECTION_RANGE;
- ret = LOCK_INIT (&selection->reflock);
- if (ret != 0)
- return -1;
+ ret = LOCK_INIT(&selection->reflock);
+ if (ret != 0)
+ return -1;
- LOCK (&selection->reflock);
- {
- while (j--) {
- selection->ref[j] = 0;
- }
+ LOCK(&selection->reflock);
+ {
+ while (j--) {
+ selection->ref[j] = 0;
}
- UNLOCK (&selection->reflock);
+ }
+ UNLOCK(&selection->reflock);
- return 0;
+ return 0;
}
int
-changelog_cleanup_event_selection (xlator_t *this,
- changelog_ev_selector_t *selection)
+changelog_cleanup_event_selection(xlator_t *this,
+ changelog_ev_selector_t *selection)
{
- int j = CHANGELOG_EV_SELECTION_RANGE;
+ int j = CHANGELOG_EV_SELECTION_RANGE;
- LOCK (&selection->reflock);
- {
- while (j--) {
- if (selection->ref[j] > 0)
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CHANGELOG_MSG_CLEANUP_ON_ACTIVE_REF,
- "changelog event selection cleaning up "
- " on active references");
- }
+ LOCK(&selection->reflock);
+ {
+ while (j--) {
+ if (selection->ref[j] > 0)
+ gf_msg(this->name, GF_LOG_WARNING, 0,
+ CHANGELOG_MSG_CLEANUP_ON_ACTIVE_REF,
+ "changelog event selection cleaning up "
+ " on active references");
}
- UNLOCK (&selection->reflock);
+ }
+ UNLOCK(&selection->reflock);
- return LOCK_DESTROY (&selection->reflock);
+ return LOCK_DESTROY(&selection->reflock);
}
static void
-changelog_perform_dispatch (xlator_t *this,
- changelog_priv_t *priv, void *mem, size_t size)
+changelog_perform_dispatch(xlator_t *this, changelog_priv_t *priv, void *mem,
+ size_t size)
{
- char *buf = NULL;
- void *opaque = NULL;
-
- buf = rbuf_reserve_write_area (priv->rbuf, size, &opaque);
- if (!buf) {
- gf_msg_callingfn (this->name,
- GF_LOG_WARNING, 0,
- CHANGELOG_MSG_DISPATCH_EVENT_FAILED,
- "failed to dispatch event");
- return;
- }
+ char *buf = NULL;
+ void *opaque = NULL;
+
+ buf = rbuf_reserve_write_area(priv->rbuf, size, &opaque);
+ if (!buf) {
+ gf_msg_callingfn(this->name, GF_LOG_WARNING, 0,
+ CHANGELOG_MSG_DISPATCH_EVENT_FAILED,
+ "failed to dispatch event");
+ return;
+ }
- memcpy (buf, mem, size);
- rbuf_write_complete (opaque);
+ memcpy(buf, mem, size);
+ rbuf_write_complete(opaque);
}
void
-changelog_dispatch_event (xlator_t *this,
- changelog_priv_t *priv, changelog_event_t *ev)
+changelog_dispatch_event(xlator_t *this, changelog_priv_t *priv,
+ changelog_event_t *ev)
{
- changelog_ev_selector_t *selection = NULL;
+ changelog_ev_selector_t *selection = NULL;
- selection = &priv->ev_selection;
- if (changelog_ev_selected (this, selection, ev->ev_type)) {
- changelog_perform_dispatch (this, priv, ev, CHANGELOG_EV_SIZE);
- }
+ selection = &priv->ev_selection;
+ if (changelog_ev_selected(this, selection, ev->ev_type)) {
+ changelog_perform_dispatch(this, priv, ev, CHANGELOG_EV_SIZE);
+ }
}
void
-changelog_set_usable_record_and_length (changelog_local_t *local,
- size_t len, int xr)
+changelog_set_usable_record_and_length(changelog_local_t *local, size_t len,
+ int xr)
{
- changelog_log_data_t *cld = NULL;
+ changelog_log_data_t *cld = NULL;
- cld = &local->cld;
+ cld = &local->cld;
- cld->cld_ptr_len = len;
- cld->cld_xtra_records = xr;
+ cld->cld_ptr_len = len;
+ cld->cld_xtra_records = xr;
}
void
-changelog_local_cleanup (xlator_t *xl, changelog_local_t *local)
+changelog_local_cleanup(xlator_t *xl, changelog_local_t *local)
{
- int i = 0;
- changelog_opt_t *co = NULL;
- changelog_log_data_t *cld = NULL;
+ int i = 0;
+ changelog_opt_t *co = NULL;
+ changelog_log_data_t *cld = NULL;
- if (!local)
- return;
+ if (!local)
+ return;
- cld = &local->cld;
+ cld = &local->cld;
- /* cleanup dynamic allocation for extra records */
- if (cld->cld_xtra_records) {
- co = (changelog_opt_t *) cld->cld_ptr;
- for (; i < cld->cld_xtra_records; i++, co++)
- if (co->co_free)
- co->co_free (co);
- }
+ /* cleanup dynamic allocation for extra records */
+ if (cld->cld_xtra_records) {
+ co = (changelog_opt_t *)cld->cld_ptr;
+ for (; i < cld->cld_xtra_records; i++, co++)
+ if (co->co_free)
+ co->co_free(co);
+ }
- CHANGELOG_IOBUF_UNREF (cld->cld_iobuf);
+ CHANGELOG_IOBUF_UNREF(cld->cld_iobuf);
- if (local->inode)
- inode_unref (local->inode);
+ if (local->inode)
+ inode_unref(local->inode);
- mem_put (local);
+ mem_put(local);
}
int
-changelog_write (int fd, char *buffer, size_t len)
+changelog_write(int fd, char *buffer, size_t len)
{
- ssize_t size = 0;
- size_t written = 0;
+ ssize_t size = 0;
+ size_t written = 0;
- while (written < len) {
- size = sys_write (fd,
- buffer + written, len - written);
- if (size <= 0)
- break;
+ while (written < len) {
+ size = sys_write(fd, buffer + written, len - written);
+ if (size <= 0)
+ break;
- written += size;
- }
+ written += size;
+ }
- return (written != len);
+ return (written != len);
}
int
-htime_update (xlator_t *this,
- changelog_priv_t *priv, unsigned long ts,
- char * buffer)
+htime_update(xlator_t *this, changelog_priv_t *priv, unsigned long ts,
+ char *buffer)
{
- char changelog_path[PATH_MAX+1] = {0,};
- int len = -1;
- char x_value[25] = {0,};
- /* time stamp(10) + : (1) + rolltime (12 ) + buffer (2) */
- int ret = 0;
-
- if (priv->htime_fd ==-1) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_HTIME_ERROR,
- "Htime fd not available for updation");
- ret = -1;
- goto out;
- }
- len = snprintf(changelog_path, PATH_MAX, "%s", buffer);
- if (len >= PATH_MAX) {
- ret = -1;
- goto out;
- }
- if (changelog_write (priv->htime_fd, (void*) changelog_path, len+1 ) < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_HTIME_ERROR,
- "Htime file content write failed");
- ret =-1;
- goto out;
- }
-
- len = snprintf (x_value, sizeof (x_value), "%lu:%d",
- ts, priv->rollover_count);
- if (len >= sizeof (x_value)) {
- ret = -1;
- goto out;
- }
-
- if (sys_fsetxattr (priv->htime_fd, HTIME_KEY, x_value,
- len, XATTR_REPLACE)) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_HTIME_ERROR,
- "Htime xattr updation failed with XATTR_REPLACE",
- "changelog=%s", changelog_path,
- NULL);
-
- if (sys_fsetxattr (priv->htime_fd, HTIME_KEY, x_value,
- len, 0)) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_HTIME_ERROR,
- "Htime xattr updation failed",
- "changelog=%s", changelog_path,
- NULL);
- ret = -1;
- goto out;
- }
- }
-
- priv->rollover_count +=1;
+ char changelog_path[PATH_MAX + 1] = {
+ 0,
+ };
+ int len = -1;
+ char x_value[25] = {
+ 0,
+ };
+ /* time stamp(10) + : (1) + rolltime (12 ) + buffer (2) */
+ int ret = 0;
+
+ if (priv->htime_fd == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_HTIME_ERROR,
+ "Htime fd not available for updation");
+ ret = -1;
+ goto out;
+ }
+ len = snprintf(changelog_path, PATH_MAX, "%s", buffer);
+ if (len >= PATH_MAX) {
+ ret = -1;
+ goto out;
+ }
+ if (changelog_write(priv->htime_fd, (void *)changelog_path, len + 1) < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_HTIME_ERROR,
+ "Htime file content write failed");
+ ret = -1;
+ goto out;
+ }
+
+ len = snprintf(x_value, sizeof(x_value), "%lu:%d", ts,
+ priv->rollover_count);
+ if (len >= sizeof(x_value)) {
+ ret = -1;
+ goto out;
+ }
+
+ if (sys_fsetxattr(priv->htime_fd, HTIME_KEY, x_value, len, XATTR_REPLACE)) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_HTIME_ERROR,
+ "Htime xattr updation failed with XATTR_REPLACE",
+ "changelog=%s", changelog_path, NULL);
+
+ if (sys_fsetxattr(priv->htime_fd, HTIME_KEY, x_value, len, 0)) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_HTIME_ERROR,
+ "Htime xattr updation failed", "changelog=%s",
+ changelog_path, NULL);
+ ret = -1;
+ goto out;
+ }
+ }
+
+ priv->rollover_count += 1;
out:
- return ret;
+ return ret;
}
/*
@@ -345,43 +330,45 @@ out:
* 0 : If NOT empty, proceed usual.
*/
int
-cl_is_empty (xlator_t *this, int fd)
+cl_is_empty(xlator_t *this, int fd)
{
- int ret = -1;
- size_t elen = 0;
- int encoding = -1;
- char buffer[1024] = {0,};
- struct stat stbuf = {0,};
- int major_version = -1;
- int minor_version = -1;
-
- ret = sys_fstat (fd, &stbuf);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FSTAT_OP_FAILED,
- "Could not stat (CHANGELOG)");
- goto out;
- }
-
- ret = sys_lseek (fd, 0, SEEK_SET);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_LSEEK_OP_FAILED,
- "Could not lseek (CHANGELOG)");
- goto out;
- }
-
- CHANGELOG_GET_HEADER_INFO (fd, buffer, sizeof (buffer), encoding,
- major_version, minor_version, elen);
-
- if (elen == stbuf.st_size) {
- ret = 1;
- } else {
- ret = 0;
- }
+ int ret = -1;
+ size_t elen = 0;
+ int encoding = -1;
+ char buffer[1024] = {
+ 0,
+ };
+ struct stat stbuf = {
+ 0,
+ };
+ int major_version = -1;
+ int minor_version = -1;
+
+ ret = sys_fstat(fd, &stbuf);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSTAT_OP_FAILED,
+ "Could not stat (CHANGELOG)");
+ goto out;
+ }
+
+ ret = sys_lseek(fd, 0, SEEK_SET);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_LSEEK_OP_FAILED,
+ "Could not lseek (CHANGELOG)");
+ goto out;
+ }
+
+ CHANGELOG_GET_HEADER_INFO(fd, buffer, sizeof(buffer), encoding,
+ major_version, minor_version, elen);
+
+ if (elen == stbuf.st_size) {
+ ret = 1;
+ } else {
+ ret = 0;
+ }
out:
- return ret;
+ return ret;
}
/*
@@ -393,162 +380,156 @@ out:
* -1 : Error
*/
int
-update_path (xlator_t *this, char *cl_path)
+update_path(xlator_t *this, char *cl_path)
{
- const char low_cl[] = "changelog";
- const char up_cl[] = "CHANGELOG";
- char *found = NULL;
- int ret = -1;
-
- found = strstr(cl_path, up_cl);
-
- if (found == NULL) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_LSEEK_OP_FAILED,
- "Could not find CHANGELOG in changelog path");
- goto out;
- } else {
- memcpy(found, low_cl, sizeof (low_cl) - 1);
- }
-
- ret = 0;
+ const char low_cl[] = "changelog";
+ const char up_cl[] = "CHANGELOG";
+ char *found = NULL;
+ int ret = -1;
+
+ found = strstr(cl_path, up_cl);
+
+ if (found == NULL) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_LSEEK_OP_FAILED,
+ "Could not find CHANGELOG in changelog path");
+ goto out;
+ } else {
+ memcpy(found, low_cl, sizeof(low_cl) - 1);
+ }
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
static int
-changelog_rollover_changelog (xlator_t *this,
- changelog_priv_t *priv, unsigned long ts)
+changelog_rollover_changelog(xlator_t *this, changelog_priv_t *priv,
+ unsigned long ts)
{
- int ret = -1;
- int notify = 0;
- int cl_empty_flag = 0;
- char ofile[PATH_MAX] = {0,};
- char nfile[PATH_MAX] = {0,};
- changelog_event_t ev = {0,};
-
- if (priv->changelog_fd != -1) {
- ret = sys_fsync (priv->changelog_fd);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FSYNC_OP_FAILED,
- "fsync failed");
- }
- ret = cl_is_empty (this, priv->changelog_fd);
- if (ret == 1) {
- cl_empty_flag = 1;
- } else if (ret == -1) {
- /* Log error but proceed as usual */
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CHANGELOG_MSG_DETECT_EMPTY_CHANGELOG_FAILED,
- "Error detecting empty changelog");
- }
- sys_close (priv->changelog_fd);
- priv->changelog_fd = -1;
+ int ret = -1;
+ int notify = 0;
+ int cl_empty_flag = 0;
+ char ofile[PATH_MAX] = {
+ 0,
+ };
+ char nfile[PATH_MAX] = {
+ 0,
+ };
+ changelog_event_t ev = {
+ 0,
+ };
+
+ if (priv->changelog_fd != -1) {
+ ret = sys_fsync(priv->changelog_fd);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_FSYNC_OP_FAILED, "fsync failed");
+ }
+ ret = cl_is_empty(this, priv->changelog_fd);
+ if (ret == 1) {
+ cl_empty_flag = 1;
+ } else if (ret == -1) {
+ /* Log error but proceed as usual */
+ gf_msg(this->name, GF_LOG_WARNING, 0,
+ CHANGELOG_MSG_DETECT_EMPTY_CHANGELOG_FAILED,
+ "Error detecting empty changelog");
+ }
+ sys_close(priv->changelog_fd);
+ priv->changelog_fd = -1;
+ }
+
+ (void)snprintf(ofile, PATH_MAX, "%s/" CHANGELOG_FILE_NAME,
+ priv->changelog_dir);
+ (void)snprintf(nfile, PATH_MAX, "%s/" CHANGELOG_FILE_NAME ".%lu",
+ priv->changelog_dir, ts);
+
+ if (cl_empty_flag == 1) {
+ ret = sys_unlink(ofile);
+ if (ret) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_UNLINK_OP_FAILED,
+ "error unlinking empty changelog", "path=%s", ofile, NULL);
+ ret = 0; /* Error in unlinking empty changelog should
+ not break further changelog operation, so
+ reset return value to 0*/
}
+ } else {
+ ret = sys_rename(ofile, nfile);
- (void) snprintf (ofile, PATH_MAX,
- "%s/"CHANGELOG_FILE_NAME, priv->changelog_dir);
- (void) snprintf (nfile, PATH_MAX,
- "%s/"CHANGELOG_FILE_NAME".%lu",
- priv->changelog_dir, ts);
-
- if (cl_empty_flag == 1) {
- ret = sys_unlink (ofile);
- if (ret) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_UNLINK_OP_FAILED,
- "error unlinking empty changelog",
- "path=%s", ofile,
- NULL);
- ret = 0; /* Error in unlinking empty changelog should
- not break further changelog operation, so
- reset return value to 0*/
- }
- } else {
- ret = sys_rename (ofile, nfile);
-
- if (ret && (errno == ENOENT)) {
- ret = 0;
- goto out;
- }
- if (ret) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_RENAME_ERROR,
- "error renaming",
- "from=%s", ofile,
- "to=%s", nfile,
- NULL);
- }
+ if (ret && (errno == ENOENT)) {
+ ret = 0;
+ goto out;
}
-
- if (!ret && (cl_empty_flag == 0)) {
- notify = 1;
+ if (ret) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_RENAME_ERROR,
+ "error renaming", "from=%s", ofile, "to=%s", nfile, NULL);
}
+ }
- if (!ret) {
- if (cl_empty_flag) {
- update_path (this, nfile);
- }
- ret = htime_update (this, priv, ts, nfile);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR,
- 0, CHANGELOG_MSG_HTIME_ERROR,
- "could not update htime file");
- goto out;
- }
- }
+ if (!ret && (cl_empty_flag == 0)) {
+ notify = 1;
+ }
- if (notify) {
- ev.ev_type = CHANGELOG_OP_TYPE_JOURNAL;
- memcpy (ev.u.journal.path, nfile, strlen (nfile) + 1);
- changelog_dispatch_event (this, priv, &ev);
+ if (!ret) {
+ if (cl_empty_flag) {
+ update_path(this, nfile);
}
- out:
- /* If this is explicit rollover initiated by snapshot,
- * wakeup reconfigure thread waiting for changelog to
- * rollover. This should happen even in failure cases as
- * well otherwise snapshot will timeout and fail. Hence
- * moved under out.
- */
- if (priv->explicit_rollover) {
- priv->explicit_rollover = _gf_false;
-
- pthread_mutex_lock (&priv->bn.bnotify_mutex);
- {
- if (ret) {
- priv->bn.bnotify_error = _gf_true;
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_EXPLICIT_ROLLOVER_FAILED,
- "Fail snapshot because of "
- "previous errors");
- } else {
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_BNOTIFY_INFO, "Explicit "
- "rollover changelog signaling "
- "bnotify",
- "changelog=%s", nfile,
- NULL);
- }
- priv->bn.bnotify = _gf_false;
- pthread_cond_signal (&priv->bn.bnotify_cond);
- }
- pthread_mutex_unlock (&priv->bn.bnotify_mutex);
+ ret = htime_update(this, priv, ts, nfile);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_HTIME_ERROR,
+ "could not update htime file");
+ goto out;
}
- return ret;
+ }
+
+ if (notify) {
+ ev.ev_type = CHANGELOG_OP_TYPE_JOURNAL;
+ memcpy(ev.u.journal.path, nfile, strlen(nfile) + 1);
+ changelog_dispatch_event(this, priv, &ev);
+ }
+out:
+ /* If this is explicit rollover initiated by snapshot,
+ * wakeup reconfigure thread waiting for changelog to
+ * rollover. This should happen even in failure cases as
+ * well otherwise snapshot will timeout and fail. Hence
+ * moved under out.
+ */
+ if (priv->explicit_rollover) {
+ priv->explicit_rollover = _gf_false;
+
+ pthread_mutex_lock(&priv->bn.bnotify_mutex);
+ {
+ if (ret) {
+ priv->bn.bnotify_error = _gf_true;
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_EXPLICIT_ROLLOVER_FAILED,
+ "Fail snapshot because of "
+ "previous errors");
+ } else {
+ gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BNOTIFY_INFO,
+ "Explicit "
+ "rollover changelog signaling "
+ "bnotify",
+ "changelog=%s", nfile, NULL);
+ }
+ priv->bn.bnotify = _gf_false;
+ pthread_cond_signal(&priv->bn.bnotify_cond);
+ }
+ pthread_mutex_unlock(&priv->bn.bnotify_mutex);
+ }
+ return ret;
}
int
-filter_cur_par_dirs (const struct dirent *entry)
+filter_cur_par_dirs(const struct dirent *entry)
{
- if (entry == NULL)
- return 0;
+ if (entry == NULL)
+ return 0;
- if ((strcmp(entry->d_name, ".") == 0) ||
- (strcmp(entry->d_name, "..") == 0))
- return 0;
- else
- return 1;
+ if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0))
+ return 0;
+ else
+ return 1;
}
/*
@@ -561,313 +542,296 @@ filter_cur_par_dirs (const struct dirent *entry)
*/
int
-find_current_htime (int ht_dir_fd, const char *ht_dir_path, char *ht_file_bname)
+find_current_htime(int ht_dir_fd, const char *ht_dir_path, char *ht_file_bname)
{
- struct dirent **namelist = NULL;
- int ret = 0;
- int cnt = 0;
- int i = 0;
- xlator_t *this = NULL;
-
- this = THIS;
- GF_ASSERT (this);
- GF_ASSERT (ht_dir_path);
-
- cnt = scandir (ht_dir_path, &namelist, filter_cur_par_dirs, alphasort);
- if (cnt < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_SCAN_DIR_FAILED,
- "scandir failed");
- } else if (cnt > 0) {
- if (snprintf (ht_file_bname, NAME_MAX, "%s",
- namelist[cnt - 1]->d_name) >= NAME_MAX) {
- ret = -1;
- goto out;
- }
- if (sys_fsetxattr (ht_dir_fd, HTIME_CURRENT, ht_file_bname,
- strlen (ht_file_bname), 0)) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FSETXATTR_FAILED,
- "fsetxattr failed: HTIME_CURRENT");
- ret = -1;
- goto out;
- }
+ struct dirent **namelist = NULL;
+ int ret = 0;
+ int cnt = 0;
+ int i = 0;
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT(this);
+ GF_ASSERT(ht_dir_path);
+
+ cnt = scandir(ht_dir_path, &namelist, filter_cur_par_dirs, alphasort);
+ if (cnt < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_SCAN_DIR_FAILED,
+ "scandir failed");
+ } else if (cnt > 0) {
+ if (snprintf(ht_file_bname, NAME_MAX, "%s",
+ namelist[cnt - 1]->d_name) >= NAME_MAX) {
+ ret = -1;
+ goto out;
+ }
+ if (sys_fsetxattr(ht_dir_fd, HTIME_CURRENT, ht_file_bname,
+ strlen(ht_file_bname), 0)) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_FSETXATTR_FAILED,
+ "fsetxattr failed: HTIME_CURRENT");
+ ret = -1;
+ goto out;
+ }
+
+ if (sys_fsync(ht_dir_fd) < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_FSYNC_OP_FAILED, "fsync failed");
+ ret = -1;
+ goto out;
+ }
+ }
- if (sys_fsync (ht_dir_fd) < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FSYNC_OP_FAILED,
- "fsync failed");
- ret = -1;
- goto out;
- }
- }
+out:
+ for (i = 0; i < cnt; i++)
+ free(namelist[i]);
+ free(namelist);
- out:
- for (i = 0; i < cnt; i++)
- free (namelist[i]);
- free (namelist);
+ if (ret)
+ cnt = ret;
- if (ret)
- cnt = ret;
-
- return cnt;
+ return cnt;
}
/* Returns 0 on successful open of htime file
* returns -1 on failure or error
*/
int
-htime_open (xlator_t *this,
- changelog_priv_t *priv, unsigned long ts)
+htime_open(xlator_t *this, changelog_priv_t *priv, unsigned long ts)
{
- int ht_file_fd = -1;
- int ht_dir_fd = -1;
- int ret = 0;
- int cnt = 0;
- char ht_dir_path[PATH_MAX] = {0,};
- char ht_file_path[PATH_MAX] = {0,};
- char ht_file_bname[NAME_MAX] = {0,};
- char x_value[NAME_MAX] = {0,};
- int flags = 0;
- unsigned long min_ts = 0;
- unsigned long max_ts = 0;
- unsigned long total = 0;
- unsigned long total1 = 0;
- ssize_t size = 0;
- struct stat stat_buf = {0,};
- unsigned long record_len = 0;
- int32_t len = 0;
-
- CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path);
-
- /* Open htime directory to get HTIME_CURRENT */
- ht_dir_fd = open (ht_dir_path, O_RDONLY);
- if (ht_dir_fd == -1) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_OPEN_FAILED, "open failed",
- "path=%s", ht_dir_path,
- NULL);
- ret = -1;
- goto out;
- }
-
- size = sys_fgetxattr (ht_dir_fd, HTIME_CURRENT, ht_file_bname,
- sizeof (ht_file_bname));
- if (size < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FGETXATTR_FAILED, "Error extracting"
- " HTIME_CURRENT.");
-
- /* If upgrade scenario, find the latest HTIME.TSTAMP file
- * and use the same. If error, create a new HTIME.TSTAMP
- * file.
- */
- cnt = find_current_htime (ht_dir_fd, ht_dir_path,
- ht_file_bname);
- if (cnt <= 0) {
- gf_msg (this->name, GF_LOG_INFO, errno,
- CHANGELOG_MSG_HTIME_INFO,
- "HTIME_CURRENT not found. Changelog enabled"
- " before init");
- sys_close (ht_dir_fd);
- return htime_create (this, priv, ts);
- }
-
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_HTIME_ERROR, "Error extracting"
- " HTIME_CURRENT.");
- }
-
- gf_smsg (this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_HTIME_INFO,
- "HTIME_CURRENT",
- "path=%s", ht_file_bname, NULL);
- len = snprintf (ht_file_path, PATH_MAX, "%s/%s", ht_dir_path,
- ht_file_bname);
- if ((len < 0) || (len >= PATH_MAX)) {
- ret = -1;
- goto out;
- }
-
- /* Open in append mode as existing htime file is used */
- flags |= (O_RDWR | O_SYNC | O_APPEND);
- ht_file_fd = open (ht_file_path, flags,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (ht_file_fd < 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_OPEN_FAILED,
- "unable to open htime file",
- "path=%s", ht_file_path,
- NULL);
- ret = -1;
- goto out;
- }
-
- /* save this htime_fd in priv->htime_fd */
- priv->htime_fd = ht_file_fd;
-
- ret = sys_fstat (ht_file_fd, &stat_buf);
- if (ret < 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_HTIME_ERROR,
- "unable to stat htime file",
- "path=%s", ht_file_path,
- NULL);
- ret = -1;
- goto out;
- }
-
- /* Initialize rollover-number in priv to current number */
- size = sys_fgetxattr (ht_file_fd, HTIME_KEY, x_value, sizeof (x_value));
- if (size < 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FGETXATTR_FAILED, "error extracting max"
- " timstamp from htime file",
- "path=%s", ht_file_path,
- NULL);
- ret = -1;
- goto out;
- }
-
- sscanf (x_value, "%lu:%lu", &max_ts, &total);
-
- /* 22 = 1(/) + 20(CHANGELOG.TIMESTAMP) + 1(\x00) */
- record_len = strlen(priv->changelog_dir) + 22;
- total1 = stat_buf.st_size/record_len;
- if (total != total1) {
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_TOTAL_LOG_INFO,
- "Mismatch of changelog count. "
- "INIT CASE",
- "xattr_total=%lu", total,
- "size_total=%lu", total1,
- NULL);
- }
-
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_TOTAL_LOG_INFO,
- "INIT CASE",
- "min=%lu", min_ts,
- "max=%lu", max_ts,
- "total_changelogs=%lu", total,
- NULL);
-
- if (total < total1)
- priv->rollover_count = total1 + 1;
- else
- priv->rollover_count = total + 1;
+ int ht_file_fd = -1;
+ int ht_dir_fd = -1;
+ int ret = 0;
+ int cnt = 0;
+ char ht_dir_path[PATH_MAX] = {
+ 0,
+ };
+ char ht_file_path[PATH_MAX] = {
+ 0,
+ };
+ char ht_file_bname[NAME_MAX] = {
+ 0,
+ };
+ char x_value[NAME_MAX] = {
+ 0,
+ };
+ int flags = 0;
+ unsigned long min_ts = 0;
+ unsigned long max_ts = 0;
+ unsigned long total = 0;
+ unsigned long total1 = 0;
+ ssize_t size = 0;
+ struct stat stat_buf = {
+ 0,
+ };
+ unsigned long record_len = 0;
+ int32_t len = 0;
+
+ CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path);
+
+ /* Open htime directory to get HTIME_CURRENT */
+ ht_dir_fd = open(ht_dir_path, O_RDONLY);
+ if (ht_dir_fd == -1) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED,
+ "open failed", "path=%s", ht_dir_path, NULL);
+ ret = -1;
+ goto out;
+ }
+
+ size = sys_fgetxattr(ht_dir_fd, HTIME_CURRENT, ht_file_bname,
+ sizeof(ht_file_bname));
+ if (size < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FGETXATTR_FAILED,
+ "Error extracting"
+ " HTIME_CURRENT.");
+
+ /* If upgrade scenario, find the latest HTIME.TSTAMP file
+ * and use the same. If error, create a new HTIME.TSTAMP
+ * file.
+ */
+ cnt = find_current_htime(ht_dir_fd, ht_dir_path, ht_file_bname);
+ if (cnt <= 0) {
+ gf_msg(this->name, GF_LOG_INFO, errno, CHANGELOG_MSG_HTIME_INFO,
+ "HTIME_CURRENT not found. Changelog enabled"
+ " before init");
+ sys_close(ht_dir_fd);
+ return htime_create(this, priv, ts);
+ }
+
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_HTIME_ERROR,
+ "Error extracting"
+ " HTIME_CURRENT.");
+ }
+
+ gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_HTIME_INFO,
+ "HTIME_CURRENT", "path=%s", ht_file_bname, NULL);
+ len = snprintf(ht_file_path, PATH_MAX, "%s/%s", ht_dir_path, ht_file_bname);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
+
+ /* Open in append mode as existing htime file is used */
+ flags |= (O_RDWR | O_SYNC | O_APPEND);
+ ht_file_fd = open(ht_file_path, flags,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (ht_file_fd < 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED,
+ "unable to open htime file", "path=%s", ht_file_path, NULL);
+ ret = -1;
+ goto out;
+ }
+
+ /* save this htime_fd in priv->htime_fd */
+ priv->htime_fd = ht_file_fd;
+
+ ret = sys_fstat(ht_file_fd, &stat_buf);
+ if (ret < 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_HTIME_ERROR,
+ "unable to stat htime file", "path=%s", ht_file_path, NULL);
+ ret = -1;
+ goto out;
+ }
+
+ /* Initialize rollover-number in priv to current number */
+ size = sys_fgetxattr(ht_file_fd, HTIME_KEY, x_value, sizeof(x_value));
+ if (size < 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FGETXATTR_FAILED,
+ "error extracting max"
+ " timstamp from htime file",
+ "path=%s", ht_file_path, NULL);
+ ret = -1;
+ goto out;
+ }
+
+ sscanf(x_value, "%lu:%lu", &max_ts, &total);
+
+ /* 22 = 1(/) + 20(CHANGELOG.TIMESTAMP) + 1(\x00) */
+ record_len = strlen(priv->changelog_dir) + 22;
+ total1 = stat_buf.st_size / record_len;
+ if (total != total1) {
+ gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_TOTAL_LOG_INFO,
+ "Mismatch of changelog count. "
+ "INIT CASE",
+ "xattr_total=%lu", total, "size_total=%lu", total1, NULL);
+ }
+
+ gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_TOTAL_LOG_INFO,
+ "INIT CASE", "min=%lu", min_ts, "max=%lu", max_ts,
+ "total_changelogs=%lu", total, NULL);
+
+ if (total < total1)
+ priv->rollover_count = total1 + 1;
+ else
+ priv->rollover_count = total + 1;
out:
- if (ht_dir_fd != -1)
- sys_close (ht_dir_fd);
- return ret;
+ if (ht_dir_fd != -1)
+ sys_close(ht_dir_fd);
+ return ret;
}
/* Returns 0 on successful creation of htime file
* returns -1 on failure or error
*/
int
-htime_create (xlator_t *this,
- changelog_priv_t *priv, unsigned long ts)
+htime_create(xlator_t *this, changelog_priv_t *priv, unsigned long ts)
{
- int ht_file_fd = -1;
- int ht_dir_fd = -1;
- int ret = 0;
- char ht_dir_path[PATH_MAX] = {0,};
- char ht_file_path[PATH_MAX] = {0,};
- char ht_file_bname[NAME_MAX + 1] = {0,};
- int flags = 0;
- int32_t len = 0;
-
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_HTIME_INFO, "Changelog enable: Creating new "
- "HTIME file",
- "name=%lu", ts,
- NULL);
-
- CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path);
-
- /* get the htime file name in ht_file_path */
- len = snprintf (ht_file_path, PATH_MAX, "%s/%s.%lu", ht_dir_path,
- HTIME_FILE_NAME, ts);
- if ((len < 0) || (len >= PATH_MAX)) {
- ret = -1;
- goto out;
- }
-
- flags |= (O_CREAT | O_RDWR | O_SYNC);
- ht_file_fd = open (ht_file_path, flags,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (ht_file_fd < 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_OPEN_FAILED,
- "unable to create htime file",
- "path=%s", ht_file_path,
- NULL);
- ret = -1;
- goto out;
- }
-
- if (sys_fsetxattr (ht_file_fd, HTIME_KEY, HTIME_INITIAL_VALUE,
- sizeof (HTIME_INITIAL_VALUE)-1, 0)) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FSETXATTR_FAILED,
- "Htime xattr initialization failed");
- ret = -1;
- goto out;
- }
-
- ret = sys_fsync (ht_file_fd);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FSYNC_OP_FAILED,
- "fsync failed");
- goto out;
- }
-
- /* save this htime_fd in priv->htime_fd */
- priv->htime_fd = ht_file_fd;
-
- ht_file_fd = -1;
-
- /* Set xattr HTIME_CURRENT on htime directory to htime filename */
- ht_dir_fd = open (ht_dir_path, O_RDONLY);
- if (ht_dir_fd == -1) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_OPEN_FAILED, "open failed",
- "path=%s", ht_dir_path,
- NULL);
- ret = -1;
- goto out;
- }
-
- (void) snprintf (ht_file_bname, sizeof (ht_file_bname), "%s.%lu",
- HTIME_FILE_NAME, ts);
- if (sys_fsetxattr (ht_dir_fd, HTIME_CURRENT, ht_file_bname,
- strlen (ht_file_bname), 0)) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FSETXATTR_FAILED, "fsetxattr failed:"
- " HTIME_CURRENT");
- ret = -1;
- goto out;
- }
-
- ret = sys_fsync (ht_dir_fd);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FSYNC_OP_FAILED,
- "fsync failed");
- goto out;
- }
-
- /* initialize rollover-number in priv to 1 */
- priv->rollover_count = 1;
+ int ht_file_fd = -1;
+ int ht_dir_fd = -1;
+ int ret = 0;
+ char ht_dir_path[PATH_MAX] = {
+ 0,
+ };
+ char ht_file_path[PATH_MAX] = {
+ 0,
+ };
+ char ht_file_bname[NAME_MAX + 1] = {
+ 0,
+ };
+ int flags = 0;
+ int32_t len = 0;
+
+ gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_HTIME_INFO,
+ "Changelog enable: Creating new "
+ "HTIME file",
+ "name=%lu", ts, NULL);
+
+ CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, ht_dir_path);
+
+ /* get the htime file name in ht_file_path */
+ len = snprintf(ht_file_path, PATH_MAX, "%s/%s.%lu", ht_dir_path,
+ HTIME_FILE_NAME, ts);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
+
+ flags |= (O_CREAT | O_RDWR | O_SYNC);
+ ht_file_fd = open(ht_file_path, flags,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (ht_file_fd < 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED,
+ "unable to create htime file", "path=%s", ht_file_path, NULL);
+ ret = -1;
+ goto out;
+ }
+
+ if (sys_fsetxattr(ht_file_fd, HTIME_KEY, HTIME_INITIAL_VALUE,
+ sizeof(HTIME_INITIAL_VALUE) - 1, 0)) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSETXATTR_FAILED,
+ "Htime xattr initialization failed");
+ ret = -1;
+ goto out;
+ }
+
+ ret = sys_fsync(ht_file_fd);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED,
+ "fsync failed");
+ goto out;
+ }
+
+ /* save this htime_fd in priv->htime_fd */
+ priv->htime_fd = ht_file_fd;
+
+ ht_file_fd = -1;
+
+ /* Set xattr HTIME_CURRENT on htime directory to htime filename */
+ ht_dir_fd = open(ht_dir_path, O_RDONLY);
+ if (ht_dir_fd == -1) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED,
+ "open failed", "path=%s", ht_dir_path, NULL);
+ ret = -1;
+ goto out;
+ }
+
+ (void)snprintf(ht_file_bname, sizeof(ht_file_bname), "%s.%lu",
+ HTIME_FILE_NAME, ts);
+ if (sys_fsetxattr(ht_dir_fd, HTIME_CURRENT, ht_file_bname,
+ strlen(ht_file_bname), 0)) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSETXATTR_FAILED,
+ "fsetxattr failed:"
+ " HTIME_CURRENT");
+ ret = -1;
+ goto out;
+ }
+
+ ret = sys_fsync(ht_dir_fd);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_FSYNC_OP_FAILED,
+ "fsync failed");
+ goto out;
+ }
+
+ /* initialize rollover-number in priv to 1 */
+ priv->rollover_count = 1;
out:
- if (ht_dir_fd != -1)
- sys_close (ht_dir_fd);
- if (ht_file_fd != -1)
- sys_close (ht_file_fd);
- return ret;
+ if (ht_dir_fd != -1)
+ sys_close(ht_dir_fd);
+ if (ht_file_fd != -1)
+ sys_close(ht_file_fd);
+ return ret;
}
/* Description:
@@ -879,53 +843,53 @@ out:
* -1 : On failure.
*/
int
-changelog_snap_open (xlator_t *this,
- changelog_priv_t *priv)
+changelog_snap_open(xlator_t *this, changelog_priv_t *priv)
{
- int fd = -1;
- int ret = 0;
- int flags = 0;
- char buffer[1024] = {0,};
- char c_snap_path[PATH_MAX] = {0,};
- char csnap_dir_path[PATH_MAX] = {0,};
- int32_t len = 0;
-
- CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir_path);
-
- len = snprintf (c_snap_path, PATH_MAX, "%s/"CSNAP_FILE_NAME,
- csnap_dir_path);
- if ((len < 0) || (len >= PATH_MAX)) {
- ret = -1;
- goto out;
- }
-
- flags |= (O_CREAT | O_RDWR | O_TRUNC);
-
- fd = open (c_snap_path, flags,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (fd < 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_OPEN_FAILED, "unable to open file",
- "path=%s", c_snap_path,
- NULL);
- ret = -1;
- goto out;
- }
- priv->c_snap_fd = fd;
-
- (void) snprintf (buffer, 1024, CHANGELOG_HEADER,
- CHANGELOG_VERSION_MAJOR,
- CHANGELOG_VERSION_MINOR,
- priv->ce->encoder);
- ret = changelog_snap_write_change (priv, buffer, strlen (buffer));
- if (ret < 0) {
- sys_close (priv->c_snap_fd);
- priv->c_snap_fd = -1;
- goto out;
- }
+ int fd = -1;
+ int ret = 0;
+ int flags = 0;
+ char buffer[1024] = {
+ 0,
+ };
+ char c_snap_path[PATH_MAX] = {
+ 0,
+ };
+ char csnap_dir_path[PATH_MAX] = {
+ 0,
+ };
+ int32_t len = 0;
+
+ CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir_path);
+
+ len = snprintf(c_snap_path, PATH_MAX, "%s/" CSNAP_FILE_NAME,
+ csnap_dir_path);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
+
+ flags |= (O_CREAT | O_RDWR | O_TRUNC);
+
+ fd = open(c_snap_path, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (fd < 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED,
+ "unable to open file", "path=%s", c_snap_path, NULL);
+ ret = -1;
+ goto out;
+ }
+ priv->c_snap_fd = fd;
+
+ (void)snprintf(buffer, 1024, CHANGELOG_HEADER, CHANGELOG_VERSION_MAJOR,
+ CHANGELOG_VERSION_MINOR, priv->ce->encoder);
+ ret = changelog_snap_write_change(priv, buffer, strlen(buffer));
+ if (ret < 0) {
+ sys_close(priv->c_snap_fd);
+ priv->c_snap_fd = -1;
+ goto out;
+ }
out:
- return ret;
+ return ret;
}
/*
@@ -936,17 +900,15 @@ out:
* -1 : On Failure.
*/
int
-changelog_snap_logging_start (xlator_t *this,
- changelog_priv_t *priv)
+changelog_snap_logging_start(xlator_t *this, changelog_priv_t *priv)
{
- int ret = 0;
+ int ret = 0;
- ret = changelog_snap_open (this, priv);
- gf_msg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_SNAP_INFO,
- "Now starting to log in call path");
+ ret = changelog_snap_open(this, priv);
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_SNAP_INFO,
+ "Now starting to log in call path");
- return ret;
+ return ret;
}
/*
@@ -957,120 +919,116 @@ changelog_snap_logging_start (xlator_t *this,
* -1 : On Failure.
*/
int
-changelog_snap_logging_stop (xlator_t *this,
- changelog_priv_t *priv)
+changelog_snap_logging_stop(xlator_t *this, changelog_priv_t *priv)
{
- int ret = 0;
+ int ret = 0;
- sys_close (priv->c_snap_fd);
- priv->c_snap_fd = -1;
+ sys_close(priv->c_snap_fd);
+ priv->c_snap_fd = -1;
- gf_msg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_SNAP_INFO,
- "Stopped to log in call path");
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_SNAP_INFO,
+ "Stopped to log in call path");
- return ret;
+ return ret;
}
int
-changelog_open_journal (xlator_t *this,
- changelog_priv_t *priv)
+changelog_open_journal(xlator_t *this, changelog_priv_t *priv)
{
- int fd = 0;
- int ret = -1;
- int flags = 0;
- char buffer[1024] = {0,};
- char changelog_path[PATH_MAX] = {0,};
-
- (void) snprintf (changelog_path, PATH_MAX,
- "%s/"CHANGELOG_FILE_NAME,
- priv->changelog_dir);
-
- flags |= (O_CREAT | O_RDWR);
- if (priv->fsync_interval == 0)
- flags |= O_SYNC;
-
- fd = open (changelog_path, flags,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (fd < 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_OPEN_FAILED,
- "unable to open/create changelog file."
- " change-logging will be"
- " inactive",
- "path=%s", changelog_path,
- NULL);
- goto out;
- }
+ int fd = 0;
+ int ret = -1;
+ int flags = 0;
+ char buffer[1024] = {
+ 0,
+ };
+ char changelog_path[PATH_MAX] = {
+ 0,
+ };
+
+ (void)snprintf(changelog_path, PATH_MAX, "%s/" CHANGELOG_FILE_NAME,
+ priv->changelog_dir);
+
+ flags |= (O_CREAT | O_RDWR);
+ if (priv->fsync_interval == 0)
+ flags |= O_SYNC;
+
+ fd = open(changelog_path, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (fd < 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_OPEN_FAILED,
+ "unable to open/create changelog file."
+ " change-logging will be"
+ " inactive",
+ "path=%s", changelog_path, NULL);
+ goto out;
+ }
+
+ priv->changelog_fd = fd;
+
+ (void)snprintf(buffer, 1024, CHANGELOG_HEADER, CHANGELOG_VERSION_MAJOR,
+ CHANGELOG_VERSION_MINOR, priv->ce->encoder);
+ ret = changelog_write_change(priv, buffer, strlen(buffer));
+ if (ret) {
+ sys_close(priv->changelog_fd);
+ priv->changelog_fd = -1;
+ goto out;
+ }
+
+ ret = 0;
- priv->changelog_fd = fd;
-
- (void) snprintf (buffer, 1024, CHANGELOG_HEADER,
- CHANGELOG_VERSION_MAJOR,
- CHANGELOG_VERSION_MINOR,
- priv->ce->encoder);
- ret = changelog_write_change (priv, buffer, strlen (buffer));
- if (ret) {
- sys_close (priv->changelog_fd);
- priv->changelog_fd = -1;
- goto out;
- }
-
- ret = 0;
-
- out:
- return ret;
+out:
+ return ret;
}
int
-changelog_start_next_change (xlator_t *this,
- changelog_priv_t *priv,
- unsigned long ts, gf_boolean_t finale)
+changelog_start_next_change(xlator_t *this, changelog_priv_t *priv,
+ unsigned long ts, gf_boolean_t finale)
{
- int ret = -1;
+ int ret = -1;
- ret = changelog_rollover_changelog (this, priv, ts);
+ ret = changelog_rollover_changelog(this, priv, ts);
- if (!ret && !finale)
- ret = changelog_open_journal (this, priv);
+ if (!ret && !finale)
+ ret = changelog_open_journal(this, priv);
- return ret;
+ return ret;
}
/**
* return the length of entry
*/
size_t
-changelog_entry_length ()
+changelog_entry_length()
{
- return sizeof (changelog_log_data_t);
+ return sizeof(changelog_log_data_t);
}
int
-changelog_fill_rollover_data (changelog_log_data_t *cld, gf_boolean_t is_last)
+changelog_fill_rollover_data(changelog_log_data_t *cld, gf_boolean_t is_last)
{
- struct timeval tv = {0,};
+ struct timeval tv = {
+ 0,
+ };
- cld->cld_type = CHANGELOG_TYPE_ROLLOVER;
+ cld->cld_type = CHANGELOG_TYPE_ROLLOVER;
- if (gettimeofday (&tv, NULL))
- return -1;
+ if (gettimeofday(&tv, NULL))
+ return -1;
- cld->cld_roll_time = (unsigned long) tv.tv_sec;
- cld->cld_finale = is_last;
- return 0;
+ cld->cld_roll_time = (unsigned long)tv.tv_sec;
+ cld->cld_finale = is_last;
+ return 0;
}
int
-changelog_snap_write_change (changelog_priv_t *priv, char *buffer, size_t len)
+changelog_snap_write_change(changelog_priv_t *priv, char *buffer, size_t len)
{
- return changelog_write (priv->c_snap_fd, buffer, len);
+ return changelog_write(priv->c_snap_fd, buffer, len);
}
int
-changelog_write_change (changelog_priv_t *priv, char *buffer, size_t len)
+changelog_write_change(changelog_priv_t *priv, char *buffer, size_t len)
{
- return changelog_write (priv->changelog_fd, buffer, len);
+ return changelog_write(priv->changelog_fd, buffer, len);
}
/*
@@ -1083,255 +1041,231 @@ changelog_write_change (changelog_priv_t *priv, char *buffer, size_t len)
* -1 : On Failure.
*/
int
-changelog_snap_handle_ascii_change (xlator_t *this,
- changelog_log_data_t *cld)
+changelog_snap_handle_ascii_change(xlator_t *this, changelog_log_data_t *cld)
{
- size_t off = 0;
- size_t gfid_len = 0;
- char *gfid_str = NULL;
- char *buffer = NULL;
- changelog_priv_t *priv = NULL;
- int ret = 0;
-
- if (this == NULL) {
- ret = -1;
- goto out;
- }
-
- priv = this->private;
-
- if (priv == NULL) {
- ret = -1;
- goto out;
- }
-
- gfid_str = uuid_utoa (cld->cld_gfid);
- gfid_len = strlen (gfid_str);
-
- /* extra bytes for decorations */
- buffer = alloca (gfid_len + cld->cld_ptr_len + 10);
- CHANGELOG_STORE_ASCII (priv, buffer,
- off, gfid_str, gfid_len, cld);
-
- CHANGELOG_FILL_BUFFER (buffer, off, "\0", 1);
-
- ret = changelog_snap_write_change (priv, buffer, off);
-
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_WRITE_FAILED,
- "error writing csnap to disk");
- }
- gf_msg (this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_SNAP_INFO,
- "Successfully wrote to csnap");
- ret = 0;
+ size_t off = 0;
+ size_t gfid_len = 0;
+ char *gfid_str = NULL;
+ char *buffer = NULL;
+ changelog_priv_t *priv = NULL;
+ int ret = 0;
+
+ if (this == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ priv = this->private;
+
+ if (priv == NULL) {
+ ret = -1;
+ goto out;
+ }
+
+ gfid_str = uuid_utoa(cld->cld_gfid);
+ gfid_len = strlen(gfid_str);
+
+ /* extra bytes for decorations */
+ buffer = alloca(gfid_len + cld->cld_ptr_len + 10);
+ CHANGELOG_STORE_ASCII(priv, buffer, off, gfid_str, gfid_len, cld);
+
+ CHANGELOG_FILL_BUFFER(buffer, off, "\0", 1);
+
+ ret = changelog_snap_write_change(priv, buffer, off);
+
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_WRITE_FAILED,
+ "error writing csnap to disk");
+ }
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_SNAP_INFO,
+ "Successfully wrote to csnap");
+ ret = 0;
out:
- return ret;
+ return ret;
}
int
-changelog_handle_change (xlator_t *this,
- changelog_priv_t *priv, changelog_log_data_t *cld)
+changelog_handle_change(xlator_t *this, changelog_priv_t *priv,
+ changelog_log_data_t *cld)
{
- int ret = 0;
-
- if (CHANGELOG_TYPE_IS_ROLLOVER (cld->cld_type)) {
- changelog_encode_change (priv);
- ret = changelog_start_next_change (this, priv,
- cld->cld_roll_time,
- cld->cld_finale);
- if (ret)
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_GET_TIME_OP_FAILED,
- "Problem rolling over changelog(s)");
- goto out;
- }
+ int ret = 0;
- /**
- * case when there is reconfigure done (disabling changelog) and there
- * are still fops that have updates in prgress.
- */
- if (priv->changelog_fd == -1)
- return 0;
-
- if (CHANGELOG_TYPE_IS_FSYNC (cld->cld_type)) {
- ret = sys_fsync (priv->changelog_fd);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_FSYNC_OP_FAILED,
- "fsync failed");
- }
- goto out;
- }
+ if (CHANGELOG_TYPE_IS_ROLLOVER(cld->cld_type)) {
+ changelog_encode_change(priv);
+ ret = changelog_start_next_change(this, priv, cld->cld_roll_time,
+ cld->cld_finale);
+ if (ret)
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_GET_TIME_OP_FAILED,
+ "Problem rolling over changelog(s)");
+ goto out;
+ }
+
+ /**
+ * case when there is reconfigure done (disabling changelog) and there
+ * are still fops that have updates in prgress.
+ */
+ if (priv->changelog_fd == -1)
+ return 0;
- ret = priv->ce->encode (this, cld);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_WRITE_FAILED,
- "error writing changelog to disk");
+ if (CHANGELOG_TYPE_IS_FSYNC(cld->cld_type)) {
+ ret = sys_fsync(priv->changelog_fd);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_FSYNC_OP_FAILED, "fsync failed");
}
+ goto out;
+ }
- out:
- return ret;
+ ret = priv->ce->encode(this, cld);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_WRITE_FAILED,
+ "error writing changelog to disk");
+ }
+
+out:
+ return ret;
}
changelog_local_t *
-changelog_local_init (xlator_t *this, inode_t *inode,
- uuid_t gfid, int xtra_records,
- gf_boolean_t update_flag)
+changelog_local_init(xlator_t *this, inode_t *inode, uuid_t gfid,
+ int xtra_records, gf_boolean_t update_flag)
{
- changelog_local_t *local = NULL;
- struct iobuf *iobuf = NULL;
-
- /**
- * We relax the presence of inode if @update_flag is true.
- * The caller (implementation of the fop) needs to be careful to
- * not blindly use local->inode.
- */
- if (!update_flag && !inode) {
- gf_msg_callingfn (this->name, GF_LOG_WARNING, 0,
- CHANGELOG_MSG_INODE_NOT_FOUND,
- "inode needed for version checking !!!");
- goto out;
- }
+ changelog_local_t *local = NULL;
+ struct iobuf *iobuf = NULL;
+
+ /**
+ * We relax the presence of inode if @update_flag is true.
+ * The caller (implementation of the fop) needs to be careful to
+ * not blindly use local->inode.
+ */
+ if (!update_flag && !inode) {
+ gf_msg_callingfn(this->name, GF_LOG_WARNING, 0,
+ CHANGELOG_MSG_INODE_NOT_FOUND,
+ "inode needed for version checking !!!");
+ goto out;
+ }
- if (xtra_records) {
- iobuf = iobuf_get2 (this->ctx->iobuf_pool,
- xtra_records * CHANGELOG_OPT_RECORD_LEN);
- if (!iobuf)
- goto out;
- }
+ if (xtra_records) {
+ iobuf = iobuf_get2(this->ctx->iobuf_pool,
+ xtra_records * CHANGELOG_OPT_RECORD_LEN);
+ if (!iobuf)
+ goto out;
+ }
- local = mem_get0 (this->local_pool);
- if (!local) {
- CHANGELOG_IOBUF_UNREF (iobuf);
- goto out;
- }
+ local = mem_get0(this->local_pool);
+ if (!local) {
+ CHANGELOG_IOBUF_UNREF(iobuf);
+ goto out;
+ }
- local->update_no_check = update_flag;
+ local->update_no_check = update_flag;
- gf_uuid_copy (local->cld.cld_gfid, gfid);
+ gf_uuid_copy(local->cld.cld_gfid, gfid);
- local->cld.cld_iobuf = iobuf;
- local->cld.cld_xtra_records = 0; /* set by the caller */
+ local->cld.cld_iobuf = iobuf;
+ local->cld.cld_xtra_records = 0; /* set by the caller */
- if (inode)
- local->inode = inode_ref (inode);
+ if (inode)
+ local->inode = inode_ref(inode);
- out:
- return local;
+out:
+ return local;
}
int
-changelog_forget (xlator_t *this, inode_t *inode)
+changelog_forget(xlator_t *this, inode_t *inode)
{
- uint64_t ctx_addr = 0;
- changelog_inode_ctx_t *ctx = NULL;
+ uint64_t ctx_addr = 0;
+ changelog_inode_ctx_t *ctx = NULL;
- inode_ctx_del (inode, this, &ctx_addr);
- if (!ctx_addr)
- return 0;
+ inode_ctx_del(inode, this, &ctx_addr);
+ if (!ctx_addr)
+ return 0;
- ctx = (changelog_inode_ctx_t *) (long) ctx_addr;
- GF_FREE (ctx);
+ ctx = (changelog_inode_ctx_t *)(long)ctx_addr;
+ GF_FREE(ctx);
- return 0;
+ return 0;
}
int
-changelog_inject_single_event (xlator_t *this,
- changelog_priv_t *priv,
- changelog_log_data_t *cld)
+changelog_inject_single_event(xlator_t *this, changelog_priv_t *priv,
+ changelog_log_data_t *cld)
{
- return priv->cd.dispatchfn (this, priv, priv->cd.cd_data, cld, NULL);
+ return priv->cd.dispatchfn(this, priv, priv->cd.cd_data, cld, NULL);
}
/* Wait till all the black fops are drained */
void
-changelog_drain_black_fops (xlator_t *this, changelog_priv_t *priv)
+changelog_drain_black_fops(xlator_t *this, changelog_priv_t *priv)
{
- int ret = 0;
-
- /* clean up framework of pthread_mutex is required here as
- * 'reconfigure' terminates the changelog_rollover thread
- * on graph change.
- */
- pthread_cleanup_push (changelog_cleanup_free_mutex,
- &priv->dm.drain_black_mutex);
- ret = pthread_mutex_lock (&priv->dm.drain_black_mutex);
- if (ret)
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_ERROR, "pthread error",
- "error=%d", ret,
- NULL);
- while (priv->dm.black_fop_cnt > 0) {
- gf_msg_debug (this->name, 0,
- "Conditional wait on black fops: %ld",
- priv->dm.black_fop_cnt);
- priv->dm.drain_wait_black = _gf_true;
- ret = pthread_cond_wait (&priv->dm.drain_black_cond,
- &priv->dm.drain_black_mutex);
- if (ret)
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED,
- "pthread cond wait failed",
- "error=%d", ret,
- NULL);
- }
- priv->dm.drain_wait_black = _gf_false;
- ret = pthread_mutex_unlock (&priv->dm.drain_black_mutex);
+ int ret = 0;
+
+ /* clean up framework of pthread_mutex is required here as
+ * 'reconfigure' terminates the changelog_rollover thread
+ * on graph change.
+ */
+ pthread_cleanup_push(changelog_cleanup_free_mutex,
+ &priv->dm.drain_black_mutex);
+ ret = pthread_mutex_lock(&priv->dm.drain_black_mutex);
+ if (ret)
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_PTHREAD_ERROR,
+ "pthread error", "error=%d", ret, NULL);
+ while (priv->dm.black_fop_cnt > 0) {
+ gf_msg_debug(this->name, 0, "Conditional wait on black fops: %ld",
+ priv->dm.black_fop_cnt);
+ priv->dm.drain_wait_black = _gf_true;
+ ret = pthread_cond_wait(&priv->dm.drain_black_cond,
+ &priv->dm.drain_black_mutex);
if (ret)
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_ERROR, "pthread error",
- "error=%d", ret,
- NULL);
- pthread_cleanup_pop (0);
- gf_msg_debug (this->name, 0,
- "Woke up: Conditional wait on black fops");
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED,
+ "pthread cond wait failed", "error=%d", ret, NULL);
+ }
+ priv->dm.drain_wait_black = _gf_false;
+ ret = pthread_mutex_unlock(&priv->dm.drain_black_mutex);
+ if (ret)
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_PTHREAD_ERROR,
+ "pthread error", "error=%d", ret, NULL);
+ pthread_cleanup_pop(0);
+ gf_msg_debug(this->name, 0, "Woke up: Conditional wait on black fops");
}
/* Wait till all the white fops are drained */
void
-changelog_drain_white_fops (xlator_t *this, changelog_priv_t *priv)
+changelog_drain_white_fops(xlator_t *this, changelog_priv_t *priv)
{
- int ret = 0;
-
- /* clean up framework of pthread_mutex is required here as
- * 'reconfigure' terminates the changelog_rollover thread
- * on graph change.
- */
- pthread_cleanup_push (changelog_cleanup_free_mutex,
- &priv->dm.drain_white_mutex);
- ret = pthread_mutex_lock (&priv->dm.drain_white_mutex);
+ int ret = 0;
+
+ /* clean up framework of pthread_mutex is required here as
+ * 'reconfigure' terminates the changelog_rollover thread
+ * on graph change.
+ */
+ pthread_cleanup_push(changelog_cleanup_free_mutex,
+ &priv->dm.drain_white_mutex);
+ ret = pthread_mutex_lock(&priv->dm.drain_white_mutex);
+ if (ret)
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_PTHREAD_ERROR,
+ "pthread error", "error=%d", ret, NULL);
+ while (priv->dm.white_fop_cnt > 0) {
+ gf_msg_debug(this->name, 0, "Conditional wait on white fops : %ld",
+ priv->dm.white_fop_cnt);
+ priv->dm.drain_wait_white = _gf_true;
+ ret = pthread_cond_wait(&priv->dm.drain_white_cond,
+ &priv->dm.drain_white_mutex);
if (ret)
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_ERROR, "pthread error",
- "error=%d", ret,
- NULL);
- while (priv->dm.white_fop_cnt > 0) {
- gf_msg_debug (this->name, 0,
- "Conditional wait on white fops : %ld",
- priv->dm.white_fop_cnt);
- priv->dm.drain_wait_white = _gf_true;
- ret = pthread_cond_wait (&priv->dm.drain_white_cond,
- &priv->dm.drain_white_mutex);
- if (ret)
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED,
- "pthread cond wait failed",
- "error=%d", ret,
- NULL);
- }
- priv->dm.drain_wait_white = _gf_false;
- ret = pthread_mutex_unlock (&priv->dm.drain_white_mutex);
- if (ret)
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_ERROR, "pthread error",
- "error=%d", ret,
- NULL);
- pthread_cleanup_pop (0);
- gf_msg_debug (this->name, 0,
- "Woke up: Conditional wait on white fops");
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_COND_WAIT_FAILED,
+ "pthread cond wait failed", "error=%d", ret, NULL);
+ }
+ priv->dm.drain_wait_white = _gf_false;
+ ret = pthread_mutex_unlock(&priv->dm.drain_white_mutex);
+ if (ret)
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_PTHREAD_ERROR,
+ "pthread error", "error=%d", ret, NULL);
+ pthread_cleanup_pop(0);
+ gf_msg_debug(this->name, 0, "Woke up: Conditional wait on white fops");
}
/**
@@ -1339,193 +1273,201 @@ changelog_drain_white_fops (xlator_t *this, changelog_priv_t *priv)
* a certain time etc..). move them into separate routine.
*/
void *
-changelog_rollover (void *data)
+changelog_rollover(void *data)
{
- int ret = 0;
- xlator_t *this = NULL;
- struct timespec tv = {0,};
- changelog_log_data_t cld = {0,};
- changelog_time_slice_t *slice = NULL;
- changelog_priv_t *priv = data;
-
- this = priv->cr.this;
- slice = &priv->slice;
-
- while (1) {
- (void) pthread_testcancel();
-
- tv.tv_sec = time (NULL) + priv->rollover_time;
- tv.tv_nsec = 0;
- ret = 0; /* Reset ret to zero */
-
- /* The race between actual rollover and explicit rollover is
- * handled. If actual rollover is being done and the
- * explicit rollover event comes, the event is not missed.
- * Since explicit rollover sets 'cr.notify' to true, this
- * thread doesn't wait on 'pthread_cond_timedwait'.
- */
- pthread_cleanup_push (changelog_cleanup_free_mutex,
- &priv->cr.lock);
- pthread_mutex_lock (&priv->cr.lock);
- {
- while (ret == 0 && !priv->cr.notify)
- ret = pthread_cond_timedwait (&priv->cr.cond,
- &priv->cr.lock,
- &tv);
- if (ret == 0)
- priv->cr.notify = _gf_false;
- }
- pthread_mutex_unlock (&priv->cr.lock);
- pthread_cleanup_pop (0);
-
- if (ret == 0) {
- gf_msg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_BARRIER_INFO,
- "Explicit wakeup on barrier notify");
- priv->explicit_rollover = _gf_true;
- } else if (ret && ret != ETIMEDOUT) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_SELECT_FAILED,
- "pthread_cond_timedwait failed");
- continue;
- } else if (ret && ret == ETIMEDOUT) {
- gf_msg_debug (this->name, 0, "Wokeup on timeout");
- }
-
- /* Reading curent_color without lock is fine here
- * as it is only modified here and is next to reading.
- */
- if (priv->current_color == FOP_COLOR_BLACK) {
- LOCK(&priv->lock);
- priv->current_color = FOP_COLOR_WHITE;
- UNLOCK(&priv->lock);
- gf_msg_debug (this->name, 0, "Black fops"
- " to be drained:%ld",
- priv->dm.black_fop_cnt);
- changelog_drain_black_fops (this, priv);
- } else {
- LOCK(&priv->lock);
- priv->current_color = FOP_COLOR_BLACK;
- UNLOCK(&priv->lock);
- gf_msg_debug (this->name, 0, "White fops"
- " to be drained:%ld",
- priv->dm.white_fop_cnt);
- changelog_drain_white_fops (this, priv);
- }
-
- /* Adding delay of 1 second only during explicit rollover:
- *
- * Changelog rollover can happen either due to actual
- * or the explicit rollover during snapshot. Actual
- * rollover is controlled by tuneable called 'rollover-time'.
- * The minimum granularity for rollover-time is 1 second.
- * Explicit rollover is asynchronous in nature and happens
- * during snapshot.
- *
- * Basically, rollover renames the current CHANGELOG file
- * to CHANGELOG.TIMESTAMP. Let's assume, at time 't1',
- * actual and explicit rollover raced against each
- * other and actual rollover won the race renaming the
- * CHANGELOG file to CHANGELOG.t1 and opens a new
- * CHANGELOG file. There is high chance that, an immediate
- * explicit rollover at time 't1' can happen with in the same
- * second to rename CHANGELOG file to CHANGELOG.t1 resulting in
- * purging the earlier CHANGELOG.t1 file created by actual
- * rollover. So adding a delay of 1 second guarantees unique
- * CHANGELOG.TIMESTAMP during explicit rollover.
- */
- if (priv->explicit_rollover == _gf_true)
- sleep (1);
-
- ret = changelog_fill_rollover_data (&cld, _gf_false);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_GET_TIME_OP_FAILED,
- "failed to fill rollover data");
- continue;
- }
+ int ret = 0;
+ xlator_t *this = NULL;
+ struct timespec tv = {
+ 0,
+ };
+ changelog_log_data_t cld = {
+ 0,
+ };
+ changelog_time_slice_t *slice = NULL;
+ changelog_priv_t *priv = data;
+
+ this = priv->cr.this;
+ slice = &priv->slice;
+
+ while (1) {
+ (void)pthread_testcancel();
+
+ tv.tv_sec = time(NULL) + priv->rollover_time;
+ tv.tv_nsec = 0;
+ ret = 0; /* Reset ret to zero */
+
+ /* The race between actual rollover and explicit rollover is
+ * handled. If actual rollover is being done and the
+ * explicit rollover event comes, the event is not missed.
+ * Since explicit rollover sets 'cr.notify' to true, this
+ * thread doesn't wait on 'pthread_cond_timedwait'.
+ */
+ pthread_cleanup_push(changelog_cleanup_free_mutex, &priv->cr.lock);
+ pthread_mutex_lock(&priv->cr.lock);
+ {
+ while (ret == 0 && !priv->cr.notify)
+ ret = pthread_cond_timedwait(&priv->cr.cond, &priv->cr.lock,
+ &tv);
+ if (ret == 0)
+ priv->cr.notify = _gf_false;
+ }
+ pthread_mutex_unlock(&priv->cr.lock);
+ pthread_cleanup_pop(0);
+
+ if (ret == 0) {
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO,
+ "Explicit wakeup on barrier notify");
+ priv->explicit_rollover = _gf_true;
+ } else if (ret && ret != ETIMEDOUT) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_SELECT_FAILED,
+ "pthread_cond_timedwait failed");
+ continue;
+ } else if (ret && ret == ETIMEDOUT) {
+ gf_msg_debug(this->name, 0, "Wokeup on timeout");
+ }
+
+ /* Reading curent_color without lock is fine here
+ * as it is only modified here and is next to reading.
+ */
+ if (priv->current_color == FOP_COLOR_BLACK) {
+ LOCK(&priv->lock);
+ priv->current_color = FOP_COLOR_WHITE;
+ UNLOCK(&priv->lock);
+ gf_msg_debug(this->name, 0,
+ "Black fops"
+ " to be drained:%ld",
+ priv->dm.black_fop_cnt);
+ changelog_drain_black_fops(this, priv);
+ } else {
+ LOCK(&priv->lock);
+ priv->current_color = FOP_COLOR_BLACK;
+ UNLOCK(&priv->lock);
+ gf_msg_debug(this->name, 0,
+ "White fops"
+ " to be drained:%ld",
+ priv->dm.white_fop_cnt);
+ changelog_drain_white_fops(this, priv);
+ }
+
+ /* Adding delay of 1 second only during explicit rollover:
+ *
+ * Changelog rollover can happen either due to actual
+ * or the explicit rollover during snapshot. Actual
+ * rollover is controlled by tuneable called 'rollover-time'.
+ * The minimum granularity for rollover-time is 1 second.
+ * Explicit rollover is asynchronous in nature and happens
+ * during snapshot.
+ *
+ * Basically, rollover renames the current CHANGELOG file
+ * to CHANGELOG.TIMESTAMP. Let's assume, at time 't1',
+ * actual and explicit rollover raced against each
+ * other and actual rollover won the race renaming the
+ * CHANGELOG file to CHANGELOG.t1 and opens a new
+ * CHANGELOG file. There is high chance that, an immediate
+ * explicit rollover at time 't1' can happen with in the same
+ * second to rename CHANGELOG file to CHANGELOG.t1 resulting in
+ * purging the earlier CHANGELOG.t1 file created by actual
+ * rollover. So adding a delay of 1 second guarantees unique
+ * CHANGELOG.TIMESTAMP during explicit rollover.
+ */
+ if (priv->explicit_rollover == _gf_true)
+ sleep(1);
- _mask_cancellation ();
+ ret = changelog_fill_rollover_data(&cld, _gf_false);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_GET_TIME_OP_FAILED,
+ "failed to fill rollover data");
+ continue;
+ }
- LOCK (&priv->lock);
- {
- ret = changelog_inject_single_event (this, priv, &cld);
- if (!ret)
- SLICE_VERSION_UPDATE (slice);
- }
- UNLOCK (&priv->lock);
+ _mask_cancellation();
- _unmask_cancellation ();
+ LOCK(&priv->lock);
+ {
+ ret = changelog_inject_single_event(this, priv, &cld);
+ if (!ret)
+ SLICE_VERSION_UPDATE(slice);
}
+ UNLOCK(&priv->lock);
- return NULL;
+ _unmask_cancellation();
+ }
+
+ return NULL;
}
void *
-changelog_fsync_thread (void *data)
+changelog_fsync_thread(void *data)
{
- int ret = 0;
- xlator_t *this = NULL;
- struct timeval tv = {0,};
- changelog_log_data_t cld = {0,};
- changelog_priv_t *priv = data;
-
- this = priv->cf.this;
- cld.cld_type = CHANGELOG_TYPE_FSYNC;
-
- while (1) {
- (void) pthread_testcancel();
-
- tv.tv_sec = priv->fsync_interval;
- tv.tv_usec = 0;
-
- ret = select (0, NULL, NULL, NULL, &tv);
- if (ret)
- continue;
+ int ret = 0;
+ xlator_t *this = NULL;
+ struct timeval tv = {
+ 0,
+ };
+ changelog_log_data_t cld = {
+ 0,
+ };
+ changelog_priv_t *priv = data;
+
+ this = priv->cf.this;
+ cld.cld_type = CHANGELOG_TYPE_FSYNC;
+
+ while (1) {
+ (void)pthread_testcancel();
+
+ tv.tv_sec = priv->fsync_interval;
+ tv.tv_usec = 0;
+
+ ret = select(0, NULL, NULL, NULL, &tv);
+ if (ret)
+ continue;
- _mask_cancellation ();
+ _mask_cancellation();
- ret = changelog_inject_single_event (this, priv, &cld);
- if (ret)
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_INJECT_FSYNC_FAILED,
- "failed to inject fsync event");
+ ret = changelog_inject_single_event(this, priv, &cld);
+ if (ret)
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_INJECT_FSYNC_FAILED,
+ "failed to inject fsync event");
- _unmask_cancellation ();
- }
+ _unmask_cancellation();
+ }
- return NULL;
+ return NULL;
}
/* macros for inode/changelog version checks */
-#define INODE_VERSION_UPDATE(priv, inode, iver, slice, type) do { \
- LOCK (&inode->lock); \
- { \
- LOCK (&priv->lock); \
- { \
- *iver = slice->changelog_version[type]; \
- } \
- UNLOCK (&priv->lock); \
- } \
- UNLOCK (&inode->lock); \
- } while (0)
-
-#define INODE_VERSION_EQUALS_SLICE(priv, ver, slice, type, upd) do { \
- LOCK (&priv->lock); \
- { \
- upd = (ver == slice->changelog_version[type]) \
- ? _gf_false : _gf_true; \
- } \
- UNLOCK (&priv->lock); \
- } while (0)
+#define INODE_VERSION_UPDATE(priv, inode, iver, slice, type) \
+ do { \
+ LOCK(&inode->lock); \
+ { \
+ LOCK(&priv->lock); \
+ { \
+ *iver = slice->changelog_version[type]; \
+ } \
+ UNLOCK(&priv->lock); \
+ } \
+ UNLOCK(&inode->lock); \
+ } while (0)
+
+#define INODE_VERSION_EQUALS_SLICE(priv, ver, slice, type, upd) \
+ do { \
+ LOCK(&priv->lock); \
+ { \
+ upd = (ver == slice->changelog_version[type]) ? _gf_false \
+ : _gf_true; \
+ } \
+ UNLOCK(&priv->lock); \
+ } while (0)
static int
-__changelog_inode_ctx_set (xlator_t *this,
- inode_t *inode, changelog_inode_ctx_t *ctx)
+__changelog_inode_ctx_set(xlator_t *this, inode_t *inode,
+ changelog_inode_ctx_t *ctx)
{
- uint64_t ctx_addr = (uint64_t) ctx;
- return __inode_ctx_set (inode, this, &ctx_addr);
+ uint64_t ctx_addr = (uint64_t)ctx;
+ return __inode_ctx_set(inode, this, &ctx_addr);
}
/**
@@ -1533,56 +1475,53 @@ __changelog_inode_ctx_set (xlator_t *this,
* for a particular type.
*/
changelog_inode_ctx_t *
-__changelog_inode_ctx_get (xlator_t *this,
- inode_t *inode, unsigned long **iver,
- unsigned long *version, changelog_log_type type)
+__changelog_inode_ctx_get(xlator_t *this, inode_t *inode, unsigned long **iver,
+ unsigned long *version, changelog_log_type type)
{
- int ret = 0;
- uint64_t ctx_addr = 0;
- changelog_inode_ctx_t *ctx = NULL;
-
- ret = __inode_ctx_get (inode, this, &ctx_addr);
- if (ret < 0)
- ctx_addr = 0;
- if (ctx_addr != 0) {
- ctx = (changelog_inode_ctx_t *) (long)ctx_addr;
- goto out;
- }
-
- ctx = GF_CALLOC (1, sizeof (*ctx), gf_changelog_mt_inode_ctx_t);
- if (!ctx)
- goto out;
+ int ret = 0;
+ uint64_t ctx_addr = 0;
+ changelog_inode_ctx_t *ctx = NULL;
+
+ ret = __inode_ctx_get(inode, this, &ctx_addr);
+ if (ret < 0)
+ ctx_addr = 0;
+ if (ctx_addr != 0) {
+ ctx = (changelog_inode_ctx_t *)(long)ctx_addr;
+ goto out;
+ }
+
+ ctx = GF_CALLOC(1, sizeof(*ctx), gf_changelog_mt_inode_ctx_t);
+ if (!ctx)
+ goto out;
+
+ ret = __changelog_inode_ctx_set(this, inode, ctx);
+ if (ret) {
+ GF_FREE(ctx);
+ ctx = NULL;
+ }
- ret = __changelog_inode_ctx_set (this, inode, ctx);
- if (ret) {
- GF_FREE (ctx);
- ctx = NULL;
- }
-
- out:
- if (ctx && iver && version) {
- *iver = CHANGELOG_INODE_VERSION_TYPE (ctx, type);
- *version = **iver;
- }
+out:
+ if (ctx && iver && version) {
+ *iver = CHANGELOG_INODE_VERSION_TYPE(ctx, type);
+ *version = **iver;
+ }
- return ctx;
+ return ctx;
}
static changelog_inode_ctx_t *
-changelog_inode_ctx_get (xlator_t *this,
- inode_t *inode, unsigned long **iver,
- unsigned long *version, changelog_log_type type)
+changelog_inode_ctx_get(xlator_t *this, inode_t *inode, unsigned long **iver,
+ unsigned long *version, changelog_log_type type)
{
- changelog_inode_ctx_t *ctx = NULL;
+ changelog_inode_ctx_t *ctx = NULL;
- LOCK (&inode->lock);
- {
- ctx = __changelog_inode_ctx_get (this,
- inode, iver, version, type);
- }
- UNLOCK (&inode->lock);
+ LOCK(&inode->lock);
+ {
+ ctx = __changelog_inode_ctx_get(this, inode, iver, version, type);
+ }
+ UNLOCK(&inode->lock);
- return ctx;
+ return ctx;
}
/**
@@ -1686,59 +1625,57 @@ changelog_inode_ctx_get (xlator_t *this,
* signifies an update was recorded in the current time slice).
*/
void
-changelog_update (xlator_t *this, changelog_priv_t *priv,
- changelog_local_t *local, changelog_log_type type)
+changelog_update(xlator_t *this, changelog_priv_t *priv,
+ changelog_local_t *local, changelog_log_type type)
{
- int ret = 0;
- unsigned long *iver = NULL;
- unsigned long version = 0;
- inode_t *inode = NULL;
- changelog_time_slice_t *slice = NULL;
- changelog_inode_ctx_t *ctx = NULL;
- changelog_log_data_t *cld_0 = NULL;
- changelog_log_data_t *cld_1 = NULL;
- changelog_local_t *next_local = NULL;
- gf_boolean_t need_upd = _gf_true;
-
- slice = &priv->slice;
-
- /**
- * for fops that do not require inode version checking
- */
- if (local->update_no_check)
- goto update;
+ int ret = 0;
+ unsigned long *iver = NULL;
+ unsigned long version = 0;
+ inode_t *inode = NULL;
+ changelog_time_slice_t *slice = NULL;
+ changelog_inode_ctx_t *ctx = NULL;
+ changelog_log_data_t *cld_0 = NULL;
+ changelog_log_data_t *cld_1 = NULL;
+ changelog_local_t *next_local = NULL;
+ gf_boolean_t need_upd = _gf_true;
- inode = local->inode;
+ slice = &priv->slice;
- ctx = changelog_inode_ctx_get (this,
- inode, &iver, &version, type);
- if (!ctx)
- goto update;
+ /**
+ * for fops that do not require inode version checking
+ */
+ if (local->update_no_check)
+ goto update;
- INODE_VERSION_EQUALS_SLICE (priv, version, slice, type, need_upd);
+ inode = local->inode;
- update:
- if (need_upd) {
- cld_0 = &local->cld;
- cld_0->cld_type = type;
+ ctx = changelog_inode_ctx_get(this, inode, &iver, &version, type);
+ if (!ctx)
+ goto update;
- if ( (next_local = local->prev_entry) != NULL ) {
- cld_1 = &next_local->cld;
- cld_1->cld_type = type;
- }
+ INODE_VERSION_EQUALS_SLICE(priv, version, slice, type, need_upd);
- ret = priv->cd.dispatchfn (this, priv,
- priv->cd.cd_data, cld_0, cld_1);
+update:
+ if (need_upd) {
+ cld_0 = &local->cld;
+ cld_0->cld_type = type;
- /**
- * update after the dispatcher has successfully done
- * it's job.
- */
- if (!local->update_no_check && iver && !ret)
- INODE_VERSION_UPDATE (priv, inode, iver, slice, type);
+ if ((next_local = local->prev_entry) != NULL) {
+ cld_1 = &next_local->cld;
+ cld_1->cld_type = type;
}
- return;
+ ret = priv->cd.dispatchfn(this, priv, priv->cd.cd_data, cld_0, cld_1);
+
+ /**
+ * update after the dispatcher has successfully done
+ * it's job.
+ */
+ if (!local->update_no_check && iver && !ret)
+ INODE_VERSION_UPDATE(priv, inode, iver, slice, type);
+ }
+
+ return;
}
/* Begin: Geo-rep snapshot dependency changes */
@@ -1754,230 +1691,223 @@ changelog_update (xlator_t *this, changelog_priv_t *priv,
*/
void
-changelog_color_fop_and_inc_cnt (xlator_t *this, changelog_priv_t *priv,
- changelog_local_t *local)
+changelog_color_fop_and_inc_cnt(xlator_t *this, changelog_priv_t *priv,
+ changelog_local_t *local)
{
- if (!priv || !local)
- return;
+ if (!priv || !local)
+ return;
- LOCK (&priv->lock);
- {
- local->color = priv->current_color;
- changelog_inc_fop_cnt (this, priv, local);
- }
- UNLOCK (&priv->lock);
+ LOCK(&priv->lock);
+ {
+ local->color = priv->current_color;
+ changelog_inc_fop_cnt(this, priv, local);
+ }
+ UNLOCK(&priv->lock);
}
/* Increments the respective fop counter based on the fop color */
void
-changelog_inc_fop_cnt (xlator_t *this, changelog_priv_t *priv,
- changelog_local_t *local)
+changelog_inc_fop_cnt(xlator_t *this, changelog_priv_t *priv,
+ changelog_local_t *local)
{
- int ret = 0;
-
- if (local) {
- if (local->color == FOP_COLOR_BLACK) {
- ret = pthread_mutex_lock (&priv->dm.drain_black_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out);
- {
- priv->dm.black_fop_cnt++;
- }
- ret = pthread_mutex_unlock(&priv->dm.drain_black_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out);
- } else {
- ret = pthread_mutex_lock (&priv->dm.drain_white_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out);
- {
- priv->dm.white_fop_cnt++;
- }
- ret = pthread_mutex_unlock(&priv->dm.drain_white_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out);
- }
- }
- out:
- return;
+ int ret = 0;
+
+ if (local) {
+ if (local->color == FOP_COLOR_BLACK) {
+ ret = pthread_mutex_lock(&priv->dm.drain_black_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out);
+ {
+ priv->dm.black_fop_cnt++;
+ }
+ ret = pthread_mutex_unlock(&priv->dm.drain_black_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out);
+ } else {
+ ret = pthread_mutex_lock(&priv->dm.drain_white_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out);
+ {
+ priv->dm.white_fop_cnt++;
+ }
+ ret = pthread_mutex_unlock(&priv->dm.drain_white_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out);
+ }
+ }
+out:
+ return;
}
/* Decrements the respective fop counter based on the fop color */
void
-changelog_dec_fop_cnt (xlator_t *this, changelog_priv_t *priv,
- changelog_local_t *local)
+changelog_dec_fop_cnt(xlator_t *this, changelog_priv_t *priv,
+ changelog_local_t *local)
{
- int ret = 0;
-
- if (local) {
- if (local->color == FOP_COLOR_BLACK) {
- ret = pthread_mutex_lock (&priv->dm.drain_black_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out);
- {
- priv->dm.black_fop_cnt--;
- if (priv->dm.black_fop_cnt == 0 &&
- priv->dm.drain_wait_black == _gf_true) {
- ret = pthread_cond_signal (
- &priv->dm.drain_black_cond);
- CHANGELOG_PTHREAD_ERROR_HANDLE_2 (ret,
- out,
- priv->dm.drain_black_mutex);
- gf_msg_debug (this->name, 0,
- "Signalled "
- "draining of black");
- }
- }
- ret = pthread_mutex_unlock(&priv->dm.drain_black_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out);
- } else {
- ret = pthread_mutex_lock (&priv->dm.drain_white_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out);
- {
- priv->dm.white_fop_cnt--;
- if (priv->dm.white_fop_cnt == 0 &&
- priv->dm.drain_wait_white == _gf_true) {
- ret = pthread_cond_signal (
- &priv->dm.drain_white_cond);
- CHANGELOG_PTHREAD_ERROR_HANDLE_2 (ret,
- out,
- priv->dm.drain_white_mutex);
- gf_msg_debug (this->name, 0,
- "Signalled "
- "draining of white");
- }
- }
- ret = pthread_mutex_unlock(&priv->dm.drain_white_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out);
+ int ret = 0;
+
+ if (local) {
+ if (local->color == FOP_COLOR_BLACK) {
+ ret = pthread_mutex_lock(&priv->dm.drain_black_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out);
+ {
+ priv->dm.black_fop_cnt--;
+ if (priv->dm.black_fop_cnt == 0 &&
+ priv->dm.drain_wait_black == _gf_true) {
+ ret = pthread_cond_signal(&priv->dm.drain_black_cond);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_2(
+ ret, out, priv->dm.drain_black_mutex);
+ gf_msg_debug(this->name, 0,
+ "Signalled "
+ "draining of black");
+ }
+ }
+ ret = pthread_mutex_unlock(&priv->dm.drain_black_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out);
+ } else {
+ ret = pthread_mutex_lock(&priv->dm.drain_white_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out);
+ {
+ priv->dm.white_fop_cnt--;
+ if (priv->dm.white_fop_cnt == 0 &&
+ priv->dm.drain_wait_white == _gf_true) {
+ ret = pthread_cond_signal(&priv->dm.drain_white_cond);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_2(
+ ret, out, priv->dm.drain_white_mutex);
+ gf_msg_debug(this->name, 0,
+ "Signalled "
+ "draining of white");
}
+ }
+ ret = pthread_mutex_unlock(&priv->dm.drain_white_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out);
}
- out:
- return;
+ }
+out:
+ return;
}
/* Write to a pipe setup between changelog main thread and changelog
* rollover thread to initiate explicit rollover of changelog journal.
*/
int
-changelog_barrier_notify (changelog_priv_t *priv, char *buf)
+changelog_barrier_notify(changelog_priv_t *priv, char *buf)
{
- int ret = 0;
-
- pthread_mutex_lock (&priv->cr.lock);
- {
- ret = pthread_cond_signal (&priv->cr.cond);
- priv->cr.notify = _gf_true;
- }
- pthread_mutex_unlock (&priv->cr.lock);
- return ret;
+ int ret = 0;
+
+ pthread_mutex_lock(&priv->cr.lock);
+ {
+ ret = pthread_cond_signal(&priv->cr.cond);
+ priv->cr.notify = _gf_true;
+ }
+ pthread_mutex_unlock(&priv->cr.lock);
+ return ret;
}
/* Clean up flags set on barrier notification */
void
-changelog_barrier_cleanup (xlator_t *this, changelog_priv_t *priv,
- struct list_head *queue)
+changelog_barrier_cleanup(xlator_t *this, changelog_priv_t *priv,
+ struct list_head *queue)
{
- int ret = 0;
-
- LOCK (&priv->bflags.lock);
- priv->bflags.barrier_ext = _gf_false;
- UNLOCK (&priv->bflags.lock);
-
- ret = pthread_mutex_lock (&priv->bn.bnotify_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out);
- {
- priv->bn.bnotify = _gf_false;
- }
- ret = pthread_mutex_unlock (&priv->bn.bnotify_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_0 (ret, out);
-
- /* Disable changelog barrier and dequeue fops */
- LOCK (&priv->lock);
- {
- if (priv->barrier_enabled == _gf_true)
- __chlog_barrier_disable (this, queue);
- else
- ret = -1;
- }
- UNLOCK (&priv->lock);
- if (ret == 0)
- chlog_barrier_dequeue_all(this, queue);
+ int ret = 0;
+
+ LOCK(&priv->bflags.lock);
+ priv->bflags.barrier_ext = _gf_false;
+ UNLOCK(&priv->bflags.lock);
+
+ ret = pthread_mutex_lock(&priv->bn.bnotify_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out);
+ {
+ priv->bn.bnotify = _gf_false;
+ }
+ ret = pthread_mutex_unlock(&priv->bn.bnotify_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_0(ret, out);
+
+ /* Disable changelog barrier and dequeue fops */
+ LOCK(&priv->lock);
+ {
+ if (priv->barrier_enabled == _gf_true)
+ __chlog_barrier_disable(this, queue);
+ else
+ ret = -1;
+ }
+ UNLOCK(&priv->lock);
+ if (ret == 0)
+ chlog_barrier_dequeue_all(this, queue);
- out:
- return;
+out:
+ return;
}
/* End: Geo-Rep snapshot dependency changes */
int32_t
-changelog_fill_entry_buf (call_frame_t *frame, xlator_t *this,
- loc_t *loc, changelog_local_t **local)
+changelog_fill_entry_buf(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ changelog_local_t **local)
{
- changelog_opt_t *co = NULL;
- size_t xtra_len = 0;
- char *dup_path = NULL;
- char *bname = NULL;
- inode_t *parent = NULL;
-
- GF_ASSERT (this);
-
- parent = inode_parent (loc->inode, 0, 0);
- if (!parent) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_INODE_NOT_FOUND,
- "Parent inode not found",
- "gfid=%s", uuid_utoa (loc->inode->gfid),
- NULL);
- goto err;
- }
-
- CHANGELOG_INIT_NOCHECK (this, *local, loc->inode, loc->inode->gfid, 5);
- if (!(*local)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_LOCAL_INIT_FAILED, "changelog local"
- " initiatilization failed");
- goto err;
- }
-
- co = changelog_get_usable_buffer (*local);
- if (!co) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_NO_MEMORY,
- "Failed to get buffer");
- goto err;
- }
-
- if (loc->inode->ia_type == IA_IFDIR) {
- CHANGLOG_FILL_FOP_NUMBER (co, GF_FOP_MKDIR, fop_fn, xtra_len);
- co++;
- CHANGELOG_FILL_UINT32 (co, S_IFDIR|0755, number_fn, xtra_len);
- co++;
- } else {
- CHANGLOG_FILL_FOP_NUMBER (co, GF_FOP_CREATE, fop_fn, xtra_len);
- co++;
- CHANGELOG_FILL_UINT32 (co, S_IFREG|0644, number_fn, xtra_len);
- co++;
- }
-
- CHANGELOG_FILL_UINT32 (co, frame->root->uid, number_fn, xtra_len);
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
+ char *dup_path = NULL;
+ char *bname = NULL;
+ inode_t *parent = NULL;
+
+ GF_ASSERT(this);
+
+ parent = inode_parent(loc->inode, 0, 0);
+ if (!parent) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, CHANGELOG_MSG_INODE_NOT_FOUND,
+ "Parent inode not found", "gfid=%s",
+ uuid_utoa(loc->inode->gfid), NULL);
+ goto err;
+ }
+
+ CHANGELOG_INIT_NOCHECK(this, *local, loc->inode, loc->inode->gfid, 5);
+ if (!(*local)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_LOCAL_INIT_FAILED,
+ "changelog local"
+ " initiatilization failed");
+ goto err;
+ }
+
+ co = changelog_get_usable_buffer(*local);
+ if (!co) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_NO_MEMORY,
+ "Failed to get buffer");
+ goto err;
+ }
+
+ if (loc->inode->ia_type == IA_IFDIR) {
+ CHANGLOG_FILL_FOP_NUMBER(co, GF_FOP_MKDIR, fop_fn, xtra_len);
co++;
-
- CHANGELOG_FILL_UINT32 (co, frame->root->gid, number_fn, xtra_len);
+ CHANGELOG_FILL_UINT32(co, S_IFDIR | 0755, number_fn, xtra_len);
+ co++;
+ } else {
+ CHANGLOG_FILL_FOP_NUMBER(co, GF_FOP_CREATE, fop_fn, xtra_len);
+ co++;
+ CHANGELOG_FILL_UINT32(co, S_IFREG | 0644, number_fn, xtra_len);
co++;
+ }
- dup_path = gf_strdup (loc->path);
- bname = basename (dup_path);
+ CHANGELOG_FILL_UINT32(co, frame->root->uid, number_fn, xtra_len);
+ co++;
- CHANGELOG_FILL_ENTRY (co, parent->gfid, bname, entry_fn, entry_free_fn,
- xtra_len, err);
- changelog_set_usable_record_and_length (*local, xtra_len, 5);
+ CHANGELOG_FILL_UINT32(co, frame->root->gid, number_fn, xtra_len);
+ co++;
- if (dup_path)
- GF_FREE (dup_path);
- if (parent)
- inode_unref (parent);
- return 0;
+ dup_path = gf_strdup(loc->path);
+ bname = basename(dup_path);
+
+ CHANGELOG_FILL_ENTRY(co, parent->gfid, bname, entry_fn, entry_free_fn,
+ xtra_len, err);
+ changelog_set_usable_record_and_length(*local, xtra_len, 5);
+
+ if (dup_path)
+ GF_FREE(dup_path);
+ if (parent)
+ inode_unref(parent);
+ return 0;
err:
- if (dup_path)
- GF_FREE (dup_path);
- if (parent)
- inode_unref (parent);
- return -1;
+ if (dup_path)
+ GF_FREE(dup_path);
+ if (parent)
+ inode_unref(parent);
+ return -1;
}
/*
@@ -1990,93 +1920,98 @@ err:
*/
int
-resolve_pargfid_to_path (xlator_t *this, const uuid_t pgfid,
- char **path, char *bname)
+resolve_pargfid_to_path(xlator_t *this, const uuid_t pgfid, char **path,
+ char *bname)
{
- char *linkname = NULL;
- char *dir_handle = NULL;
- char *pgfidstr = NULL;
- char *saveptr = NULL;
- ssize_t len = 0;
- int ret = 0;
- uuid_t tmp_gfid = {0, };
- uuid_t pargfid = {0, };
- changelog_priv_t *priv = NULL;
- char gpath[PATH_MAX] = {0,};
- char result[PATH_MAX] = {0,};
- char *dir_name = NULL;
- char pre_dir_name[PATH_MAX] = {0,};
-
- GF_ASSERT (this);
- priv = this->private;
- GF_ASSERT (priv);
-
- gf_uuid_copy (pargfid, pgfid);
- if (!path || gf_uuid_is_null (pargfid)) {
- ret = -1;
- goto out;
- }
-
- if (__is_root_gfid (pargfid)) {
- if (bname)
- *path = gf_strdup (bname);
- else
- *path = gf_strdup (".");
- return ret;
- }
+ char *linkname = NULL;
+ char *dir_handle = NULL;
+ char *pgfidstr = NULL;
+ char *saveptr = NULL;
+ ssize_t len = 0;
+ int ret = 0;
+ uuid_t tmp_gfid = {
+ 0,
+ };
+ uuid_t pargfid = {
+ 0,
+ };
+ changelog_priv_t *priv = NULL;
+ char gpath[PATH_MAX] = {
+ 0,
+ };
+ char result[PATH_MAX] = {
+ 0,
+ };
+ char *dir_name = NULL;
+ char pre_dir_name[PATH_MAX] = {
+ 0,
+ };
+
+ GF_ASSERT(this);
+ priv = this->private;
+ GF_ASSERT(priv);
+
+ gf_uuid_copy(pargfid, pgfid);
+ if (!path || gf_uuid_is_null(pargfid)) {
+ ret = -1;
+ goto out;
+ }
+
+ if (__is_root_gfid(pargfid)) {
+ if (bname)
+ *path = gf_strdup(bname);
+ else
+ *path = gf_strdup(".");
+ return ret;
+ }
- dir_handle = alloca (PATH_MAX);
- linkname = alloca (PATH_MAX);
- (void) snprintf (gpath, PATH_MAX, "%s/.glusterfs/",
- priv->changelog_brick);
-
- while (!(__is_root_gfid (pargfid))) {
- len = snprintf (dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath,
- pargfid[0], pargfid[1], uuid_utoa (pargfid));
- if ((len < 0) || (len >= PATH_MAX)) {
- ret = -1;
- goto out;
- }
+ dir_handle = alloca(PATH_MAX);
+ linkname = alloca(PATH_MAX);
+ (void)snprintf(gpath, PATH_MAX, "%s/.glusterfs/", priv->changelog_brick);
- len = sys_readlink (dir_handle, linkname, PATH_MAX);
- if (len < 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_READLINK_OP_FAILED,
- "could not read the "
- "link from the gfid handle",
- "handle=%s", dir_handle,
- NULL);
- ret = -1;
- goto out;
- }
+ while (!(__is_root_gfid(pargfid))) {
+ len = snprintf(dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath,
+ pargfid[0], pargfid[1], uuid_utoa(pargfid));
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
- linkname[len] = '\0';
+ len = sys_readlink(dir_handle, linkname, PATH_MAX);
+ if (len < 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_READLINK_OP_FAILED,
+ "could not read the "
+ "link from the gfid handle",
+ "handle=%s", dir_handle, NULL);
+ ret = -1;
+ goto out;
+ }
- pgfidstr = strtok_r (linkname + strlen("../../00/00/"), "/",
- &saveptr);
- dir_name = strtok_r (NULL, "/", &saveptr);
+ linkname[len] = '\0';
- len = snprintf (result, PATH_MAX, "%s/%s", dir_name,
- pre_dir_name);
- if ((len < 0) || (len >= PATH_MAX)) {
- ret = -1;
- goto out;
- }
- if (snprintf (pre_dir_name, len + 1, "%s", result)
- >= len + 1) {
- ret = -1;
- goto out;
- }
+ pgfidstr = strtok_r(linkname + strlen("../../00/00/"), "/", &saveptr);
+ dir_name = strtok_r(NULL, "/", &saveptr);
- gf_uuid_parse (pgfidstr, tmp_gfid);
- gf_uuid_copy (pargfid, tmp_gfid);
+ len = snprintf(result, PATH_MAX, "%s/%s", dir_name, pre_dir_name);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
+ if (snprintf(pre_dir_name, len + 1, "%s", result) >= len + 1) {
+ ret = -1;
+ goto out;
}
- if (bname)
- strncat (result, bname, strlen(bname) + 1);
+ gf_uuid_parse(pgfidstr, tmp_gfid);
+ gf_uuid_copy(pargfid, tmp_gfid);
+ }
- *path = gf_strdup (result);
+ if (bname)
+ strncat(result, bname, strlen(bname) + 1);
+
+ *path = gf_strdup(result);
out:
- return ret;
+ return ret;
}
diff --git a/xlators/features/changelog/src/changelog-rpc-common.c b/xlators/features/changelog/src/changelog-rpc-common.c
index 056519232cf..ce01bf7a133 100644
--- a/xlators/features/changelog/src/changelog-rpc-common.c
+++ b/xlators/features/changelog/src/changelog-rpc-common.c
@@ -24,65 +24,63 @@
*/
void *
-changelog_rpc_poller (void *arg)
+changelog_rpc_poller(void *arg)
{
- xlator_t *this = arg;
+ xlator_t *this = arg;
- (void) event_dispatch (this->ctx->event_pool);
- return NULL;
+ (void)event_dispatch(this->ctx->event_pool);
+ return NULL;
}
struct rpc_clnt *
-changelog_rpc_client_init (xlator_t *this, void *cbkdata,
- char *sockfile, rpc_clnt_notify_t fn)
+changelog_rpc_client_init(xlator_t *this, void *cbkdata, char *sockfile,
+ rpc_clnt_notify_t fn)
{
- int ret = 0;
- struct rpc_clnt *rpc = NULL;
- dict_t *options = NULL;
-
- if (!cbkdata)
- cbkdata = this;
-
- options = dict_new ();
- if (!options)
- goto error_return;
-
- ret = rpc_transport_unix_options_build (&options, sockfile, 0);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_RPC_BUILD_ERROR,
- "failed to build rpc options");
- goto dealloc_dict;
- }
-
- rpc = rpc_clnt_new (options, this, this->name, 16);
- if (!rpc)
- goto dealloc_dict;
-
- ret = rpc_clnt_register_notify (rpc, fn, cbkdata);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_NOTIFY_REGISTER_FAILED,
- "failed to register notify");
- goto dealloc_rpc_clnt;
- }
-
- ret = rpc_clnt_start (rpc);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_RPC_START_ERROR,
- "failed to start rpc");
- goto dealloc_rpc_clnt;
- }
-
- return rpc;
-
- dealloc_rpc_clnt:
- rpc_clnt_unref (rpc);
- dealloc_dict:
- dict_unref (options);
- error_return:
- return NULL;
+ int ret = 0;
+ struct rpc_clnt *rpc = NULL;
+ dict_t *options = NULL;
+
+ if (!cbkdata)
+ cbkdata = this;
+
+ options = dict_new();
+ if (!options)
+ goto error_return;
+
+ ret = rpc_transport_unix_options_build(&options, sockfile, 0);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_BUILD_ERROR,
+ "failed to build rpc options");
+ goto dealloc_dict;
+ }
+
+ rpc = rpc_clnt_new(options, this, this->name, 16);
+ if (!rpc)
+ goto dealloc_dict;
+
+ ret = rpc_clnt_register_notify(rpc, fn, cbkdata);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_NOTIFY_REGISTER_FAILED,
+ "failed to register notify");
+ goto dealloc_rpc_clnt;
+ }
+
+ ret = rpc_clnt_start(rpc);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_START_ERROR,
+ "failed to start rpc");
+ goto dealloc_rpc_clnt;
+ }
+
+ return rpc;
+
+dealloc_rpc_clnt:
+ rpc_clnt_unref(rpc);
+dealloc_dict:
+ dict_unref(options);
+error_return:
+ return NULL;
}
/**
@@ -90,96 +88,96 @@ changelog_rpc_client_init (xlator_t *this, void *cbkdata,
* RPC server.
*/
int
-changelog_rpc_sumbit_req (struct rpc_clnt *rpc, void *req,
- call_frame_t *frame, rpc_clnt_prog_t *prog,
- int procnum, struct iovec *payload, int payloadcnt,
- struct iobref *iobref, xlator_t *this,
- fop_cbk_fn_t cbkfn, xdrproc_t xdrproc)
+changelog_rpc_sumbit_req(struct rpc_clnt *rpc, void *req, call_frame_t *frame,
+ rpc_clnt_prog_t *prog, int procnum,
+ struct iovec *payload, int payloadcnt,
+ struct iobref *iobref, xlator_t *this,
+ fop_cbk_fn_t cbkfn, xdrproc_t xdrproc)
{
- int ret = 0;
- int count = 0;
- struct iovec iov = {0, };
- struct iobuf *iobuf = NULL;
- char new_iobref = 0;
- ssize_t xdr_size = 0;
-
- GF_ASSERT (this);
+ int ret = 0;
+ int count = 0;
+ struct iovec iov = {
+ 0,
+ };
+ struct iobuf *iobuf = NULL;
+ char new_iobref = 0;
+ ssize_t xdr_size = 0;
- if (req) {
- xdr_size = xdr_sizeof (xdrproc, req);
+ GF_ASSERT(this);
- iobuf = iobuf_get2 (this->ctx->iobuf_pool, xdr_size);
- if (!iobuf) {
- goto out;
- };
+ if (req) {
+ xdr_size = xdr_sizeof(xdrproc, req);
- if (!iobref) {
- iobref = iobref_new ();
- if (!iobref) {
- goto out;
- }
+ iobuf = iobuf_get2(this->ctx->iobuf_pool, xdr_size);
+ if (!iobuf) {
+ goto out;
+ };
- new_iobref = 1;
- }
+ if (!iobref) {
+ iobref = iobref_new();
+ if (!iobref) {
+ goto out;
+ }
- iobref_add (iobref, iobuf);
+ new_iobref = 1;
+ }
- iov.iov_base = iobuf->ptr;
- iov.iov_len = iobuf_size (iobuf);
+ iobref_add(iobref, iobuf);
- /* Create the xdr payload */
- ret = xdr_serialize_generic (iov, req, xdrproc);
- if (ret == -1) {
- goto out;
- }
+ iov.iov_base = iobuf->ptr;
+ iov.iov_len = iobuf_size(iobuf);
- iov.iov_len = ret;
- count = 1;
+ /* Create the xdr payload */
+ ret = xdr_serialize_generic(iov, req, xdrproc);
+ if (ret == -1) {
+ goto out;
}
- ret = rpc_clnt_submit (rpc, prog, procnum, cbkfn, &iov, count,
- payload, payloadcnt, iobref, frame, NULL,
- 0, NULL, 0, NULL);
+ iov.iov_len = ret;
+ count = 1;
+ }
- out:
- if (new_iobref)
- iobref_unref (iobref);
- if (iobuf)
- iobuf_unref (iobuf);
- return ret;
+ ret = rpc_clnt_submit(rpc, prog, procnum, cbkfn, &iov, count, payload,
+ payloadcnt, iobref, frame, NULL, 0, NULL, 0, NULL);
+
+out:
+ if (new_iobref)
+ iobref_unref(iobref);
+ if (iobuf)
+ iobuf_unref(iobuf);
+ return ret;
}
/**
* Entry point to perform a remote procedure call
*/
int
-changelog_invoke_rpc (xlator_t *this, struct rpc_clnt *rpc,
- rpc_clnt_prog_t *prog, int procidx, void *arg)
+changelog_invoke_rpc(xlator_t *this, struct rpc_clnt *rpc,
+ rpc_clnt_prog_t *prog, int procidx, void *arg)
{
- int ret = 0;
- call_frame_t *frame = NULL;
- rpc_clnt_procedure_t *proc = NULL;
-
- if (!this || !prog)
- goto error_return;
-
- frame = create_frame (this, this->ctx->pool);
- if (!frame) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_CREATE_FRAME_FAILED,
- "failed to create frame");
- goto error_return;
- }
+ int ret = 0;
+ call_frame_t *frame = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
- proc = &prog->proctable[procidx];
- if (proc->fn)
- ret = proc->fn (frame, this, arg);
+ if (!this || !prog)
+ goto error_return;
- STACK_DESTROY (frame->root);
- return ret;
+ frame = create_frame(this, this->ctx->pool);
+ if (!frame) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_CREATE_FRAME_FAILED,
+ "failed to create frame");
+ goto error_return;
+ }
- error_return:
- return -1;
+ proc = &prog->proctable[procidx];
+ if (proc->fn)
+ ret = proc->fn(frame, this, arg);
+
+ STACK_DESTROY(frame->root);
+ return ret;
+
+error_return:
+ return -1;
}
/**
@@ -189,170 +187,169 @@ changelog_invoke_rpc (xlator_t *this, struct rpc_clnt *rpc,
*/
struct iobuf *
-__changelog_rpc_serialize_reply (rpcsvc_request_t *req, void *arg,
- struct iovec *outmsg, xdrproc_t xdrproc)
+__changelog_rpc_serialize_reply(rpcsvc_request_t *req, void *arg,
+ struct iovec *outmsg, xdrproc_t xdrproc)
{
- struct iobuf *iob = NULL;
- ssize_t retlen = 0;
- ssize_t rsp_size = 0;
+ struct iobuf *iob = NULL;
+ ssize_t retlen = 0;
+ ssize_t rsp_size = 0;
- rsp_size = xdr_sizeof (xdrproc, arg);
- iob = iobuf_get2 (req->svc->ctx->iobuf_pool, rsp_size);
- if (!iob)
- goto error_return;
+ rsp_size = xdr_sizeof(xdrproc, arg);
+ iob = iobuf_get2(req->svc->ctx->iobuf_pool, rsp_size);
+ if (!iob)
+ goto error_return;
- iobuf_to_iovec (iob, outmsg);
+ iobuf_to_iovec(iob, outmsg);
- retlen = xdr_serialize_generic (*outmsg, arg, xdrproc);
- if (retlen == -1)
- goto unref_iob;
+ retlen = xdr_serialize_generic(*outmsg, arg, xdrproc);
+ if (retlen == -1)
+ goto unref_iob;
- outmsg->iov_len = retlen;
- return iob;
+ outmsg->iov_len = retlen;
+ return iob;
- unref_iob:
- iobuf_unref (iob);
- error_return:
- return NULL;
+unref_iob:
+ iobuf_unref(iob);
+error_return:
+ return NULL;
}
int
-changelog_rpc_sumbit_reply (rpcsvc_request_t *req,
- void *arg, struct iovec *payload, int payloadcount,
- struct iobref *iobref, xdrproc_t xdrproc)
+changelog_rpc_sumbit_reply(rpcsvc_request_t *req, void *arg,
+ struct iovec *payload, int payloadcount,
+ struct iobref *iobref, xdrproc_t xdrproc)
{
- int ret = -1;
- struct iobuf *iob = NULL;
- struct iovec iov = {0,};
- char new_iobref = 0;
-
- if (!req)
- goto return_ret;
-
- if (!iobref) {
- iobref = iobref_new ();
- if (!iobref)
- goto return_ret;
- new_iobref = 1;
- }
-
- iob = __changelog_rpc_serialize_reply (req, arg, &iov, xdrproc);
- if (!iob)
- gf_msg ("", GF_LOG_ERROR, 0,
- CHANGELOG_MSG_RPC_SUBMIT_REPLY_FAILED,
- "failed to serialize reply");
- else
- iobref_add (iobref, iob);
-
- ret = rpcsvc_submit_generic (req, &iov,
- 1, payload, payloadcount, iobref);
-
- if (new_iobref)
- iobref_unref (iobref);
- if (iob)
- iobuf_unref (iob);
- return_ret:
- return ret;
+ int ret = -1;
+ struct iobuf *iob = NULL;
+ struct iovec iov = {
+ 0,
+ };
+ char new_iobref = 0;
+
+ if (!req)
+ goto return_ret;
+
+ if (!iobref) {
+ iobref = iobref_new();
+ if (!iobref)
+ goto return_ret;
+ new_iobref = 1;
+ }
+
+ iob = __changelog_rpc_serialize_reply(req, arg, &iov, xdrproc);
+ if (!iob)
+ gf_msg("", GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_SUBMIT_REPLY_FAILED,
+ "failed to serialize reply");
+ else
+ iobref_add(iobref, iob);
+
+ ret = rpcsvc_submit_generic(req, &iov, 1, payload, payloadcount, iobref);
+
+ if (new_iobref)
+ iobref_unref(iobref);
+ if (iob)
+ iobuf_unref(iob);
+return_ret:
+ return ret;
}
void
-changelog_rpc_server_destroy (xlator_t *this, rpcsvc_t *rpc, char *sockfile,
- rpcsvc_notify_t fn, struct rpcsvc_program **progs)
+changelog_rpc_server_destroy(xlator_t *this, rpcsvc_t *rpc, char *sockfile,
+ rpcsvc_notify_t fn, struct rpcsvc_program **progs)
{
- rpcsvc_listener_t *listener = NULL;
- rpcsvc_listener_t *next = NULL;
- struct rpcsvc_program *prog = NULL;
-
- while (*progs) {
- prog = *progs;
- (void) rpcsvc_program_unregister (rpc, prog);
- progs++;
- }
-
- list_for_each_entry_safe (listener, next, &rpc->listeners, list) {
- rpcsvc_listener_destroy (listener);
- }
-
- (void) rpcsvc_unregister_notify (rpc, fn, this);
- sys_unlink (sockfile);
- if (rpc->rxpool) {
- mem_pool_destroy (rpc->rxpool);
- rpc->rxpool = NULL;
- }
-
- /* TODO Avoid freeing rpc object in case of brick multiplex
- after freeing rpc object svc->rpclock corrupted and it takes
- more time to detach a brick
- */
- if (!this->cleanup_starting)
- GF_FREE (rpc);
+ rpcsvc_listener_t *listener = NULL;
+ rpcsvc_listener_t *next = NULL;
+ struct rpcsvc_program *prog = NULL;
+
+ while (*progs) {
+ prog = *progs;
+ (void)rpcsvc_program_unregister(rpc, prog);
+ progs++;
+ }
+
+ list_for_each_entry_safe(listener, next, &rpc->listeners, list)
+ {
+ rpcsvc_listener_destroy(listener);
+ }
+
+ (void)rpcsvc_unregister_notify(rpc, fn, this);
+ sys_unlink(sockfile);
+ if (rpc->rxpool) {
+ mem_pool_destroy(rpc->rxpool);
+ rpc->rxpool = NULL;
+ }
+
+ /* TODO Avoid freeing rpc object in case of brick multiplex
+ after freeing rpc object svc->rpclock corrupted and it takes
+ more time to detach a brick
+ */
+ if (!this->cleanup_starting)
+ GF_FREE(rpc);
}
rpcsvc_t *
-changelog_rpc_server_init (xlator_t *this, char *sockfile, void *cbkdata,
- rpcsvc_notify_t fn, struct rpcsvc_program **progs)
+changelog_rpc_server_init(xlator_t *this, char *sockfile, void *cbkdata,
+ rpcsvc_notify_t fn, struct rpcsvc_program **progs)
{
- int ret = 0;
- rpcsvc_t *rpc = NULL;
- dict_t *options = NULL;
- struct rpcsvc_program *prog = NULL;
-
- if (!cbkdata)
- cbkdata = this;
-
- options = dict_new ();
- if (!options)
- goto error_return;
-
- ret = rpcsvc_transport_unix_options_build (&options, sockfile);
- if (ret)
- goto dealloc_dict;
-
- rpc = rpcsvc_init (this, this->ctx, options, 8);
- if (rpc == NULL) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_RPC_START_ERROR,
- "failed to init rpc");
- goto dealloc_dict;
- }
-
- ret = rpcsvc_register_notify (rpc, fn, cbkdata);
+ int ret = 0;
+ rpcsvc_t *rpc = NULL;
+ dict_t *options = NULL;
+ struct rpcsvc_program *prog = NULL;
+
+ if (!cbkdata)
+ cbkdata = this;
+
+ options = dict_new();
+ if (!options)
+ goto error_return;
+
+ ret = rpcsvc_transport_unix_options_build(&options, sockfile);
+ if (ret)
+ goto dealloc_dict;
+
+ rpc = rpcsvc_init(this, this->ctx, options, 8);
+ if (rpc == NULL) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_RPC_START_ERROR,
+ "failed to init rpc");
+ goto dealloc_dict;
+ }
+
+ ret = rpcsvc_register_notify(rpc, fn, cbkdata);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_NOTIFY_REGISTER_FAILED,
+ "failed to register notify function");
+ goto dealloc_rpc;
+ }
+
+ ret = rpcsvc_create_listeners(rpc, options, this->name);
+ if (ret != 1) {
+ gf_msg_debug(this->name, 0, "failed to create listeners");
+ goto dealloc_rpc;
+ }
+
+ while (*progs) {
+ prog = *progs;
+ ret = rpcsvc_program_register(rpc, prog, _gf_false);
if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_NOTIFY_REGISTER_FAILED,
- "failed to register notify function");
- goto dealloc_rpc;
- }
-
- ret = rpcsvc_create_listeners (rpc, options, this->name);
- if (ret != 1) {
- gf_msg_debug (this->name,
- 0, "failed to create listeners");
- goto dealloc_rpc;
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_PROGRAM_NAME_REG_FAILED,
+ "cannot register program "
+ "(name: %s, prognum: %d, pogver: %d)",
+ prog->progname, prog->prognum, prog->progver);
+ goto dealloc_rpc;
}
- while (*progs) {
- prog = *progs;
- ret = rpcsvc_program_register (rpc, prog, _gf_false);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_PROGRAM_NAME_REG_FAILED,
- "cannot register program "
- "(name: %s, prognum: %d, pogver: %d)",
- prog->progname, prog->prognum, prog->progver);
- goto dealloc_rpc;
- }
-
- progs++;
- }
+ progs++;
+ }
- dict_unref (options);
- return rpc;
+ dict_unref(options);
+ return rpc;
- dealloc_rpc:
- GF_FREE (rpc);
- dealloc_dict:
- dict_unref (options);
- error_return:
- return NULL;
+dealloc_rpc:
+ GF_FREE(rpc);
+dealloc_dict:
+ dict_unref(options);
+error_return:
+ return NULL;
}
diff --git a/xlators/features/changelog/src/changelog-rpc.c b/xlators/features/changelog/src/changelog-rpc.c
index 9027fe10a2a..828f85e8e45 100644
--- a/xlators/features/changelog/src/changelog-rpc.c
+++ b/xlators/features/changelog/src/changelog-rpc.c
@@ -16,256 +16,246 @@
struct rpcsvc_program *changelog_programs[];
static void
-changelog_cleanup_dispatchers (xlator_t *this,
- changelog_priv_t *priv, int count)
+changelog_cleanup_dispatchers(xlator_t *this, changelog_priv_t *priv, int count)
{
- for (count--; count >= 0; count--) {
- (void) changelog_thread_cleanup
- (this, priv->ev_dispatcher[count]);
- priv->ev_dispatcher[count] = 0;
- }
+ for (count--; count >= 0; count--) {
+ (void)changelog_thread_cleanup(this, priv->ev_dispatcher[count]);
+ priv->ev_dispatcher[count] = 0;
+ }
}
int
-changelog_cleanup_rpc_threads (xlator_t *this, changelog_priv_t *priv)
+changelog_cleanup_rpc_threads(xlator_t *this, changelog_priv_t *priv)
{
- int ret = 0;
- changelog_clnt_t *conn = NULL;
-
- conn = &priv->connections;
- if (!conn)
- return 0;
-
- /** terminate RPC thread(s) */
- ret = changelog_thread_cleanup (this, priv->connector);
- if (ret != 0)
- goto error_return;
- priv->connector = 0;
-
- /** terminate dispatcher thread(s) */
- changelog_cleanup_dispatchers (this, priv, priv->nr_dispatchers);
-
- /* TODO: what about pending and waiting connections? */
- changelog_ev_cleanup_connections (this, conn);
-
- /* destroy locks */
- ret = pthread_mutex_destroy (&conn->pending_lock);
- if (ret != 0)
- goto error_return;
- ret = pthread_cond_destroy (&conn->pending_cond);
- if (ret != 0)
- goto error_return;
- ret = LOCK_DESTROY (&conn->active_lock);
- if (ret != 0)
- goto error_return;
- ret = LOCK_DESTROY (&conn->wait_lock);
- if (ret != 0)
- goto error_return;
+ int ret = 0;
+ changelog_clnt_t *conn = NULL;
+
+ conn = &priv->connections;
+ if (!conn)
return 0;
- error_return:
- return -1;
+ /** terminate RPC thread(s) */
+ ret = changelog_thread_cleanup(this, priv->connector);
+ if (ret != 0)
+ goto error_return;
+ priv->connector = 0;
+
+ /** terminate dispatcher thread(s) */
+ changelog_cleanup_dispatchers(this, priv, priv->nr_dispatchers);
+
+ /* TODO: what about pending and waiting connections? */
+ changelog_ev_cleanup_connections(this, conn);
+
+ /* destroy locks */
+ ret = pthread_mutex_destroy(&conn->pending_lock);
+ if (ret != 0)
+ goto error_return;
+ ret = pthread_cond_destroy(&conn->pending_cond);
+ if (ret != 0)
+ goto error_return;
+ ret = LOCK_DESTROY(&conn->active_lock);
+ if (ret != 0)
+ goto error_return;
+ ret = LOCK_DESTROY(&conn->wait_lock);
+ if (ret != 0)
+ goto error_return;
+ return 0;
+
+error_return:
+ return -1;
}
static int
-changelog_init_rpc_threads (xlator_t *this, changelog_priv_t *priv,
- rbuf_t *rbuf, int nr_dispatchers)
+changelog_init_rpc_threads(xlator_t *this, changelog_priv_t *priv, rbuf_t *rbuf,
+ int nr_dispatchers)
{
- int j = 0;
- int ret = 0;
- changelog_clnt_t *conn = NULL;
- char thread_name[GF_THREAD_NAMEMAX] = {0,};
-
-
- conn = &priv->connections;
-
- conn->this = this;
- conn->rbuf = rbuf;
- conn->sequence = 1; /* start with sequence number one */
-
- INIT_LIST_HEAD (&conn->pending);
- INIT_LIST_HEAD (&conn->active);
- INIT_LIST_HEAD (&conn->waitq);
-
- ret = pthread_mutex_init (&conn->pending_lock, NULL);
- if (ret)
- goto error_return;
- ret = pthread_cond_init (&conn->pending_cond, NULL);
- if (ret)
- goto cleanup_pending_lock;
-
- ret = LOCK_INIT (&conn->active_lock);
- if (ret)
- goto cleanup_pending_cond;
- ret = LOCK_INIT (&conn->wait_lock);
- if (ret)
- goto cleanup_active_lock;
-
- /* spawn reverse connection thread */
- ret = gf_thread_create (&priv->connector,
- NULL, changelog_ev_connector, conn, "clogecon");
- if (ret != 0)
- goto cleanup_wait_lock;
-
- /* spawn dispatcher thread(s) */
- priv->ev_dispatcher = GF_CALLOC (nr_dispatchers, sizeof(pthread_t),
- gf_changelog_mt_ev_dispatcher_t);
- if (!priv->ev_dispatcher)
- goto cleanup_connector;
-
- /* spawn dispatcher threads */
- for (; j < nr_dispatchers; j++) {
- snprintf (thread_name, sizeof(thread_name),
- "clogd%03hx", (j & 0x3ff));
- ret = gf_thread_create (&priv->ev_dispatcher[j],
- NULL, changelog_ev_dispatch, conn,
- thread_name);
- if (ret != 0) {
- changelog_cleanup_dispatchers (this, priv, j);
- break;
- }
+ int j = 0;
+ int ret = 0;
+ changelog_clnt_t *conn = NULL;
+ char thread_name[GF_THREAD_NAMEMAX] = {
+ 0,
+ };
+
+ conn = &priv->connections;
+
+ conn->this = this;
+ conn->rbuf = rbuf;
+ conn->sequence = 1; /* start with sequence number one */
+
+ INIT_LIST_HEAD(&conn->pending);
+ INIT_LIST_HEAD(&conn->active);
+ INIT_LIST_HEAD(&conn->waitq);
+
+ ret = pthread_mutex_init(&conn->pending_lock, NULL);
+ if (ret)
+ goto error_return;
+ ret = pthread_cond_init(&conn->pending_cond, NULL);
+ if (ret)
+ goto cleanup_pending_lock;
+
+ ret = LOCK_INIT(&conn->active_lock);
+ if (ret)
+ goto cleanup_pending_cond;
+ ret = LOCK_INIT(&conn->wait_lock);
+ if (ret)
+ goto cleanup_active_lock;
+
+ /* spawn reverse connection thread */
+ ret = gf_thread_create(&priv->connector, NULL, changelog_ev_connector, conn,
+ "clogecon");
+ if (ret != 0)
+ goto cleanup_wait_lock;
+
+ /* spawn dispatcher thread(s) */
+ priv->ev_dispatcher = GF_CALLOC(nr_dispatchers, sizeof(pthread_t),
+ gf_changelog_mt_ev_dispatcher_t);
+ if (!priv->ev_dispatcher)
+ goto cleanup_connector;
+
+ /* spawn dispatcher threads */
+ for (; j < nr_dispatchers; j++) {
+ snprintf(thread_name, sizeof(thread_name), "clogd%03hx", (j & 0x3ff));
+ ret = gf_thread_create(&priv->ev_dispatcher[j], NULL,
+ changelog_ev_dispatch, conn, thread_name);
+ if (ret != 0) {
+ changelog_cleanup_dispatchers(this, priv, j);
+ break;
}
-
- if (ret != 0)
- goto cleanup_connector;
-
- priv->nr_dispatchers = nr_dispatchers;
- return 0;
-
- cleanup_connector:
- (void) pthread_cancel (priv->connector);
- cleanup_wait_lock:
- LOCK_DESTROY (&conn->wait_lock);
- cleanup_active_lock:
- LOCK_DESTROY (&conn->active_lock);
- cleanup_pending_cond:
- (void) pthread_cond_destroy (&conn->pending_cond);
- cleanup_pending_lock:
- (void) pthread_mutex_destroy (&conn->pending_lock);
- error_return:
- return -1;
+ }
+
+ if (ret != 0)
+ goto cleanup_connector;
+
+ priv->nr_dispatchers = nr_dispatchers;
+ return 0;
+
+cleanup_connector:
+ (void)pthread_cancel(priv->connector);
+cleanup_wait_lock:
+ LOCK_DESTROY(&conn->wait_lock);
+cleanup_active_lock:
+ LOCK_DESTROY(&conn->active_lock);
+cleanup_pending_cond:
+ (void)pthread_cond_destroy(&conn->pending_cond);
+cleanup_pending_lock:
+ (void)pthread_mutex_destroy(&conn->pending_lock);
+error_return:
+ return -1;
}
int
-changelog_rpcsvc_notify (rpcsvc_t *rpc,
- void *xl, rpcsvc_event_t event, void *data)
+changelog_rpcsvc_notify(rpcsvc_t *rpc, void *xl, rpcsvc_event_t event,
+ void *data)
{
- return 0;
+ return 0;
}
void
-changelog_destroy_rpc_listner (xlator_t *this, changelog_priv_t *priv)
+changelog_destroy_rpc_listner(xlator_t *this, changelog_priv_t *priv)
{
- char sockfile[UNIX_PATH_MAX] = {0,};
- changelog_clnt_t *c_clnt = &priv->connections;
- changelog_rpc_clnt_t *crpc = NULL;
- int nofconn = 0;
-
- /* sockfile path could have been saved to avoid this */
- CHANGELOG_MAKE_SOCKET_PATH (priv->changelog_brick,
- sockfile, UNIX_PATH_MAX);
- changelog_rpc_server_destroy (this,
- priv->rpc, sockfile,
- changelog_rpcsvc_notify,
- changelog_programs);
-
- /* TODO Below approach is not perfect to wait for cleanup
- all active connections without this code brick process
- can be crash in case of brick multiplexing if any in-progress
- request process on rpc by changelog xlator after
- cleanup resources
- */
-
- if (c_clnt) {
- do {
- nofconn = 0;
- LOCK (&c_clnt->active_lock);
- list_for_each_entry (crpc, &c_clnt->active, list) {
- nofconn++;
- }
- UNLOCK (&c_clnt->active_lock);
- LOCK (&c_clnt->wait_lock);
- list_for_each_entry (crpc, &c_clnt->waitq, list) {
- nofconn++;
- }
- UNLOCK (&c_clnt->wait_lock);
- pthread_mutex_lock (&c_clnt->pending_lock);
- list_for_each_entry (crpc, &c_clnt->pending, list) {
- nofconn++;
- }
- pthread_mutex_unlock (&c_clnt->pending_lock);
-
- } while (nofconn); /* Wait for all connection cleanup */
- }
-
- (void) changelog_cleanup_rpc_threads (this, priv);
+ char sockfile[UNIX_PATH_MAX] = {
+ 0,
+ };
+ changelog_clnt_t *c_clnt = &priv->connections;
+ changelog_rpc_clnt_t *crpc = NULL;
+ int nofconn = 0;
+
+ /* sockfile path could have been saved to avoid this */
+ CHANGELOG_MAKE_SOCKET_PATH(priv->changelog_brick, sockfile, UNIX_PATH_MAX);
+ changelog_rpc_server_destroy(this, priv->rpc, sockfile,
+ changelog_rpcsvc_notify, changelog_programs);
+
+ /* TODO Below approach is not perfect to wait for cleanup
+ all active connections without this code brick process
+ can be crash in case of brick multiplexing if any in-progress
+ request process on rpc by changelog xlator after
+ cleanup resources
+ */
+
+ if (c_clnt) {
+ do {
+ nofconn = 0;
+ LOCK(&c_clnt->active_lock);
+ list_for_each_entry(crpc, &c_clnt->active, list) { nofconn++; }
+ UNLOCK(&c_clnt->active_lock);
+ LOCK(&c_clnt->wait_lock);
+ list_for_each_entry(crpc, &c_clnt->waitq, list) { nofconn++; }
+ UNLOCK(&c_clnt->wait_lock);
+ pthread_mutex_lock(&c_clnt->pending_lock);
+ list_for_each_entry(crpc, &c_clnt->pending, list) { nofconn++; }
+ pthread_mutex_unlock(&c_clnt->pending_lock);
+
+ } while (nofconn); /* Wait for all connection cleanup */
+ }
+
+ (void)changelog_cleanup_rpc_threads(this, priv);
}
rpcsvc_t *
-changelog_init_rpc_listener (xlator_t *this, changelog_priv_t *priv,
+changelog_init_rpc_listener(xlator_t *this, changelog_priv_t *priv,
rbuf_t *rbuf, int nr_dispatchers)
{
- int ret = 0;
- char sockfile[UNIX_PATH_MAX] = {0,};
- rpcsvc_t *svcp;
-
- ret = changelog_init_rpc_threads (this, priv, rbuf, nr_dispatchers);
- if (ret)
- return NULL;
-
- CHANGELOG_MAKE_SOCKET_PATH (priv->changelog_brick,
- sockfile, UNIX_PATH_MAX);
- (void) sys_unlink (sockfile);
- svcp = changelog_rpc_server_init (this, sockfile, NULL,
- changelog_rpcsvc_notify,
- changelog_programs);
- return svcp;
+ int ret = 0;
+ char sockfile[UNIX_PATH_MAX] = {
+ 0,
+ };
+ rpcsvc_t *svcp;
+
+ ret = changelog_init_rpc_threads(this, priv, rbuf, nr_dispatchers);
+ if (ret)
+ return NULL;
+
+ CHANGELOG_MAKE_SOCKET_PATH(priv->changelog_brick, sockfile, UNIX_PATH_MAX);
+ (void)sys_unlink(sockfile);
+ svcp = changelog_rpc_server_init(
+ this, sockfile, NULL, changelog_rpcsvc_notify, changelog_programs);
+ return svcp;
}
void
-changelog_rpc_clnt_cleanup (changelog_rpc_clnt_t *crpc)
+changelog_rpc_clnt_cleanup(changelog_rpc_clnt_t *crpc)
{
- if (!crpc)
- return;
- crpc->c_clnt = NULL;
- LOCK_DESTROY (&crpc->lock);
- GF_FREE (crpc);
+ if (!crpc)
+ return;
+ crpc->c_clnt = NULL;
+ LOCK_DESTROY(&crpc->lock);
+ GF_FREE(crpc);
}
static changelog_rpc_clnt_t *
-changelog_rpc_clnt_init (xlator_t *this,
- changelog_probe_req *rpc_req, changelog_clnt_t *c_clnt)
+changelog_rpc_clnt_init(xlator_t *this, changelog_probe_req *rpc_req,
+ changelog_clnt_t *c_clnt)
{
- int ret = 0;
- changelog_rpc_clnt_t *crpc = NULL;
-
- crpc = GF_CALLOC (1, sizeof (*crpc), gf_changelog_mt_rpc_clnt_t);
- if (!crpc)
- goto error_return;
- INIT_LIST_HEAD (&crpc->list);
-
- /* Take a ref, the last unref will be on RPC_CLNT_DESTROY
- * which comes as a result of last rpc_clnt_unref.
- */
- GF_ATOMIC_INIT (crpc->ref, 1);
- changelog_set_disconnect_flag (crpc, _gf_false);
-
- crpc->filter = rpc_req->filter;
- (void) memcpy (crpc->sock, rpc_req->sock, strlen (rpc_req->sock));
-
- crpc->this = this;
- crpc->c_clnt = c_clnt;
- crpc->cleanup = changelog_rpc_clnt_cleanup;
-
- ret = LOCK_INIT (&crpc->lock);
- if (ret != 0)
- goto dealloc_crpc;
- return crpc;
-
- dealloc_crpc:
- GF_FREE (crpc);
- error_return:
- return NULL;
+ int ret = 0;
+ changelog_rpc_clnt_t *crpc = NULL;
+
+ crpc = GF_CALLOC(1, sizeof(*crpc), gf_changelog_mt_rpc_clnt_t);
+ if (!crpc)
+ goto error_return;
+ INIT_LIST_HEAD(&crpc->list);
+
+ /* Take a ref, the last unref will be on RPC_CLNT_DESTROY
+ * which comes as a result of last rpc_clnt_unref.
+ */
+ GF_ATOMIC_INIT(crpc->ref, 1);
+ changelog_set_disconnect_flag(crpc, _gf_false);
+
+ crpc->filter = rpc_req->filter;
+ (void)memcpy(crpc->sock, rpc_req->sock, strlen(rpc_req->sock));
+
+ crpc->this = this;
+ crpc->c_clnt = c_clnt;
+ crpc->cleanup = changelog_rpc_clnt_cleanup;
+
+ ret = LOCK_INIT(&crpc->lock);
+ if (ret != 0)
+ goto dealloc_crpc;
+ return crpc;
+
+dealloc_crpc:
+ GF_FREE(crpc);
+error_return:
+ return NULL;
}
/**
@@ -279,58 +269,59 @@ changelog_rpc_clnt_init (xlator_t *this,
*/
int
-changelog_handle_probe (rpcsvc_request_t *req)
+changelog_handle_probe(rpcsvc_request_t *req)
{
- int ret = 0;
- xlator_t *this = NULL;
- rpcsvc_t *svc = NULL;
- changelog_priv_t *priv = NULL;
- changelog_clnt_t *c_clnt = NULL;
- changelog_rpc_clnt_t *crpc = NULL;
-
- changelog_probe_req rpc_req = {0,};
- changelog_probe_rsp rpc_rsp = {0,};
-
-
- this = req->trans->xl;
- if (this->cleanup_starting) {
- gf_msg (this->name, GF_LOG_DEBUG, 0,
- CHANGELOG_MSG_HANDLE_PROBE_ERROR,
- "cleanup_starting flag is already set for xl");
- return 0;
- }
-
- ret = xdr_to_generic (req->msg[0],
- &rpc_req, (xdrproc_t)xdr_changelog_probe_req);
- if (ret < 0) {
- gf_msg ("", GF_LOG_ERROR, 0,
- CHANGELOG_MSG_HANDLE_PROBE_ERROR,
- "xdr decoding error");
- req->rpc_err = GARBAGE_ARGS;
- goto handle_xdr_error;
- }
-
- /* ->xl hidden in rpcsvc */
- svc = rpcsvc_request_service (req);
- this = svc->xl;
- priv = this->private;
- c_clnt = &priv->connections;
-
- crpc = changelog_rpc_clnt_init (this, &rpc_req, c_clnt);
- if (!crpc)
- goto handle_xdr_error;
-
- changelog_ev_queue_connection (c_clnt, crpc);
- rpc_rsp.op_ret = 0;
-
- goto submit_rpc;
-
- handle_xdr_error:
- rpc_rsp.op_ret = -1;
- submit_rpc:
- (void) changelog_rpc_sumbit_reply (req, &rpc_rsp, NULL, 0, NULL,
- (xdrproc_t)xdr_changelog_probe_rsp);
+ int ret = 0;
+ xlator_t *this = NULL;
+ rpcsvc_t *svc = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_clnt_t *c_clnt = NULL;
+ changelog_rpc_clnt_t *crpc = NULL;
+
+ changelog_probe_req rpc_req = {
+ 0,
+ };
+ changelog_probe_rsp rpc_rsp = {
+ 0,
+ };
+
+ this = req->trans->xl;
+ if (this->cleanup_starting) {
+ gf_msg(this->name, GF_LOG_DEBUG, 0, CHANGELOG_MSG_HANDLE_PROBE_ERROR,
+ "cleanup_starting flag is already set for xl");
return 0;
+ }
+
+ ret = xdr_to_generic(req->msg[0], &rpc_req,
+ (xdrproc_t)xdr_changelog_probe_req);
+ if (ret < 0) {
+ gf_msg("", GF_LOG_ERROR, 0, CHANGELOG_MSG_HANDLE_PROBE_ERROR,
+ "xdr decoding error");
+ req->rpc_err = GARBAGE_ARGS;
+ goto handle_xdr_error;
+ }
+
+ /* ->xl hidden in rpcsvc */
+ svc = rpcsvc_request_service(req);
+ this = svc->xl;
+ priv = this->private;
+ c_clnt = &priv->connections;
+
+ crpc = changelog_rpc_clnt_init(this, &rpc_req, c_clnt);
+ if (!crpc)
+ goto handle_xdr_error;
+
+ changelog_ev_queue_connection(c_clnt, crpc);
+ rpc_rsp.op_ret = 0;
+
+ goto submit_rpc;
+
+handle_xdr_error:
+ rpc_rsp.op_ret = -1;
+submit_rpc:
+ (void)changelog_rpc_sumbit_reply(req, &rpc_rsp, NULL, 0, NULL,
+ (xdrproc_t)xdr_changelog_probe_rsp);
+ return 0;
}
/**
@@ -338,22 +329,21 @@ changelog_handle_probe (rpcsvc_request_t *req)
*/
rpcsvc_actor_t changelog_svc_actors[CHANGELOG_RPC_PROC_MAX] = {
- [CHANGELOG_RPC_PROBE_FILTER] = {
- "CHANGELOG PROBE FILTER", CHANGELOG_RPC_PROBE_FILTER,
- changelog_handle_probe, NULL, 0, DRC_NA
- },
+ [CHANGELOG_RPC_PROBE_FILTER] = {"CHANGELOG PROBE FILTER",
+ CHANGELOG_RPC_PROBE_FILTER,
+ changelog_handle_probe, NULL, 0, DRC_NA},
};
struct rpcsvc_program changelog_svc_prog = {
- .progname = CHANGELOG_RPC_PROGNAME,
- .prognum = CHANGELOG_RPC_PROGNUM,
- .progver = CHANGELOG_RPC_PROGVER,
- .numactors = CHANGELOG_RPC_PROC_MAX,
- .actors = changelog_svc_actors,
- .synctask = _gf_true,
+ .progname = CHANGELOG_RPC_PROGNAME,
+ .prognum = CHANGELOG_RPC_PROGNUM,
+ .progver = CHANGELOG_RPC_PROGVER,
+ .numactors = CHANGELOG_RPC_PROC_MAX,
+ .actors = changelog_svc_actors,
+ .synctask = _gf_true,
};
struct rpcsvc_program *changelog_programs[] = {
- &changelog_svc_prog,
- NULL,
+ &changelog_svc_prog,
+ NULL,
};
diff --git a/xlators/features/changelog/src/changelog-rt.c b/xlators/features/changelog/src/changelog-rt.c
index c262820c64c..968c76b8b20 100644
--- a/xlators/features/changelog/src/changelog-rt.c
+++ b/xlators/features/changelog/src/changelog-rt.c
@@ -16,52 +16,51 @@
#include "changelog-mem-types.h"
int
-changelog_rt_init (xlator_t *this, changelog_dispatcher_t *cd)
+changelog_rt_init(xlator_t *this, changelog_dispatcher_t *cd)
{
- changelog_rt_t *crt = NULL;
+ changelog_rt_t *crt = NULL;
- crt = GF_CALLOC (1, sizeof (*crt),
- gf_changelog_mt_rt_t);
- if (!crt)
- return -1;
+ crt = GF_CALLOC(1, sizeof(*crt), gf_changelog_mt_rt_t);
+ if (!crt)
+ return -1;
- LOCK_INIT (&crt->lock);
+ LOCK_INIT(&crt->lock);
- cd->cd_data = crt;
- cd->dispatchfn = &changelog_rt_enqueue;
+ cd->cd_data = crt;
+ cd->dispatchfn = &changelog_rt_enqueue;
- return 0;
+ return 0;
}
int
-changelog_rt_fini (xlator_t *this, changelog_dispatcher_t *cd)
+changelog_rt_fini(xlator_t *this, changelog_dispatcher_t *cd)
{
- changelog_rt_t *crt = NULL;
+ changelog_rt_t *crt = NULL;
- crt = cd->cd_data;
+ crt = cd->cd_data;
- LOCK_DESTROY (&crt->lock);
- GF_FREE (crt);
+ LOCK_DESTROY(&crt->lock);
+ GF_FREE(crt);
- return 0;
+ return 0;
}
int
-changelog_rt_enqueue (xlator_t *this, changelog_priv_t *priv, void *cbatch,
- changelog_log_data_t *cld_0, changelog_log_data_t *cld_1)
+changelog_rt_enqueue(xlator_t *this, changelog_priv_t *priv, void *cbatch,
+ changelog_log_data_t *cld_0, changelog_log_data_t *cld_1)
{
- int ret = 0;
- changelog_rt_t *crt = NULL;
+ int ret = 0;
+ changelog_rt_t *crt = NULL;
- crt = (changelog_rt_t *) cbatch;
+ crt = (changelog_rt_t *)cbatch;
- LOCK (&crt->lock);
- {
- ret = changelog_handle_change (this, priv, cld_0);
- if (!ret && cld_1)
- ret = changelog_handle_change (this, priv, cld_1);
- }
- UNLOCK (&crt->lock);
+ LOCK(&crt->lock);
+ {
+ ret = changelog_handle_change(this, priv, cld_0);
+ if (!ret && cld_1)
+ ret = changelog_handle_change(this, priv, cld_1);
+ }
+ UNLOCK(&crt->lock);
- return ret;
+ return ret;
}
diff --git a/xlators/features/changelog/src/changelog.c b/xlators/features/changelog/src/changelog.c
index ab42ad869c0..35a523316ed 100644
--- a/xlators/features/changelog/src/changelog.c
+++ b/xlators/features/changelog/src/changelog.c
@@ -26,13 +26,12 @@
#include "changelog-rpc.h"
#include "errno.h"
-static struct changelog_bootstrap
-cb_bootstrap[] = {
- {
- .mode = CHANGELOG_MODE_RT,
- .ctor = changelog_rt_init,
- .dtor = changelog_rt_fini,
- },
+static struct changelog_bootstrap cb_bootstrap[] = {
+ {
+ .mode = CHANGELOG_MODE_RT,
+ .ctor = changelog_rt_init,
+ .dtor = changelog_rt_fini,
+ },
};
/* Entry operations - TYPE III */
@@ -46,1111 +45,1060 @@ cb_bootstrap[] = {
/* rmdir */
int32_t
-changelog_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+changelog_rmdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (rmdir, frame, op_ret, op_errno,
- preparent, postparent, xdata);
- return 0;
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(rmdir, frame, op_ret, op_errno, preparent,
+ postparent, xdata);
+ return 0;
}
int32_t
-changelog_rmdir_resume (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int xflags, dict_t *xdata)
+changelog_rmdir_resume(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ int xflags, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- gf_msg_debug (this->name, 0, "Dequeue rmdir");
- changelog_color_fop_and_inc_cnt (this, priv,
- frame->local);
- STACK_WIND (frame, changelog_rmdir_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->rmdir,
- loc, xflags, xdata);
- return 0;
+ gf_msg_debug(this->name, 0, "Dequeue rmdir");
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_rmdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rmdir, loc, xflags, xdata);
+ return 0;
}
int32_t
-changelog_rmdir (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int xflags, dict_t *xdata)
-{
- size_t xtra_len = 0;
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- call_stub_t *stub = NULL;
- struct list_head queue = {0, };
- gf_boolean_t barrier_enabled = _gf_false;
-
- INIT_LIST_HEAD (&queue);
-
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
-
- CHANGELOG_INIT_NOCHECK (this, frame->local,
- NULL, loc->inode->gfid, 2);
-
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
-
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
-
- co++;
- if (priv->capture_del_path) {
- CHANGELOG_FILL_ENTRY_DIR_PATH (co, loc->pargfid, loc->name,
- del_entry_fn, del_entry_free_fn,
- xtra_len, wind, _gf_true);
+changelog_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflags,
+ dict_t *xdata)
+{
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ call_stub_t *stub = NULL;
+ struct list_head queue = {
+ 0,
+ };
+ gf_boolean_t barrier_enabled = _gf_false;
+
+ INIT_LIST_HEAD(&queue);
+
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+
+ CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, loc->inode->gfid, 2);
+
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
+
+ co++;
+ if (priv->capture_del_path) {
+ CHANGELOG_FILL_ENTRY_DIR_PATH(co, loc->pargfid, loc->name, del_entry_fn,
+ del_entry_free_fn, xtra_len, wind,
+ _gf_true);
+ } else {
+ CHANGELOG_FILL_ENTRY_DIR_PATH(co, loc->pargfid, loc->name, del_entry_fn,
+ del_entry_free_fn, xtra_len, wind,
+ _gf_false);
+ }
+
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 2);
+
+ /* changelog barrier */
+ /* Color assignment and increment of fop_cnt for rmdir/unlink/rename
+ * should be made with in priv lock if changelog barrier is not enabled.
+ * Because if counter is not incremented yet, draining wakes up and
+ * publishes the changelog but later these fops might hit the disk and
+ * present in snapped volume but where as the intention is these fops
+ * should not be present in snapped volume.
+ */
+ LOCK(&priv->lock);
+ {
+ if ((barrier_enabled = priv->barrier_enabled)) {
+ stub = fop_rmdir_stub(frame, changelog_rmdir_resume, loc, xflags,
+ xdata);
+ if (!stub)
+ __chlog_barrier_disable(this, &queue);
+ else
+ __chlog_barrier_enqueue(this, stub);
} else {
- CHANGELOG_FILL_ENTRY_DIR_PATH (co, loc->pargfid, loc->name,
- del_entry_fn, del_entry_free_fn,
- xtra_len, wind, _gf_false);
- }
-
- changelog_set_usable_record_and_length (frame->local, xtra_len, 2);
-
-/* changelog barrier */
- /* Color assignment and increment of fop_cnt for rmdir/unlink/rename
- * should be made with in priv lock if changelog barrier is not enabled.
- * Because if counter is not incremented yet, draining wakes up and
- * publishes the changelog but later these fops might hit the disk and
- * present in snapped volume but where as the intention is these fops
- * should not be present in snapped volume.
- */
- LOCK (&priv->lock);
- {
- if ((barrier_enabled = priv->barrier_enabled)) {
- stub = fop_rmdir_stub (frame, changelog_rmdir_resume,
- loc, xflags, xdata);
- if (!stub)
- __chlog_barrier_disable (this, &queue);
- else
- __chlog_barrier_enqueue (this, stub);
- } else {
- ((changelog_local_t *)frame->local)->color
- = priv->current_color;
- changelog_inc_fop_cnt (this, priv, frame->local);
- }
- }
- UNLOCK (&priv->lock);
-
- if (barrier_enabled && stub) {
- gf_msg_debug (this->name, 0, "Enqueue rmdir");
- goto out;
- }
- if (barrier_enabled && !stub) {
- gf_smsg (this->name, GF_LOG_ERROR, ENOMEM,
- CHANGELOG_MSG_NO_MEMORY,
- "Failed to barrier FOPs, disabling changelog barrier",
- "fop=rmdir",
- NULL);
- chlog_barrier_dequeue_all (this, &queue);
- }
-
-/* changelog barrier */
-
- wind:
- STACK_WIND (frame, changelog_rmdir_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->rmdir,
- loc, xflags, xdata);
- out:
- return 0;
+ ((changelog_local_t *)frame->local)->color = priv->current_color;
+ changelog_inc_fop_cnt(this, priv, frame->local);
+ }
+ }
+ UNLOCK(&priv->lock);
+
+ if (barrier_enabled && stub) {
+ gf_msg_debug(this->name, 0, "Enqueue rmdir");
+ goto out;
+ }
+ if (barrier_enabled && !stub) {
+ gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY,
+ "Failed to barrier FOPs, disabling changelog barrier",
+ "fop=rmdir", NULL);
+ chlog_barrier_dequeue_all(this, &queue);
+ }
+
+ /* changelog barrier */
+
+wind:
+ STACK_WIND(frame, changelog_rmdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rmdir, loc, xflags, xdata);
+out:
+ return 0;
}
/* unlink */
int32_t
-changelog_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+changelog_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (unlink, frame, op_ret, op_errno,
- preparent, postparent, xdata);
- return 0;
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(unlink, frame, op_ret, op_errno, preparent,
+ postparent, xdata);
+ return 0;
}
int32_t
-changelog_unlink_resume (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int xflags, dict_t *xdata)
+changelog_unlink_resume(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ int xflags, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- gf_msg_debug (this->name, 0, "Dequeue unlink");
- changelog_color_fop_and_inc_cnt
- (this, priv, frame->local);
- STACK_WIND (frame, changelog_unlink_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->unlink,
- loc, xflags, xdata);
- return 0;
+ gf_msg_debug(this->name, 0, "Dequeue unlink");
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, loc, xflags, xdata);
+ return 0;
}
int32_t
-changelog_unlink (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int xflags, dict_t *xdata)
-{
- size_t xtra_len = 0;
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- call_stub_t *stub = NULL;
- struct list_head queue = {0, };
- gf_boolean_t barrier_enabled = _gf_false;
- dht_changelog_rename_info_t *info = NULL;
- int ret = 0;
- char *old_name = NULL;
- char *new_name = NULL;
- char *nname = NULL;
-
- INIT_LIST_HEAD (&queue);
- priv = this->private;
-
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
-
- ret = dict_get_bin (xdata, DHT_CHANGELOG_RENAME_OP_KEY, (void **)&info);
- if (!ret) { /* special case: unlink considered as rename */
- /* 3 == fop + oldloc + newloc */
- old_name = alloca (info->oldname_len);
- new_name = alloca (info->newname_len);
- CHANGELOG_INIT_NOCHECK (this, frame->local,
- NULL, loc->inode->gfid, 3);
-
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
-
- CHANGLOG_FILL_FOP_NUMBER (co, GF_FOP_RENAME, fop_fn, xtra_len);
-
- co++;
- strncpy (old_name, info->buffer, info->oldname_len);
- CHANGELOG_FILL_ENTRY (co, info->old_pargfid, old_name,
- entry_fn, entry_free_fn, xtra_len, wind);
-
- co++;
- /* new name resides just after old name */
- nname = info->buffer + info->oldname_len;
- strncpy (new_name, nname, info->newname_len);
- CHANGELOG_FILL_ENTRY (co, info->new_pargfid, new_name,
- entry_fn, entry_free_fn, xtra_len, wind);
-
- changelog_set_usable_record_and_length (frame->local,
- xtra_len, 3);
- } else { /* default unlink */
- CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, wind);
- CHANGELOG_INIT_NOCHECK (this, frame->local, NULL,
- loc->inode->gfid, 2);
-
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
-
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op,
- fop_fn, xtra_len);
-
- co++;
- if (priv->capture_del_path) {
- CHANGELOG_FILL_ENTRY_DIR_PATH (co, loc->pargfid,
- loc->name, del_entry_fn, del_entry_free_fn,
- xtra_len, wind, _gf_true);
- } else {
- CHANGELOG_FILL_ENTRY_DIR_PATH (co, loc->pargfid,
- loc->name, del_entry_fn, del_entry_free_fn,
- xtra_len, wind, _gf_false);
- }
+changelog_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflags,
+ dict_t *xdata)
+{
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ call_stub_t *stub = NULL;
+ struct list_head queue = {
+ 0,
+ };
+ gf_boolean_t barrier_enabled = _gf_false;
+ dht_changelog_rename_info_t *info = NULL;
+ int ret = 0;
+ char *old_name = NULL;
+ char *new_name = NULL;
+ char *nname = NULL;
+
+ INIT_LIST_HEAD(&queue);
+ priv = this->private;
+
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+
+ ret = dict_get_bin(xdata, DHT_CHANGELOG_RENAME_OP_KEY, (void **)&info);
+ if (!ret) { /* special case: unlink considered as rename */
+ /* 3 == fop + oldloc + newloc */
+ old_name = alloca(info->oldname_len);
+ new_name = alloca(info->newname_len);
+ CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, loc->inode->gfid, 3);
- changelog_set_usable_record_and_length (frame->local,
- xtra_len, 2);
- }
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
-/* changelog barrier */
- LOCK (&priv->lock);
- {
- if ((barrier_enabled = priv->barrier_enabled)) {
- stub = fop_unlink_stub (frame, changelog_unlink_resume,
- loc, xflags, xdata);
- if (!stub)
- __chlog_barrier_disable (this, &queue);
- else
- __chlog_barrier_enqueue (this, stub);
- } else {
- ((changelog_local_t *)frame->local)->color
- = priv->current_color;
- changelog_inc_fop_cnt (this, priv, frame->local);
- }
- }
- UNLOCK (&priv->lock);
+ CHANGLOG_FILL_FOP_NUMBER(co, GF_FOP_RENAME, fop_fn, xtra_len);
- if (barrier_enabled && stub) {
- gf_msg_debug (this->name, 0, "Enqueue unlink");
- goto out;
- }
- if (barrier_enabled && !stub) {
- gf_smsg (this->name, GF_LOG_ERROR, ENOMEM,
- CHANGELOG_MSG_NO_MEMORY,
- "Failed to barrier FOPs, disabling changelog barrier",
- "fop=unlink",
- NULL);
- chlog_barrier_dequeue_all (this, &queue);
- }
+ co++;
+ strncpy(old_name, info->buffer, info->oldname_len);
+ CHANGELOG_FILL_ENTRY(co, info->old_pargfid, old_name, entry_fn,
+ entry_free_fn, xtra_len, wind);
-/* changelog barrier */
+ co++;
+ /* new name resides just after old name */
+ nname = info->buffer + info->oldname_len;
+ strncpy(new_name, nname, info->newname_len);
+ CHANGELOG_FILL_ENTRY(co, info->new_pargfid, new_name, entry_fn,
+ entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 3);
+ } else { /* default unlink */
+ CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, wind);
+ CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, loc->inode->gfid, 2);
+
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
- wind:
- STACK_WIND (frame, changelog_unlink_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->unlink,
- loc, xflags, xdata);
- out:
- return 0;
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
+
+ co++;
+ if (priv->capture_del_path) {
+ CHANGELOG_FILL_ENTRY_DIR_PATH(co, loc->pargfid, loc->name,
+ del_entry_fn, del_entry_free_fn,
+ xtra_len, wind, _gf_true);
+ } else {
+ CHANGELOG_FILL_ENTRY_DIR_PATH(co, loc->pargfid, loc->name,
+ del_entry_fn, del_entry_free_fn,
+ xtra_len, wind, _gf_false);
+ }
+
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 2);
+ }
+
+ /* changelog barrier */
+ LOCK(&priv->lock);
+ {
+ if ((barrier_enabled = priv->barrier_enabled)) {
+ stub = fop_unlink_stub(frame, changelog_unlink_resume, loc, xflags,
+ xdata);
+ if (!stub)
+ __chlog_barrier_disable(this, &queue);
+ else
+ __chlog_barrier_enqueue(this, stub);
+ } else {
+ ((changelog_local_t *)frame->local)->color = priv->current_color;
+ changelog_inc_fop_cnt(this, priv, frame->local);
+ }
+ }
+ UNLOCK(&priv->lock);
+
+ if (barrier_enabled && stub) {
+ gf_msg_debug(this->name, 0, "Enqueue unlink");
+ goto out;
+ }
+ if (barrier_enabled && !stub) {
+ gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY,
+ "Failed to barrier FOPs, disabling changelog barrier",
+ "fop=unlink", NULL);
+ chlog_barrier_dequeue_all(this, &queue);
+ }
+
+ /* changelog barrier */
+
+wind:
+ STACK_WIND(frame, changelog_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, loc, xflags, xdata);
+out:
+ return 0;
}
/* rename */
int32_t
-changelog_rename_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iatt *buf, struct iatt *preoldparent,
- struct iatt *postoldparent, struct iatt *prenewparent,
- struct iatt *postnewparent, dict_t *xdata)
-{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
-
- priv = this->private;
- local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (rename, frame, op_ret, op_errno,
- buf, preoldparent, postoldparent,
- prenewparent, postnewparent, xdata);
- return 0;
+changelog_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf,
+ struct iatt *preoldparent, struct iatt *postoldparent,
+ struct iatt *prenewparent, struct iatt *postnewparent,
+ dict_t *xdata)
+{
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
+
+ priv = this->private;
+ local = frame->local;
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY);
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(rename, frame, op_ret, op_errno, buf, preoldparent,
+ postoldparent, prenewparent, postnewparent, xdata);
+ return 0;
}
int32_t
-changelog_rename_resume (call_frame_t *frame, xlator_t *this,
- loc_t *oldloc, loc_t *newloc, dict_t *xdata)
+changelog_rename_resume(call_frame_t *frame, xlator_t *this, loc_t *oldloc,
+ loc_t *newloc, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- gf_msg_debug (this->name, 0, "Dequeue rename");
- changelog_color_fop_and_inc_cnt
- (this, priv, frame->local);
- STACK_WIND (frame, changelog_rename_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->rename,
- oldloc, newloc, xdata);
- return 0;
+ gf_msg_debug(this->name, 0, "Dequeue rename");
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_rename_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rename, oldloc, newloc, xdata);
+ return 0;
}
int32_t
-changelog_rename (call_frame_t *frame, xlator_t *this,
- loc_t *oldloc, loc_t *newloc, dict_t *xdata)
-{
- size_t xtra_len = 0;
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- call_stub_t *stub = NULL;
- struct list_head queue = {0, };
- gf_boolean_t barrier_enabled = _gf_false;
- dht_changelog_rename_info_t *info = NULL;
- int ret = 0;
-
- INIT_LIST_HEAD (&queue);
-
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
-
- ret = dict_get_bin (xdata, DHT_CHANGELOG_RENAME_OP_KEY, (void **)&info);
- if (ret && oldloc->inode->ia_type != IA_IFDIR) {
- /* xdata "NOT" set for a non-directory,
- * Special rename => avoid logging */
- goto wind;
- }
-
- /* 3 == fop + oldloc + newloc */
- CHANGELOG_INIT_NOCHECK (this, frame->local,
- NULL, oldloc->inode->gfid, 3);
-
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
-
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
-
- co++;
- CHANGELOG_FILL_ENTRY (co, oldloc->pargfid, oldloc->name,
- entry_fn, entry_free_fn, xtra_len, wind);
-
- co++;
- CHANGELOG_FILL_ENTRY (co, newloc->pargfid, newloc->name,
- entry_fn, entry_free_fn, xtra_len, wind);
-
- changelog_set_usable_record_and_length (frame->local, xtra_len, 3);
-/* changelog barrier */
- LOCK (&priv->lock);
- {
- if ((barrier_enabled = priv->barrier_enabled)) {
- stub = fop_rename_stub (frame, changelog_rename_resume,
- oldloc, newloc, xdata);
- if (!stub)
- __chlog_barrier_disable (this, &queue);
- else
- __chlog_barrier_enqueue (this, stub);
- } else {
- ((changelog_local_t *)frame->local)->color
- = priv->current_color;
- changelog_inc_fop_cnt (this, priv, frame->local);
- }
- }
- UNLOCK (&priv->lock);
-
- if (barrier_enabled && stub) {
- gf_msg_debug (this->name, 0, "Enqueue rename");
- goto out;
- }
- if (barrier_enabled && !stub) {
- gf_smsg (this->name, GF_LOG_ERROR, ENOMEM,
- CHANGELOG_MSG_NO_MEMORY,
- "Failed to barrier FOPs, disabling changelog barrier",
- "fop=rename",
- NULL);
- chlog_barrier_dequeue_all (this, &queue);
- }
-/* changelog barrier */
-
- wind:
- STACK_WIND (frame, changelog_rename_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->rename,
- oldloc, newloc, xdata);
- out:
- return 0;
+changelog_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc,
+ loc_t *newloc, dict_t *xdata)
+{
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ call_stub_t *stub = NULL;
+ struct list_head queue = {
+ 0,
+ };
+ gf_boolean_t barrier_enabled = _gf_false;
+ dht_changelog_rename_info_t *info = NULL;
+ int ret = 0;
+
+ INIT_LIST_HEAD(&queue);
+
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+
+ ret = dict_get_bin(xdata, DHT_CHANGELOG_RENAME_OP_KEY, (void **)&info);
+ if (ret && oldloc->inode->ia_type != IA_IFDIR) {
+ /* xdata "NOT" set for a non-directory,
+ * Special rename => avoid logging */
+ goto wind;
+ }
+
+ /* 3 == fop + oldloc + newloc */
+ CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, oldloc->inode->gfid, 3);
+
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
+
+ co++;
+ CHANGELOG_FILL_ENTRY(co, oldloc->pargfid, oldloc->name, entry_fn,
+ entry_free_fn, xtra_len, wind);
+
+ co++;
+ CHANGELOG_FILL_ENTRY(co, newloc->pargfid, newloc->name, entry_fn,
+ entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 3);
+ /* changelog barrier */
+ LOCK(&priv->lock);
+ {
+ if ((barrier_enabled = priv->barrier_enabled)) {
+ stub = fop_rename_stub(frame, changelog_rename_resume, oldloc,
+ newloc, xdata);
+ if (!stub)
+ __chlog_barrier_disable(this, &queue);
+ else
+ __chlog_barrier_enqueue(this, stub);
+ } else {
+ ((changelog_local_t *)frame->local)->color = priv->current_color;
+ changelog_inc_fop_cnt(this, priv, frame->local);
+ }
+ }
+ UNLOCK(&priv->lock);
+
+ if (barrier_enabled && stub) {
+ gf_msg_debug(this->name, 0, "Enqueue rename");
+ goto out;
+ }
+ if (barrier_enabled && !stub) {
+ gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY,
+ "Failed to barrier FOPs, disabling changelog barrier",
+ "fop=rename", NULL);
+ chlog_barrier_dequeue_all(this, &queue);
+ }
+ /* changelog barrier */
+
+wind:
+ STACK_WIND(frame, changelog_rename_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rename, oldloc, newloc, xdata);
+out:
+ return 0;
}
/* link */
int32_t
-changelog_link_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+changelog_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (link, frame, op_ret, op_errno,
- inode, buf, preparent, postparent, xdata);
- return 0;
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(link, frame, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
+ return 0;
}
int32_t
-changelog_link_resume (call_frame_t *frame, xlator_t *this,
- loc_t *oldloc, loc_t *newloc, dict_t *xdata)
+changelog_link_resume(call_frame_t *frame, xlator_t *this, loc_t *oldloc,
+ loc_t *newloc, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- GF_VALIDATE_OR_GOTO ("changelog", this, out);
- GF_VALIDATE_OR_GOTO ("changelog", this->fops, out);
- GF_VALIDATE_OR_GOTO ("changelog", frame, out);
+ GF_VALIDATE_OR_GOTO("changelog", this, out);
+ GF_VALIDATE_OR_GOTO("changelog", this->fops, out);
+ GF_VALIDATE_OR_GOTO("changelog", frame, out);
- priv = this->private;
+ priv = this->private;
- gf_msg_debug (this->name, 0, "Dequeuing link");
- changelog_color_fop_and_inc_cnt
- (this, priv, frame->local);
- STACK_WIND (frame, changelog_link_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->link,
- oldloc, newloc, xdata);
- return 0;
+ gf_msg_debug(this->name, 0, "Dequeuing link");
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_link_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata);
+ return 0;
out:
- return -1;
+ return -1;
}
int32_t
-changelog_link (call_frame_t *frame,
- xlator_t *this, loc_t *oldloc,
- loc_t *newloc, dict_t *xdata)
-{
- size_t xtra_len = 0;
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- call_stub_t *stub = NULL;
- struct list_head queue = {0, };
- gf_boolean_t barrier_enabled = _gf_false;
-
- priv = this->private;
-
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, wind);
-
- CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, oldloc->gfid, 2);
-
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
-
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
-
- co++;
- CHANGELOG_FILL_ENTRY (co, newloc->pargfid, newloc->name,
- entry_fn, entry_free_fn, xtra_len, wind);
-
- changelog_set_usable_record_and_length (frame->local, xtra_len, 2);
-
- LOCK (&priv->lock);
- {
- if ((barrier_enabled = priv->barrier_enabled)) {
- stub = fop_link_stub (frame, changelog_link_resume,
- oldloc, newloc, xdata);
- if (!stub)
- __chlog_barrier_disable (this, &queue);
- else
- __chlog_barrier_enqueue (this, stub);
- } else {
- ((changelog_local_t *)frame->local)->color
- = priv->current_color;
- changelog_inc_fop_cnt (this, priv, frame->local);
- }
- }
- UNLOCK (&priv->lock);
-
- if (barrier_enabled && stub) {
- gf_msg_debug (this->name, 0, "Enqueued link");
- goto out;
- }
-
- if (barrier_enabled && !stub) {
- gf_smsg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_NO_MEMORY,
- "Failed to barrier FOPs, disabling changelog barrier",
- "fop=link",
- NULL);
- chlog_barrier_dequeue_all (this, &queue);
- }
- wind:
- STACK_WIND (frame, changelog_link_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->link,
- oldloc, newloc, xdata);
+changelog_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc,
+ loc_t *newloc, dict_t *xdata)
+{
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ call_stub_t *stub = NULL;
+ struct list_head queue = {
+ 0,
+ };
+ gf_boolean_t barrier_enabled = _gf_false;
+
+ priv = this->private;
+
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+ CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, wind);
+
+ CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, oldloc->gfid, 2);
+
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
+
+ co++;
+ CHANGELOG_FILL_ENTRY(co, newloc->pargfid, newloc->name, entry_fn,
+ entry_free_fn, xtra_len, wind);
+
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 2);
+
+ LOCK(&priv->lock);
+ {
+ if ((barrier_enabled = priv->barrier_enabled)) {
+ stub = fop_link_stub(frame, changelog_link_resume, oldloc, newloc,
+ xdata);
+ if (!stub)
+ __chlog_barrier_disable(this, &queue);
+ else
+ __chlog_barrier_enqueue(this, stub);
+ } else {
+ ((changelog_local_t *)frame->local)->color = priv->current_color;
+ changelog_inc_fop_cnt(this, priv, frame->local);
+ }
+ }
+ UNLOCK(&priv->lock);
+
+ if (barrier_enabled && stub) {
+ gf_msg_debug(this->name, 0, "Enqueued link");
+ goto out;
+ }
+
+ if (barrier_enabled && !stub) {
+ gf_smsg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_NO_MEMORY,
+ "Failed to barrier FOPs, disabling changelog barrier",
+ "fop=link", NULL);
+ chlog_barrier_dequeue_all(this, &queue);
+ }
+wind:
+ STACK_WIND(frame, changelog_link_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata);
out:
- return 0;
+ return 0;
}
/* mkdir */
int32_t
-changelog_mkdir_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+changelog_mkdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (mkdir, frame, op_ret, op_errno,
- inode, buf, preparent, postparent, xdata);
- return 0;
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(mkdir, frame, op_ret, op_errno, inode, buf,
+ preparent, postparent, xdata);
+ return 0;
}
int32_t
-changelog_mkdir_resume (call_frame_t *frame, xlator_t *this,
- loc_t *loc, mode_t mode,
- mode_t umask, dict_t *xdata)
+changelog_mkdir_resume(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ mode_t mode, mode_t umask, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- GF_VALIDATE_OR_GOTO ("changelog", this, out);
- GF_VALIDATE_OR_GOTO ("changelog", this->fops, out);
- GF_VALIDATE_OR_GOTO ("changelog", frame, out);
+ GF_VALIDATE_OR_GOTO("changelog", this, out);
+ GF_VALIDATE_OR_GOTO("changelog", this->fops, out);
+ GF_VALIDATE_OR_GOTO("changelog", frame, out);
- priv = this->private;
+ priv = this->private;
- gf_msg_debug (this->name, 0, "Dequeuing mkdir");
- changelog_color_fop_and_inc_cnt
- (this, priv, frame->local);
- STACK_WIND (frame, changelog_mkdir_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->mkdir,
- loc, mode, umask, xdata);
- return 0;
+ gf_msg_debug(this->name, 0, "Dequeuing mkdir");
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_mkdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mkdir, loc, mode, umask, xdata);
+ return 0;
out:
- return -1;
+ return -1;
}
int32_t
-changelog_mkdir (call_frame_t *frame, xlator_t *this,
- loc_t *loc, mode_t mode, mode_t umask, dict_t *xdata)
-{
- int ret = -1;
- uuid_t gfid = {0,};
- size_t xtra_len = 0;
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- call_stub_t *stub = NULL;
- struct list_head queue = {0, };
- gf_boolean_t barrier_enabled = _gf_false;
-
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
-
- ret = dict_get_gfuuid (xdata, "gfid-req", &gfid);
- if (ret) {
- gf_msg_debug (this->name, 0,
- "failed to get gfid from dict");
- goto wind;
- }
-
- CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, gfid, 5);
-
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
-
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_UINT32 (co, S_IFDIR | mode, number_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_UINT32 (co, frame->root->uid, number_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_UINT32 (co, frame->root->gid, number_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
- entry_fn, entry_free_fn, xtra_len, wind);
-
- changelog_set_usable_record_and_length (frame->local, xtra_len, 5);
-
- LOCK (&priv->lock);
- {
- if ((barrier_enabled = priv->barrier_enabled)) {
- stub = fop_mkdir_stub (frame, changelog_mkdir_resume,
- loc, mode, umask, xdata);
- if (!stub)
- __chlog_barrier_disable (this, &queue);
- else
- __chlog_barrier_enqueue (this, stub);
- } else {
- ((changelog_local_t *)frame->local)->color
- = priv->current_color;
- changelog_inc_fop_cnt (this, priv, frame->local);
- }
- }
- UNLOCK (&priv->lock);
-
- if (barrier_enabled && stub) {
- gf_msg_debug (this->name, 0, "Enqueued mkdir");
- goto out;
- }
-
- if (barrier_enabled && !stub) {
- gf_smsg (this->name, GF_LOG_ERROR, ENOMEM,
- CHANGELOG_MSG_NO_MEMORY,
- "Failed to barrier FOPs, disabling changelog barrier",
- "fop=mkdir",
- NULL);
- chlog_barrier_dequeue_all (this, &queue);
- }
-
- wind:
- STACK_WIND (frame, changelog_mkdir_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->mkdir,
- loc, mode, umask, xdata);
+changelog_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ mode_t umask, dict_t *xdata)
+{
+ int ret = -1;
+ uuid_t gfid = {
+ 0,
+ };
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ call_stub_t *stub = NULL;
+ struct list_head queue = {
+ 0,
+ };
+ gf_boolean_t barrier_enabled = _gf_false;
+
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+
+ ret = dict_get_gfuuid(xdata, "gfid-req", &gfid);
+ if (ret) {
+ gf_msg_debug(this->name, 0, "failed to get gfid from dict");
+ goto wind;
+ }
+
+ CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, gfid, 5);
+
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32(co, S_IFDIR | mode, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32(co, frame->root->uid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32(co, frame->root->gid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_ENTRY(co, loc->pargfid, loc->name, entry_fn, entry_free_fn,
+ xtra_len, wind);
+
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 5);
+
+ LOCK(&priv->lock);
+ {
+ if ((barrier_enabled = priv->barrier_enabled)) {
+ stub = fop_mkdir_stub(frame, changelog_mkdir_resume, loc, mode,
+ umask, xdata);
+ if (!stub)
+ __chlog_barrier_disable(this, &queue);
+ else
+ __chlog_barrier_enqueue(this, stub);
+ } else {
+ ((changelog_local_t *)frame->local)->color = priv->current_color;
+ changelog_inc_fop_cnt(this, priv, frame->local);
+ }
+ }
+ UNLOCK(&priv->lock);
+
+ if (barrier_enabled && stub) {
+ gf_msg_debug(this->name, 0, "Enqueued mkdir");
+ goto out;
+ }
+
+ if (barrier_enabled && !stub) {
+ gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY,
+ "Failed to barrier FOPs, disabling changelog barrier",
+ "fop=mkdir", NULL);
+ chlog_barrier_dequeue_all(this, &queue);
+ }
+
+wind:
+ STACK_WIND(frame, changelog_mkdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mkdir, loc, mode, umask, xdata);
out:
- return 0;
+ return 0;
}
/* symlink */
int32_t
-changelog_symlink_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- inode_t *inode, struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+changelog_symlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (symlink, frame, op_ret, op_errno,
- inode, buf, preparent, postparent, xdata);
- return 0;
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(symlink, frame, op_ret, op_errno, inode, buf,
+ preparent, postparent, xdata);
+ return 0;
}
-
int32_t
-changelog_symlink_resume (call_frame_t *frame, xlator_t *this,
- const char *linkname, loc_t *loc,
- mode_t umask, dict_t *xdata)
+changelog_symlink_resume(call_frame_t *frame, xlator_t *this,
+ const char *linkname, loc_t *loc, mode_t umask,
+ dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- GF_VALIDATE_OR_GOTO ("changelog", this, out);
- GF_VALIDATE_OR_GOTO ("changelog", this->fops, out);
- GF_VALIDATE_OR_GOTO ("changelog", frame, out);
+ GF_VALIDATE_OR_GOTO("changelog", this, out);
+ GF_VALIDATE_OR_GOTO("changelog", this->fops, out);
+ GF_VALIDATE_OR_GOTO("changelog", frame, out);
- priv = this->private;
+ priv = this->private;
- gf_msg_debug (this->name, 0, "Dequeuing symlink");
- changelog_color_fop_and_inc_cnt
- (this, priv, frame->local);
- STACK_WIND (frame, changelog_symlink_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->symlink,
- linkname, loc, umask, xdata);
- return 0;
+ gf_msg_debug(this->name, 0, "Dequeuing symlink");
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_symlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->symlink, linkname, loc, umask, xdata);
+ return 0;
out:
- return -1;
+ return -1;
}
int32_t
-changelog_symlink (call_frame_t *frame, xlator_t *this,
- const char *linkname, loc_t *loc,
- mode_t umask, dict_t *xdata)
-{
- int ret = -1;
- size_t xtra_len = 0;
- uuid_t gfid = {0,};
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- call_stub_t *stub = NULL;
- struct list_head queue = {0, };
- gf_boolean_t barrier_enabled = _gf_false;
-
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
-
- ret = dict_get_gfuuid (xdata, "gfid-req", &gfid);
- if (ret) {
- gf_msg_debug (this->name, 0,
- "failed to get gfid from dict");
- goto wind;
- }
-
- CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, gfid, 2);
-
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
-
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
- entry_fn, entry_free_fn, xtra_len, wind);
-
- changelog_set_usable_record_and_length (frame->local, xtra_len, 2);
-
- LOCK (&priv->lock);
- {
- if ((barrier_enabled = priv->barrier_enabled)) {
- stub = fop_symlink_stub (frame,
- changelog_symlink_resume,
- linkname, loc, umask, xdata);
- if (!stub)
- __chlog_barrier_disable (this, &queue);
- else
- __chlog_barrier_enqueue (this, stub);
- } else {
- ((changelog_local_t *)frame->local)->color
- = priv->current_color;
- changelog_inc_fop_cnt (this, priv, frame->local);
- }
- }
- UNLOCK (&priv->lock);
-
- if (barrier_enabled && stub) {
- gf_msg_debug (this->name, 0, "Enqueued symlink");
- goto out;
- }
-
- if (barrier_enabled && !stub) {
- gf_smsg (this->name, GF_LOG_ERROR, ENOMEM,
- CHANGELOG_MSG_NO_MEMORY,
- "Failed to barrier FOPs, disabling changelog barrier",
- "fop=symlink",
- NULL);
- chlog_barrier_dequeue_all (this, &queue);
- }
-
- wind:
- STACK_WIND (frame, changelog_symlink_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->symlink,
- linkname, loc, umask, xdata);
+changelog_symlink(call_frame_t *frame, xlator_t *this, const char *linkname,
+ loc_t *loc, mode_t umask, dict_t *xdata)
+{
+ int ret = -1;
+ size_t xtra_len = 0;
+ uuid_t gfid = {
+ 0,
+ };
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ call_stub_t *stub = NULL;
+ struct list_head queue = {
+ 0,
+ };
+ gf_boolean_t barrier_enabled = _gf_false;
+
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+
+ ret = dict_get_gfuuid(xdata, "gfid-req", &gfid);
+ if (ret) {
+ gf_msg_debug(this->name, 0, "failed to get gfid from dict");
+ goto wind;
+ }
+
+ CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, gfid, 2);
+
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_ENTRY(co, loc->pargfid, loc->name, entry_fn, entry_free_fn,
+ xtra_len, wind);
+
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 2);
+
+ LOCK(&priv->lock);
+ {
+ if ((barrier_enabled = priv->barrier_enabled)) {
+ stub = fop_symlink_stub(frame, changelog_symlink_resume, linkname,
+ loc, umask, xdata);
+ if (!stub)
+ __chlog_barrier_disable(this, &queue);
+ else
+ __chlog_barrier_enqueue(this, stub);
+ } else {
+ ((changelog_local_t *)frame->local)->color = priv->current_color;
+ changelog_inc_fop_cnt(this, priv, frame->local);
+ }
+ }
+ UNLOCK(&priv->lock);
+
+ if (barrier_enabled && stub) {
+ gf_msg_debug(this->name, 0, "Enqueued symlink");
+ goto out;
+ }
+
+ if (barrier_enabled && !stub) {
+ gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY,
+ "Failed to barrier FOPs, disabling changelog barrier",
+ "fop=symlink", NULL);
+ chlog_barrier_dequeue_all(this, &queue);
+ }
+
+wind:
+ STACK_WIND(frame, changelog_symlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->symlink, linkname, loc, umask, xdata);
out:
- return 0;
+ return 0;
}
/* mknod */
int32_t
-changelog_mknod_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+changelog_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (mknod, frame, op_ret, op_errno,
- inode, buf, preparent, postparent, xdata);
- return 0;
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(mknod, frame, op_ret, op_errno, inode, buf,
+ preparent, postparent, xdata);
+ return 0;
}
int32_t
-changelog_mknod_resume (call_frame_t *frame, xlator_t *this,
- loc_t *loc, mode_t mode, dev_t rdev,
- mode_t umask, dict_t *xdata)
+changelog_mknod_resume(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ mode_t mode, dev_t rdev, mode_t umask, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- GF_VALIDATE_OR_GOTO ("changelog", this, out);
- GF_VALIDATE_OR_GOTO ("changelog", this->fops, out);
- GF_VALIDATE_OR_GOTO ("changelog", frame, out);
+ GF_VALIDATE_OR_GOTO("changelog", this, out);
+ GF_VALIDATE_OR_GOTO("changelog", this->fops, out);
+ GF_VALIDATE_OR_GOTO("changelog", frame, out);
- priv = this->private;
+ priv = this->private;
- gf_msg_debug (this->name, 0, "Dequeuing mknod");
- changelog_color_fop_and_inc_cnt
- (this, priv, frame->local);
- STACK_WIND (frame, changelog_mknod_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->mknod,
- loc, mode, rdev, umask, xdata);
- return 0;
+ gf_msg_debug(this->name, 0, "Dequeuing mknod");
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_mknod_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mknod, loc, mode, rdev, umask, xdata);
+ return 0;
out:
- return -1;
+ return -1;
}
int32_t
-changelog_mknod (call_frame_t *frame,
- xlator_t *this, loc_t *loc,
- mode_t mode, dev_t dev, mode_t umask, dict_t *xdata)
-{
- int ret = -1;
- uuid_t gfid = {0,};
- size_t xtra_len = 0;
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- call_stub_t *stub = NULL;
- struct list_head queue = {0, };
- gf_boolean_t barrier_enabled = _gf_false;
-
- priv = this->private;
-
- /* Check whether changelog active */
- if (!(priv->active))
- goto wind;
-
- /* Check whether rebalance activity */
- if (frame->root->pid == GF_CLIENT_PID_DEFRAG)
- goto wind;
-
- /* If tier-dht linkto is SET, ignore about verifiying :
- * 1. Whether internal fop AND
- * 2. Whether tier rebalance process activity (this will help in
- * recording mknod if tier rebalance process calls this mknod) */
- if (!(dict_get (xdata, "trusted.tier.tier-dht.linkto"))) {
- CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, wind);
- if (frame->root->pid == GF_CLIENT_PID_TIER_DEFRAG)
- goto wind;
- }
-
- ret = dict_get_gfuuid (xdata, "gfid-req", &gfid);
- if (ret) {
- gf_msg_debug (this->name, 0,
- "failed to get gfid from dict");
- goto wind;
- }
-
- CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, gfid, 5);
-
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
-
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_UINT32 (co, mode, number_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_UINT32 (co, frame->root->uid, number_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_UINT32 (co, frame->root->gid, number_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
- entry_fn, entry_free_fn, xtra_len, wind);
-
- changelog_set_usable_record_and_length (frame->local, xtra_len, 5);
-
- LOCK (&priv->lock);
- {
- if ((barrier_enabled = priv->barrier_enabled)) {
- stub = fop_mknod_stub (frame, changelog_mknod_resume,
- loc, mode, dev, umask, xdata);
- if (!stub)
- __chlog_barrier_disable (this, &queue);
- else
- __chlog_barrier_enqueue (this, stub);
- } else {
- ((changelog_local_t *)frame->local)->color
- = priv->current_color;
- changelog_inc_fop_cnt (this, priv, frame->local);
- }
- }
- UNLOCK (&priv->lock);
-
- if (barrier_enabled && stub) {
- gf_msg_debug (this->name, 0, "Enqueued mknod");
- goto out;
- }
-
- if (barrier_enabled && !stub) {
- gf_smsg (this->name, GF_LOG_ERROR, ENOMEM,
- CHANGELOG_MSG_NO_MEMORY,
- "Failed to barrier FOPs, disabling changelog barrier",
- "fop=mknod",
- NULL);
- chlog_barrier_dequeue_all (this, &queue);
- }
-
- wind:
- STACK_WIND (frame, changelog_mknod_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->mknod,
- loc, mode, dev, umask, xdata);
+changelog_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ dev_t dev, mode_t umask, dict_t *xdata)
+{
+ int ret = -1;
+ uuid_t gfid = {
+ 0,
+ };
+ size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ call_stub_t *stub = NULL;
+ struct list_head queue = {
+ 0,
+ };
+ gf_boolean_t barrier_enabled = _gf_false;
+
+ priv = this->private;
+
+ /* Check whether changelog active */
+ if (!(priv->active))
+ goto wind;
+
+ /* Check whether rebalance activity */
+ if (frame->root->pid == GF_CLIENT_PID_DEFRAG)
+ goto wind;
+
+ /* If tier-dht linkto is SET, ignore about verifiying :
+ * 1. Whether internal fop AND
+ * 2. Whether tier rebalance process activity (this will help in
+ * recording mknod if tier rebalance process calls this mknod) */
+ if (!(dict_get(xdata, "trusted.tier.tier-dht.linkto"))) {
+ CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, wind);
+ if (frame->root->pid == GF_CLIENT_PID_TIER_DEFRAG)
+ goto wind;
+ }
+
+ ret = dict_get_gfuuid(xdata, "gfid-req", &gfid);
+ if (ret) {
+ gf_msg_debug(this->name, 0, "failed to get gfid from dict");
+ goto wind;
+ }
+
+ CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, gfid, 5);
+
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32(co, mode, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32(co, frame->root->uid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32(co, frame->root->gid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_ENTRY(co, loc->pargfid, loc->name, entry_fn, entry_free_fn,
+ xtra_len, wind);
+
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 5);
+
+ LOCK(&priv->lock);
+ {
+ if ((barrier_enabled = priv->barrier_enabled)) {
+ stub = fop_mknod_stub(frame, changelog_mknod_resume, loc, mode, dev,
+ umask, xdata);
+ if (!stub)
+ __chlog_barrier_disable(this, &queue);
+ else
+ __chlog_barrier_enqueue(this, stub);
+ } else {
+ ((changelog_local_t *)frame->local)->color = priv->current_color;
+ changelog_inc_fop_cnt(this, priv, frame->local);
+ }
+ }
+ UNLOCK(&priv->lock);
+
+ if (barrier_enabled && stub) {
+ gf_msg_debug(this->name, 0, "Enqueued mknod");
+ goto out;
+ }
+
+ if (barrier_enabled && !stub) {
+ gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY,
+ "Failed to barrier FOPs, disabling changelog barrier",
+ "fop=mknod", NULL);
+ chlog_barrier_dequeue_all(this, &queue);
+ }
+
+wind:
+ STACK_WIND(frame, changelog_mknod_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mknod, loc, mode, dev, umask, xdata);
out:
- return 0;
+ return 0;
}
/* create */
int32_t
-changelog_create_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- fd_t *fd, inode_t *inode, struct iatt *buf,
- struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+changelog_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode,
+ struct iatt *buf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- int32_t ret = 0;
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
- changelog_event_t ev = {0,};
-
- priv = this->private;
- local = frame->local;
-
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
-
- /* fill the event structure.. similar to open() */
- ev.ev_type = CHANGELOG_OP_TYPE_CREATE;
- gf_uuid_copy (ev.u.create.gfid, buf->ia_gfid);
- ev.u.create.flags = fd->flags;
- changelog_dispatch_event (this, priv, &ev);
-
- if (changelog_ev_selected
- (this, &priv->ev_selection, CHANGELOG_OP_TYPE_RELEASE)) {
- ret = fd_ctx_set (fd, this, (uint64_t)(long) 0x1);
- if (ret)
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CHANGELOG_MSG_SET_FD_CONTEXT,
- "could not set fd context (for release cbk)");
- }
+ int32_t ret = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
+ changelog_event_t ev = {
+ 0,
+ };
- changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
+ priv = this->private;
+ local = frame->local;
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (create, frame,
- op_ret, op_errno, fd, inode,
- buf, preparent, postparent, xdata);
- return 0;
-}
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
-int32_t
-changelog_create_resume (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int32_t flags, mode_t mode,
- mode_t umask, fd_t *fd, dict_t *xdata)
-{
- changelog_priv_t *priv = NULL;
+ /* fill the event structure.. similar to open() */
+ ev.ev_type = CHANGELOG_OP_TYPE_CREATE;
+ gf_uuid_copy(ev.u.create.gfid, buf->ia_gfid);
+ ev.u.create.flags = fd->flags;
+ changelog_dispatch_event(this, priv, &ev);
- GF_VALIDATE_OR_GOTO ("changelog", this, out);
- GF_VALIDATE_OR_GOTO ("changelog", this->fops, out);
- GF_VALIDATE_OR_GOTO ("changelog", frame, out);
-
- priv = this->private;
+ if (changelog_ev_selected(this, &priv->ev_selection,
+ CHANGELOG_OP_TYPE_RELEASE)) {
+ ret = fd_ctx_set(fd, this, (uint64_t)(long)0x1);
+ if (ret)
+ gf_msg(this->name, GF_LOG_WARNING, 0, CHANGELOG_MSG_SET_FD_CONTEXT,
+ "could not set fd context (for release cbk)");
+ }
- gf_msg_debug (this->name, 0, "Dequeuing create");
- changelog_color_fop_and_inc_cnt
- (this, priv, frame->local);
- STACK_WIND (frame, changelog_create_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->create,
- loc, flags, mode, umask, fd, xdata);
- return 0;
+ changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY);
-out:
- return -1;
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(create, frame, op_ret, op_errno, fd, inode, buf,
+ preparent, postparent, xdata);
+ return 0;
}
int32_t
-changelog_create (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int32_t flags, mode_t mode,
- mode_t umask, fd_t *fd, dict_t *xdata)
-{
- int ret = -1;
- uuid_t gfid = {0,};
- changelog_opt_t *co = NULL;
- changelog_priv_t *priv = NULL;
- size_t xtra_len = 0;
- call_stub_t *stub = NULL;
- struct list_head queue = {0, };
- gf_boolean_t barrier_enabled = _gf_false;
-
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
-
- ret = dict_get_gfuuid (xdata, "gfid-req", &gfid);
- if (ret) {
- gf_msg_debug (this->name, 0,
- "failed to get gfid from dict");
- goto wind;
- }
-
- /* init with two extra records */
- CHANGELOG_INIT_NOCHECK (this, frame->local, NULL, gfid, 5);
- if (!frame->local)
- goto wind;
-
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
-
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_UINT32 (co, mode, number_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_UINT32 (co, frame->root->uid, number_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_UINT32 (co, frame->root->gid, number_fn, xtra_len);
- co++;
-
- CHANGELOG_FILL_ENTRY (co, loc->pargfid, loc->name,
- entry_fn, entry_free_fn, xtra_len, wind);
+changelog_create_resume(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ int32_t flags, mode_t mode, mode_t umask, fd_t *fd,
+ dict_t *xdata)
+{
+ changelog_priv_t *priv = NULL;
- changelog_set_usable_record_and_length (frame->local, xtra_len, 5);
+ GF_VALIDATE_OR_GOTO("changelog", this, out);
+ GF_VALIDATE_OR_GOTO("changelog", this->fops, out);
+ GF_VALIDATE_OR_GOTO("changelog", frame, out);
- LOCK (&priv->lock);
- {
- if ((barrier_enabled = priv->barrier_enabled)) {
- stub = fop_create_stub (frame, changelog_create_resume,
- loc, flags, mode, umask, fd,
- xdata);
- if (!stub)
- __chlog_barrier_disable (this, &queue);
- else
- __chlog_barrier_enqueue (this, stub);
- } else {
- ((changelog_local_t *)frame->local)->color
- = priv->current_color;
- changelog_inc_fop_cnt (this, priv, frame->local);
- }
- }
- UNLOCK (&priv->lock);
+ priv = this->private;
- if (barrier_enabled && stub) {
- gf_msg_debug (this->name, 0, "Enqueued create");
- goto out;
- }
+ gf_msg_debug(this->name, 0, "Dequeuing create");
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_create_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->create, loc, flags, mode, umask, fd,
+ xdata);
+ return 0;
- if (barrier_enabled && !stub) {
- gf_smsg (this->name, GF_LOG_ERROR, ENOMEM,
- CHANGELOG_MSG_NO_MEMORY,
- "Failed to barrier FOPs, disabling changelog barrier",
- "fop=create",
- NULL);
- chlog_barrier_dequeue_all (this, &queue);
- }
+out:
+ return -1;
+}
- wind:
- STACK_WIND (frame, changelog_create_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->create,
- loc, flags, mode, umask, fd, xdata);
+int32_t
+changelog_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
+{
+ int ret = -1;
+ uuid_t gfid = {
+ 0,
+ };
+ changelog_opt_t *co = NULL;
+ changelog_priv_t *priv = NULL;
+ size_t xtra_len = 0;
+ call_stub_t *stub = NULL;
+ struct list_head queue = {
+ 0,
+ };
+ gf_boolean_t barrier_enabled = _gf_false;
+
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+
+ ret = dict_get_gfuuid(xdata, "gfid-req", &gfid);
+ if (ret) {
+ gf_msg_debug(this->name, 0, "failed to get gfid from dict");
+ goto wind;
+ }
+
+ /* init with two extra records */
+ CHANGELOG_INIT_NOCHECK(this, frame->local, NULL, gfid, 5);
+ if (!frame->local)
+ goto wind;
+
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
+
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32(co, mode, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32(co, frame->root->uid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_UINT32(co, frame->root->gid, number_fn, xtra_len);
+ co++;
+
+ CHANGELOG_FILL_ENTRY(co, loc->pargfid, loc->name, entry_fn, entry_free_fn,
+ xtra_len, wind);
+
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 5);
+
+ LOCK(&priv->lock);
+ {
+ if ((barrier_enabled = priv->barrier_enabled)) {
+ stub = fop_create_stub(frame, changelog_create_resume, loc, flags,
+ mode, umask, fd, xdata);
+ if (!stub)
+ __chlog_barrier_disable(this, &queue);
+ else
+ __chlog_barrier_enqueue(this, stub);
+ } else {
+ ((changelog_local_t *)frame->local)->color = priv->current_color;
+ changelog_inc_fop_cnt(this, priv, frame->local);
+ }
+ }
+ UNLOCK(&priv->lock);
+
+ if (barrier_enabled && stub) {
+ gf_msg_debug(this->name, 0, "Enqueued create");
+ goto out;
+ }
+
+ if (barrier_enabled && !stub) {
+ gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY,
+ "Failed to barrier FOPs, disabling changelog barrier",
+ "fop=create", NULL);
+ chlog_barrier_dequeue_all(this, &queue);
+ }
+
+wind:
+ STACK_WIND(frame, changelog_create_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->create, loc, flags, mode, umask, fd,
+ xdata);
out:
- return 0;
+ return 0;
}
/* }}} */
-
/* Metadata modification fops - TYPE II */
/* {{{ */
@@ -1158,268 +1106,253 @@ out:
/* {f}setattr */
int32_t
-changelog_fsetattr_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, struct iatt *preop_stbuf,
- struct iatt *postop_stbuf, dict_t *xdata)
+changelog_fsetattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ struct iatt *preop_stbuf, struct iatt *postop_stbuf,
+ dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
-
- priv = this->private;
- local = frame->local;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ priv = this->private;
+ local = frame->local;
- changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (fsetattr, frame, op_ret, op_errno,
- preop_stbuf, postop_stbuf, xdata);
-
- return 0;
+ changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA);
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(fsetattr, frame, op_ret, op_errno, preop_stbuf,
+ postop_stbuf, xdata);
+ return 0;
}
int32_t
-changelog_fsetattr (call_frame_t *frame,
- xlator_t *this, fd_t *fd,
- struct iatt *stbuf, int32_t valid, dict_t *xdata)
+changelog_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- size_t xtra_len = 0;
-
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
- CHANGELOG_OP_BOUNDARY_CHECK (frame, wind);
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- CHANGELOG_INIT (this, frame->local,
- fd->inode, fd->inode->gfid, 1);
- if (!frame->local)
- goto wind;
+ CHANGELOG_OP_BOUNDARY_CHECK(frame, wind);
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
-
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 1);
+ if (!frame->local)
+ goto wind;
- changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_fsetattr_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->fsetattr,
- fd, stbuf, valid, xdata);
- return 0;
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 1);
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_fsetattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetattr, fd, stbuf, valid, xdata);
+ return 0;
}
int32_t
-changelog_setattr_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, struct iatt *preop_stbuf,
- struct iatt *postop_stbuf, dict_t *xdata)
+changelog_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ struct iatt *preop_stbuf, struct iatt *postop_stbuf,
+ dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (setattr, frame, op_ret, op_errno,
- preop_stbuf, postop_stbuf, xdata);
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(setattr, frame, op_ret, op_errno, preop_stbuf,
+ postop_stbuf, xdata);
- return 0;
+ return 0;
}
int32_t
-changelog_setattr (call_frame_t *frame,
- xlator_t *this, loc_t *loc,
- struct iatt *stbuf, int32_t valid, dict_t *xdata)
+changelog_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- size_t xtra_len = 0;
- uuid_t shard_root_gfid = {0,};
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
+ uuid_t shard_root_gfid = {
+ 0,
+ };
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, wind);
+ CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, wind);
- /* Do not record META on .shard */
- gf_uuid_parse (SHARD_ROOT_GFID, shard_root_gfid);
- if (gf_uuid_compare (loc->gfid, shard_root_gfid) == 0) {
- goto wind;
- }
+ /* Do not record META on .shard */
+ gf_uuid_parse(SHARD_ROOT_GFID, shard_root_gfid);
+ if (gf_uuid_compare(loc->gfid, shard_root_gfid) == 0) {
+ goto wind;
+ }
- CHANGELOG_OP_BOUNDARY_CHECK (frame, wind);
+ CHANGELOG_OP_BOUNDARY_CHECK(frame, wind);
- CHANGELOG_INIT (this, frame->local,
- loc->inode, loc->inode->gfid, 1);
- if (!frame->local)
- goto wind;
+ CHANGELOG_INIT(this, frame->local, loc->inode, loc->inode->gfid, 1);
+ if (!frame->local)
+ goto wind;
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
- changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 1);
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_setattr_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->setattr,
- loc, stbuf, valid, xdata);
- return 0;
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_setattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid, xdata);
+ return 0;
}
/* {f}removexattr */
int32_t
-changelog_fremovexattr_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+changelog_fremovexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA_XATTR);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA_XATTR);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (fremovexattr, frame, op_ret, op_errno, xdata);
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(fremovexattr, frame, op_ret, op_errno, xdata);
- return 0;
+ return 0;
}
int32_t
-changelog_fremovexattr (call_frame_t *frame, xlator_t *this,
- fd_t *fd, const char *name, dict_t *xdata)
+changelog_fremovexattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ const char *name, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- CHANGELOG_OP_BOUNDARY_CHECK (frame, wind);
+ CHANGELOG_OP_BOUNDARY_CHECK(frame, wind);
- CHANGELOG_INIT (this, frame->local,
- fd->inode, fd->inode->gfid, 1);
+ CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 1);
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
- changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 1);
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_fremovexattr_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->fremovexattr,
- fd, name, xdata);
- return 0;
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_fremovexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fremovexattr, fd, name, xdata);
+ return 0;
}
int32_t
-changelog_removexattr_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+changelog_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA_XATTR);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA_XATTR);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (removexattr, frame, op_ret, op_errno, xdata);
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(removexattr, frame, op_ret, op_errno, xdata);
- return 0;
+ return 0;
}
int32_t
-changelog_removexattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc, const char *name, dict_t *xdata)
+changelog_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- CHANGELOG_OP_BOUNDARY_CHECK (frame, wind);
+ CHANGELOG_OP_BOUNDARY_CHECK(frame, wind);
- CHANGELOG_INIT (this, frame->local,
- loc->inode, loc->inode->gfid, 1);
+ CHANGELOG_INIT(this, frame->local, loc->inode, loc->inode->gfid, 1);
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
- changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 1);
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_removexattr_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->removexattr,
- loc, name, xdata);
- return 0;
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_removexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr, loc, name, xdata);
+ return 0;
}
/* {f}setxattr */
int32_t
-changelog_setxattr_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+changelog_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA_XATTR);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA_XATTR);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (setxattr, frame, op_ret, op_errno, xdata);
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(setxattr, frame, op_ret, op_errno, xdata);
- return 0;
+ return 0;
}
/* changelog_handle_virtual_xattr:
@@ -1432,276 +1365,258 @@ changelog_setxattr_cbk (call_frame_t *frame,
* any other value: ENOTSUP is returned.
*/
static void
-changelog_handle_virtual_xattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc, dict_t *dict)
+changelog_handle_virtual_xattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ dict_t *dict)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
- int32_t value = 0;
- int ret = 0;
- int dict_ret = 0;
- gf_boolean_t valid = _gf_false;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
+ int32_t value = 0;
+ int ret = 0;
+ int dict_ret = 0;
+ gf_boolean_t valid = _gf_false;
- priv = this->private;
- GF_ASSERT (priv);
+ priv = this->private;
+ GF_ASSERT(priv);
- dict_ret = dict_get_int32 (dict, GF_XATTR_TRIGGER_SYNC, &value);
+ dict_ret = dict_get_int32(dict, GF_XATTR_TRIGGER_SYNC, &value);
- if ((dict_ret == 0 && value == 1) && ((loc->inode->ia_type == IA_IFDIR)
- || (loc->inode->ia_type == IA_IFREG)))
- valid = _gf_true;
+ if ((dict_ret == 0 && value == 1) && ((loc->inode->ia_type == IA_IFDIR) ||
+ (loc->inode->ia_type == IA_IFREG)))
+ valid = _gf_true;
- if (valid) {
- ret = changelog_fill_entry_buf (frame, this, loc, &local);
- if (ret) {
- gf_smsg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_ENTRY_BUF_INFO,
- "Entry cannot be"
- " captured for gfid, Capturing DATA"
- " entry.",
- "gfid=%s", uuid_utoa (loc->inode->gfid),
- NULL);
- goto unwind;
- }
- changelog_update (this, priv, local, CHANGELOG_TYPE_ENTRY);
-
- unwind:
- /* Capture DATA only if it's a file. */
- if (loc->inode->ia_type != IA_IFDIR)
- changelog_update (this, priv, frame->local,
- CHANGELOG_TYPE_DATA);
- /* Assign local to prev_entry, so unwind will take
- * care of cleanup. */
- ((changelog_local_t *)(frame->local))->prev_entry = local;
- CHANGELOG_STACK_UNWIND (setxattr, frame, 0, 0, NULL);
- return;
- } else {
- CHANGELOG_STACK_UNWIND (setxattr, frame, -1, ENOTSUP, NULL);
- return;
- }
+ if (valid) {
+ ret = changelog_fill_entry_buf(frame, this, loc, &local);
+ if (ret) {
+ gf_smsg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_ENTRY_BUF_INFO,
+ "Entry cannot be"
+ " captured for gfid, Capturing DATA"
+ " entry.",
+ "gfid=%s", uuid_utoa(loc->inode->gfid), NULL);
+ goto unwind;
+ }
+ changelog_update(this, priv, local, CHANGELOG_TYPE_ENTRY);
+
+ unwind:
+ /* Capture DATA only if it's a file. */
+ if (loc->inode->ia_type != IA_IFDIR)
+ changelog_update(this, priv, frame->local, CHANGELOG_TYPE_DATA);
+ /* Assign local to prev_entry, so unwind will take
+ * care of cleanup. */
+ ((changelog_local_t *)(frame->local))->prev_entry = local;
+ CHANGELOG_STACK_UNWIND(setxattr, frame, 0, 0, NULL);
+ return;
+ } else {
+ CHANGELOG_STACK_UNWIND(setxattr, frame, -1, ENOTSUP, NULL);
+ return;
+ }
}
int32_t
-changelog_setxattr (call_frame_t *frame,
- xlator_t *this, loc_t *loc,
- dict_t *dict, int32_t flags, dict_t *xdata)
+changelog_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ dict_t *dict, int32_t flags, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- CHANGELOG_OP_BOUNDARY_CHECK (frame, wind);
+ CHANGELOG_OP_BOUNDARY_CHECK(frame, wind);
- CHANGELOG_INIT (this, frame->local,
- loc->inode, loc->inode->gfid, 1);
+ CHANGELOG_INIT(this, frame->local, loc->inode, loc->inode->gfid, 1);
- /* On setting this virtual xattr on a file, an explicit data
- * sync is triggered from geo-rep as CREATE|DATA entry is
- * recorded in changelog based on xattr value.
- */
- if (dict_get (dict, GF_XATTR_TRIGGER_SYNC)) {
- changelog_handle_virtual_xattr (frame, this, loc, dict);
- return 0;
- }
+ /* On setting this virtual xattr on a file, an explicit data
+ * sync is triggered from geo-rep as CREATE|DATA entry is
+ * recorded in changelog based on xattr value.
+ */
+ if (dict_get(dict, GF_XATTR_TRIGGER_SYNC)) {
+ changelog_handle_virtual_xattr(frame, this, loc, dict);
+ return 0;
+ }
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
- changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 1);
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_setxattr_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->setxattr,
- loc, dict, flags, xdata);
- return 0;
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_setxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, loc, dict, flags, xdata);
+ return 0;
}
int32_t
-changelog_fsetxattr_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, dict_t *xdata)
+changelog_fsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA_XATTR);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA_XATTR);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (fsetxattr, frame, op_ret, op_errno, xdata);
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(fsetxattr, frame, op_ret, op_errno, xdata);
- return 0;
+ return 0;
}
int32_t
-changelog_fsetxattr (call_frame_t *frame,
- xlator_t *this, fd_t *fd, dict_t *dict,
- int32_t flags, dict_t *xdata)
+changelog_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
+ int32_t flags, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- size_t xtra_len = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, wind);
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+ CHANGELOG_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, wind);
- CHANGELOG_OP_BOUNDARY_CHECK (frame, wind);
+ CHANGELOG_OP_BOUNDARY_CHECK(frame, wind);
- CHANGELOG_INIT (this, frame->local,
- fd->inode, fd->inode->gfid, 1);
+ CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 1);
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
- changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 1);
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_fsetxattr_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->fsetxattr,
- fd, dict, flags, xdata);
- return 0;
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_fsetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata);
+ return 0;
}
int32_t
-changelog_xattrop_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, dict_t *xattr, dict_t *xdata)
+changelog_xattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xattr,
+ dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (xattrop, frame, op_ret, op_errno, xattr, xdata);
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(xattrop, frame, op_ret, op_errno, xattr, xdata);
- return 0;
+ return 0;
}
int32_t
-changelog_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc,
- gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata)
+changelog_xattrop(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- size_t xtra_len = 0;
- int ret = 0;
- void *size_attr = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
+ int ret = 0;
+ void *size_attr = NULL;
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- ret = dict_get_ptr (xattr, GF_XATTR_SHARD_FILE_SIZE, &size_attr);
- if (ret)
- goto wind;
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+ ret = dict_get_ptr(xattr, GF_XATTR_SHARD_FILE_SIZE, &size_attr);
+ if (ret)
+ goto wind;
- CHANGELOG_OP_BOUNDARY_CHECK (frame, wind);
+ CHANGELOG_OP_BOUNDARY_CHECK(frame, wind);
- CHANGELOG_INIT (this, frame->local,
- loc->inode, loc->inode->gfid, 1);
+ CHANGELOG_INIT(this, frame->local, loc->inode, loc->inode->gfid, 1);
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
- changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 1);
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_xattrop_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->xattrop,
- loc, optype, xattr, xdata);
- return 0;
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_xattrop_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->xattrop, loc, optype, xattr, xdata);
+ return 0;
}
int32_t
-changelog_fxattrop_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, dict_t *xattr, dict_t *xdata)
+changelog_fxattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xattr,
+ dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_METADATA_XATTR);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_METADATA_XATTR);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (fxattrop, frame,
- op_ret, op_errno, xattr, xdata);
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(fxattrop, frame, op_ret, op_errno, xattr, xdata);
- return 0;
+ return 0;
}
int32_t
-changelog_fxattrop (call_frame_t *frame,
- xlator_t *this, fd_t *fd, gf_xattrop_flags_t optype,
- dict_t *xattr, dict_t *xdata)
-{
- changelog_priv_t *priv = NULL;
- changelog_opt_t *co = NULL;
- size_t xtra_len = 0;
- void *size_attr = NULL;
- int ret = 0;
-
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
- ret = dict_get_ptr (xattr, GF_XATTR_SHARD_FILE_SIZE, &size_attr);
- if (ret)
- goto wind;
+changelog_fxattrop(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata)
+{
+ changelog_priv_t *priv = NULL;
+ changelog_opt_t *co = NULL;
+ size_t xtra_len = 0;
+ void *size_attr = NULL;
+ int ret = 0;
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
+ ret = dict_get_ptr(xattr, GF_XATTR_SHARD_FILE_SIZE, &size_attr);
+ if (ret)
+ goto wind;
- CHANGELOG_OP_BOUNDARY_CHECK (frame, wind);
+ CHANGELOG_OP_BOUNDARY_CHECK(frame, wind);
- CHANGELOG_INIT (this, frame->local,
- fd->inode, fd->inode->gfid, 1);
+ CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 1);
- co = changelog_get_usable_buffer (frame->local);
- if (!co)
- goto wind;
+ co = changelog_get_usable_buffer(frame->local);
+ if (!co)
+ goto wind;
- CHANGLOG_FILL_FOP_NUMBER (co, frame->root->op, fop_fn, xtra_len);
+ CHANGLOG_FILL_FOP_NUMBER(co, frame->root->op, fop_fn, xtra_len);
- changelog_set_usable_record_and_length (frame->local, xtra_len, 1);
+ changelog_set_usable_record_and_length(frame->local, xtra_len, 1);
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_fxattrop_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->fxattrop,
- fd, optype, xattr, xdata);
- return 0;
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_fxattrop_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fxattrop, fd, optype, xattr, xdata);
+ return 0;
}
/* }}} */
-
/* Data modification fops - TYPE I */
/* {{{ */
@@ -1709,164 +1624,151 @@ changelog_fxattrop (call_frame_t *frame,
/* {f}truncate() */
int32_t
-changelog_truncate_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+changelog_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_DATA);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_DATA);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (truncate, frame,
- op_ret, op_errno, prebuf, postbuf, xdata);
- return 0;
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(truncate, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ return 0;
}
int32_t
-changelog_truncate (call_frame_t *frame,
- xlator_t *this, loc_t *loc, off_t offset, dict_t *xdata)
+changelog_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ off_t offset, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- CHANGELOG_INIT (this, frame->local,
- loc->inode, loc->inode->gfid, 0);
- LOCK(&priv->c_snap_lock);
- {
- if (priv->c_snap_fd != -1 &&
- priv->barrier_enabled == _gf_true) {
- changelog_snap_handle_ascii_change (this,
- &( ((changelog_local_t *)(frame->local))->cld));
- }
+ CHANGELOG_INIT(this, frame->local, loc->inode, loc->inode->gfid, 0);
+ LOCK(&priv->c_snap_lock);
+ {
+ if (priv->c_snap_fd != -1 && priv->barrier_enabled == _gf_true) {
+ changelog_snap_handle_ascii_change(
+ this, &(((changelog_local_t *)(frame->local))->cld));
}
- UNLOCK(&priv->c_snap_lock);
-
+ }
+ UNLOCK(&priv->c_snap_lock);
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_truncate_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->truncate,
- loc, offset, xdata);
- return 0;
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_truncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
+ return 0;
}
int32_t
-changelog_ftruncate_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+changelog_ftruncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_DATA);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_DATA);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (ftruncate, frame,
- op_ret, op_errno, prebuf, postbuf, xdata);
- return 0;
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(ftruncate, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ return 0;
}
int32_t
-changelog_ftruncate (call_frame_t *frame,
- xlator_t *this, fd_t *fd, off_t offset, dict_t *xdata)
+changelog_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- CHANGELOG_INIT (this, frame->local,
- fd->inode, fd->inode->gfid, 0);
- LOCK(&priv->c_snap_lock);
- {
- if (priv->c_snap_fd != -1 &&
- priv->barrier_enabled == _gf_true) {
- changelog_snap_handle_ascii_change (this,
- &( ((changelog_local_t *)(frame->local))->cld));
- }
+ CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 0);
+ LOCK(&priv->c_snap_lock);
+ {
+ if (priv->c_snap_fd != -1 && priv->barrier_enabled == _gf_true) {
+ changelog_snap_handle_ascii_change(
+ this, &(((changelog_local_t *)(frame->local))->cld));
}
- UNLOCK(&priv->c_snap_lock);
+ }
+ UNLOCK(&priv->c_snap_lock);
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_ftruncate_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->ftruncate,
- fd, offset, xdata);
- return 0;
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_ftruncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
+ return 0;
}
/* writev() */
int32_t
-changelog_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf,
- dict_t *xdata)
+changelog_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
- changelog_local_t *local = NULL;
+ changelog_priv_t *priv = NULL;
+ changelog_local_t *local = NULL;
- priv = this->private;
- local = frame->local;
+ priv = this->private;
+ local = frame->local;
- CHANGELOG_COND_GOTO (priv, ((op_ret <= 0) || !local), unwind);
+ CHANGELOG_COND_GOTO(priv, ((op_ret <= 0) || !local), unwind);
- changelog_update (this, priv, local, CHANGELOG_TYPE_DATA);
+ changelog_update(this, priv, local, CHANGELOG_TYPE_DATA);
- unwind:
- changelog_dec_fop_cnt (this, priv, local);
- CHANGELOG_STACK_UNWIND (writev, frame,
- op_ret, op_errno, prebuf, postbuf, xdata);
- return 0;
+unwind:
+ changelog_dec_fop_cnt(this, priv, local);
+ CHANGELOG_STACK_UNWIND(writev, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ return 0;
}
int32_t
-changelog_writev (call_frame_t *frame,
- xlator_t *this, fd_t *fd, struct iovec *vector,
- int32_t count, off_t offset, uint32_t flags,
- struct iobref *iobref, dict_t *xdata)
+changelog_writev(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *vector, int32_t count, off_t offset,
+ uint32_t flags, struct iobref *iobref, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- CHANGELOG_INIT (this, frame->local,
- fd->inode, fd->inode->gfid, 0);
- LOCK(&priv->c_snap_lock);
- {
- if (priv->c_snap_fd != -1 &&
- priv->barrier_enabled == _gf_true) {
- changelog_snap_handle_ascii_change (this,
- &( ((changelog_local_t *)(frame->local))->cld));
- }
+ CHANGELOG_INIT(this, frame->local, fd->inode, fd->inode->gfid, 0);
+ LOCK(&priv->c_snap_lock);
+ {
+ if (priv->c_snap_fd != -1 && priv->barrier_enabled == _gf_true) {
+ changelog_snap_handle_ascii_change(
+ this, &(((changelog_local_t *)(frame->local))->cld));
}
- UNLOCK(&priv->c_snap_lock);
+ }
+ UNLOCK(&priv->c_snap_lock);
- wind:
- changelog_color_fop_and_inc_cnt (this, priv, frame->local);
- STACK_WIND (frame, changelog_writev_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->writev, fd, vector,
- count, offset, flags, iobref, xdata);
- return 0;
+wind:
+ changelog_color_fop_and_inc_cnt(this, priv, frame->local);
+ STACK_WIND(frame, changelog_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, vector, count, offset,
+ flags, iobref, xdata);
+ return 0;
}
/* }}} */
@@ -1875,81 +1777,79 @@ changelog_writev (call_frame_t *frame,
/* {{{ */
-
-
int
-changelog_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, fd_t *fd, dict_t *xdata)
-{
- int ret = 0;
- changelog_priv_t *priv = NULL;
- changelog_event_t ev = {0,};
- gf_boolean_t logopen = _gf_false;
-
- priv = this->private;
- if (frame->local) {
- frame->local = NULL;
- logopen = _gf_true;
- }
-
- CHANGELOG_COND_GOTO (priv, ((op_ret < 0) || !logopen), unwind);
-
- /* fill the event structure */
- ev.ev_type = CHANGELOG_OP_TYPE_OPEN;
- gf_uuid_copy (ev.u.open.gfid, fd->inode->gfid);
- ev.u.open.flags = fd->flags;
- changelog_dispatch_event (this, priv, &ev);
-
- if (changelog_ev_selected
- (this, &priv->ev_selection, CHANGELOG_OP_TYPE_RELEASE)) {
- ret = fd_ctx_set (fd, this, (uint64_t)(long) 0x1);
- if (ret)
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CHANGELOG_MSG_SET_FD_CONTEXT,
- "could not set fd context (for release cbk)");
- }
+changelog_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, fd_t *fd, dict_t *xdata)
+{
+ int ret = 0;
+ changelog_priv_t *priv = NULL;
+ changelog_event_t ev = {
+ 0,
+ };
+ gf_boolean_t logopen = _gf_false;
+
+ priv = this->private;
+ if (frame->local) {
+ frame->local = NULL;
+ logopen = _gf_true;
+ }
+
+ CHANGELOG_COND_GOTO(priv, ((op_ret < 0) || !logopen), unwind);
+
+ /* fill the event structure */
+ ev.ev_type = CHANGELOG_OP_TYPE_OPEN;
+ gf_uuid_copy(ev.u.open.gfid, fd->inode->gfid);
+ ev.u.open.flags = fd->flags;
+ changelog_dispatch_event(this, priv, &ev);
+
+ if (changelog_ev_selected(this, &priv->ev_selection,
+ CHANGELOG_OP_TYPE_RELEASE)) {
+ ret = fd_ctx_set(fd, this, (uint64_t)(long)0x1);
+ if (ret)
+ gf_msg(this->name, GF_LOG_WARNING, 0, CHANGELOG_MSG_SET_FD_CONTEXT,
+ "could not set fd context (for release cbk)");
+ }
- unwind:
- CHANGELOG_STACK_UNWIND (open, frame, op_ret, op_errno, fd, xdata);
- return 0;
+unwind:
+ CHANGELOG_STACK_UNWIND(open, frame, op_ret, op_errno, fd, xdata);
+ return 0;
}
int
-changelog_open (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int flags, fd_t *fd, dict_t *xdata)
+changelog_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
+ fd_t *fd, dict_t *xdata)
{
- changelog_priv_t *priv = NULL;
+ changelog_priv_t *priv = NULL;
- priv = this->private;
- CHANGELOG_NOT_ACTIVE_THEN_GOTO (frame, priv, wind);
+ priv = this->private;
+ CHANGELOG_NOT_ACTIVE_THEN_GOTO(frame, priv, wind);
- frame->local = (void *)0x1; /* do not dereference in ->cbk */
+ frame->local = (void *)0x1; /* do not dereference in ->cbk */
- wind:
- STACK_WIND (frame, changelog_open_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->open, loc, flags, fd, xdata);
- return 0;
+wind:
+ STACK_WIND(frame, changelog_open_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata);
+ return 0;
}
/* }}} */
/* {{{ */
-
/* }}} */
int32_t
-_changelog_generic_dispatcher (dict_t *dict,
- char *key, data_t *value, void *data)
+_changelog_generic_dispatcher(dict_t *dict, char *key, data_t *value,
+ void *data)
{
- xlator_t *this = NULL;
- changelog_priv_t *priv = NULL;
+ xlator_t *this = NULL;
+ changelog_priv_t *priv = NULL;
- this = data;
- priv = this->private;
+ this = data;
+ priv = this->private;
- changelog_dispatch_event (this, priv, (changelog_event_t *)value->data);
- return 0;
+ changelog_dispatch_event(this, priv, (changelog_event_t *)value->data);
+ return 0;
}
/**
@@ -1958,46 +1858,45 @@ _changelog_generic_dispatcher (dict_t *dict,
* traverses the dictionary).
*/
int32_t
-changelog_ipc (call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata)
+changelog_ipc(call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata)
{
- if (op != GF_IPC_TARGET_CHANGELOG)
- goto wind;
+ if (op != GF_IPC_TARGET_CHANGELOG)
+ goto wind;
- /* it's for us, do the job */
- if (xdata)
- (void) dict_foreach (xdata,
- _changelog_generic_dispatcher, this);
+ /* it's for us, do the job */
+ if (xdata)
+ (void)dict_foreach(xdata, _changelog_generic_dispatcher, this);
- STACK_UNWIND_STRICT (ipc, frame, 0, 0, NULL);
- return 0;
+ STACK_UNWIND_STRICT(ipc, frame, 0, 0, NULL);
+ return 0;
- wind:
- STACK_WIND (frame, default_ipc_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->ipc, op, xdata);
- return 0;
+wind:
+ STACK_WIND(frame, default_ipc_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ipc, op, xdata);
+ return 0;
}
-
/* {{{ */
int32_t
-changelog_release (xlator_t *this, fd_t *fd)
+changelog_release(xlator_t *this, fd_t *fd)
{
- changelog_event_t ev = {0,};
- changelog_priv_t *priv = NULL;
+ changelog_event_t ev = {
+ 0,
+ };
+ changelog_priv_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- ev.ev_type = CHANGELOG_OP_TYPE_RELEASE;
- gf_uuid_copy (ev.u.release.gfid, fd->inode->gfid);
- changelog_dispatch_event (this, priv, &ev);
+ ev.ev_type = CHANGELOG_OP_TYPE_RELEASE;
+ gf_uuid_copy(ev.u.release.gfid, fd->inode->gfid);
+ changelog_dispatch_event(this, priv, &ev);
- (void) fd_ctx_del (fd, this, NULL);
+ (void)fd_ctx_del(fd, this, NULL);
- return 0;
+ return 0;
}
-
/* }}} */
/**
@@ -2012,1040 +1911,1002 @@ changelog_release (xlator_t *this, fd_t *fd)
* needed if there are more operation modes in the future.
*/
static void
-changelog_assign_opmode (changelog_priv_t *priv, char *mode)
+changelog_assign_opmode(changelog_priv_t *priv, char *mode)
{
- if ( strncmp (mode, "realtime", 8) == 0 ) {
- priv->op_mode = CHANGELOG_MODE_RT;
- }
+ if (strncmp(mode, "realtime", 8) == 0) {
+ priv->op_mode = CHANGELOG_MODE_RT;
+ }
}
static void
-changelog_assign_encoding (changelog_priv_t *priv, char *enc)
+changelog_assign_encoding(changelog_priv_t *priv, char *enc)
{
- if ( strncmp (enc, "binary", 6) == 0 ) {
- priv->encode_mode = CHANGELOG_ENCODE_BINARY;
- } else if ( strncmp (enc, "ascii", 5) == 0 ) {
- priv->encode_mode = CHANGELOG_ENCODE_ASCII;
- }
+ if (strncmp(enc, "binary", 6) == 0) {
+ priv->encode_mode = CHANGELOG_ENCODE_BINARY;
+ } else if (strncmp(enc, "ascii", 5) == 0) {
+ priv->encode_mode = CHANGELOG_ENCODE_ASCII;
+ }
}
static void
changelog_assign_barrier_timeout(changelog_priv_t *priv, uint32_t timeout)
{
- LOCK (&priv->lock);
- {
- priv->timeout.tv_sec = timeout;
- }
- UNLOCK (&priv->lock);
+ LOCK(&priv->lock);
+ {
+ priv->timeout.tv_sec = timeout;
+ }
+ UNLOCK(&priv->lock);
}
/* cleanup any helper threads that are running */
static void
-changelog_cleanup_helper_threads (xlator_t *this, changelog_priv_t *priv)
+changelog_cleanup_helper_threads(xlator_t *this, changelog_priv_t *priv)
{
- if (priv->cr.rollover_th) {
- (void) changelog_thread_cleanup (this, priv->cr.rollover_th);
- priv->cr.rollover_th = 0;
- }
+ if (priv->cr.rollover_th) {
+ (void)changelog_thread_cleanup(this, priv->cr.rollover_th);
+ priv->cr.rollover_th = 0;
+ }
- if (priv->cf.fsync_th) {
- (void) changelog_thread_cleanup (this, priv->cf.fsync_th);
- priv->cf.fsync_th = 0;
- }
+ if (priv->cf.fsync_th) {
+ (void)changelog_thread_cleanup(this, priv->cf.fsync_th);
+ priv->cf.fsync_th = 0;
+ }
}
/* spawn helper thread; cleaning up in case of errors */
static int
-changelog_spawn_helper_threads (xlator_t *this, changelog_priv_t *priv)
-{
- int ret = 0;
-
- /* Geo-Rep snapshot dependency:
- *
- * To implement explicit rollover of changlog journal on barrier
- * notification, a pipe is created to communicate between
- * 'changelog_rollover' thread and changelog main thread. The select
- * call used to wait till roll-over time in changelog_rollover thread
- * is modified to wait on read end of the pipe. When barrier
- * notification comes (i.e, in 'reconfigure'), select in
- * changelog_rollover thread is woken up explicitly by writing into
- * the write end of the pipe in 'reconfigure'.
- */
-
- priv->cr.notify = _gf_false;
- priv->cr.this = this;
- ret = gf_thread_create (&priv->cr.rollover_th,
- NULL, changelog_rollover, priv, "clogro");
- if (ret)
- goto out;
-
- if (priv->fsync_interval) {
- priv->cf.this = this;
- ret = gf_thread_create (&priv->cf.fsync_th,
- NULL, changelog_fsync_thread, priv,
- "clogfsyn");
- }
+changelog_spawn_helper_threads(xlator_t *this, changelog_priv_t *priv)
+{
+ int ret = 0;
+
+ /* Geo-Rep snapshot dependency:
+ *
+ * To implement explicit rollover of changlog journal on barrier
+ * notification, a pipe is created to communicate between
+ * 'changelog_rollover' thread and changelog main thread. The select
+ * call used to wait till roll-over time in changelog_rollover thread
+ * is modified to wait on read end of the pipe. When barrier
+ * notification comes (i.e, in 'reconfigure'), select in
+ * changelog_rollover thread is woken up explicitly by writing into
+ * the write end of the pipe in 'reconfigure'.
+ */
+
+ priv->cr.notify = _gf_false;
+ priv->cr.this = this;
+ ret = gf_thread_create(&priv->cr.rollover_th, NULL, changelog_rollover,
+ priv, "clogro");
+ if (ret)
+ goto out;
+
+ if (priv->fsync_interval) {
+ priv->cf.this = this;
+ ret = gf_thread_create(&priv->cf.fsync_th, NULL, changelog_fsync_thread,
+ priv, "clogfsyn");
+ }
+
+ if (ret)
+ changelog_cleanup_helper_threads(this, priv);
- if (ret)
- changelog_cleanup_helper_threads (this, priv);
-
- out:
- return ret;
+out:
+ return ret;
}
int
-notify (xlator_t *this, int event, void *data, ...)
-{
- changelog_priv_t *priv = NULL;
- dict_t *dict = NULL;
- char buf[1] = {1};
- int barrier = DICT_DEFAULT;
- gf_boolean_t bclean_req = _gf_false;
- int ret = 0;
- int ret1 = 0;
- struct list_head queue = {0, };
-
- INIT_LIST_HEAD (&queue);
-
- priv = this->private;
- if (!priv)
+notify(xlator_t *this, int event, void *data, ...)
+{
+ changelog_priv_t *priv = NULL;
+ dict_t *dict = NULL;
+ char buf[1] = {1};
+ int barrier = DICT_DEFAULT;
+ gf_boolean_t bclean_req = _gf_false;
+ int ret = 0;
+ int ret1 = 0;
+ struct list_head queue = {
+ 0,
+ };
+
+ INIT_LIST_HEAD(&queue);
+
+ priv = this->private;
+ if (!priv)
+ goto out;
+
+ if (event == GF_EVENT_TRANSLATOR_OP) {
+ dict = data;
+
+ barrier = dict_get_str_boolean(dict, "barrier", DICT_DEFAULT);
+
+ switch (barrier) {
+ case DICT_ERROR:
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_DICT_GET_FAILED,
+ "Barrier dict_get_str_boolean failed");
+ ret = -1;
goto out;
- if (event == GF_EVENT_TRANSLATOR_OP) {
+ case BARRIER_OFF:
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO,
+ "Barrier off notification");
- dict = data;
-
- barrier = dict_get_str_boolean (dict, "barrier", DICT_DEFAULT);
+ CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, out);
+ LOCK(&priv->c_snap_lock);
+ {
+ changelog_snap_logging_stop(this, priv);
+ }
+ UNLOCK(&priv->c_snap_lock);
- switch (barrier) {
- case DICT_ERROR:
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_DICT_GET_FAILED,
- "Barrier dict_get_str_boolean failed");
- ret = -1;
- goto out;
-
- case BARRIER_OFF:
- gf_msg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_BARRIER_INFO,
- "Barrier off notification");
-
- CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, out);
- LOCK(&priv->c_snap_lock);
- {
- changelog_snap_logging_stop (this, priv);
- }
- UNLOCK(&priv->c_snap_lock);
-
- LOCK (&priv->bflags.lock);
- {
- if (priv->bflags.barrier_ext == _gf_false)
- ret = -1;
- }
- UNLOCK (&priv->bflags.lock);
-
- if (ret == -1 ) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_BARRIER_ERROR,
- "Received another barrier off"
- " notification while already off");
- goto out;
- }
-
- /* Stop changelog barrier and dequeue all fops */
- LOCK (&priv->lock);
- {
- if (priv->barrier_enabled == _gf_true)
- __chlog_barrier_disable (this, &queue);
- else
- ret = -1;
- }
- UNLOCK (&priv->lock);
- /* If ret = -1, then changelog barrier is already
- * disabled because of error or timeout.
- */
- if (ret == 0) {
- chlog_barrier_dequeue_all(this, &queue);
- gf_msg(this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_BARRIER_INFO,
- "Disabled changelog barrier");
- } else {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_BARRIER_ERROR,
- "Changelog barrier already disabled");
- }
-
- LOCK (&priv->bflags.lock);
- {
- priv->bflags.barrier_ext = _gf_false;
- }
- UNLOCK (&priv->bflags.lock);
-
- goto out;
-
- case BARRIER_ON:
- gf_msg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_BARRIER_INFO,
- "Barrier on notification");
-
- CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, out);
- LOCK(&priv->c_snap_lock);
- {
- changelog_snap_logging_start (this, priv);
- }
- UNLOCK(&priv->c_snap_lock);
-
- LOCK (&priv->bflags.lock);
- {
- if (priv->bflags.barrier_ext == _gf_true)
- ret = -1;
- else
- priv->bflags.barrier_ext = _gf_true;
- }
- UNLOCK (&priv->bflags.lock);
-
- if (ret == -1 ) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_BARRIER_ERROR,
- "Received another barrier on"
- "notification when last one is"
- "not served yet");
- goto out;
- }
-
- ret = pthread_mutex_lock (&priv->bn.bnotify_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret, out,
- bclean_req);
- {
- priv->bn.bnotify = _gf_true;
- }
- ret = pthread_mutex_unlock (&priv->bn.bnotify_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret, out,
- bclean_req);
-
- /* Start changelog barrier */
- LOCK (&priv->lock);
- {
- ret = __chlog_barrier_enable (this, priv);
- }
- UNLOCK (&priv->lock);
- if (ret == -1) {
- changelog_barrier_cleanup (this, priv, &queue);
- goto out;
- }
-
- gf_msg(this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_BARRIER_INFO,
- "Enabled changelog barrier");
-
- ret = changelog_barrier_notify(priv, buf);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_WRITE_FAILED,
- "Explicit roll over: write failed");
- changelog_barrier_cleanup (this, priv, &queue);
- ret = -1;
- goto out;
- }
-
- ret = pthread_mutex_lock (&priv->bn.bnotify_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret, out,
- bclean_req);
- {
- /* The while condition check is required here to
- * handle spurious wakeup of cond wait that can
- * happen with pthreads. See man page */
- while (priv->bn.bnotify == _gf_true) {
- ret = pthread_cond_wait (
- &priv->bn.bnotify_cond,
- &priv->bn.bnotify_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret,
- out,
- bclean_req);
- }
- if (priv->bn.bnotify_error == _gf_true) {
- ret = -1;
- priv->bn.bnotify_error = _gf_false;
- }
- }
- ret1 = pthread_mutex_unlock (&priv->bn.bnotify_mutex);
- CHANGELOG_PTHREAD_ERROR_HANDLE_1 (ret1, out,
- bclean_req);
- gf_msg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_BNOTIFY_INFO,
- "Woke up: bnotify conditional wait");
-
- goto out;
-
- case DICT_DEFAULT:
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_DICT_GET_FAILED,
- "barrier key not found");
+ LOCK(&priv->bflags.lock);
+ {
+ if (priv->bflags.barrier_ext == _gf_false)
ret = -1;
- goto out;
+ }
+ UNLOCK(&priv->bflags.lock);
+
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_BARRIER_ERROR,
+ "Received another barrier off"
+ " notification while already off");
+ goto out;
+ }
- default:
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- CHANGELOG_MSG_DICT_GET_FAILED,
- "Something went bad in dict_get_str_boolean");
+ /* Stop changelog barrier and dequeue all fops */
+ LOCK(&priv->lock);
+ {
+ if (priv->barrier_enabled == _gf_true)
+ __chlog_barrier_disable(this, &queue);
+ else
ret = -1;
- goto out;
}
- } else {
- ret = default_notify (this, event, data);
- }
+ UNLOCK(&priv->lock);
+ /* If ret = -1, then changelog barrier is already
+ * disabled because of error or timeout.
+ */
+ if (ret == 0) {
+ chlog_barrier_dequeue_all(this, &queue);
+ gf_msg(this->name, GF_LOG_INFO, 0,
+ CHANGELOG_MSG_BARRIER_INFO,
+ "Disabled changelog barrier");
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_BARRIER_ERROR,
+ "Changelog barrier already disabled");
+ }
- out:
- if (bclean_req)
- changelog_barrier_cleanup (this, priv, &queue);
+ LOCK(&priv->bflags.lock);
+ {
+ priv->bflags.barrier_ext = _gf_false;
+ }
+ UNLOCK(&priv->bflags.lock);
- return ret;
-}
+ goto out;
-int32_t
-mem_acct_init (xlator_t *this)
-{
- int ret = -1;
+ case BARRIER_ON:
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO,
+ "Barrier on notification");
- if (!this)
- return ret;
+ CHANGELOG_NOT_ON_THEN_GOTO(priv, ret, out);
+ LOCK(&priv->c_snap_lock);
+ {
+ changelog_snap_logging_start(this, priv);
+ }
+ UNLOCK(&priv->c_snap_lock);
- ret = xlator_mem_acct_init (this, gf_changelog_mt_end + 1);
+ LOCK(&priv->bflags.lock);
+ {
+ if (priv->bflags.barrier_ext == _gf_true)
+ ret = -1;
+ else
+ priv->bflags.barrier_ext = _gf_true;
+ }
+ UNLOCK(&priv->bflags.lock);
+
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_BARRIER_ERROR,
+ "Received another barrier on"
+ "notification when last one is"
+ "not served yet");
+ goto out;
+ }
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, ENOMEM,
- CHANGELOG_MSG_NO_MEMORY, "Memory accounting"
- " init failed");
- return ret;
- }
+ ret = pthread_mutex_lock(&priv->bn.bnotify_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret, out, bclean_req);
+ {
+ priv->bn.bnotify = _gf_true;
+ }
+ ret = pthread_mutex_unlock(&priv->bn.bnotify_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret, out, bclean_req);
- return ret;
-}
+ /* Start changelog barrier */
+ LOCK(&priv->lock);
+ {
+ ret = __chlog_barrier_enable(this, priv);
+ }
+ UNLOCK(&priv->lock);
+ if (ret == -1) {
+ changelog_barrier_cleanup(this, priv, &queue);
+ goto out;
+ }
-static int
-changelog_init (xlator_t *this, changelog_priv_t *priv)
-{
- int i = 0;
- int ret = -1;
- struct timeval tv = {0,};
- changelog_log_data_t cld = {0,};
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BARRIER_INFO,
+ "Enabled changelog barrier");
- ret = gettimeofday (&tv, NULL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_GET_TIME_OP_FAILED,
- "gettimeofday() failure");
- goto out;
- }
+ ret = changelog_barrier_notify(priv, buf);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_WRITE_FAILED,
+ "Explicit roll over: write failed");
+ changelog_barrier_cleanup(this, priv, &queue);
+ ret = -1;
+ goto out;
+ }
+
+ ret = pthread_mutex_lock(&priv->bn.bnotify_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret, out, bclean_req);
+ {
+ /* The while condition check is required here to
+ * handle spurious wakeup of cond wait that can
+ * happen with pthreads. See man page */
+ while (priv->bn.bnotify == _gf_true) {
+ ret = pthread_cond_wait(&priv->bn.bnotify_cond,
+ &priv->bn.bnotify_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret, out, bclean_req);
+ }
+ if (priv->bn.bnotify_error == _gf_true) {
+ ret = -1;
+ priv->bn.bnotify_error = _gf_false;
+ }
+ }
+ ret1 = pthread_mutex_unlock(&priv->bn.bnotify_mutex);
+ CHANGELOG_PTHREAD_ERROR_HANDLE_1(ret1, out, bclean_req);
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_BNOTIFY_INFO,
+ "Woke up: bnotify conditional wait");
- priv->slice.tv_start = tv;
+ goto out;
- priv->maps[CHANGELOG_TYPE_DATA] = "D ";
- priv->maps[CHANGELOG_TYPE_METADATA] = "M ";
- priv->maps[CHANGELOG_TYPE_METADATA_XATTR] = "M ";
- priv->maps[CHANGELOG_TYPE_ENTRY] = "E ";
+ case DICT_DEFAULT:
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_DICT_GET_FAILED, "barrier key not found");
+ ret = -1;
+ goto out;
- for (; i < CHANGELOG_MAX_TYPE; i++) {
- /* start with version 1 */
- priv->slice.changelog_version[i] = 1;
+ default:
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL,
+ CHANGELOG_MSG_DICT_GET_FAILED,
+ "Something went bad in dict_get_str_boolean");
+ ret = -1;
+ goto out;
}
+ } else {
+ ret = default_notify(this, event, data);
+ }
- if (!priv->active)
- return ret;
+out:
+ if (bclean_req)
+ changelog_barrier_cleanup(this, priv, &queue);
- /**
- * start with a fresh changelog file every time. this is done
- * in case there was an encoding change. so... things are kept
- * simple here.
- */
- ret = changelog_fill_rollover_data (&cld, _gf_false);
- if(ret)
- goto out;
+ return ret;
+}
- ret = htime_open (this, priv, cld.cld_roll_time);
- /* call htime open with cld's rollover_time */
- if (ret)
- goto out;
+int32_t
+mem_acct_init(xlator_t *this)
+{
+ int ret = -1;
- LOCK (&priv->lock);
- {
- ret = changelog_inject_single_event (this, priv, &cld);
- }
- UNLOCK (&priv->lock);
+ if (!this)
+ return ret;
- /* ... and finally spawn the helpers threads */
- ret = changelog_spawn_helper_threads (this, priv);
+ ret = xlator_mem_acct_init(this, gf_changelog_mt_end + 1);
- out:
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, ENOMEM, CHANGELOG_MSG_NO_MEMORY,
+ "Memory accounting"
+ " init failed");
return ret;
+ }
+
+ return ret;
+}
+
+static int
+changelog_init(xlator_t *this, changelog_priv_t *priv)
+{
+ int i = 0;
+ int ret = -1;
+ struct timeval tv = {
+ 0,
+ };
+ changelog_log_data_t cld = {
+ 0,
+ };
+
+ ret = gettimeofday(&tv, NULL);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_GET_TIME_OP_FAILED, "gettimeofday() failure");
+ goto out;
+ }
+
+ priv->slice.tv_start = tv;
+
+ priv->maps[CHANGELOG_TYPE_DATA] = "D ";
+ priv->maps[CHANGELOG_TYPE_METADATA] = "M ";
+ priv->maps[CHANGELOG_TYPE_METADATA_XATTR] = "M ";
+ priv->maps[CHANGELOG_TYPE_ENTRY] = "E ";
+
+ for (; i < CHANGELOG_MAX_TYPE; i++) {
+ /* start with version 1 */
+ priv->slice.changelog_version[i] = 1;
+ }
+
+ if (!priv->active)
+ return ret;
+
+ /**
+ * start with a fresh changelog file every time. this is done
+ * in case there was an encoding change. so... things are kept
+ * simple here.
+ */
+ ret = changelog_fill_rollover_data(&cld, _gf_false);
+ if (ret)
+ goto out;
+
+ ret = htime_open(this, priv, cld.cld_roll_time);
+ /* call htime open with cld's rollover_time */
+ if (ret)
+ goto out;
+
+ LOCK(&priv->lock);
+ {
+ ret = changelog_inject_single_event(this, priv, &cld);
+ }
+ UNLOCK(&priv->lock);
+
+ /* ... and finally spawn the helpers threads */
+ ret = changelog_spawn_helper_threads(this, priv);
+
+out:
+ return ret;
}
/**
* Init barrier related condition variables and locks
*/
static int
-changelog_barrier_pthread_init (xlator_t *this, changelog_priv_t *priv)
-{
- gf_boolean_t bn_mutex_init = _gf_false;
- gf_boolean_t bn_cond_init = _gf_false;
- gf_boolean_t dm_mutex_black_init = _gf_false;
- gf_boolean_t dm_cond_black_init = _gf_false;
- gf_boolean_t dm_mutex_white_init = _gf_false;
- gf_boolean_t dm_cond_white_init = _gf_false;
- gf_boolean_t cr_mutex_init = _gf_false;
- gf_boolean_t cr_cond_init = _gf_false;
- int ret = 0;
-
- if ((ret = pthread_mutex_init(&priv->bn.bnotify_mutex, NULL)) != 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED,
- "bnotify pthread_mutex_init failed",
- "ret=%d", ret,
- NULL);
- ret = -1;
- goto out;
- }
- bn_mutex_init = _gf_true;
-
- if ((ret = pthread_cond_init(&priv->bn.bnotify_cond, NULL)) != 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED,
- "bnotify pthread_cond_init failed",
- "ret=%d", ret,
- NULL);
- ret = -1;
- goto out;
- }
- bn_cond_init = _gf_true;
-
- if ((ret = pthread_mutex_init(&priv->dm.drain_black_mutex, NULL)) != 0)
- {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED,
- "drain_black pthread_mutex_init failed",
- "ret=%d", ret,
- NULL);
- ret = -1;
- goto out;
- }
- dm_mutex_black_init = _gf_true;
-
- if ((ret = pthread_cond_init(&priv->dm.drain_black_cond, NULL)) != 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED,
- "drain_black pthread_cond_init failed",
- "ret=%d", ret,
- NULL);
- ret = -1;
- goto out;
- }
- dm_cond_black_init = _gf_true;
-
- if ((ret = pthread_mutex_init(&priv->dm.drain_white_mutex, NULL)) != 0)
- {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED,
- "drain_white pthread_mutex_init failed",
- "ret=%d", ret,
- NULL);
- ret = -1;
- goto out;
- }
- dm_mutex_white_init = _gf_true;
-
- if ((ret = pthread_cond_init(&priv->dm.drain_white_cond, NULL)) != 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED,
- "drain_white pthread_cond_init failed",
- "ret=%d", ret,
- NULL);
- ret = -1;
- goto out;
- }
- dm_cond_white_init = _gf_true;
-
- if ((pthread_mutex_init(&priv->cr.lock, NULL)) != 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED,
- "changelog_rollover lock init failed",
- "ret=%d", ret,
- NULL);
- ret = -1;
- goto out;
- }
- cr_mutex_init = _gf_true;
-
- if ((pthread_cond_init(&priv->cr.cond, NULL)) != 0) {
- gf_smsg (this->name, GF_LOG_ERROR, errno,
- CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED,
- "changelog_rollover cond init failed",
- "ret=%d", ret,
- NULL);
- ret = -1;
- goto out;
- }
- cr_cond_init = _gf_true;
- out:
- if (ret) {
- if (bn_mutex_init)
- pthread_mutex_destroy(&priv->bn.bnotify_mutex);
- if (bn_cond_init)
- pthread_cond_destroy (&priv->bn.bnotify_cond);
- if (dm_mutex_black_init)
- pthread_mutex_destroy(&priv->dm.drain_black_mutex);
- if (dm_cond_black_init)
- pthread_cond_destroy (&priv->dm.drain_black_cond);
- if (dm_mutex_white_init)
- pthread_mutex_destroy(&priv->dm.drain_white_mutex);
- if (dm_cond_white_init)
- pthread_cond_destroy (&priv->dm.drain_white_cond);
- if (cr_mutex_init)
- pthread_mutex_destroy(&priv->cr.lock);
- if (cr_cond_init)
- pthread_cond_destroy (&priv->cr.cond);
- }
- return ret;
+changelog_barrier_pthread_init(xlator_t *this, changelog_priv_t *priv)
+{
+ gf_boolean_t bn_mutex_init = _gf_false;
+ gf_boolean_t bn_cond_init = _gf_false;
+ gf_boolean_t dm_mutex_black_init = _gf_false;
+ gf_boolean_t dm_cond_black_init = _gf_false;
+ gf_boolean_t dm_mutex_white_init = _gf_false;
+ gf_boolean_t dm_cond_white_init = _gf_false;
+ gf_boolean_t cr_mutex_init = _gf_false;
+ gf_boolean_t cr_cond_init = _gf_false;
+ int ret = 0;
+
+ if ((ret = pthread_mutex_init(&priv->bn.bnotify_mutex, NULL)) != 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED,
+ "bnotify pthread_mutex_init failed", "ret=%d", ret, NULL);
+ ret = -1;
+ goto out;
+ }
+ bn_mutex_init = _gf_true;
+
+ if ((ret = pthread_cond_init(&priv->bn.bnotify_cond, NULL)) != 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED,
+ "bnotify pthread_cond_init failed", "ret=%d", ret, NULL);
+ ret = -1;
+ goto out;
+ }
+ bn_cond_init = _gf_true;
+
+ if ((ret = pthread_mutex_init(&priv->dm.drain_black_mutex, NULL)) != 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED,
+ "drain_black pthread_mutex_init failed", "ret=%d", ret, NULL);
+ ret = -1;
+ goto out;
+ }
+ dm_mutex_black_init = _gf_true;
+
+ if ((ret = pthread_cond_init(&priv->dm.drain_black_cond, NULL)) != 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED,
+ "drain_black pthread_cond_init failed", "ret=%d", ret, NULL);
+ ret = -1;
+ goto out;
+ }
+ dm_cond_black_init = _gf_true;
+
+ if ((ret = pthread_mutex_init(&priv->dm.drain_white_mutex, NULL)) != 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED,
+ "drain_white pthread_mutex_init failed", "ret=%d", ret, NULL);
+ ret = -1;
+ goto out;
+ }
+ dm_mutex_white_init = _gf_true;
+
+ if ((ret = pthread_cond_init(&priv->dm.drain_white_cond, NULL)) != 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED,
+ "drain_white pthread_cond_init failed", "ret=%d", ret, NULL);
+ ret = -1;
+ goto out;
+ }
+ dm_cond_white_init = _gf_true;
+
+ if ((pthread_mutex_init(&priv->cr.lock, NULL)) != 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_MUTEX_INIT_FAILED,
+ "changelog_rollover lock init failed", "ret=%d", ret, NULL);
+ ret = -1;
+ goto out;
+ }
+ cr_mutex_init = _gf_true;
+
+ if ((pthread_cond_init(&priv->cr.cond, NULL)) != 0) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno,
+ CHANGELOG_MSG_PTHREAD_COND_INIT_FAILED,
+ "changelog_rollover cond init failed", "ret=%d", ret, NULL);
+ ret = -1;
+ goto out;
+ }
+ cr_cond_init = _gf_true;
+out:
+ if (ret) {
+ if (bn_mutex_init)
+ pthread_mutex_destroy(&priv->bn.bnotify_mutex);
+ if (bn_cond_init)
+ pthread_cond_destroy(&priv->bn.bnotify_cond);
+ if (dm_mutex_black_init)
+ pthread_mutex_destroy(&priv->dm.drain_black_mutex);
+ if (dm_cond_black_init)
+ pthread_cond_destroy(&priv->dm.drain_black_cond);
+ if (dm_mutex_white_init)
+ pthread_mutex_destroy(&priv->dm.drain_white_mutex);
+ if (dm_cond_white_init)
+ pthread_cond_destroy(&priv->dm.drain_white_cond);
+ if (cr_mutex_init)
+ pthread_mutex_destroy(&priv->cr.lock);
+ if (cr_cond_init)
+ pthread_cond_destroy(&priv->cr.cond);
+ }
+ return ret;
}
/* Destroy barrier related condition variables and locks */
static void
-changelog_barrier_pthread_destroy (changelog_priv_t *priv)
+changelog_barrier_pthread_destroy(changelog_priv_t *priv)
{
- pthread_mutex_destroy (&priv->bn.bnotify_mutex);
- pthread_cond_destroy (&priv->bn.bnotify_cond);
- pthread_mutex_destroy (&priv->dm.drain_black_mutex);
- pthread_cond_destroy (&priv->dm.drain_black_cond);
- pthread_mutex_destroy (&priv->dm.drain_white_mutex);
- pthread_cond_destroy (&priv->dm.drain_white_cond);
- pthread_mutex_destroy(&priv->cr.lock);
- pthread_cond_destroy (&priv->cr.cond);
- LOCK_DESTROY (&priv->bflags.lock);
+ pthread_mutex_destroy(&priv->bn.bnotify_mutex);
+ pthread_cond_destroy(&priv->bn.bnotify_cond);
+ pthread_mutex_destroy(&priv->dm.drain_black_mutex);
+ pthread_cond_destroy(&priv->dm.drain_black_cond);
+ pthread_mutex_destroy(&priv->dm.drain_white_mutex);
+ pthread_cond_destroy(&priv->dm.drain_white_cond);
+ pthread_mutex_destroy(&priv->cr.lock);
+ pthread_cond_destroy(&priv->cr.cond);
+ LOCK_DESTROY(&priv->bflags.lock);
}
int
-reconfigure (xlator_t *this, dict_t *options)
-{
- int ret = 0;
- char *tmp = NULL;
- changelog_priv_t *priv = NULL;
- gf_boolean_t active_earlier = _gf_true;
- gf_boolean_t active_now = _gf_true;
- changelog_time_slice_t *slice = NULL;
- changelog_log_data_t cld = {0,};
- char htime_dir[PATH_MAX] = {0,};
- char csnap_dir[PATH_MAX] = {0,};
- struct timeval tv = {0,};
- uint32_t timeout = 0;
-
- priv = this->private;
- if (!priv)
- goto out;
-
- ret = -1;
- active_earlier = priv->active;
-
- /* first stop the rollover and the fsync thread */
- changelog_cleanup_helper_threads (this, priv);
-
- GF_OPTION_RECONF ("changelog-dir", tmp, options, str, out);
- if (!tmp) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_DIR_OPTIONS_NOT_SET,
- "\"changelog-dir\" option is not set");
- goto out;
- }
-
- GF_FREE (priv->changelog_dir);
- priv->changelog_dir = gf_strdup (tmp);
- if (!priv->changelog_dir)
- goto out;
-
- ret = mkdir_p (priv->changelog_dir, 0600, _gf_true);
-
+reconfigure(xlator_t *this, dict_t *options)
+{
+ int ret = 0;
+ char *tmp = NULL;
+ changelog_priv_t *priv = NULL;
+ gf_boolean_t active_earlier = _gf_true;
+ gf_boolean_t active_now = _gf_true;
+ changelog_time_slice_t *slice = NULL;
+ changelog_log_data_t cld = {
+ 0,
+ };
+ char htime_dir[PATH_MAX] = {
+ 0,
+ };
+ char csnap_dir[PATH_MAX] = {
+ 0,
+ };
+ struct timeval tv = {
+ 0,
+ };
+ uint32_t timeout = 0;
+
+ priv = this->private;
+ if (!priv)
+ goto out;
+
+ ret = -1;
+ active_earlier = priv->active;
+
+ /* first stop the rollover and the fsync thread */
+ changelog_cleanup_helper_threads(this, priv);
+
+ GF_OPTION_RECONF("changelog-dir", tmp, options, str, out);
+ if (!tmp) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_DIR_OPTIONS_NOT_SET,
+ "\"changelog-dir\" option is not set");
+ goto out;
+ }
+
+ GF_FREE(priv->changelog_dir);
+ priv->changelog_dir = gf_strdup(tmp);
+ if (!priv->changelog_dir)
+ goto out;
+
+ ret = mkdir_p(priv->changelog_dir, 0600, _gf_true);
+
+ if (ret)
+ goto out;
+ CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, htime_dir);
+ ret = mkdir_p(htime_dir, 0600, _gf_true);
+
+ if (ret)
+ goto out;
+
+ CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir);
+ ret = mkdir_p(csnap_dir, 0600, _gf_true);
+
+ if (ret)
+ goto out;
+
+ GF_OPTION_RECONF("changelog", active_now, options, bool, out);
+
+ /**
+ * changelog_handle_change() handles changes that could possibly
+ * have been submit changes before changelog deactivation.
+ */
+ if (!active_now)
+ priv->active = _gf_false;
+
+ GF_OPTION_RECONF("op-mode", tmp, options, str, out);
+ changelog_assign_opmode(priv, tmp);
+
+ tmp = NULL;
+
+ GF_OPTION_RECONF("encoding", tmp, options, str, out);
+ changelog_assign_encoding(priv, tmp);
+
+ GF_OPTION_RECONF("rollover-time", priv->rollover_time, options, int32, out);
+ GF_OPTION_RECONF("fsync-interval", priv->fsync_interval, options, int32,
+ out);
+ GF_OPTION_RECONF("changelog-barrier-timeout", timeout, options, time, out);
+ changelog_assign_barrier_timeout(priv, timeout);
+
+ GF_OPTION_RECONF("capture-del-path", priv->capture_del_path, options, bool,
+ out);
+
+ if (active_now || active_earlier) {
+ ret = changelog_fill_rollover_data(&cld, !active_now);
if (ret)
- goto out;
- CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, htime_dir);
- ret = mkdir_p (htime_dir, 0600, _gf_true);
+ goto out;
- if (ret)
- goto out;
+ slice = &priv->slice;
- CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir);
- ret = mkdir_p (csnap_dir, 0600, _gf_true);
+ LOCK(&priv->lock);
+ {
+ ret = changelog_inject_single_event(this, priv, &cld);
+ if (!ret && active_now)
+ SLICE_VERSION_UPDATE(slice);
+ }
+ UNLOCK(&priv->lock);
if (ret)
- goto out;
-
- GF_OPTION_RECONF ("changelog", active_now, options, bool, out);
-
- /**
- * changelog_handle_change() handles changes that could possibly
- * have been submit changes before changelog deactivation.
- */
- if (!active_now)
- priv->active = _gf_false;
-
- GF_OPTION_RECONF ("op-mode", tmp, options, str, out);
- changelog_assign_opmode (priv, tmp);
-
- tmp = NULL;
-
- GF_OPTION_RECONF ("encoding", tmp, options, str, out);
- changelog_assign_encoding (priv, tmp);
-
- GF_OPTION_RECONF ("rollover-time",
- priv->rollover_time, options, int32, out);
- GF_OPTION_RECONF ("fsync-interval",
- priv->fsync_interval, options, int32, out);
- GF_OPTION_RECONF ("changelog-barrier-timeout",
- timeout, options, time, out);
- changelog_assign_barrier_timeout (priv, timeout);
-
- GF_OPTION_RECONF ("capture-del-path", priv->capture_del_path, options,
- bool, out);
-
- if (active_now || active_earlier) {
- ret = changelog_fill_rollover_data (&cld, !active_now);
- if (ret)
- goto out;
-
- slice = &priv->slice;
-
- LOCK (&priv->lock);
- {
- ret = changelog_inject_single_event (this, priv, &cld);
- if (!ret && active_now)
- SLICE_VERSION_UPDATE (slice);
- }
- UNLOCK (&priv->lock);
-
- if (ret)
- goto out;
-
- if (active_now) {
- if (!active_earlier) {
- gf_msg (this->name, GF_LOG_INFO, 0,
- CHANGELOG_MSG_HTIME_INFO,
- "Reconfigure: Changelog Enable");
- if (gettimeofday(&tv, NULL) ) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_HTIME_ERROR,
- "unable to fetch htime");
- ret = -1;
- goto out;
- }
- htime_create (this, priv, tv.tv_sec);
- }
- ret = changelog_spawn_helper_threads (this, priv);
+ goto out;
+
+ if (active_now) {
+ if (!active_earlier) {
+ gf_msg(this->name, GF_LOG_INFO, 0, CHANGELOG_MSG_HTIME_INFO,
+ "Reconfigure: Changelog Enable");
+ if (gettimeofday(&tv, NULL)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CHANGELOG_MSG_HTIME_ERROR, "unable to fetch htime");
+ ret = -1;
+ goto out;
}
+ htime_create(this, priv, tv.tv_sec);
+ }
+ ret = changelog_spawn_helper_threads(this, priv);
}
+ }
- out:
- if (ret) {
- /* TODO */
- } else {
- gf_msg_debug (this->name, 0,
- "changelog reconfigured");
- if (active_now && priv)
- priv->active = _gf_true;
- }
+out:
+ if (ret) {
+ /* TODO */
+ } else {
+ gf_msg_debug(this->name, 0, "changelog reconfigured");
+ if (active_now && priv)
+ priv->active = _gf_true;
+ }
- return ret;
+ return ret;
}
static void
-changelog_freeup_options (xlator_t *this, changelog_priv_t *priv)
+changelog_freeup_options(xlator_t *this, changelog_priv_t *priv)
{
- int ret = 0;
+ int ret = 0;
- ret = priv->cb->dtor (this, &priv->cd);
- if (ret)
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_FREEUP_FAILED,
- "could not cleanup bootstrapper");
- GF_FREE (priv->changelog_brick);
- GF_FREE (priv->changelog_dir);
+ ret = priv->cb->dtor(this, &priv->cd);
+ if (ret)
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_FREEUP_FAILED,
+ "could not cleanup bootstrapper");
+ GF_FREE(priv->changelog_brick);
+ GF_FREE(priv->changelog_dir);
}
static int
-changelog_init_options (xlator_t *this, changelog_priv_t *priv)
+changelog_init_options(xlator_t *this, changelog_priv_t *priv)
{
- int ret = 0;
- char *tmp = NULL;
- uint32_t timeout = 0;
- char htime_dir[PATH_MAX] = {0,};
- char csnap_dir[PATH_MAX] = {0,};
+ int ret = 0;
+ char *tmp = NULL;
+ uint32_t timeout = 0;
+ char htime_dir[PATH_MAX] = {
+ 0,
+ };
+ char csnap_dir[PATH_MAX] = {
+ 0,
+ };
- GF_OPTION_INIT ("changelog-brick", tmp, str, error_return);
- priv->changelog_brick = gf_strdup (tmp);
- if (!priv->changelog_brick)
- goto error_return;
+ GF_OPTION_INIT("changelog-brick", tmp, str, error_return);
+ priv->changelog_brick = gf_strdup(tmp);
+ if (!priv->changelog_brick)
+ goto error_return;
- tmp = NULL;
+ tmp = NULL;
- GF_OPTION_INIT ("changelog-dir", tmp, str, dealloc_1);
- priv->changelog_dir = gf_strdup (tmp);
- if (!priv->changelog_dir)
- goto dealloc_1;
+ GF_OPTION_INIT("changelog-dir", tmp, str, dealloc_1);
+ priv->changelog_dir = gf_strdup(tmp);
+ if (!priv->changelog_dir)
+ goto dealloc_1;
- tmp = NULL;
+ tmp = NULL;
- /**
- * create the directory even if change-logging would be inactive
- * so that consumers can _look_ into it (finding nothing...)
- */
- ret = mkdir_p (priv->changelog_dir, 0600, _gf_true);
+ /**
+ * create the directory even if change-logging would be inactive
+ * so that consumers can _look_ into it (finding nothing...)
+ */
+ ret = mkdir_p(priv->changelog_dir, 0600, _gf_true);
- if (ret)
- goto dealloc_2;
+ if (ret)
+ goto dealloc_2;
- CHANGELOG_FILL_HTIME_DIR (priv->changelog_dir, htime_dir);
- ret = mkdir_p (htime_dir, 0600, _gf_true);
- if (ret)
- goto dealloc_2;
+ CHANGELOG_FILL_HTIME_DIR(priv->changelog_dir, htime_dir);
+ ret = mkdir_p(htime_dir, 0600, _gf_true);
+ if (ret)
+ goto dealloc_2;
- CHANGELOG_FILL_CSNAP_DIR (priv->changelog_dir, csnap_dir);
- ret = mkdir_p (csnap_dir, 0600, _gf_true);
- if (ret)
- goto dealloc_2;
+ CHANGELOG_FILL_CSNAP_DIR(priv->changelog_dir, csnap_dir);
+ ret = mkdir_p(csnap_dir, 0600, _gf_true);
+ if (ret)
+ goto dealloc_2;
- GF_OPTION_INIT ("changelog", priv->active, bool, dealloc_2);
- GF_OPTION_INIT ("capture-del-path", priv->capture_del_path,
- bool, dealloc_2);
+ GF_OPTION_INIT("changelog", priv->active, bool, dealloc_2);
+ GF_OPTION_INIT("capture-del-path", priv->capture_del_path, bool, dealloc_2);
- GF_OPTION_INIT ("op-mode", tmp, str, dealloc_2);
- changelog_assign_opmode (priv, tmp);
+ GF_OPTION_INIT("op-mode", tmp, str, dealloc_2);
+ changelog_assign_opmode(priv, tmp);
- tmp = NULL;
+ tmp = NULL;
- GF_OPTION_INIT ("encoding", tmp, str, dealloc_2);
- changelog_assign_encoding (priv, tmp);
- changelog_encode_change (priv);
+ GF_OPTION_INIT("encoding", tmp, str, dealloc_2);
+ changelog_assign_encoding(priv, tmp);
+ changelog_encode_change(priv);
- GF_OPTION_INIT ("rollover-time",
- priv->rollover_time, int32, dealloc_2);
+ GF_OPTION_INIT("rollover-time", priv->rollover_time, int32, dealloc_2);
- GF_OPTION_INIT ("fsync-interval",
- priv->fsync_interval, int32, dealloc_2);
+ GF_OPTION_INIT("fsync-interval", priv->fsync_interval, int32, dealloc_2);
- GF_OPTION_INIT ("changelog-barrier-timeout",
- timeout, time, dealloc_2);
- changelog_assign_barrier_timeout (priv, timeout);
+ GF_OPTION_INIT("changelog-barrier-timeout", timeout, time, dealloc_2);
+ changelog_assign_barrier_timeout(priv, timeout);
- GF_ASSERT (cb_bootstrap[priv->op_mode].mode == priv->op_mode);
- priv->cb = &cb_bootstrap[priv->op_mode];
+ GF_ASSERT(cb_bootstrap[priv->op_mode].mode == priv->op_mode);
+ priv->cb = &cb_bootstrap[priv->op_mode];
- /* ... now bootstrap the logger */
- ret = priv->cb->ctor (this, &priv->cd);
- if (ret)
- goto dealloc_2;
+ /* ... now bootstrap the logger */
+ ret = priv->cb->ctor(this, &priv->cd);
+ if (ret)
+ goto dealloc_2;
- priv->changelog_fd = -1;
+ priv->changelog_fd = -1;
- return 0;
+ return 0;
- dealloc_2:
- GF_FREE (priv->changelog_dir);
- dealloc_1:
- GF_FREE (priv->changelog_brick);
- error_return:
- return -1;
+dealloc_2:
+ GF_FREE(priv->changelog_dir);
+dealloc_1:
+ GF_FREE(priv->changelog_brick);
+error_return:
+ return -1;
}
static void
-changelog_cleanup_rpc (xlator_t *this, changelog_priv_t *priv)
+changelog_cleanup_rpc(xlator_t *this, changelog_priv_t *priv)
{
- /* terminate rpc server */
- changelog_destroy_rpc_listner (this, priv);
+ /* terminate rpc server */
+ changelog_destroy_rpc_listner(this, priv);
- /* cleanup rot buffs */
- rbuf_dtor (priv->rbuf);
+ /* cleanup rot buffs */
+ rbuf_dtor(priv->rbuf);
- /* cleanup poller thread */
- if (priv->poller)
- (void) changelog_thread_cleanup (this, priv->poller);
+ /* cleanup poller thread */
+ if (priv->poller)
+ (void)changelog_thread_cleanup(this, priv->poller);
}
static int
-changelog_init_rpc (xlator_t *this, changelog_priv_t *priv)
+changelog_init_rpc(xlator_t *this, changelog_priv_t *priv)
{
- rpcsvc_t *rpc = NULL;
- changelog_ev_selector_t *selection = NULL;
+ rpcsvc_t *rpc = NULL;
+ changelog_ev_selector_t *selection = NULL;
- selection = &priv->ev_selection;
+ selection = &priv->ev_selection;
- /* initialize event selection */
- changelog_init_event_selection (this, selection);
+ /* initialize event selection */
+ changelog_init_event_selection(this, selection);
- priv->rbuf = rbuf_init (NR_ROTT_BUFFS);
- if (!priv->rbuf)
- goto cleanup_thread;
+ priv->rbuf = rbuf_init(NR_ROTT_BUFFS);
+ if (!priv->rbuf)
+ goto cleanup_thread;
- rpc = changelog_init_rpc_listener (this, priv,
- priv->rbuf, NR_DISPATCHERS);
- if (!rpc)
- goto cleanup_rbuf;
- priv->rpc = rpc;
+ rpc = changelog_init_rpc_listener(this, priv, priv->rbuf, NR_DISPATCHERS);
+ if (!rpc)
+ goto cleanup_rbuf;
+ priv->rpc = rpc;
- return 0;
+ return 0;
- cleanup_rbuf:
- rbuf_dtor (priv->rbuf);
- cleanup_thread:
- if (priv->poller)
- (void) changelog_thread_cleanup (this, priv->poller);
+cleanup_rbuf:
+ rbuf_dtor(priv->rbuf);
+cleanup_thread:
+ if (priv->poller)
+ (void)changelog_thread_cleanup(this, priv->poller);
- return -1;
+ return -1;
}
int32_t
-init (xlator_t *this)
-{
- int ret = -1;
- changelog_priv_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO ("changelog", this, error_return);
-
- if (!this->children || this->children->next) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_CHILD_MISCONFIGURED,
- "translator needs a single subvolume");
- goto error_return;
- }
-
- if (!this->parents) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CHANGELOG_MSG_VOL_MISCONFIGURED,
- "dangling volume. please check volfile");
- goto error_return;
- }
-
- priv = GF_CALLOC (1, sizeof (*priv), gf_changelog_mt_priv_t);
- if (!priv)
- goto error_return;
-
- this->local_pool = mem_pool_new (changelog_local_t, 64);
- if (!this->local_pool) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
- CHANGELOG_MSG_NO_MEMORY,
- "failed to create local memory pool");
- goto cleanup_priv;
- }
-
- LOCK_INIT (&priv->lock);
- LOCK_INIT (&priv->c_snap_lock);
-
- ret = changelog_init_options (this, priv);
- if (ret)
- goto cleanup_mempool;
-
- /* snap dependency changes */
- priv->dm.black_fop_cnt = 0;
- priv->dm.white_fop_cnt = 0;
- priv->dm.drain_wait_black = _gf_false;
- priv->dm.drain_wait_white = _gf_false;
- priv->current_color = FOP_COLOR_BLACK;
- priv->explicit_rollover = _gf_false;
-
- priv->cr.notify = _gf_false;
- /* Mutex is not needed as threads are not spawned yet */
- priv->bn.bnotify = _gf_false;
- priv->bn.bnotify_error = _gf_false;
- ret = changelog_barrier_pthread_init (this, priv);
- if (ret)
- goto cleanup_options;
- LOCK_INIT (&priv->bflags.lock);
- priv->bflags.barrier_ext = _gf_false;
-
- /* Changelog barrier init */
- INIT_LIST_HEAD (&priv->queue);
- priv->barrier_enabled = _gf_false;
-
- /* RPC ball rolling.. */
- ret = changelog_init_rpc (this, priv);
- if (ret)
- goto cleanup_barrier;
-
- ret = changelog_init (this, priv);
- if (ret)
- goto cleanup_rpc;
-
- gf_msg_debug (this->name, 0, "changelog translator loaded");
-
- this->private = priv;
- return 0;
-
- cleanup_rpc:
- changelog_cleanup_rpc (this, priv);
- cleanup_barrier:
- changelog_barrier_pthread_destroy (priv);
- cleanup_options:
- changelog_freeup_options (this, priv);
- cleanup_mempool:
- mem_pool_destroy (this->local_pool);
- cleanup_priv:
- GF_FREE (priv);
- error_return:
- this->private = NULL;
- return -1;
+init(xlator_t *this)
+{
+ int ret = -1;
+ changelog_priv_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO("changelog", this, error_return);
+
+ if (!this->children || this->children->next) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_CHILD_MISCONFIGURED,
+ "translator needs a single subvolume");
+ goto error_return;
+ }
+
+ if (!this->parents) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CHANGELOG_MSG_VOL_MISCONFIGURED,
+ "dangling volume. please check volfile");
+ goto error_return;
+ }
+
+ priv = GF_CALLOC(1, sizeof(*priv), gf_changelog_mt_priv_t);
+ if (!priv)
+ goto error_return;
+
+ this->local_pool = mem_pool_new(changelog_local_t, 64);
+ if (!this->local_pool) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, CHANGELOG_MSG_NO_MEMORY,
+ "failed to create local memory pool");
+ goto cleanup_priv;
+ }
+
+ LOCK_INIT(&priv->lock);
+ LOCK_INIT(&priv->c_snap_lock);
+
+ ret = changelog_init_options(this, priv);
+ if (ret)
+ goto cleanup_mempool;
+
+ /* snap dependency changes */
+ priv->dm.black_fop_cnt = 0;
+ priv->dm.white_fop_cnt = 0;
+ priv->dm.drain_wait_black = _gf_false;
+ priv->dm.drain_wait_white = _gf_false;
+ priv->current_color = FOP_COLOR_BLACK;
+ priv->explicit_rollover = _gf_false;
+
+ priv->cr.notify = _gf_false;
+ /* Mutex is not needed as threads are not spawned yet */
+ priv->bn.bnotify = _gf_false;
+ priv->bn.bnotify_error = _gf_false;
+ ret = changelog_barrier_pthread_init(this, priv);
+ if (ret)
+ goto cleanup_options;
+ LOCK_INIT(&priv->bflags.lock);
+ priv->bflags.barrier_ext = _gf_false;
+
+ /* Changelog barrier init */
+ INIT_LIST_HEAD(&priv->queue);
+ priv->barrier_enabled = _gf_false;
+
+ /* RPC ball rolling.. */
+ ret = changelog_init_rpc(this, priv);
+ if (ret)
+ goto cleanup_barrier;
+
+ ret = changelog_init(this, priv);
+ if (ret)
+ goto cleanup_rpc;
+
+ gf_msg_debug(this->name, 0, "changelog translator loaded");
+
+ this->private = priv;
+ return 0;
+
+cleanup_rpc:
+ changelog_cleanup_rpc(this, priv);
+cleanup_barrier:
+ changelog_barrier_pthread_destroy(priv);
+cleanup_options:
+ changelog_freeup_options(this, priv);
+cleanup_mempool:
+ mem_pool_destroy(this->local_pool);
+cleanup_priv:
+ GF_FREE(priv);
+error_return:
+ this->private = NULL;
+ return -1;
}
void
-fini (xlator_t *this)
+fini(xlator_t *this)
{
- changelog_priv_t *priv = NULL;
- struct list_head queue = {0, };
+ changelog_priv_t *priv = NULL;
+ struct list_head queue = {
+ 0,
+ };
- priv = this->private;
+ priv = this->private;
- if (priv) {
- /* terminate RPC server/threads */
- changelog_cleanup_rpc (this, priv);
+ if (priv) {
+ /* terminate RPC server/threads */
+ changelog_cleanup_rpc(this, priv);
- /* call barrier_disable to cancel timer */
- if (priv->barrier_enabled)
- __chlog_barrier_disable (this, &queue);
+ /* call barrier_disable to cancel timer */
+ if (priv->barrier_enabled)
+ __chlog_barrier_disable(this, &queue);
- /* cleanup barrier related objects */
- changelog_barrier_pthread_destroy (priv);
+ /* cleanup barrier related objects */
+ changelog_barrier_pthread_destroy(priv);
- /* cleanup helper threads */
- changelog_cleanup_helper_threads (this, priv);
+ /* cleanup helper threads */
+ changelog_cleanup_helper_threads(this, priv);
- /* cleanup allocated options */
- changelog_freeup_options (this, priv);
+ /* cleanup allocated options */
+ changelog_freeup_options(this, priv);
- /* deallocate mempool */
- mem_pool_destroy (this->local_pool);
+ /* deallocate mempool */
+ mem_pool_destroy(this->local_pool);
- if (priv->htime_fd != -1) {
- sys_close (priv->htime_fd);
- }
-
- /* finally, dealloac private variable */
- GF_FREE (priv);
+ if (priv->htime_fd != -1) {
+ sys_close(priv->htime_fd);
}
- this->private = NULL;
- this->local_pool = NULL;
+ /* finally, dealloac private variable */
+ GF_FREE(priv);
+ }
- return;
+ this->private = NULL;
+ this->local_pool = NULL;
+
+ return;
}
struct xlator_fops fops = {
- .open = changelog_open,
- .mknod = changelog_mknod,
- .mkdir = changelog_mkdir,
- .create = changelog_create,
- .symlink = changelog_symlink,
- .writev = changelog_writev,
- .truncate = changelog_truncate,
- .ftruncate = changelog_ftruncate,
- .link = changelog_link,
- .rename = changelog_rename,
- .unlink = changelog_unlink,
- .rmdir = changelog_rmdir,
- .setattr = changelog_setattr,
- .fsetattr = changelog_fsetattr,
- .setxattr = changelog_setxattr,
- .fsetxattr = changelog_fsetxattr,
- .removexattr = changelog_removexattr,
- .fremovexattr = changelog_fremovexattr,
- .ipc = changelog_ipc,
- .xattrop = changelog_xattrop,
- .fxattrop = changelog_fxattrop,
+ .open = changelog_open,
+ .mknod = changelog_mknod,
+ .mkdir = changelog_mkdir,
+ .create = changelog_create,
+ .symlink = changelog_symlink,
+ .writev = changelog_writev,
+ .truncate = changelog_truncate,
+ .ftruncate = changelog_ftruncate,
+ .link = changelog_link,
+ .rename = changelog_rename,
+ .unlink = changelog_unlink,
+ .rmdir = changelog_rmdir,
+ .setattr = changelog_setattr,
+ .fsetattr = changelog_fsetattr,
+ .setxattr = changelog_setxattr,
+ .fsetxattr = changelog_fsetxattr,
+ .removexattr = changelog_removexattr,
+ .fremovexattr = changelog_fremovexattr,
+ .ipc = changelog_ipc,
+ .xattrop = changelog_xattrop,
+ .fxattrop = changelog_fxattrop,
};
struct xlator_cbks cbks = {
- .forget = changelog_forget,
- .release = changelog_release,
+ .forget = changelog_forget,
+ .release = changelog_release,
};
struct volume_options options[] = {
- {.key = {"changelog"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .description = "enable/disable change-logging",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE,
- .level = OPT_STATUS_BASIC,
- .tags = {"journal", "georep", "glusterfind"}
- },
- {.key = {"changelog-brick"},
- .type = GF_OPTION_TYPE_PATH,
- .description = "brick path to generate unique socket file name."
- " should be the export directory of the volume strictly.",
- .default_value = "{{ brick.path }}",
- .op_version = {3},
- .tags = {"journal"}
- },
- {.key = {"changelog-dir"},
- .type = GF_OPTION_TYPE_PATH,
- .description = "directory for the changelog files",
- .default_value = "{{ brick.path }}/.glusterfs/changelogs",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE,
- .level = OPT_STATUS_ADVANCED,
- .tags = {"journal", "georep", "glusterfind"}
- },
- {.key = {"op-mode"},
- .type = GF_OPTION_TYPE_STR,
- .default_value = "realtime",
- .value = {"realtime"},
- .description = "operation mode - futuristic operation modes",
- .op_version = {3},
- .tags = {"journal"}
- },
- {.key = {"encoding"},
- .type = GF_OPTION_TYPE_STR,
- .default_value = "ascii",
- .value = {"binary", "ascii"},
- .description = "encoding type for changelogs",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE,
- .level = OPT_STATUS_ADVANCED,
- .tags = {"journal"}
- },
- {.key = {"rollover-time"},
- .default_value = "15",
- .type = GF_OPTION_TYPE_TIME,
- .description = "time to switch to a new changelog file (in seconds)",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE,
- .level = OPT_STATUS_ADVANCED,
- .tags = {"journal", "georep", "glusterfind"}
- },
- {.key = {"fsync-interval"},
- .type = GF_OPTION_TYPE_TIME,
- .default_value = "5",
- .description = "do not open CHANGELOG file with O_SYNC mode."
- " instead perform fsync() at specified intervals",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE,
- .level = OPT_STATUS_ADVANCED,
- .tags = {"journal"}
- },
- { .key = {"changelog-barrier-timeout"},
- .type = GF_OPTION_TYPE_TIME,
- .default_value = BARRIER_TIMEOUT,
- .description = "After 'timeout' seconds since the time 'barrier' "
- "option was set to \"on\", unlink/rmdir/rename "
- "operations are no longer blocked and previously "
- "blocked fops are allowed to go through",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE,
- .level = OPT_STATUS_ADVANCED,
- .tags = {"journal"}
- },
- {.key = {"capture-del-path"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .description = "enable/disable capturing paths of deleted entries",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE,
- .level = OPT_STATUS_BASIC,
- .tags = {"journal", "glusterfind"}
- },
- {.key = {NULL}
- },
+ {.key = {"changelog"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .description = "enable/disable change-logging",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE,
+ .level = OPT_STATUS_BASIC,
+ .tags = {"journal", "georep", "glusterfind"}},
+ {.key = {"changelog-brick"},
+ .type = GF_OPTION_TYPE_PATH,
+ .description = "brick path to generate unique socket file name."
+ " should be the export directory of the volume strictly.",
+ .default_value = "{{ brick.path }}",
+ .op_version = {3},
+ .tags = {"journal"}},
+ {.key = {"changelog-dir"},
+ .type = GF_OPTION_TYPE_PATH,
+ .description = "directory for the changelog files",
+ .default_value = "{{ brick.path }}/.glusterfs/changelogs",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE,
+ .level = OPT_STATUS_ADVANCED,
+ .tags = {"journal", "georep", "glusterfind"}},
+ {.key = {"op-mode"},
+ .type = GF_OPTION_TYPE_STR,
+ .default_value = "realtime",
+ .value = {"realtime"},
+ .description = "operation mode - futuristic operation modes",
+ .op_version = {3},
+ .tags = {"journal"}},
+ {.key = {"encoding"},
+ .type = GF_OPTION_TYPE_STR,
+ .default_value = "ascii",
+ .value = {"binary", "ascii"},
+ .description = "encoding type for changelogs",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE,
+ .level = OPT_STATUS_ADVANCED,
+ .tags = {"journal"}},
+ {.key = {"rollover-time"},
+ .default_value = "15",
+ .type = GF_OPTION_TYPE_TIME,
+ .description = "time to switch to a new changelog file (in seconds)",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE,
+ .level = OPT_STATUS_ADVANCED,
+ .tags = {"journal", "georep", "glusterfind"}},
+ {.key = {"fsync-interval"},
+ .type = GF_OPTION_TYPE_TIME,
+ .default_value = "5",
+ .description = "do not open CHANGELOG file with O_SYNC mode."
+ " instead perform fsync() at specified intervals",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE,
+ .level = OPT_STATUS_ADVANCED,
+ .tags = {"journal"}},
+ {.key = {"changelog-barrier-timeout"},
+ .type = GF_OPTION_TYPE_TIME,
+ .default_value = BARRIER_TIMEOUT,
+ .description = "After 'timeout' seconds since the time 'barrier' "
+ "option was set to \"on\", unlink/rmdir/rename "
+ "operations are no longer blocked and previously "
+ "blocked fops are allowed to go through",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE,
+ .level = OPT_STATUS_ADVANCED,
+ .tags = {"journal"}},
+ {.key = {"capture-del-path"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .description = "enable/disable capturing paths of deleted entries",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE,
+ .level = OPT_STATUS_BASIC,
+ .tags = {"journal", "glusterfind"}},
+ {.key = {NULL}},
};
diff --git a/xlators/features/changetimerecorder/src/changetimerecorder.c b/xlators/features/changetimerecorder/src/changetimerecorder.c
index bc87518c0c0..04b89e5a540 100644
--- a/xlators/features/changetimerecorder/src/changetimerecorder.c
+++ b/xlators/features/changetimerecorder/src/changetimerecorder.c
@@ -20,10 +20,10 @@
/*******************************inode forget***********************************/
int
-ctr_forget (xlator_t *this, inode_t *inode)
+ctr_forget(xlator_t *this, inode_t *inode)
{
- fini_ctr_xlator_ctx (this, inode);
- return 0;
+ fini_ctr_xlator_ctx(this, inode);
+ return 0;
}
/************************** Look up heal **************************************/
@@ -78,125 +78,116 @@ What is pending:
*/
-
/* This function does not write anything to the db,
* just created the local variable
* for the frame and sets values for the ctr_db_record */
static int
-ctr_lookup_wind(call_frame_t *frame,
- xlator_t *this,
- gf_ctr_inode_context_t *ctr_inode_cx)
+ctr_lookup_wind(call_frame_t *frame, xlator_t *this,
+ gf_ctr_inode_context_t *ctr_inode_cx)
{
- int ret = -1;
- gf_ctr_private_t *_priv = NULL;
- gf_ctr_local_t *ctr_local = NULL;
-
- GF_ASSERT(frame);
- GF_ASSERT(frame->root);
- GF_ASSERT(this);
- IS_CTR_INODE_CX_SANE(ctr_inode_cx);
-
- _priv = this->private;
- GF_ASSERT (_priv);
-
- if (_priv->ctr_record_wind && ctr_inode_cx->ia_type != IA_IFDIR) {
-
- frame->local = init_ctr_local_t (this);
- if (!frame->local) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_CREATE_CTR_LOCAL_ERROR_WIND,
- "WIND: Error while creating ctr local");
- goto out;
- };
- ctr_local = frame->local;
- /*Definitely no internal fops will reach here*/
- ctr_local->is_internal_fop = _gf_false;
- /*Don't record counters*/
- CTR_DB_REC(ctr_local).do_record_counters = _gf_false;
- /*Don't record time at all*/
- CTR_DB_REC(ctr_local).do_record_times = _gf_false;
-
- /* Copy gfid into db record*/
- gf_uuid_copy (CTR_DB_REC(ctr_local).gfid,
- *(ctr_inode_cx->gfid));
-
- /* Set fop_path and fop_type, required by libgfdb to make
- * decision while inserting the record */
- CTR_DB_REC(ctr_local).gfdb_fop_path = ctr_inode_cx->fop_path;
- CTR_DB_REC(ctr_local).gfdb_fop_type = ctr_inode_cx->fop_type;
-
- /* Copy hard link info*/
- gf_uuid_copy (CTR_DB_REC(ctr_local).pargfid,
- *((NEW_LINK_CX(ctr_inode_cx))->pargfid));
- if (snprintf (CTR_DB_REC(ctr_local).file_name,
- sizeof (CTR_DB_REC(ctr_local).file_name), "%s",
- NEW_LINK_CX(ctr_inode_cx)->basename) >=
- sizeof (CTR_DB_REC(ctr_local).file_name)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_CREATE_CTR_LOCAL_ERROR_WIND,
- "WIND: Error copying filename of ctr local");
- goto out;
- }
- /* Since we are in lookup we can ignore errors while
- * Inserting in the DB, because there may be many
- * to write to the DB attempts for healing.
- * We don't want to log all failed attempts and
- * bloat the log*/
- ctr_local->gfdb_db_record.ignore_errors = _gf_true;
- }
+ int ret = -1;
+ gf_ctr_private_t *_priv = NULL;
+ gf_ctr_local_t *ctr_local = NULL;
+
+ GF_ASSERT(frame);
+ GF_ASSERT(frame->root);
+ GF_ASSERT(this);
+ IS_CTR_INODE_CX_SANE(ctr_inode_cx);
- ret = 0;
+ _priv = this->private;
+ GF_ASSERT(_priv);
+
+ if (_priv->ctr_record_wind && ctr_inode_cx->ia_type != IA_IFDIR) {
+ frame->local = init_ctr_local_t(this);
+ if (!frame->local) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_CREATE_CTR_LOCAL_ERROR_WIND,
+ "WIND: Error while creating ctr local");
+ goto out;
+ };
+ ctr_local = frame->local;
+ /*Definitely no internal fops will reach here*/
+ ctr_local->is_internal_fop = _gf_false;
+ /*Don't record counters*/
+ CTR_DB_REC(ctr_local).do_record_counters = _gf_false;
+ /*Don't record time at all*/
+ CTR_DB_REC(ctr_local).do_record_times = _gf_false;
+
+ /* Copy gfid into db record*/
+ gf_uuid_copy(CTR_DB_REC(ctr_local).gfid, *(ctr_inode_cx->gfid));
+
+ /* Set fop_path and fop_type, required by libgfdb to make
+ * decision while inserting the record */
+ CTR_DB_REC(ctr_local).gfdb_fop_path = ctr_inode_cx->fop_path;
+ CTR_DB_REC(ctr_local).gfdb_fop_type = ctr_inode_cx->fop_type;
+
+ /* Copy hard link info*/
+ gf_uuid_copy(CTR_DB_REC(ctr_local).pargfid,
+ *((NEW_LINK_CX(ctr_inode_cx))->pargfid));
+ if (snprintf(CTR_DB_REC(ctr_local).file_name,
+ sizeof(CTR_DB_REC(ctr_local).file_name), "%s",
+ NEW_LINK_CX(ctr_inode_cx)->basename) >=
+ sizeof(CTR_DB_REC(ctr_local).file_name)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_CREATE_CTR_LOCAL_ERROR_WIND,
+ "WIND: Error copying filename of ctr local");
+ goto out;
+ }
+ /* Since we are in lookup we can ignore errors while
+ * Inserting in the DB, because there may be many
+ * to write to the DB attempts for healing.
+ * We don't want to log all failed attempts and
+ * bloat the log*/
+ ctr_local->gfdb_db_record.ignore_errors = _gf_true;
+ }
+
+ ret = 0;
out:
- if (ret) {
- free_ctr_local (ctr_local);
- frame->local = NULL;
- }
+ if (ret) {
+ free_ctr_local(ctr_local);
+ frame->local = NULL;
+ }
- return ret;
+ return ret;
}
-
/* This function inserts the ctr_db_record populated by ctr_lookup_wind
* in to the db. It also destroys the frame->local created by ctr_lookup_wind */
static int
-ctr_lookup_unwind (call_frame_t *frame,
- xlator_t *this)
+ctr_lookup_unwind(call_frame_t *frame, xlator_t *this)
{
- int ret = -1;
- gf_ctr_private_t *_priv = NULL;
- gf_ctr_local_t *ctr_local = NULL;
+ int ret = -1;
+ gf_ctr_private_t *_priv = NULL;
+ gf_ctr_local_t *ctr_local = NULL;
- GF_ASSERT(frame);
- GF_ASSERT(this);
+ GF_ASSERT(frame);
+ GF_ASSERT(this);
- _priv = this->private;
- GF_ASSERT (_priv);
+ _priv = this->private;
+ GF_ASSERT(_priv);
- GF_ASSERT(_priv->_db_conn);
+ GF_ASSERT(_priv->_db_conn);
- ctr_local = frame->local;
+ ctr_local = frame->local;
- if (ctr_local && (ctr_local->ia_inode_type != IA_IFDIR)) {
-
- ret = insert_record(_priv->_db_conn,
- &ctr_local->gfdb_db_record);
- if (ret == -1) {
- gf_msg (this->name,
- _gfdb_log_level (GF_LOG_ERROR,
- ctr_local->
- gfdb_db_record.ignore_errors),
- 0, CTR_MSG_FILL_CTR_LOCAL_ERROR_UNWIND,
- "UNWIND: Error filling ctr local");
- goto out;
- }
+ if (ctr_local && (ctr_local->ia_inode_type != IA_IFDIR)) {
+ ret = insert_record(_priv->_db_conn, &ctr_local->gfdb_db_record);
+ if (ret == -1) {
+ gf_msg(this->name,
+ _gfdb_log_level(GF_LOG_ERROR,
+ ctr_local->gfdb_db_record.ignore_errors),
+ 0, CTR_MSG_FILL_CTR_LOCAL_ERROR_UNWIND,
+ "UNWIND: Error filling ctr local");
+ goto out;
}
- ret = 0;
+ }
+ ret = 0;
out:
- free_ctr_local (ctr_local);
- frame->local = NULL;
- return ret;
+ free_ctr_local(ctr_local);
+ frame->local = NULL;
+ return ret;
}
/******************************************************************************
@@ -207,1488 +198,1378 @@ out:
/****************************LOOKUP********************************************/
-
int32_t
-ctr_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, dict_t *dict, struct iatt *postparent)
+ctr_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, dict_t *dict, struct iatt *postparent)
{
- int ret = -1;
- ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
- gf_ctr_local_t *ctr_local = NULL;
- ctr_heal_ret_val_t ret_val = CTR_CTX_ERROR;
- gf_boolean_t _is_heal_needed = _gf_false;
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
-
- /* if the lookup failed lookup don't do anything*/
- if (op_ret == -1) {
- gf_msg_trace (this->name, 0, "lookup failed with %s",
- strerror (op_errno));
- goto out;
- }
-
- /* Ignore directory lookups */
- if (inode->ia_type == IA_IFDIR) {
- goto out;
- }
-
- /* if frame local was not set by the ctr_lookup()
- * so don't so anything*/
- if (!frame->local) {
- goto out;
- }
-
- /* if the lookup is for dht link donot record*/
- if (dht_is_linkfile (buf, dict)) {
- gf_msg_trace (this->name, 0, "Ignoring Lookup "
- "for dht link file");
- goto out;
- }
-
- ctr_local = frame->local;
- /*Assign the proper inode type*/
- ctr_local->ia_inode_type = inode->ia_type;
-
- /* Copy gfid directly from inode */
- gf_uuid_copy (CTR_DB_REC(ctr_local).gfid, inode->gfid);
+ int ret = -1;
+ ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
+ gf_ctr_local_t *ctr_local = NULL;
+ ctr_heal_ret_val_t ret_val = CTR_CTX_ERROR;
+ gf_boolean_t _is_heal_needed = _gf_false;
+
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+
+ /* if the lookup failed lookup don't do anything*/
+ if (op_ret == -1) {
+ gf_msg_trace(this->name, 0, "lookup failed with %s",
+ strerror(op_errno));
+ goto out;
+ }
- /* Checking if gfid and parent gfid is valid */
- if (gf_uuid_is_null(CTR_DB_REC(ctr_local).gfid) ||
- gf_uuid_is_null(CTR_DB_REC(ctr_local).pargfid)) {
- gf_msg_trace (this->name, 0,
- "Invalid GFID");
- goto out;
- }
+ /* Ignore directory lookups */
+ if (inode->ia_type == IA_IFDIR) {
+ goto out;
+ }
- /* if its a first entry
- * then mark the ctr_record for create
- * A create will attempt a file and a hard link created in the db*/
- ctr_xlator_ctx = get_ctr_xlator_ctx (this, inode);
- if (!ctr_xlator_ctx) {
- /* This marks inode heal */
- CTR_DB_REC(ctr_local).gfdb_fop_type = GFDB_FOP_CREATE_WRITE;
- _is_heal_needed = _gf_true;
- }
+ /* if frame local was not set by the ctr_lookup()
+ * so don't so anything*/
+ if (!frame->local) {
+ goto out;
+ }
- /* Copy the correct gfid from resolved inode */
- gf_uuid_copy (CTR_DB_REC(ctr_local).gfid, inode->gfid);
+ /* if the lookup is for dht link donot record*/
+ if (dht_is_linkfile(buf, dict)) {
+ gf_msg_trace(this->name, 0,
+ "Ignoring Lookup "
+ "for dht link file");
+ goto out;
+ }
- /* Add hard link to the list */
- ret_val = add_hard_link_ctx (frame, this, inode);
- if (ret_val == CTR_CTX_ERROR) {
- gf_msg_trace (this->name, 0,
- "Failed adding hardlink to list");
- goto out;
- }
- /* If inode needs healing then heal the hardlink also */
- else if (ret_val & CTR_TRY_INODE_HEAL) {
- /* This marks inode heal */
- CTR_DB_REC(ctr_local).gfdb_fop_type = GFDB_FOP_CREATE_WRITE;
- _is_heal_needed = _gf_true;
- }
- /* If hardlink needs healing */
- else if (ret_val & CTR_TRY_HARDLINK_HEAL) {
- _is_heal_needed = _gf_true;
- }
+ ctr_local = frame->local;
+ /*Assign the proper inode type*/
+ ctr_local->ia_inode_type = inode->ia_type;
- /* If lookup heal needed */
- if (!_is_heal_needed)
- goto out;
+ /* Copy gfid directly from inode */
+ gf_uuid_copy(CTR_DB_REC(ctr_local).gfid, inode->gfid);
- /* FINALLY HEAL : Inserts the ctr_db_record populated by ctr_lookup_wind
- * in to the db. It also destroys the frame->local
- * created by ctr_lookup_wind */
- ret = ctr_lookup_unwind(frame, this);
- if (ret) {
- gf_msg_trace (this->name, 0,
- "Failed healing/inserting link");
- }
+ /* Checking if gfid and parent gfid is valid */
+ if (gf_uuid_is_null(CTR_DB_REC(ctr_local).gfid) ||
+ gf_uuid_is_null(CTR_DB_REC(ctr_local).pargfid)) {
+ gf_msg_trace(this->name, 0, "Invalid GFID");
+ goto out;
+ }
+
+ /* if its a first entry
+ * then mark the ctr_record for create
+ * A create will attempt a file and a hard link created in the db*/
+ ctr_xlator_ctx = get_ctr_xlator_ctx(this, inode);
+ if (!ctr_xlator_ctx) {
+ /* This marks inode heal */
+ CTR_DB_REC(ctr_local).gfdb_fop_type = GFDB_FOP_CREATE_WRITE;
+ _is_heal_needed = _gf_true;
+ }
+
+ /* Copy the correct gfid from resolved inode */
+ gf_uuid_copy(CTR_DB_REC(ctr_local).gfid, inode->gfid);
+
+ /* Add hard link to the list */
+ ret_val = add_hard_link_ctx(frame, this, inode);
+ if (ret_val == CTR_CTX_ERROR) {
+ gf_msg_trace(this->name, 0, "Failed adding hardlink to list");
+ goto out;
+ }
+ /* If inode needs healing then heal the hardlink also */
+ else if (ret_val & CTR_TRY_INODE_HEAL) {
+ /* This marks inode heal */
+ CTR_DB_REC(ctr_local).gfdb_fop_type = GFDB_FOP_CREATE_WRITE;
+ _is_heal_needed = _gf_true;
+ }
+ /* If hardlink needs healing */
+ else if (ret_val & CTR_TRY_HARDLINK_HEAL) {
+ _is_heal_needed = _gf_true;
+ }
+
+ /* If lookup heal needed */
+ if (!_is_heal_needed)
+ goto out;
+ /* FINALLY HEAL : Inserts the ctr_db_record populated by ctr_lookup_wind
+ * in to the db. It also destroys the frame->local
+ * created by ctr_lookup_wind */
+ ret = ctr_lookup_unwind(frame, this);
+ if (ret) {
+ gf_msg_trace(this->name, 0, "Failed healing/inserting link");
+ }
out:
- free_ctr_local ((gf_ctr_local_t *)frame->local);
- frame->local = NULL;
+ free_ctr_local((gf_ctr_local_t *)frame->local);
+ frame->local = NULL;
- STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf,
- dict, postparent);
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, buf, dict,
+ postparent);
- return 0;
+ return 0;
}
-
-
int32_t
-ctr_lookup (call_frame_t *frame, xlator_t *this,
- loc_t *loc, dict_t *xdata)
+ctr_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- gf_ctr_link_context_t ctr_link_cx;
- gf_ctr_link_context_t *_link_cx = &ctr_link_cx;
- int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ gf_ctr_link_context_t ctr_link_cx;
+ gf_ctr_link_context_t *_link_cx = &ctr_link_cx;
+ int ret = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
- GF_ASSERT(frame);
- GF_ASSERT(frame->root);
+ GF_ASSERT(frame);
+ GF_ASSERT(frame->root);
- /* Don't handle nameless lookups*/
- if (!loc->parent || !loc->name)
- goto out;
+ /* Don't handle nameless lookups*/
+ if (!loc->parent || !loc->name)
+ goto out;
- /*fill ctr link context*/
- FILL_CTR_LINK_CX(_link_cx, loc->parent->gfid, loc->name, out);
-
- /* Fill ctr inode context*/
- /* IA_IFREG : We assume its a file in the wind
- * but in the unwind we are sure what the inode is a file
- * or directory
- * gfid: we are just filling loc->gfid which is not correct.
- * In unwind we fill the correct gfid for successful lookup*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, IA_IFREG,
- loc->gfid, _link_cx, NULL,
- GFDB_FOP_DENTRY_WRITE, GFDB_FOP_WIND);
-
- /* Create the frame->local and populate ctr_db_record
- * No writing to the db yet */
- ret = ctr_lookup_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_LINK_WIND_FAILED,
- "Failed to insert link wind");
- }
+ /*fill ctr link context*/
+ FILL_CTR_LINK_CX(_link_cx, loc->parent->gfid, loc->name, out);
+
+ /* Fill ctr inode context*/
+ /* IA_IFREG : We assume its a file in the wind
+ * but in the unwind we are sure what the inode is a file
+ * or directory
+ * gfid: we are just filling loc->gfid which is not correct.
+ * In unwind we fill the correct gfid for successful lookup*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, IA_IFREG, loc->gfid, _link_cx, NULL,
+ GFDB_FOP_DENTRY_WRITE, GFDB_FOP_WIND);
+
+ /* Create the frame->local and populate ctr_db_record
+ * No writing to the db yet */
+ ret = ctr_lookup_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_LINK_WIND_FAILED,
+ "Failed to insert link wind");
+ }
out:
- STACK_WIND (frame, ctr_lookup_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->lookup, loc, xdata);
- return 0;
+ STACK_WIND(frame, ctr_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, loc, xdata);
+ return 0;
}
-
-
-
/****************************WRITEV********************************************/
int32_t
-ctr_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf,
- dict_t *xdata)
+ctr_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- int ret = -1;
-
- CTR_IS_DISABLED_THEN_GOTO (this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ int ret = -1;
- ret = ctr_insert_unwind (frame, this,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_WRITEV_UNWIND_FAILED,
- "Failed to insert writev unwind");
- }
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_WRITEV_UNWIND_FAILED,
+ "Failed to insert writev unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf,
- postbuf, xdata);
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
- return 0;
+ return 0;
}
int32_t
-ctr_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *vector, int32_t count, off_t off,
- uint32_t flags,
- struct iobref *iobref, dict_t *xdata)
+ctr_writev(call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector,
+ int32_t count, off_t off, uint32_t flags, struct iobref *iobref,
+ dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type,
- fd->inode->gfid, NULL, NULL,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type, fd->inode->gfid, NULL,
+ NULL, GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_WRITEV_WIND_FAILED,
- "Failed to insert writev wind");
- }
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_WRITEV_WIND_FAILED,
+ "Failed to insert writev wind");
+ }
out:
- STACK_WIND (frame, ctr_writev_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->writev, fd, vector, count,
- off, flags, iobref, xdata);
+ STACK_WIND(frame, ctr_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, vector, count, off, flags,
+ iobref, xdata);
- return 0;
+ return 0;
}
/******************************setattr*****************************************/
int32_t
-ctr_setattr_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, struct iatt *preop_stbuf,
- struct iatt *postop_stbuf, dict_t *xdata)
+ctr_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *preop_stbuf,
+ struct iatt *postop_stbuf, dict_t *xdata)
{
+ int ret = -1;
- int ret = -1;
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
-
- ret = ctr_insert_unwind(frame, this,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_SETATTR_UNWIND_FAILED,
- "Failed to insert setattr unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_SETATTR_UNWIND_FAILED,
+ "Failed to insert setattr unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno, preop_stbuf,
- postop_stbuf, xdata);
+ STACK_UNWIND_STRICT(setattr, frame, op_ret, op_errno, preop_stbuf,
+ postop_stbuf, xdata);
- return 0;
+ return 0;
}
int32_t
-ctr_setattr (call_frame_t *frame,
- xlator_t *this, loc_t *loc,
- struct iatt *stbuf, int32_t valid, dict_t *xdata)
+ctr_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc, struct iatt *stbuf,
+ int32_t valid, dict_t *xdata)
{
-
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
- CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO (this, out);
-
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type,
- loc->inode->gfid, NULL, NULL, GFDB_FOP_INODE_WRITE,
- GFDB_FOP_WIND);
-
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_SETATTR_WIND_FAILED,
- "Failed to insert setattr wind");
- }
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
+ CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO(this, out);
+
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type, loc->inode->gfid,
+ NULL, NULL, GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
+
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_SETATTR_WIND_FAILED,
+ "Failed to insert setattr wind");
+ }
out:
- STACK_WIND (frame, ctr_setattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setattr, loc, stbuf,
- valid, xdata);
+ STACK_WIND(frame, ctr_setattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid, xdata);
- return 0;
+ return 0;
}
/*************************** fsetattr ***************************************/
int32_t
-ctr_fsetattr_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, struct iatt *preop_stbuf,
- struct iatt *postop_stbuf, dict_t *xdata)
+ctr_fsetattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *preop_stbuf,
+ struct iatt *postop_stbuf, dict_t *xdata)
{
- int ret = -1;
+ int ret = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- ret = ctr_insert_unwind(frame, this,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_SETATTR_UNWIND_FAILED,
- "Failed to insert fsetattr unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_SETATTR_UNWIND_FAILED,
+ "Failed to insert fsetattr unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (fsetattr, frame, op_ret, op_errno,
- preop_stbuf, postop_stbuf, xdata);
+ STACK_UNWIND_STRICT(fsetattr, frame, op_ret, op_errno, preop_stbuf,
+ postop_stbuf, xdata);
- return 0;
+ return 0;
}
-
int32_t
-ctr_fsetattr (call_frame_t *frame,
- xlator_t *this, fd_t *fd,
- struct iatt *stbuf, int32_t valid, dict_t *xdata)
+ctr_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd, struct iatt *stbuf,
+ int32_t valid, dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
- CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO (this, out);
-
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type,
- fd->inode->gfid, NULL, NULL, GFDB_FOP_INODE_WRITE,
- GFDB_FOP_WIND);
-
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_SETATTR_WIND_FAILED,
- "Failed to insert fsetattr wind");
- }
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
+ CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO(this, out);
+
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type, fd->inode->gfid, NULL,
+ NULL, GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
+
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_SETATTR_WIND_FAILED,
+ "Failed to insert fsetattr wind");
+ }
out:
- STACK_WIND (frame, ctr_fsetattr_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->fsetattr,
- fd, stbuf, valid, xdata);
+ STACK_WIND(frame, ctr_fsetattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetattr, fd, stbuf, valid, xdata);
- return 0;
+ return 0;
}
/****************************fremovexattr************************************/
int32_t
-ctr_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+ctr_fremovexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- int ret = -1;
+ int ret = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- ret = ctr_insert_unwind(frame, this,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_FREMOVEXATTR_UNWIND_FAILED,
- "Failed to insert fremovexattr unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_FREMOVEXATTR_UNWIND_FAILED,
+ "Failed to insert fremovexattr unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (fremovexattr, frame, op_ret, op_errno, xdata);
+ STACK_UNWIND_STRICT(fremovexattr, frame, op_ret, op_errno, xdata);
- return 0;
+ return 0;
}
int32_t
-ctr_fremovexattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
- const char *name, dict_t *xdata)
+ctr_fremovexattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ const char *name, dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
- CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO (this, out);
-
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type,
- fd->inode->gfid, NULL, NULL, GFDB_FOP_INODE_WRITE,
- GFDB_FOP_WIND);
-
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_FREMOVEXATTR_WIND_FAILED,
- "Failed to insert fremovexattr wind");
- }
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
+ CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO(this, out);
+
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type, fd->inode->gfid, NULL,
+ NULL, GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
+
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_FREMOVEXATTR_WIND_FAILED,
+ "Failed to insert fremovexattr wind");
+ }
out:
- STACK_WIND (frame, ctr_fremovexattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->fremovexattr,
- fd, name, xdata);
- return 0;
+ STACK_WIND(frame, ctr_fremovexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fremovexattr, fd, name, xdata);
+ return 0;
}
/****************************removexattr*************************************/
int32_t
-ctr_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+ctr_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- int ret = -1;
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
+ int ret = -1;
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
- ret = ctr_insert_unwind(frame, this,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_REMOVEXATTR_UNWIND_FAILED,
- "Failed to insert removexattr unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_REMOVEXATTR_UNWIND_FAILED,
+ "Failed to insert removexattr unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno, xdata);
+ STACK_UNWIND_STRICT(removexattr, frame, op_ret, op_errno, xdata);
- return 0;
+ return 0;
}
int32_t
-ctr_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- const char *name, dict_t *xdata)
+ctr_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
- CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO (this, out);
-
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type,
- loc->inode->gfid, NULL, NULL, GFDB_FOP_INODE_WRITE,
- GFDB_FOP_WIND);
-
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_REMOVEXATTR_WIND_FAILED,
- "Failed to insert removexattr wind");
- }
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
+ CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO(this, out);
+
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type, loc->inode->gfid,
+ NULL, NULL, GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
+
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_REMOVEXATTR_WIND_FAILED,
+ "Failed to insert removexattr wind");
+ }
out:
- STACK_WIND (frame, ctr_removexattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->removexattr,
- loc, name, xdata);
- return 0;
+ STACK_WIND(frame, ctr_removexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr, loc, name, xdata);
+ return 0;
}
/****************************truncate****************************************/
int32_t
-ctr_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+ctr_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- int ret = -1;
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ int ret = -1;
- ret = ctr_insert_unwind(frame, this,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_TRUNCATE_UNWIND_FAILED,
- "Failed to insert truncate unwind");
- }
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_TRUNCATE_UNWIND_FAILED,
+ "Failed to insert truncate unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, prebuf,
- postbuf, xdata);
+ STACK_UNWIND_STRICT(truncate, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
- return 0;
+ return 0;
}
int32_t
-ctr_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc,
- off_t offset, dict_t *xdata)
+ctr_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
+ dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
-
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type,
- loc->inode->gfid, NULL, NULL, GFDB_FOP_INODE_WRITE,
- GFDB_FOP_WIND);
-
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_TRUNCATE_WIND_FAILED,
- "Failed to insert truncate wind");
- }
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
+
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type, loc->inode->gfid,
+ NULL, NULL, GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
+
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_TRUNCATE_WIND_FAILED,
+ "Failed to insert truncate wind");
+ }
out:
- STACK_WIND (frame, ctr_truncate_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->truncate,
- loc, offset, xdata);
- return 0;
+ STACK_WIND(frame, ctr_truncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
+ return 0;
}
/****************************ftruncate***************************************/
int32_t
-ctr_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+ctr_ftruncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- int ret = -1;
+ int ret = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- ret = ctr_insert_unwind(frame, this,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_FTRUNCATE_UNWIND_FAILED,
- "Failed to insert ftruncate unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_FTRUNCATE_UNWIND_FAILED,
+ "Failed to insert ftruncate unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, prebuf,
- postbuf, xdata);
+ STACK_UNWIND_STRICT(ftruncate, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
- return 0;
+ return 0;
}
int32_t
-ctr_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd,
- off_t offset, dict_t *xdata)
+ctr_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type,
- fd->inode->gfid, NULL, NULL, GFDB_FOP_INODE_WRITE,
- GFDB_FOP_WIND);
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type, fd->inode->gfid, NULL,
+ NULL, GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_FTRUNCATE_WIND_FAILED,
- "Failed to insert ftruncate wind");
- }
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_FTRUNCATE_WIND_FAILED,
+ "Failed to insert ftruncate wind");
+ }
out:
- STACK_WIND (frame, ctr_ftruncate_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->ftruncate,
- fd, offset, xdata);
- return 0;
+ STACK_WIND(frame, ctr_ftruncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
+ return 0;
}
/****************************rename******************************************/
int32_t
-ctr_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *buf,
- struct iatt *preoldparent, struct iatt *postoldparent,
- struct iatt *prenewparent, struct iatt *postnewparent,
- dict_t *xdata)
+ctr_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf,
+ struct iatt *preoldparent, struct iatt *postoldparent,
+ struct iatt *prenewparent, struct iatt *postnewparent,
+ dict_t *xdata)
{
- int ret = -1;
- uint32_t remaining_links = -1;
- gf_ctr_local_t *ctr_local = NULL;
- gfdb_fop_type_t fop_type = GFDB_FOP_INVALID_OP;
- gfdb_fop_path_t fop_path = GFDB_FOP_INVALID;
-
- GF_ASSERT(frame);
- GF_ASSERT(this);
-
- CTR_IS_DISABLED_THEN_GOTO (this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
-
- ret = ctr_insert_unwind (frame, this,
- GFDB_FOP_DENTRY_WRITE, GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_RENAME_UNWIND_FAILED,
- "Failed to insert rename unwind");
- goto out;
- }
-
- if (!xdata)
- goto out;
- /*
- *
- * Extracting GF_RESPONSE_LINK_COUNT_XDATA from POSIX Xlator
- * This is only set when we are overwriting hardlinks.
- *
- * */
- ret = dict_get_uint32 (xdata , GF_RESPONSE_LINK_COUNT_XDATA,
- &remaining_links);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_GET_CTR_RESPONSE_LINK_COUNT_XDATA_FAILED,
- "Failed to getting GF_RESPONSE_LINK_COUNT_XDATA");
- remaining_links = -1;
- goto out;
- }
+ int ret = -1;
+ uint32_t remaining_links = -1;
+ gf_ctr_local_t *ctr_local = NULL;
+ gfdb_fop_type_t fop_type = GFDB_FOP_INVALID_OP;
+ gfdb_fop_path_t fop_path = GFDB_FOP_INVALID;
+
+ GF_ASSERT(frame);
+ GF_ASSERT(this);
+
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
+
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_DENTRY_WRITE,
+ GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_RENAME_UNWIND_FAILED,
+ "Failed to insert rename unwind");
+ goto out;
+ }
- ctr_local = frame->local;
- if (!ctr_local) {
- gf_msg (this->name, GF_LOG_ERROR, 0, CTR_MSG_NULL_LOCAL,
- "ctr_local is NULL.");
- goto out;
- }
+ if (!xdata)
+ goto out;
+ /*
+ *
+ * Extracting GF_RESPONSE_LINK_COUNT_XDATA from POSIX Xlator
+ * This is only set when we are overwriting hardlinks.
+ *
+ * */
+ ret = dict_get_uint32(xdata, GF_RESPONSE_LINK_COUNT_XDATA,
+ &remaining_links);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_GET_CTR_RESPONSE_LINK_COUNT_XDATA_FAILED,
+ "Failed to getting GF_RESPONSE_LINK_COUNT_XDATA");
+ remaining_links = -1;
+ goto out;
+ }
- /* This is not the only link */
- if (remaining_links > 1) {
- fop_type = GFDB_FOP_DENTRY_WRITE;
- fop_path = GFDB_FOP_UNDEL;
- }
- /* Last link that was deleted */
- else if (remaining_links == 1) {
- fop_type = GFDB_FOP_DENTRY_WRITE;
- fop_path = GFDB_FOP_UNDEL_ALL;
- } else {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_RENAME_UNWIND_FAILED,
- "Invalid link count from posix");
- goto out;
- }
+ ctr_local = frame->local;
+ if (!ctr_local) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_NULL_LOCAL,
+ "ctr_local is NULL.");
+ goto out;
+ }
+
+ /* This is not the only link */
+ if (remaining_links > 1) {
+ fop_type = GFDB_FOP_DENTRY_WRITE;
+ fop_path = GFDB_FOP_UNDEL;
+ }
+ /* Last link that was deleted */
+ else if (remaining_links == 1) {
+ fop_type = GFDB_FOP_DENTRY_WRITE;
+ fop_path = GFDB_FOP_UNDEL_ALL;
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_RENAME_UNWIND_FAILED,
+ "Invalid link count from posix");
+ goto out;
+ }
- ret = ctr_delete_hard_link_from_db (this,
- CTR_DB_REC(ctr_local).old_gfid,
- CTR_DB_REC(ctr_local).pargfid,
- CTR_DB_REC(ctr_local).file_name,
- fop_type, fop_path);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_UNLINK_UNWIND_FAILED,
- "Failed to delete records of %s",
- CTR_DB_REC(ctr_local).old_file_name);
- }
+ ret = ctr_delete_hard_link_from_db(
+ this, CTR_DB_REC(ctr_local).old_gfid, CTR_DB_REC(ctr_local).pargfid,
+ CTR_DB_REC(ctr_local).file_name, fop_type, fop_path);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_UNLINK_UNWIND_FAILED,
+ "Failed to delete records of %s",
+ CTR_DB_REC(ctr_local).old_file_name);
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (rename, frame, op_ret, op_errno, buf,
- preoldparent, postoldparent, prenewparent,
- postnewparent,
- xdata);
+ STACK_UNWIND_STRICT(rename, frame, op_ret, op_errno, buf, preoldparent,
+ postoldparent, prenewparent, postnewparent, xdata);
- return 0;
+ return 0;
}
int32_t
-ctr_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
- loc_t *newloc, dict_t *xdata)
+ctr_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
+ dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- gf_ctr_link_context_t new_link_cx, old_link_cx;
- gf_ctr_link_context_t *_nlink_cx = &new_link_cx;
- gf_ctr_link_context_t *_olink_cx = &old_link_cx;
- int is_dict_created = 0;
- ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
-
- /*Fill old link context*/
- FILL_CTR_LINK_CX(_olink_cx, oldloc->pargfid, oldloc->name, out);
-
- /*Fill new link context*/
- FILL_CTR_LINK_CX(_nlink_cx, newloc->pargfid, newloc->name, out);
-
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, oldloc->inode->ia_type,
- oldloc->inode->gfid, _nlink_cx, _olink_cx,
- GFDB_FOP_DENTRY_WRITE, GFDB_FOP_WIND);
-
-
- /* If the rename is a overwrite of hardlink
- * rename ("file1", "file2")
- * file1 is hardlink for gfid say 00000000-0000-0000-0000-00000000000A
- * file2 is hardlink for gfid say 00000000-0000-0000-0000-00000000000B
- * so we are saving file2 gfid in old_gfid so that we delete entries
- * from the db during rename callback if the fop is successful
- * */
- if (newloc->inode) {
- /* This is the GFID from where the newloc hardlink will be
- * unlinked */
- _inode_cx->old_gfid = &newloc->inode->gfid;
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ gf_ctr_link_context_t new_link_cx, old_link_cx;
+ gf_ctr_link_context_t *_nlink_cx = &new_link_cx;
+ gf_ctr_link_context_t *_olink_cx = &old_link_cx;
+ int is_dict_created = 0;
+ ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
+
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
+
+ /*Fill old link context*/
+ FILL_CTR_LINK_CX(_olink_cx, oldloc->pargfid, oldloc->name, out);
+
+ /*Fill new link context*/
+ FILL_CTR_LINK_CX(_nlink_cx, newloc->pargfid, newloc->name, out);
+
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, oldloc->inode->ia_type,
+ oldloc->inode->gfid, _nlink_cx, _olink_cx,
+ GFDB_FOP_DENTRY_WRITE, GFDB_FOP_WIND);
+
+ /* If the rename is a overwrite of hardlink
+ * rename ("file1", "file2")
+ * file1 is hardlink for gfid say 00000000-0000-0000-0000-00000000000A
+ * file2 is hardlink for gfid say 00000000-0000-0000-0000-00000000000B
+ * so we are saving file2 gfid in old_gfid so that we delete entries
+ * from the db during rename callback if the fop is successful
+ * */
+ if (newloc->inode) {
+ /* This is the GFID from where the newloc hardlink will be
+ * unlinked */
+ _inode_cx->old_gfid = &newloc->inode->gfid;
+ }
+
+ /* Is a metatdata fop */
+ _inode_cx->is_metadata_fop = _gf_true;
+
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_RENAME_WIND_FAILED,
+ "Failed to insert rename wind");
+ } else {
+ /* We are doing updation of hard link in inode context in wind
+ * As we don't get the "inode" in the call back for rename */
+ ret = update_hard_link_ctx(frame, this, oldloc->inode);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_UPDATE_HARDLINK_FAILED,
+ "Failed "
+ "updating hard link in ctr inode context");
+ goto out;
}
- /* Is a metatdata fop */
- _inode_cx->is_metadata_fop = _gf_true;
-
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_RENAME_WIND_FAILED,
- "Failed to insert rename wind");
- } else {
- /* We are doing updation of hard link in inode context in wind
- * As we don't get the "inode" in the call back for rename */
- ret = update_hard_link_ctx (frame, this, oldloc->inode);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_UPDATE_HARDLINK_FAILED, "Failed "
- "updating hard link in ctr inode context");
- goto out;
- }
-
- /* If the newloc has an inode. i.e acquiring hardlink of an
- * exisitng file i.e overwritting a file.
- * */
- if (newloc->inode) {
-
- /* Getting the ctr inode context variable for
- * inode whose hardlink will be acquired during
- * the rename
- * */
- ctr_xlator_ctx = get_ctr_xlator_ctx (this,
- newloc->inode);
- if (!ctr_xlator_ctx) {
- /* Since there is no ctr inode context
- * so nothing more to do */
- ret = 0;
- goto out;
- }
-
- /* Deleting hardlink from context variable */
- ret = ctr_delete_hard_link (this, ctr_xlator_ctx,
- newloc->pargfid, newloc->name);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_DELETE_HARDLINK_FAILED,
- "Failed to delete hard link");
- goto out;
- }
-
- /* Requesting for number of hardlinks on the newloc
- * inode from POSIX.
- * */
- is_dict_created = set_posix_link_request (this, &xdata);
- if (is_dict_created == -1) {
- ret = -1;
- goto out;
- }
- }
+ /* If the newloc has an inode. i.e acquiring hardlink of an
+ * exisitng file i.e overwritting a file.
+ * */
+ if (newloc->inode) {
+ /* Getting the ctr inode context variable for
+ * inode whose hardlink will be acquired during
+ * the rename
+ * */
+ ctr_xlator_ctx = get_ctr_xlator_ctx(this, newloc->inode);
+ if (!ctr_xlator_ctx) {
+ /* Since there is no ctr inode context
+ * so nothing more to do */
+ ret = 0;
+ goto out;
+ }
+
+ /* Deleting hardlink from context variable */
+ ret = ctr_delete_hard_link(this, ctr_xlator_ctx, newloc->pargfid,
+ newloc->name);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_DELETE_HARDLINK_FAILED,
+ "Failed to delete hard link");
+ goto out;
+ }
+
+ /* Requesting for number of hardlinks on the newloc
+ * inode from POSIX.
+ * */
+ is_dict_created = set_posix_link_request(this, &xdata);
+ if (is_dict_created == -1) {
+ ret = -1;
+ goto out;
+ }
}
+ }
out:
- STACK_WIND (frame, ctr_rename_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->rename,
- oldloc, newloc, xdata);
+ STACK_WIND(frame, ctr_rename_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rename, oldloc, newloc, xdata);
- if (is_dict_created == 1) {
- dict_unref (xdata);
- }
+ if (is_dict_created == 1) {
+ dict_unref(xdata);
+ }
- return 0;
+ return 0;
}
/****************************unlink******************************************/
int32_t
-ctr_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+ctr_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- int ret = -1;
- uint32_t remaining_links = -1;
+ int ret = -1;
+ uint32_t remaining_links = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- if (!xdata)
- goto out;
+ if (!xdata)
+ goto out;
- /*
- *
- * Extracting GF_RESPONSE_LINK_COUNT_XDATA from POSIX Xlator
- *
- * */
- ret = dict_get_uint32 (xdata , GF_RESPONSE_LINK_COUNT_XDATA,
- &remaining_links);
+ /*
+ *
+ * Extracting GF_RESPONSE_LINK_COUNT_XDATA from POSIX Xlator
+ *
+ * */
+ ret = dict_get_uint32(xdata, GF_RESPONSE_LINK_COUNT_XDATA,
+ &remaining_links);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_GET_CTR_RESPONSE_LINK_COUNT_XDATA_FAILED,
+ "Failed to getting GF_RESPONSE_LINK_COUNT_XDATA");
+ remaining_links = -1;
+ }
+
+ /*This is not the only link*/
+ if (remaining_links != 1) {
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_DENTRY_WRITE,
+ GFDB_FOP_UNDEL);
if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_GET_CTR_RESPONSE_LINK_COUNT_XDATA_FAILED,
- "Failed to getting GF_RESPONSE_LINK_COUNT_XDATA");
- remaining_links = -1;
- }
-
- /*This is not the only link*/
- if (remaining_links != 1) {
-
- ret = ctr_insert_unwind(frame, this, GFDB_FOP_DENTRY_WRITE,
- GFDB_FOP_UNDEL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_UNLINK_UNWIND_FAILED,
- "Failed to insert unlink unwind");
- }
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_UNLINK_UNWIND_FAILED,
+ "Failed to insert unlink unwind");
}
- /*Last link that was deleted*/
- else if (remaining_links == 1) {
-
- ret = ctr_insert_unwind(frame, this, GFDB_FOP_DENTRY_WRITE,
- GFDB_FOP_UNDEL_ALL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_UNLINK_UNWIND_FAILED,
- "Failed to insert unlink unwind");
- }
+ }
+ /*Last link that was deleted*/
+ else if (remaining_links == 1) {
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_DENTRY_WRITE,
+ GFDB_FOP_UNDEL_ALL);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_INSERT_UNLINK_UNWIND_FAILED,
+ "Failed to insert unlink unwind");
}
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, preparent,
- postparent, xdata);
+ STACK_UNWIND_STRICT(unlink, frame, op_ret, op_errno, preparent, postparent,
+ xdata);
- return 0;
+ return 0;
}
int32_t
-ctr_unlink (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int xflag, dict_t *xdata)
+ctr_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
+ dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- gf_ctr_link_context_t ctr_link_cx;
- gf_ctr_link_context_t *_link_cx = &ctr_link_cx;
- gf_boolean_t is_xdata_created = _gf_false;
- struct iatt dummy_stat = {0};
-
- GF_ASSERT (frame);
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ gf_ctr_link_context_t ctr_link_cx;
+ gf_ctr_link_context_t *_link_cx = &ctr_link_cx;
+ gf_boolean_t is_xdata_created = _gf_false;
+ struct iatt dummy_stat = {0};
- CTR_IS_DISABLED_THEN_GOTO(this, out);
+ GF_ASSERT(frame);
- /*Fill link context*/
- FILL_CTR_LINK_CX(_link_cx, loc->pargfid, loc->name, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type,
- loc->inode->gfid, _link_cx, NULL,
- GFDB_FOP_DENTRY_WRITE, GFDB_FOP_WDEL);
+ /*Fill link context*/
+ FILL_CTR_LINK_CX(_link_cx, loc->pargfid, loc->name, out);
- /*Internal FOP*/
- _inode_cx->is_internal_fop = is_internal_fop (frame, xdata);
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type, loc->inode->gfid,
+ _link_cx, NULL, GFDB_FOP_DENTRY_WRITE,
+ GFDB_FOP_WDEL);
- /* Is a metadata FOP */
- _inode_cx->is_metadata_fop = _gf_true;
+ /*Internal FOP*/
+ _inode_cx->is_internal_fop = is_internal_fop(frame, xdata);
- /* If its a internal FOP and dht link file donot record*/
- if (_inode_cx->is_internal_fop &&
- dht_is_linkfile (&dummy_stat, xdata)) {
- goto out;
- }
+ /* Is a metadata FOP */
+ _inode_cx->is_metadata_fop = _gf_true;
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
+ /* If its a internal FOP and dht link file donot record*/
+ if (_inode_cx->is_internal_fop && dht_is_linkfile(&dummy_stat, xdata)) {
+ goto out;
+ }
+
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_UNLINK_UNWIND_FAILED,
+ "Failed to insert unlink wind");
+ } else {
+ /* We are doing delete of hard link in inode context in wind
+ * As we don't get the "inode" in the call back for rename */
+ ret = delete_hard_link_ctx(frame, this, loc->inode);
if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_UNLINK_UNWIND_FAILED,
- "Failed to insert unlink wind");
- } else {
- /* We are doing delete of hard link in inode context in wind
- * As we don't get the "inode" in the call back for rename */
- ret = delete_hard_link_ctx (frame, this, loc->inode);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_DELETE_HARDLINK_FAILED, "Failed "
- "deleting hard link from ctr inode context");
- }
- }
-
- /*
- *
- * Sending GF_REQUEST_LINK_COUNT_XDATA
- * to POSIX Xlator to send link count in unwind path
- *
- * */
- /*create xdata if NULL*/
- if (!xdata) {
- xdata = dict_new();
- is_xdata_created = (xdata) ? _gf_true : _gf_false;
- }
- if (!xdata) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_XDATA_NULL, "xdata is NULL :Cannot send "
- "GF_REQUEST_LINK_COUNT_XDATA to posix");
- goto out;
- }
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_DELETE_HARDLINK_FAILED,
+ "Failed "
+ "deleting hard link from ctr inode context");
+ }
+ }
+
+ /*
+ *
+ * Sending GF_REQUEST_LINK_COUNT_XDATA
+ * to POSIX Xlator to send link count in unwind path
+ *
+ * */
+ /*create xdata if NULL*/
+ if (!xdata) {
+ xdata = dict_new();
+ is_xdata_created = (xdata) ? _gf_true : _gf_false;
+ }
+ if (!xdata) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_XDATA_NULL,
+ "xdata is NULL :Cannot send "
+ "GF_REQUEST_LINK_COUNT_XDATA to posix");
+ goto out;
+ }
- ret = dict_set_int32 (xdata, GF_REQUEST_LINK_COUNT_XDATA, 1);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_SET_CTR_RESPONSE_LINK_COUNT_XDATA_FAILED,
- "Failed setting GF_REQUEST_LINK_COUNT_XDATA");
- if (is_xdata_created) {
- dict_unref (xdata);
- }
- goto out;
+ ret = dict_set_int32(xdata, GF_REQUEST_LINK_COUNT_XDATA, 1);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_SET_CTR_RESPONSE_LINK_COUNT_XDATA_FAILED,
+ "Failed setting GF_REQUEST_LINK_COUNT_XDATA");
+ if (is_xdata_created) {
+ dict_unref(xdata);
}
+ goto out;
+ }
out:
- STACK_WIND (frame, ctr_unlink_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->unlink,
- loc, xflag, xdata);
+ STACK_WIND(frame, ctr_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, loc, xflag, xdata);
- if (is_xdata_created)
- dict_unref (xdata);
+ if (is_xdata_created)
+ dict_unref(xdata);
- return 0;
+ return 0;
}
/****************************fsync******************************************/
int32_t
-ctr_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+ctr_fsync_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct iatt *prebuf, struct iatt *postbuf,
+ dict_t *xdata)
{
- int ret = -1;
+ int ret = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE,
- GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_FSYNC_UNWIND_FAILED,
- "Failed to insert fsync unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_FSYNC_UNWIND_FAILED,
+ "Failed to insert fsync unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, prebuf, postbuf,
- xdata);
+ STACK_UNWIND_STRICT(fsync, frame, op_ret, op_errno, prebuf, postbuf, xdata);
- return 0;
+ return 0;
}
int32_t
-ctr_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd,
- int32_t flags, dict_t *xdata)
+ctr_fsync(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags,
+ dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type,
- fd->inode->gfid, NULL, NULL,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type, fd->inode->gfid, NULL,
+ NULL, GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_FSYNC_WIND_FAILED,
- "Failed to insert fsync wind");
- }
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_FSYNC_WIND_FAILED,
+ "Failed to insert fsync wind");
+ }
out:
- STACK_WIND (frame, ctr_fsync_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->fsync,
- fd, flags, xdata);
- return 0;
+ STACK_WIND(frame, ctr_fsync_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsync, fd, flags, xdata);
+ return 0;
}
/****************************setxattr****************************************/
int
-ctr_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+ctr_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- int ret = -1;
+ int ret = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
- ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE,
- GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_FSYNC_UNWIND_FAILED,
- "Failed to insert setxattr unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_FSYNC_UNWIND_FAILED,
+ "Failed to insert setxattr unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata);
+ STACK_UNWIND_STRICT(setxattr, frame, op_ret, op_errno, xdata);
- return 0;
+ return 0;
}
int
-ctr_setxattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc, dict_t *xattr, int flags, dict_t *xdata)
+ctr_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr,
+ int flags, dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
- CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO (this, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
+ CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO(this, out);
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type,
- loc->inode->gfid, NULL, NULL,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type, loc->inode->gfid,
+ NULL, NULL, GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_SETATTR_WIND_FAILED,
- "Failed to insert setxattr wind");
- }
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_SETATTR_WIND_FAILED,
+ "Failed to insert setxattr wind");
+ }
out:
- STACK_WIND (frame, ctr_setxattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->setxattr,
- loc, xattr, flags, xdata);
- return 0;
+ STACK_WIND(frame, ctr_setxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, loc, xattr, flags, xdata);
+ return 0;
}
/**************************** fsetxattr *************************************/
int32_t
-ctr_fsetxattr_cbk (call_frame_t *frame,
- void *cookie, xlator_t *this, int32_t op_ret,
- int32_t op_errno, dict_t *xdata)
+ctr_fsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- int ret = -1;
+ int ret = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE,
- GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_FSYNC_UNWIND_FAILED,
- "Failed to insert fsetxattr unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_WRITE, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_FSYNC_UNWIND_FAILED,
+ "Failed to insert fsetxattr unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, xdata);
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, xdata);
- return 0;
+ return 0;
}
int32_t
-ctr_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
- int32_t flags, dict_t *xdata)
+ctr_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
+ int32_t flags, dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
- CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO (this, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
+ CTR_RECORD_METADATA_HEAT_IS_DISABLED_THEN_GOTO(this, out);
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type,
- fd->inode->gfid, NULL, NULL,
- GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type, fd->inode->gfid, NULL,
+ NULL, GFDB_FOP_INODE_WRITE, GFDB_FOP_WIND);
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_SETATTR_WIND_FAILED,
- "Failed to insert fsetxattr wind");
- }
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_SETATTR_WIND_FAILED,
+ "Failed to insert fsetxattr wind");
+ }
out:
- STACK_WIND (frame, ctr_fsetxattr_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->fsetxattr,
- fd, dict, flags, xdata);
- return 0;
+ STACK_WIND(frame, ctr_fsetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata);
+ return 0;
}
/****************************mknod*******************************************/
-
int32_t
-ctr_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+ctr_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, inode_t *inode, struct iatt *buf,
+ struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- int ret = -1;
- ctr_heal_ret_val_t ret_val = CTR_CTX_ERROR;
+ int ret = -1;
+ ctr_heal_ret_val_t ret_val = CTR_CTX_ERROR;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- /* Add hard link to the list */
- ret_val = add_hard_link_ctx (frame, this, inode);
- if (ret_val == CTR_CTX_ERROR) {
- gf_msg_trace (this->name, 0, "Failed adding hard link");
- }
+ /* Add hard link to the list */
+ ret_val = add_hard_link_ctx(frame, this, inode);
+ if (ret_val == CTR_CTX_ERROR) {
+ gf_msg_trace(this->name, 0, "Failed adding hard link");
+ }
- ret = ctr_insert_unwind(frame, this, GFDB_FOP_CREATE_WRITE,
- GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_MKNOD_UNWIND_FAILED,
- "Failed to insert mknod unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_CREATE_WRITE,
+ GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_MKNOD_UNWIND_FAILED,
+ "Failed to insert mknod unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (mknod, frame, op_ret, op_errno, inode, buf,
- preparent, postparent, xdata);
+ STACK_UNWIND_STRICT(mknod, frame, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
- return 0;
+ return 0;
}
-
int
-ctr_mknod (call_frame_t *frame, xlator_t *this,
- loc_t *loc, mode_t mode, dev_t rdev, mode_t umask, dict_t *xdata)
+ctr_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ dev_t rdev, mode_t umask, dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- gf_ctr_link_context_t ctr_link_cx;
- gf_ctr_link_context_t *_link_cx = &ctr_link_cx;
- uuid_t gfid = {0,};
- uuid_t *ptr_gfid = &gfid;
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
-
- GF_ASSERT(frame);
- GF_ASSERT(frame->root);
-
- /*get gfid from xdata dict*/
- ret = dict_get_gfuuid (xdata, "gfid-req", &gfid);
- if (ret) {
- gf_msg_debug (this->name, 0, "failed to get gfid from dict");
- goto out;
- }
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ gf_ctr_link_context_t ctr_link_cx;
+ gf_ctr_link_context_t *_link_cx = &ctr_link_cx;
+ uuid_t gfid = {
+ 0,
+ };
+ uuid_t *ptr_gfid = &gfid;
+
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
+
+ GF_ASSERT(frame);
+ GF_ASSERT(frame->root);
+
+ /*get gfid from xdata dict*/
+ ret = dict_get_gfuuid(xdata, "gfid-req", &gfid);
+ if (ret) {
+ gf_msg_debug(this->name, 0, "failed to get gfid from dict");
+ goto out;
+ }
- /*fill ctr link context*/
- FILL_CTR_LINK_CX (_link_cx, loc->pargfid, loc->name, out);
+ /*fill ctr link context*/
+ FILL_CTR_LINK_CX(_link_cx, loc->pargfid, loc->name, out);
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT (_inode_cx, loc->inode->ia_type,
- *ptr_gfid, _link_cx, NULL,
- GFDB_FOP_CREATE_WRITE, GFDB_FOP_WIND);
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type, *ptr_gfid, _link_cx,
+ NULL, GFDB_FOP_CREATE_WRITE, GFDB_FOP_WIND);
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_MKNOD_WIND_FAILED,
- "Failed to insert mknod wind");
- }
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_MKNOD_WIND_FAILED,
+ "Failed to insert mknod wind");
+ }
out:
- STACK_WIND (frame, ctr_mknod_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->mknod,
- loc, mode, rdev, umask, xdata);
- return 0;
+ STACK_WIND(frame, ctr_mknod_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mknod, loc, mode, rdev, umask, xdata);
+ return 0;
}
/****************************create******************************************/
int
-ctr_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno,
- fd_t *fd, inode_t *inode, struct iatt *stbuf,
- struct iatt *preparent, struct iatt *postparent,
- dict_t *xdata)
+ctr_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, fd_t *fd, inode_t *inode, struct iatt *stbuf,
+ struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- int ret = -1;
+ int ret = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- ret = add_hard_link_ctx (frame, this, inode);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_ADD_HARDLINK_FAILED,
- "Failed adding hard link");
- }
+ ret = add_hard_link_ctx(frame, this, inode);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_ADD_HARDLINK_FAILED,
+ "Failed adding hard link");
+ }
- ret = ctr_insert_unwind(frame, this, GFDB_FOP_CREATE_WRITE,
- GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_CREATE_UNWIND_FAILED,
- "Failed to insert create unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_CREATE_WRITE,
+ GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_CREATE_UNWIND_FAILED,
+ "Failed to insert create unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode,
- stbuf,
+ STACK_UNWIND_STRICT(create, frame, op_ret, op_errno, fd, inode, stbuf,
preparent, postparent, xdata);
- return 0;
+ return 0;
}
int
-ctr_create (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int32_t flags, mode_t mode,
- mode_t umask, fd_t *fd, dict_t *xdata)
+ctr_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- gf_ctr_link_context_t ctr_link_cx;
- gf_ctr_link_context_t *_link_cx = &ctr_link_cx;
- uuid_t gfid = {0,};
- uuid_t *ptr_gfid = &gfid;
- struct iatt dummy_stat = {0};
-
- CTR_IS_DISABLED_THEN_GOTO(this, out);
-
- GF_ASSERT(frame);
- GF_ASSERT(frame->root);
-
- /*Get GFID from Xdata dict*/
- ret = dict_get_gfuuid (xdata, "gfid-req", &gfid);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_GET_GFID_FROM_DICT_FAILED,
- "failed to get gfid from dict");
- goto out;
- }
-
- /*fill ctr link context*/
- FILL_CTR_LINK_CX(_link_cx, loc->pargfid, loc->name, out);
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ gf_ctr_link_context_t ctr_link_cx;
+ gf_ctr_link_context_t *_link_cx = &ctr_link_cx;
+ uuid_t gfid = {
+ 0,
+ };
+ uuid_t *ptr_gfid = &gfid;
+ struct iatt dummy_stat = {0};
+
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+
+ GF_ASSERT(frame);
+ GF_ASSERT(frame->root);
+
+ /*Get GFID from Xdata dict*/
+ ret = dict_get_gfuuid(xdata, "gfid-req", &gfid);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_GET_GFID_FROM_DICT_FAILED,
+ "failed to get gfid from dict");
+ goto out;
+ }
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type,
- *ptr_gfid, _link_cx, NULL,
- GFDB_FOP_CREATE_WRITE, GFDB_FOP_WIND);
+ /*fill ctr link context*/
+ FILL_CTR_LINK_CX(_link_cx, loc->pargfid, loc->name, out);
- /*Internal FOP*/
- _inode_cx->is_internal_fop = is_internal_fop (frame, xdata);
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, loc->inode->ia_type, *ptr_gfid, _link_cx,
+ NULL, GFDB_FOP_CREATE_WRITE, GFDB_FOP_WIND);
- /* If its a internal FOP and dht link file donot record*/
- if (_inode_cx->is_internal_fop &&
- dht_is_linkfile (&dummy_stat, xdata)) {
- goto out;
- }
+ /*Internal FOP*/
+ _inode_cx->is_internal_fop = is_internal_fop(frame, xdata);
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, &ctr_inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_CREATE_WIND_FAILED,
- "Failed to insert create wind");
- }
+ /* If its a internal FOP and dht link file donot record*/
+ if (_inode_cx->is_internal_fop && dht_is_linkfile(&dummy_stat, xdata)) {
+ goto out;
+ }
+
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, &ctr_inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_CREATE_WIND_FAILED,
+ "Failed to insert create wind");
+ }
out:
- STACK_WIND (frame, ctr_create_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->create,
- loc, flags, mode, umask, fd, xdata);
- return 0;
+ STACK_WIND(frame, ctr_create_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->create, loc, flags, mode, umask, fd,
+ xdata);
+ return 0;
}
/****************************link********************************************/
int
-ctr_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno,
- inode_t *inode, struct iatt *stbuf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+ctr_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, inode_t *inode, struct iatt *stbuf,
+ struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- int ret = -1;
+ int ret = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- /* Add hard link to the list */
- ret = add_hard_link_ctx (frame, this, inode);
- if (ret) {
- gf_msg_trace (this->name, 0, "Failed adding hard link");
- }
+ /* Add hard link to the list */
+ ret = add_hard_link_ctx(frame, this, inode);
+ if (ret) {
+ gf_msg_trace(this->name, 0, "Failed adding hard link");
+ }
- ret = ctr_insert_unwind(frame, this, GFDB_FOP_DENTRY_WRITE,
- GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_CREATE_UNWIND_FAILED,
- "Failed to insert create unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_DENTRY_WRITE,
+ GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_CREATE_UNWIND_FAILED,
+ "Failed to insert create unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (link, frame, op_ret, op_errno, inode, stbuf,
- preparent, postparent, xdata);
- return 0;
+ STACK_UNWIND_STRICT(link, frame, op_ret, op_errno, inode, stbuf, preparent,
+ postparent, xdata);
+ return 0;
}
int
-ctr_link (call_frame_t *frame, xlator_t *this,
- loc_t *oldloc, loc_t *newloc, dict_t *xdata)
+ctr_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
+ dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- gf_ctr_link_context_t ctr_link_cx;
- gf_ctr_link_context_t *_link_cx = &ctr_link_cx;
- struct iatt dummy_stat = {0};
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ gf_ctr_link_context_t ctr_link_cx;
+ gf_ctr_link_context_t *_link_cx = &ctr_link_cx;
+ struct iatt dummy_stat = {0};
- CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
- GF_ASSERT(frame);
- GF_ASSERT(frame->root);
+ GF_ASSERT(frame);
+ GF_ASSERT(frame->root);
- /*fill ctr link context*/
- FILL_CTR_LINK_CX(_link_cx, newloc->pargfid, newloc->name, out);
+ /*fill ctr link context*/
+ FILL_CTR_LINK_CX(_link_cx, newloc->pargfid, newloc->name, out);
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, oldloc->inode->ia_type,
- oldloc->inode->gfid, _link_cx, NULL,
- GFDB_FOP_DENTRY_WRITE, GFDB_FOP_WIND);
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, oldloc->inode->ia_type,
+ oldloc->inode->gfid, _link_cx, NULL,
+ GFDB_FOP_DENTRY_WRITE, GFDB_FOP_WIND);
- /*Internal FOP*/
- _inode_cx->is_internal_fop = is_internal_fop (frame, xdata);
+ /*Internal FOP*/
+ _inode_cx->is_internal_fop = is_internal_fop(frame, xdata);
- /* Is a metadata fop */
- _inode_cx->is_metadata_fop = _gf_true;
-
- /* If its a internal FOP and dht link file donot record*/
- if (_inode_cx->is_internal_fop &&
- dht_is_linkfile (&dummy_stat, xdata)) {
- goto out;
- }
+ /* Is a metadata fop */
+ _inode_cx->is_metadata_fop = _gf_true;
+ /* If its a internal FOP and dht link file donot record*/
+ if (_inode_cx->is_internal_fop && dht_is_linkfile(&dummy_stat, xdata)) {
+ goto out;
+ }
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_LINK_WIND_FAILED,
- "Failed to insert link wind");
- }
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_LINK_WIND_FAILED,
+ "Failed to insert link wind");
+ }
out:
- STACK_WIND (frame, ctr_link_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->link,
- oldloc, newloc, xdata);
- return 0;
+ STACK_WIND(frame, ctr_link_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata);
+ return 0;
}
/******************************readv*****************************************/
-int ctr_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno,
- struct iovec *vector, int count, struct iatt *stbuf,
- struct iobref *iobref, dict_t *xdata) {
-
- int ret = -1;
+int
+ctr_readv_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct iovec *vector, int count, struct iatt *stbuf,
+ struct iobref *iobref, dict_t *xdata)
+{
+ int ret = -1;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_FOP_FAILED_THEN_GOTO (this, op_ret, op_errno, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_FOP_FAILED_THEN_GOTO(this, op_ret, op_errno, out);
- ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_READ,
- GFDB_FOP_UNWIND);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_CREATE_UNWIND_FAILED,
- "Failed to insert create unwind");
- }
+ ret = ctr_insert_unwind(frame, this, GFDB_FOP_INODE_READ, GFDB_FOP_UNWIND);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_CREATE_UNWIND_FAILED,
+ "Failed to insert create unwind");
+ }
out:
- ctr_free_frame_local (frame);
+ ctr_free_frame_local(frame);
- STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector, count,
- stbuf, iobref, xdata);
- return 0;
+ STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, vector, count, stbuf,
+ iobref, xdata);
+ return 0;
}
-
int
-ctr_readv (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t off, uint32_t flags, dict_t *xdata)
+ctr_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, off_t off,
+ uint32_t flags, dict_t *xdata)
{
- int ret = -1;
- gf_ctr_inode_context_t ctr_inode_cx;
- gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
+ int ret = -1;
+ gf_ctr_inode_context_t ctr_inode_cx;
+ gf_ctr_inode_context_t *_inode_cx = &ctr_inode_cx;
- CTR_IS_DISABLED_THEN_GOTO(this, out);
- CTR_IF_INTERNAL_FOP_THEN_GOTO (frame, xdata, out);
+ CTR_IS_DISABLED_THEN_GOTO(this, out);
+ CTR_IF_INTERNAL_FOP_THEN_GOTO(frame, xdata, out);
- /*Fill ctr inode context*/
- FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type,
- fd->inode->gfid, NULL, NULL,
- GFDB_FOP_INODE_READ, GFDB_FOP_WIND);
+ /*Fill ctr inode context*/
+ FILL_CTR_INODE_CONTEXT(_inode_cx, fd->inode->ia_type, fd->inode->gfid, NULL,
+ NULL, GFDB_FOP_INODE_READ, GFDB_FOP_WIND);
- /*record into the database*/
- ret = ctr_insert_wind(frame, this, _inode_cx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INSERT_READV_WIND_FAILED,
- "Failed to insert readv wind");
- }
+ /*record into the database*/
+ ret = ctr_insert_wind(frame, this, _inode_cx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INSERT_READV_WIND_FAILED,
+ "Failed to insert readv wind");
+ }
out:
- STACK_WIND (frame, ctr_readv_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->readv,
- fd, size, off, flags, xdata);
- return 0;
+ STACK_WIND(frame, ctr_readv_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readv, fd, size, off, flags, xdata);
+ return 0;
}
/*******************************ctr_ipc****************************************/
/*This is the call back function per record/file from data base*/
static int
-ctr_db_query_callback (gfdb_query_record_t *gfdb_query_record,
- void *args) {
- int ret = -1;
- ctr_query_cbk_args_t *query_cbk_args = args;
+ctr_db_query_callback(gfdb_query_record_t *gfdb_query_record, void *args)
+{
+ int ret = -1;
+ ctr_query_cbk_args_t *query_cbk_args = args;
- GF_VALIDATE_OR_GOTO ("ctr", query_cbk_args, out);
+ GF_VALIDATE_OR_GOTO("ctr", query_cbk_args, out);
- ret = gfdb_write_query_record (query_cbk_args->query_fd,
- gfdb_query_record);
- if (ret) {
- gf_msg ("ctr", GF_LOG_ERROR, 0,
- CTR_MSG_FATAL_ERROR,
- "Failed to write to query file");
- goto out;
- }
+ ret = gfdb_write_query_record(query_cbk_args->query_fd, gfdb_query_record);
+ if (ret) {
+ gf_msg("ctr", GF_LOG_ERROR, 0, CTR_MSG_FATAL_ERROR,
+ "Failed to write to query file");
+ goto out;
+ }
- query_cbk_args->count++;
+ query_cbk_args->count++;
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
/* This function does all the db queries related to tiering and
@@ -1703,867 +1584,775 @@ out:
* On failure -1
* */
int
-ctr_db_query (xlator_t *this,
- void *conn_node,
- char *query_file,
- gfdb_ipc_ctr_params_t *ipc_ctr_params)
+ctr_db_query(xlator_t *this, void *conn_node, char *query_file,
+ gfdb_ipc_ctr_params_t *ipc_ctr_params)
{
- int ret = -1;
- ctr_query_cbk_args_t query_cbk_args = {0};
-
- GF_VALIDATE_OR_GOTO ("ctr", this, out);
- GF_VALIDATE_OR_GOTO (this->name, conn_node, out);
- GF_VALIDATE_OR_GOTO (this->name, query_file, out);
- GF_VALIDATE_OR_GOTO (this->name, ipc_ctr_params, out);
-
- /*Query for eligible files from db*/
- query_cbk_args.query_fd = open (query_file,
- O_WRONLY | O_CREAT | O_APPEND,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (query_cbk_args.query_fd < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CTR_MSG_FATAL_ERROR,
- "Failed to open query file %s", query_file);
- goto out;
- }
- if (!ipc_ctr_params->is_promote) {
- if (ipc_ctr_params->emergency_demote) {
- /* emergency demotion mode */
- ret = find_all (conn_node,
- ctr_db_query_callback,
- (void *)&query_cbk_args,
- ipc_ctr_params->query_limit);
- } else {
- if (ipc_ctr_params->write_freq_threshold == 0 &&
- ipc_ctr_params->read_freq_threshold == 0) {
- ret = find_unchanged_for_time (
- conn_node,
- ctr_db_query_callback,
- (void *)&query_cbk_args,
- &ipc_ctr_params->time_stamp);
- } else {
- ret = find_unchanged_for_time_freq (
- conn_node,
- ctr_db_query_callback,
- (void *)&query_cbk_args,
- &ipc_ctr_params->time_stamp,
- ipc_ctr_params->write_freq_threshold,
- ipc_ctr_params->read_freq_threshold,
- _gf_false);
- }
- }
+ int ret = -1;
+ ctr_query_cbk_args_t query_cbk_args = {0};
+
+ GF_VALIDATE_OR_GOTO("ctr", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, conn_node, out);
+ GF_VALIDATE_OR_GOTO(this->name, query_file, out);
+ GF_VALIDATE_OR_GOTO(this->name, ipc_ctr_params, out);
+
+ /*Query for eligible files from db*/
+ query_cbk_args.query_fd = open(query_file, O_WRONLY | O_CREAT | O_APPEND,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (query_cbk_args.query_fd < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, CTR_MSG_FATAL_ERROR,
+ "Failed to open query file %s", query_file);
+ goto out;
+ }
+ if (!ipc_ctr_params->is_promote) {
+ if (ipc_ctr_params->emergency_demote) {
+ /* emergency demotion mode */
+ ret = find_all(conn_node, ctr_db_query_callback,
+ (void *)&query_cbk_args,
+ ipc_ctr_params->query_limit);
} else {
- if (ipc_ctr_params->write_freq_threshold == 0 &&
- ipc_ctr_params->read_freq_threshold == 0) {
- ret = find_recently_changed_files (
- conn_node,
- ctr_db_query_callback,
- (void *)&query_cbk_args,
- &ipc_ctr_params->time_stamp);
- } else {
- ret = find_recently_changed_files_freq (
- conn_node,
- ctr_db_query_callback,
- (void *)&query_cbk_args,
- &ipc_ctr_params->time_stamp,
- ipc_ctr_params->write_freq_threshold,
- ipc_ctr_params->read_freq_threshold,
- _gf_false);
- }
- }
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_FATAL_ERROR,
- "FATAL: query from db failed");
- goto out;
- }
+ if (ipc_ctr_params->write_freq_threshold == 0 &&
+ ipc_ctr_params->read_freq_threshold == 0) {
+ ret = find_unchanged_for_time(conn_node, ctr_db_query_callback,
+ (void *)&query_cbk_args,
+ &ipc_ctr_params->time_stamp);
+ } else {
+ ret = find_unchanged_for_time_freq(
+ conn_node, ctr_db_query_callback, (void *)&query_cbk_args,
+ &ipc_ctr_params->time_stamp,
+ ipc_ctr_params->write_freq_threshold,
+ ipc_ctr_params->read_freq_threshold, _gf_false);
+ }
+ }
+ } else {
+ if (ipc_ctr_params->write_freq_threshold == 0 &&
+ ipc_ctr_params->read_freq_threshold == 0) {
+ ret = find_recently_changed_files(conn_node, ctr_db_query_callback,
+ (void *)&query_cbk_args,
+ &ipc_ctr_params->time_stamp);
+ } else {
+ ret = find_recently_changed_files_freq(
+ conn_node, ctr_db_query_callback, (void *)&query_cbk_args,
+ &ipc_ctr_params->time_stamp,
+ ipc_ctr_params->write_freq_threshold,
+ ipc_ctr_params->read_freq_threshold, _gf_false);
+ }
+ }
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_FATAL_ERROR,
+ "FATAL: query from db failed");
+ goto out;
+ }
- ret = clear_files_heat (conn_node);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_FATAL_ERROR,
- "FATAL: Failed to clear db entries");
- goto out;
- }
+ ret = clear_files_heat(conn_node);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_FATAL_ERROR,
+ "FATAL: Failed to clear db entries");
+ goto out;
+ }
- ret = 0;
+ ret = 0;
out:
- if (!ret)
- ret = query_cbk_args.count;
+ if (!ret)
+ ret = query_cbk_args.count;
- if (query_cbk_args.query_fd >= 0) {
- sys_close (query_cbk_args.query_fd);
- query_cbk_args.query_fd = -1;
- }
+ if (query_cbk_args.query_fd >= 0) {
+ sys_close(query_cbk_args.query_fd);
+ query_cbk_args.query_fd = -1;
+ }
- return ret;
+ return ret;
}
void *
-ctr_compact_thread (void *args)
+ctr_compact_thread(void *args)
{
- int ret = -1;
- void *db_conn = NULL;
+ int ret = -1;
+ void *db_conn = NULL;
- xlator_t *this = NULL;
- gf_ctr_private_t *priv = NULL;
- gf_boolean_t compact_active = _gf_false;
- gf_boolean_t compact_mode_switched = _gf_false;
+ xlator_t *this = NULL;
+ gf_ctr_private_t *priv = NULL;
+ gf_boolean_t compact_active = _gf_false;
+ gf_boolean_t compact_mode_switched = _gf_false;
- this = (xlator_t *)args;
+ this = (xlator_t *)args;
- GF_VALIDATE_OR_GOTO("ctr", this, out);
+ GF_VALIDATE_OR_GOTO("ctr", this, out);
- priv = this->private;
+ priv = this->private;
- db_conn = priv->_db_conn;
- compact_active = priv->compact_active;
- compact_mode_switched = priv->compact_mode_switched;
+ db_conn = priv->_db_conn;
+ compact_active = priv->compact_active;
+ compact_mode_switched = priv->compact_mode_switched;
- gf_msg ("ctr-compact", GF_LOG_INFO, 0, CTR_MSG_SET,
- "Starting compaction");
+ gf_msg("ctr-compact", GF_LOG_INFO, 0, CTR_MSG_SET, "Starting compaction");
- ret = compact_db(db_conn, compact_active,
- compact_mode_switched);
+ ret = compact_db(db_conn, compact_active, compact_mode_switched);
- if (ret) {
- gf_msg ("ctr-compact", GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed to perform the compaction");
- }
+ if (ret) {
+ gf_msg("ctr-compact", GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed to perform the compaction");
+ }
- ret = pthread_mutex_lock (&priv->compact_lock);
+ ret = pthread_mutex_lock(&priv->compact_lock);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed to acquire lock");
- goto out;
- }
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed to acquire lock");
+ goto out;
+ }
- /* We are done compaction on this brick. Set all flags to false */
- priv->compact_active = _gf_false;
- priv->compact_mode_switched = _gf_false;
+ /* We are done compaction on this brick. Set all flags to false */
+ priv->compact_active = _gf_false;
+ priv->compact_mode_switched = _gf_false;
- ret = pthread_mutex_unlock (&priv->compact_lock);
+ ret = pthread_mutex_unlock(&priv->compact_lock);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed to release lock");
- goto out;
- }
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed to release lock");
+ goto out;
+ }
out:
- return NULL;
+ return NULL;
}
int
-ctr_ipc_helper (xlator_t *this, dict_t *in_dict,
- dict_t *out_dict)
+ctr_ipc_helper(xlator_t *this, dict_t *in_dict, dict_t *out_dict)
{
- int ret = -1;
- char *ctr_ipc_ops = NULL;
- gf_ctr_private_t *priv = NULL;
- char *db_version = NULL;
- char *db_param_key = NULL;
- char *db_param = NULL;
- char *query_file = NULL;
- gfdb_ipc_ctr_params_t *ipc_ctr_params = NULL;
- int result = 0;
- pthread_t compact_thread;
-
- GF_VALIDATE_OR_GOTO ("ctr", this, out);
- GF_VALIDATE_OR_GOTO (this->name, this->private, out);
- priv = this->private;
- GF_VALIDATE_OR_GOTO (this->name, priv->_db_conn, out);
- GF_VALIDATE_OR_GOTO (this->name, in_dict, out);
- GF_VALIDATE_OR_GOTO (this->name, out_dict, out);
-
- GET_DB_PARAM_FROM_DICT(this->name, in_dict, GFDB_IPC_CTR_KEY,
- ctr_ipc_ops, out);
-
- /*if its a db clear operation */
- if (strncmp (ctr_ipc_ops, GFDB_IPC_CTR_CLEAR_OPS,
- SLEN (GFDB_IPC_CTR_CLEAR_OPS)) == 0) {
-
- ret = clear_files_heat (priv->_db_conn);
- if (ret)
- goto out;
-
- } /* if its a query operation, in which case its query + clear db*/
- else if (strncmp (ctr_ipc_ops, GFDB_IPC_CTR_QUERY_OPS,
- SLEN (GFDB_IPC_CTR_QUERY_OPS)) == 0) {
-
- ret = dict_get_str (in_dict, GFDB_IPC_CTR_GET_QFILE_PATH,
- &query_file);
- if (ret) {
- gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed extracting query file path");
- goto out;
- }
-
- ret = dict_get_bin (in_dict, GFDB_IPC_CTR_GET_QUERY_PARAMS,
- (void *)&ipc_ctr_params);
- if (ret) {
- gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed extracting query parameters");
- goto out;
- }
-
- ret = ctr_db_query (this, priv->_db_conn, query_file,
- ipc_ctr_params);
-
- ret = dict_set_int32 (out_dict,
- GFDB_IPC_CTR_RET_QUERY_COUNT, ret);
- if (ret) {
- gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed setting query reply");
- goto out;
- }
-
- } /* if its a query for db version */
- else if (strncmp (ctr_ipc_ops, GFDB_IPC_CTR_GET_DB_VERSION_OPS,
- SLEN (GFDB_IPC_CTR_GET_DB_VERSION_OPS)) == 0) {
-
- ret = get_db_version (priv->_db_conn, &db_version);
- if (ret == -1 || !db_version) {
- gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed extracting db version ");
- goto out;
- }
-
- SET_DB_PARAM_TO_DICT(this->name, out_dict,
- GFDB_IPC_CTR_RET_DB_VERSION,
- db_version, ret, error);
-
- } /* if its a query for a db setting */
- else if (strncmp (ctr_ipc_ops, GFDB_IPC_CTR_GET_DB_PARAM_OPS,
- SLEN (GFDB_IPC_CTR_GET_DB_PARAM_OPS)) == 0) {
-
- ret = dict_get_str (in_dict, GFDB_IPC_CTR_GET_DB_KEY,
- &db_param_key);
- if (ret) {
- gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed extracting db param key");
- goto out;
- }
-
- ret = get_db_params (priv->_db_conn, db_param_key, &db_param);
- if (ret == -1 || !db_param) {
- goto out;
- }
-
- SET_DB_PARAM_TO_DICT(this->name, out_dict,
- db_param_key,
- db_param, ret, error);
- } /* if its an attempt to compact the database */
- else if (strncmp (ctr_ipc_ops, GFDB_IPC_CTR_SET_COMPACT_PRAGMA,
- SLEN (GFDB_IPC_CTR_SET_COMPACT_PRAGMA)) == 0) {
-
- ret = pthread_mutex_lock (&priv->compact_lock);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed to acquire lock for compaction");
- goto out;
- }
-
- if ((priv->compact_active || priv->compact_mode_switched)) {
- /* Compaction in progress. LEAVE */
- gf_msg (this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Compaction already in progress.");
- pthread_mutex_unlock (&priv->compact_lock);
- goto out;
- }
- /* At this point, we should be the only one on the brick */
- /* compacting */
-
- /* Grab the arguments from the dictionary */
- ret = dict_get_int32 (in_dict, "compact_active", &result);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed to get compaction type");
- goto out;
- }
-
- if (result) {
- priv->compact_active = _gf_true;
- }
-
- ret = dict_get_int32 (in_dict, "compact_mode_switched"
- , &result);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed to see if compaction switched");
- goto out;
- }
-
- if (result) {
- priv->compact_mode_switched = _gf_true;
- gf_msg ("ctr-compact", GF_LOG_TRACE, 0, CTR_MSG_SET,
- "Pre-thread: Compact mode switch is true");
- } else {
- gf_msg ("ctr-compact", GF_LOG_TRACE, 0, CTR_MSG_SET,
- "Pre-thread: Compact mode switch is false");
- }
-
- ret = pthread_mutex_unlock (&priv->compact_lock);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed to release lock for compaction");
- goto out;
- }
-
- ret = gf_thread_create (&compact_thread, NULL,
- ctr_compact_thread, (void *)this,
- "ctrcomp");
-
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed to spawn compaction thread");
- goto out;
- }
+ int ret = -1;
+ char *ctr_ipc_ops = NULL;
+ gf_ctr_private_t *priv = NULL;
+ char *db_version = NULL;
+ char *db_param_key = NULL;
+ char *db_param = NULL;
+ char *query_file = NULL;
+ gfdb_ipc_ctr_params_t *ipc_ctr_params = NULL;
+ int result = 0;
+ pthread_t compact_thread;
+
+ GF_VALIDATE_OR_GOTO("ctr", this, out);
+ GF_VALIDATE_OR_GOTO(this->name, this->private, out);
+ priv = this->private;
+ GF_VALIDATE_OR_GOTO(this->name, priv->_db_conn, out);
+ GF_VALIDATE_OR_GOTO(this->name, in_dict, out);
+ GF_VALIDATE_OR_GOTO(this->name, out_dict, out);
+
+ GET_DB_PARAM_FROM_DICT(this->name, in_dict, GFDB_IPC_CTR_KEY, ctr_ipc_ops,
+ out);
+
+ /*if its a db clear operation */
+ if (strncmp(ctr_ipc_ops, GFDB_IPC_CTR_CLEAR_OPS,
+ SLEN(GFDB_IPC_CTR_CLEAR_OPS)) == 0) {
+ ret = clear_files_heat(priv->_db_conn);
+ if (ret)
+ goto out;
+
+ } /* if its a query operation, in which case its query + clear db*/
+ else if (strncmp(ctr_ipc_ops, GFDB_IPC_CTR_QUERY_OPS,
+ SLEN(GFDB_IPC_CTR_QUERY_OPS)) == 0) {
+ ret = dict_get_str(in_dict, GFDB_IPC_CTR_GET_QFILE_PATH, &query_file);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed extracting query file path");
+ goto out;
+ }
- goto out;
- } /* default case */
- else {
- goto out;
+ ret = dict_get_bin(in_dict, GFDB_IPC_CTR_GET_QUERY_PARAMS,
+ (void *)&ipc_ctr_params);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed extracting query parameters");
+ goto out;
}
- ret = 0;
- goto out;
-error:
- GF_FREE (db_param_key);
- GF_FREE (db_param);
- GF_FREE (db_version);
-out:
- return ret;
-}
+ ret = ctr_db_query(this, priv->_db_conn, query_file, ipc_ctr_params);
+ ret = dict_set_int32(out_dict, GFDB_IPC_CTR_RET_QUERY_COUNT, ret);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed setting query reply");
+ goto out;
+ }
-/* IPC Call from tier migrator to clear the heat on the DB */
-int32_t
-ctr_ipc (call_frame_t *frame, xlator_t *this, int32_t op,
- dict_t *in_dict)
-{
- int ret = -1;
- gf_ctr_private_t *priv = NULL;
- dict_t *out_dict = NULL;
+ } /* if its a query for db version */
+ else if (strncmp(ctr_ipc_ops, GFDB_IPC_CTR_GET_DB_VERSION_OPS,
+ SLEN(GFDB_IPC_CTR_GET_DB_VERSION_OPS)) == 0) {
+ ret = get_db_version(priv->_db_conn, &db_version);
+ if (ret == -1 || !db_version) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed extracting db version ");
+ goto out;
+ }
- GF_ASSERT(this);
- priv = this->private;
- GF_ASSERT (priv);
- GF_ASSERT(priv->_db_conn);
- GF_VALIDATE_OR_GOTO (this->name, in_dict, wind);
+ SET_DB_PARAM_TO_DICT(this->name, out_dict, GFDB_IPC_CTR_RET_DB_VERSION,
+ db_version, ret, error);
+ } /* if its a query for a db setting */
+ else if (strncmp(ctr_ipc_ops, GFDB_IPC_CTR_GET_DB_PARAM_OPS,
+ SLEN(GFDB_IPC_CTR_GET_DB_PARAM_OPS)) == 0) {
+ ret = dict_get_str(in_dict, GFDB_IPC_CTR_GET_DB_KEY, &db_param_key);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed extracting db param key");
+ goto out;
+ }
- if (op != GF_IPC_TARGET_CTR)
- goto wind;
+ ret = get_db_params(priv->_db_conn, db_param_key, &db_param);
+ if (ret == -1 || !db_param) {
+ goto out;
+ }
- out_dict = dict_new();
- if (!out_dict) {
- goto out;
+ SET_DB_PARAM_TO_DICT(this->name, out_dict, db_param_key, db_param, ret,
+ error);
+ } /* if its an attempt to compact the database */
+ else if (strncmp(ctr_ipc_ops, GFDB_IPC_CTR_SET_COMPACT_PRAGMA,
+ SLEN(GFDB_IPC_CTR_SET_COMPACT_PRAGMA)) == 0) {
+ ret = pthread_mutex_lock(&priv->compact_lock);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed to acquire lock for compaction");
+ goto out;
+ }
+
+ if ((priv->compact_active || priv->compact_mode_switched)) {
+ /* Compaction in progress. LEAVE */
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Compaction already in progress.");
+ pthread_mutex_unlock(&priv->compact_lock);
+ goto out;
}
+ /* At this point, we should be the only one on the brick */
+ /* compacting */
- ret = ctr_ipc_helper (this, in_dict, out_dict);
+ /* Grab the arguments from the dictionary */
+ ret = dict_get_int32(in_dict, "compact_active", &result);
if (ret) {
- gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
- "Failed in ctr_ipc_helper");
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed to get compaction type");
+ goto out;
}
-out:
- STACK_UNWIND_STRICT (ipc, frame, ret, 0, out_dict);
+ if (result) {
+ priv->compact_active = _gf_true;
+ }
- if (out_dict)
- dict_unref(out_dict);
+ ret = dict_get_int32(in_dict, "compact_mode_switched", &result);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed to see if compaction switched");
+ goto out;
+ }
- return 0;
+ if (result) {
+ priv->compact_mode_switched = _gf_true;
+ gf_msg("ctr-compact", GF_LOG_TRACE, 0, CTR_MSG_SET,
+ "Pre-thread: Compact mode switch is true");
+ } else {
+ gf_msg("ctr-compact", GF_LOG_TRACE, 0, CTR_MSG_SET,
+ "Pre-thread: Compact mode switch is false");
+ }
- wind:
- STACK_WIND (frame, default_ipc_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->ipc, op, in_dict);
+ ret = pthread_mutex_unlock(&priv->compact_lock);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed to release lock for compaction");
+ goto out;
+ }
+ ret = gf_thread_create(&compact_thread, NULL, ctr_compact_thread,
+ (void *)this, "ctrcomp");
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed to spawn compaction thread");
+ goto out;
+ }
- return 0;
-}
+ goto out;
+ } /* default case */
+ else {
+ goto out;
+ }
+ ret = 0;
+ goto out;
+error:
+ GF_FREE(db_param_key);
+ GF_FREE(db_param);
+ GF_FREE(db_version);
+out:
+ return ret;
+}
-/* Call to initialize db for ctr xlator while ctr is enabled */
+/* IPC Call from tier migrator to clear the heat on the DB */
int32_t
-initialize_ctr_resource (xlator_t *this, gf_ctr_private_t *priv)
+ctr_ipc(call_frame_t *frame, xlator_t *this, int32_t op, dict_t *in_dict)
{
- int ret_db = -1;
- dict_t *params_dict = NULL;
-
- if (!priv)
- goto error;
-
- /* For compaction */
- priv->compact_active = _gf_false;
- priv->compact_mode_switched = _gf_false;
- ret_db = pthread_mutex_init (&priv->compact_lock, NULL);
-
- if (ret_db) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_FATAL_ERROR,
- "FATAL: Failed initializing compaction mutex");
- goto error;
- }
+ int ret = -1;
+ gf_ctr_private_t *priv = NULL;
+ dict_t *out_dict = NULL;
- params_dict = dict_new ();
- if (!params_dict) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_INIT_DB_PARAMS_FAILED,
- "DB Params cannot initialized!");
- goto error;
- }
+ GF_ASSERT(this);
+ priv = this->private;
+ GF_ASSERT(priv);
+ GF_ASSERT(priv->_db_conn);
+ GF_VALIDATE_OR_GOTO(this->name, in_dict, wind);
- /*Extract db params options*/
- ret_db = extract_db_params(this, params_dict, priv->gfdb_db_type);
- if (ret_db) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_EXTRACT_DB_PARAM_OPTIONS_FAILED,
- "Failed extracting db params options");
- goto error;
- }
+ if (op != GF_IPC_TARGET_CTR)
+ goto wind;
- /*Create a memory pool for ctr xlator*/
- this->local_pool = mem_pool_new (gf_ctr_local_t, 64);
- if (!this->local_pool) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_CREATE_LOCAL_MEMORY_POOL_FAILED,
- "failed to create local memory pool");
- ret_db = -1;
- goto error;
- }
+ out_dict = dict_new();
+ if (!out_dict) {
+ goto out;
+ }
- /*Initialize Database Connection*/
- priv->_db_conn = init_db(params_dict, priv->gfdb_db_type);
- if (!priv->_db_conn) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_FATAL_ERROR,
- "FATAL: Failed initializing data base");
- ret_db = -1;
- goto error;
- }
+ ret = ctr_ipc_helper(this, in_dict, out_dict);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_SET,
+ "Failed in ctr_ipc_helper");
+ }
+out:
- ret_db = 0;
- goto out;
+ STACK_UNWIND_STRICT(ipc, frame, ret, 0, out_dict);
+
+ if (out_dict)
+ dict_unref(out_dict);
+
+ return 0;
+
+wind:
+ STACK_WIND(frame, default_ipc_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ipc, op, in_dict);
+
+ return 0;
+}
+
+/* Call to initialize db for ctr xlator while ctr is enabled */
+int32_t
+initialize_ctr_resource(xlator_t *this, gf_ctr_private_t *priv)
+{
+ int ret_db = -1;
+ dict_t *params_dict = NULL;
+
+ if (!priv)
+ goto error;
+
+ /* For compaction */
+ priv->compact_active = _gf_false;
+ priv->compact_mode_switched = _gf_false;
+ ret_db = pthread_mutex_init(&priv->compact_lock, NULL);
+
+ if (ret_db) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_FATAL_ERROR,
+ "FATAL: Failed initializing compaction mutex");
+ goto error;
+ }
+
+ params_dict = dict_new();
+ if (!params_dict) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_INIT_DB_PARAMS_FAILED,
+ "DB Params cannot initialized!");
+ goto error;
+ }
+
+ /*Extract db params options*/
+ ret_db = extract_db_params(this, params_dict, priv->gfdb_db_type);
+ if (ret_db) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_EXTRACT_DB_PARAM_OPTIONS_FAILED,
+ "Failed extracting db params options");
+ goto error;
+ }
+
+ /*Create a memory pool for ctr xlator*/
+ this->local_pool = mem_pool_new(gf_ctr_local_t, 64);
+ if (!this->local_pool) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_CREATE_LOCAL_MEMORY_POOL_FAILED,
+ "failed to create local memory pool");
+ ret_db = -1;
+ goto error;
+ }
+
+ /*Initialize Database Connection*/
+ priv->_db_conn = init_db(params_dict, priv->gfdb_db_type);
+ if (!priv->_db_conn) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_FATAL_ERROR,
+ "FATAL: Failed initializing data base");
+ ret_db = -1;
+ goto error;
+ }
+
+ ret_db = 0;
+ goto out;
error:
- if (this)
- mem_pool_destroy (this->local_pool);
+ if (this)
+ mem_pool_destroy(this->local_pool);
- if (priv) {
- GF_FREE (priv->ctr_db_path);
- }
- GF_FREE (priv);
+ if (priv) {
+ GF_FREE(priv->ctr_db_path);
+ }
+ GF_FREE(priv);
out:
- if (params_dict)
- dict_unref (params_dict);
+ if (params_dict)
+ dict_unref(params_dict);
- return ret_db;
+ return ret_db;
}
/******************************************************************************/
int
-reconfigure (xlator_t *this, dict_t *options)
+reconfigure(xlator_t *this, dict_t *options)
{
- char *temp_str = NULL;
- int ret = 0;
- gf_ctr_private_t *priv = NULL;
+ char *temp_str = NULL;
+ int ret = 0;
+ gf_ctr_private_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- if (dict_get_str(options, "changetimerecorder.frequency",
- &temp_str)) {
- gf_msg(this->name, GF_LOG_TRACE, 0, CTR_MSG_SET, "set");
- }
+ if (dict_get_str(options, "changetimerecorder.frequency", &temp_str)) {
+ gf_msg(this->name, GF_LOG_TRACE, 0, CTR_MSG_SET, "set");
+ }
- GF_OPTION_RECONF ("ctr-enabled", priv->enabled, options,
- bool, out);
- if (!priv->enabled) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_INFO, 0,
- CTR_MSG_XLATOR_DISABLED,
- "CTR Xlator is not enabled so skip ctr reconfigure");
- goto out;
+ GF_OPTION_RECONF("ctr-enabled", priv->enabled, options, bool, out);
+ if (!priv->enabled) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_INFO, 0, CTR_MSG_XLATOR_DISABLED,
+ "CTR Xlator is not enabled so skip ctr reconfigure");
+ goto out;
+ }
+
+ /* If ctr is enabled after skip init for ctr xlator then call
+ initialize_ctr_resource during reconfigure phase to allocate resources
+ for xlator
+ */
+ if (priv->enabled && !priv->_db_conn) {
+ ret = initialize_ctr_resource(this, priv);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_FATAL_ERROR,
+ "FATAL: Failed ctr initialize resource");
+ goto out;
}
+ }
- /* If ctr is enabled after skip init for ctr xlator then call
- initialize_ctr_resource during reconfigure phase to allocate resources for
- xlator
- */
- if (priv->enabled && !priv->_db_conn) {
- ret = initialize_ctr_resource (this, priv);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_FATAL_ERROR,
- "FATAL: Failed ctr initialize resource");
- goto out;
- }
- }
+ GF_OPTION_RECONF("record-counters", priv->ctr_record_counter, options, bool,
+ out);
- GF_OPTION_RECONF ("record-counters", priv->ctr_record_counter, options,
- bool, out);
-
- GF_OPTION_RECONF ("ctr-record-metadata-heat",
- priv->ctr_record_metadata_heat, options,
- bool, out);
-
- GF_OPTION_RECONF ("ctr_link_consistency", priv->ctr_link_consistency,
- options, bool, out);
-
- GF_OPTION_RECONF ("ctr_lookupheal_inode_timeout",
- priv->ctr_lookupheal_inode_timeout,
- options, uint64, out);
-
- GF_OPTION_RECONF ("ctr_lookupheal_link_timeout",
- priv->ctr_lookupheal_link_timeout,
- options, uint64, out);
-
- GF_OPTION_RECONF ("record-exit", priv->ctr_record_unwind, options,
- bool, out);
-
- GF_OPTION_RECONF ("record-entry", priv->ctr_record_wind, options,
- bool, out);
-
-
-
-
- /* If database is sqlite */
- if (priv->gfdb_db_type == GFDB_SQLITE3) {
-
- /* AUTOCHECKPOINT */
- if (dict_get_str (options, GFDB_SQL_PARAM_WAL_AUTOCHECK,
- &temp_str) == 0) {
- ret = set_db_params (priv->_db_conn,
- "wal_autocheckpoint", temp_str);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_SET_VALUE_TO_SQL_PARAM_FAILED,
- "Failed to set %s",
- GFDB_SQL_PARAM_WAL_AUTOCHECK);
- }
- }
-
- /* CACHE_SIZE */
- if (dict_get_str (options, GFDB_SQL_PARAM_CACHE_SIZE, &temp_str)
- == 0) {
- ret = set_db_params (priv->_db_conn, "cache_size",
- temp_str);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_SET_VALUE_TO_SQL_PARAM_FAILED,
- "Failed to set %s",
- GFDB_SQL_PARAM_CACHE_SIZE);
- }
- }
- }
+ GF_OPTION_RECONF("ctr-record-metadata-heat", priv->ctr_record_metadata_heat,
+ options, bool, out);
- ret = 0;
+ GF_OPTION_RECONF("ctr_link_consistency", priv->ctr_link_consistency,
+ options, bool, out);
-out:
+ GF_OPTION_RECONF("ctr_lookupheal_inode_timeout",
+ priv->ctr_lookupheal_inode_timeout, options, uint64, out);
- return ret;
-}
+ GF_OPTION_RECONF("ctr_lookupheal_link_timeout",
+ priv->ctr_lookupheal_link_timeout, options, uint64, out);
-/****************************init********************************************/
+ GF_OPTION_RECONF("record-exit", priv->ctr_record_unwind, options, bool,
+ out);
-int32_t
-init (xlator_t *this)
-{
- gf_ctr_private_t *priv = NULL;
- int ret_db = -1;
-
- if (!this) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_FATAL_ERROR,
- "FATAL: ctr this is not initialized");
- return -1;
- }
+ GF_OPTION_RECONF("record-entry", priv->ctr_record_wind, options, bool, out);
- if (!this->children || this->children->next) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_FATAL_ERROR,
- "FATAL: ctr should have exactly one child");
- return -1;
+ /* If database is sqlite */
+ if (priv->gfdb_db_type == GFDB_SQLITE3) {
+ /* AUTOCHECKPOINT */
+ if (dict_get_str(options, GFDB_SQL_PARAM_WAL_AUTOCHECK, &temp_str) ==
+ 0) {
+ ret = set_db_params(priv->_db_conn, "wal_autocheckpoint", temp_str);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_SET_VALUE_TO_SQL_PARAM_FAILED,
+ "Failed to set %s", GFDB_SQL_PARAM_WAL_AUTOCHECK);
+ }
}
- if (!this->parents) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CTR_MSG_DANGLING_VOLUME,
- "dangling volume. check volfile ");
+ /* CACHE_SIZE */
+ if (dict_get_str(options, GFDB_SQL_PARAM_CACHE_SIZE, &temp_str) == 0) {
+ ret = set_db_params(priv->_db_conn, "cache_size", temp_str);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_SET_VALUE_TO_SQL_PARAM_FAILED,
+ "Failed to set %s", GFDB_SQL_PARAM_CACHE_SIZE);
+ }
}
+ }
- priv = GF_CALLOC (1, sizeof (*priv), gf_ctr_mt_private_t);
- if (!priv) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
- CTR_MSG_CALLOC_FAILED,
- "Calloc did not work!!!");
- return -1;
- }
+ ret = 0;
- /*Default values for the translator*/
- priv->ctr_record_wind = _gf_true;
- priv->ctr_record_unwind = _gf_false;
- priv->ctr_hot_brick = _gf_false;
- priv->gfdb_db_type = GFDB_SQLITE3;
- priv->gfdb_sync_type = GFDB_DB_SYNC;
- priv->_db_conn = NULL;
- priv->ctr_lookupheal_link_timeout =
- CTR_DEFAULT_HARDLINK_EXP_PERIOD;
- priv->ctr_lookupheal_inode_timeout =
- CTR_DEFAULT_INODE_EXP_PERIOD;
-
- /*Extract ctr xlator options*/
- ret_db = extract_ctr_options (this, priv);
- if (ret_db) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_EXTRACT_CTR_XLATOR_OPTIONS_FAILED,
- "Failed extracting ctr xlator options");
- return -1;
- }
+out:
- if (!priv->enabled) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_INFO, 0,
- CTR_MSG_XLATOR_DISABLED,
- "CTR Xlator is not enabled so skip ctr init");
- goto out;
- }
+ return ret;
+}
- ret_db = initialize_ctr_resource (this, priv);
- if (ret_db) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_FATAL_ERROR,
- "FATAL: Failed ctr initialize resource");
- return -1;
- }
+/****************************init********************************************/
+
+int32_t
+init(xlator_t *this)
+{
+ gf_ctr_private_t *priv = NULL;
+ int ret_db = -1;
+
+ if (!this) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_FATAL_ERROR,
+ "FATAL: ctr this is not initialized");
+ return -1;
+ }
+
+ if (!this->children || this->children->next) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_FATAL_ERROR,
+ "FATAL: ctr should have exactly one child");
+ return -1;
+ }
+
+ if (!this->parents) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, CTR_MSG_DANGLING_VOLUME,
+ "dangling volume. check volfile ");
+ }
+
+ priv = GF_CALLOC(1, sizeof(*priv), gf_ctr_mt_private_t);
+ if (!priv) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, CTR_MSG_CALLOC_FAILED,
+ "Calloc did not work!!!");
+ return -1;
+ }
+
+ /*Default values for the translator*/
+ priv->ctr_record_wind = _gf_true;
+ priv->ctr_record_unwind = _gf_false;
+ priv->ctr_hot_brick = _gf_false;
+ priv->gfdb_db_type = GFDB_SQLITE3;
+ priv->gfdb_sync_type = GFDB_DB_SYNC;
+ priv->_db_conn = NULL;
+ priv->ctr_lookupheal_link_timeout = CTR_DEFAULT_HARDLINK_EXP_PERIOD;
+ priv->ctr_lookupheal_inode_timeout = CTR_DEFAULT_INODE_EXP_PERIOD;
+
+ /*Extract ctr xlator options*/
+ ret_db = extract_ctr_options(this, priv);
+ if (ret_db) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_EXTRACT_CTR_XLATOR_OPTIONS_FAILED,
+ "Failed extracting ctr xlator options");
+ return -1;
+ }
+
+ if (!priv->enabled) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_INFO, 0, CTR_MSG_XLATOR_DISABLED,
+ "CTR Xlator is not enabled so skip ctr init");
+ goto out;
+ }
+
+ ret_db = initialize_ctr_resource(this, priv);
+ if (ret_db) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_FATAL_ERROR,
+ "FATAL: Failed ctr initialize resource");
+ return -1;
+ }
out:
- this->private = (void *)priv;
- return 0;
+ this->private = (void *)priv;
+ return 0;
}
int
-notify (xlator_t *this, int event, void *data, ...)
+notify(xlator_t *this, int event, void *data, ...)
{
+ gf_ctr_private_t *priv = NULL;
+ int ret = 0;
- gf_ctr_private_t *priv = NULL;
- int ret = 0;
-
- priv = this->private;
+ priv = this->private;
- if (!priv)
- goto out;
+ if (!priv)
+ goto out;
- ret = default_notify (this, event, data);
+ ret = default_notify(this, event, data);
out:
- return ret;
-
+ return ret;
}
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int ret = -1;
+ int ret = -1;
- GF_VALIDATE_OR_GOTO ("ctr", this, out);
+ GF_VALIDATE_OR_GOTO("ctr", this, out);
- ret = xlator_mem_acct_init (this, gf_ctr_mt_end + 1);
+ ret = xlator_mem_acct_init(this, gf_ctr_mt_end + 1);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_MEM_ACC_INIT_FAILED, "Memory accounting init"
- "failed");
- return ret;
- }
-out:
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_MEM_ACC_INIT_FAILED,
+ "Memory accounting init"
+ "failed");
return ret;
+ }
+out:
+ return ret;
}
-
void
-fini (xlator_t *this)
+fini(xlator_t *this)
{
- gf_ctr_private_t *priv = NULL;
-
- priv = this->private;
-
- if (priv && priv->enabled) {
- if (fini_db (priv->_db_conn)) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CTR_MSG_CLOSE_DB_CONN_FAILED, "Failed closing "
- "db connection");
- }
-
- if (priv->_db_conn)
- priv->_db_conn = NULL;
-
- GF_FREE (priv->ctr_db_path);
- if (pthread_mutex_destroy (&priv->compact_lock)) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- CTR_MSG_CLOSE_DB_CONN_FAILED, "Failed to "
- "destroy the compaction mutex");
- }
+ gf_ctr_private_t *priv = NULL;
+
+ priv = this->private;
+
+ if (priv && priv->enabled) {
+ if (fini_db(priv->_db_conn)) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, CTR_MSG_CLOSE_DB_CONN_FAILED,
+ "Failed closing "
+ "db connection");
}
- GF_FREE (priv);
- mem_pool_destroy (this->local_pool);
- this->local_pool = NULL;
- return;
+ if (priv->_db_conn)
+ priv->_db_conn = NULL;
+
+ GF_FREE(priv->ctr_db_path);
+ if (pthread_mutex_destroy(&priv->compact_lock)) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, CTR_MSG_CLOSE_DB_CONN_FAILED,
+ "Failed to "
+ "destroy the compaction mutex");
+ }
+ }
+ GF_FREE(priv);
+ mem_pool_destroy(this->local_pool);
+ this->local_pool = NULL;
+
+ return;
}
struct xlator_fops fops = {
- /*lookup*/
- .lookup = ctr_lookup,
- /*write fops */
- .mknod = ctr_mknod,
- .create = ctr_create,
- .truncate = ctr_truncate,
- .ftruncate = ctr_ftruncate,
- .setxattr = ctr_setxattr,
- .fsetxattr = ctr_fsetxattr,
- .removexattr = ctr_removexattr,
- .fremovexattr = ctr_fremovexattr,
- .unlink = ctr_unlink,
- .link = ctr_link,
- .rename = ctr_rename,
- .writev = ctr_writev,
- .setattr = ctr_setattr,
- .fsetattr = ctr_fsetattr,
- /*read fops*/
- .readv = ctr_readv,
- /* IPC call*/
- .ipc = ctr_ipc
-};
-
-struct xlator_cbks cbks = {
- .forget = ctr_forget
-};
+ /*lookup*/
+ .lookup = ctr_lookup,
+ /*write fops */
+ .mknod = ctr_mknod,
+ .create = ctr_create,
+ .truncate = ctr_truncate,
+ .ftruncate = ctr_ftruncate,
+ .setxattr = ctr_setxattr,
+ .fsetxattr = ctr_fsetxattr,
+ .removexattr = ctr_removexattr,
+ .fremovexattr = ctr_fremovexattr,
+ .unlink = ctr_unlink,
+ .link = ctr_link,
+ .rename = ctr_rename,
+ .writev = ctr_writev,
+ .setattr = ctr_setattr,
+ .fsetattr = ctr_fsetattr,
+ /*read fops*/
+ .readv = ctr_readv,
+ /* IPC call*/
+ .ipc = ctr_ipc};
+
+struct xlator_cbks cbks = {.forget = ctr_forget};
struct volume_options options[] = {
- { .key = {"ctr-enabled",},
- .type = GF_OPTION_TYPE_BOOL,
- .value = {"on", "off"},
- .default_value = "off",
- .description = "Enables the CTR",
- .flags = OPT_FLAG_SETTABLE
- },
- { .key = {"record-entry"},
- .type = GF_OPTION_TYPE_BOOL,
- .value = {"on", "off"},
- .default_value = "on"
- },
- { .key = {"record-exit"},
- .type = GF_OPTION_TYPE_BOOL,
- .value = {"on", "off"},
- .default_value = "off"
- },
- { .key = {"record-counters"},
- .type = GF_OPTION_TYPE_BOOL,
- .value = {"on", "off"},
- .default_value = "off",
- .op_version = {GD_OP_VERSION_3_7_0},
- .flags = OPT_FLAG_SETTABLE,
- .tags = {}
- },
- { .key = {"ctr-record-metadata-heat"},
- .type = GF_OPTION_TYPE_BOOL,
- .value = {"on", "off"},
- .default_value = "off",
- .flags = OPT_FLAG_SETTABLE,
- .op_version = {GD_OP_VERSION_3_7_0},
- .tags = {}
- },
- { .key = {"ctr_link_consistency"},
- .type = GF_OPTION_TYPE_BOOL,
- .value = {"on", "off"},
- .default_value = "off",
- .flags = OPT_FLAG_SETTABLE,
- .op_version = {GD_OP_VERSION_3_7_0},
- .tags = {}
- },
- { .key = {"ctr_lookupheal_link_timeout"},
- .type = GF_OPTION_TYPE_INT,
- .default_value = "300",
- .flags = OPT_FLAG_SETTABLE,
- .op_version = {GD_OP_VERSION_3_7_2},
- .tags = {}
- },
- { .key = {"ctr_lookupheal_inode_timeout"},
- .type = GF_OPTION_TYPE_INT,
- .default_value = "300",
- .flags = OPT_FLAG_SETTABLE,
- .op_version = {GD_OP_VERSION_3_7_2},
- .tags = {}
- },
- { .key = {"hot-brick"},
- .type = GF_OPTION_TYPE_BOOL,
- .value = {"on", "off"},
- .default_value = "off"
- },
- { .key = {"db-type"},
- .type = GF_OPTION_TYPE_STR,
- .value = {"hashfile", "rocksdb", "changelog", "sqlite3",
- "hyperdex"},
- .default_value = "sqlite3",
- .op_version = {GD_OP_VERSION_3_7_0},
- .flags = OPT_FLAG_SETTABLE,
- .tags = {}
- },
- { .key = {"db-sync"},
- .type = GF_OPTION_TYPE_STR,
- .value = {"sync", "async"},
- .default_value = "sync"
- },
- { .key = {"db-path"},
- .type = GF_OPTION_TYPE_PATH
- },
- { .key = {"db-name"},
- .type = GF_OPTION_TYPE_STR
- },
- { .key = {GFDB_SQL_PARAM_SYNC},
- .type = GF_OPTION_TYPE_STR,
- .value = {"off", "normal", "full"},
- .default_value = "normal"
- },
- { .key = {GFDB_SQL_PARAM_JOURNAL_MODE},
- .type = GF_OPTION_TYPE_STR,
- .value = {"delete", "truncate", "persist", "memory", "wal", "off"},
- .default_value = "wal",
- .flags = OPT_FLAG_SETTABLE,
- .op_version = {GD_OP_VERSION_3_7_0},
- .tags = {}
- },
- { .key = {GFDB_SQL_PARAM_AUTO_VACUUM},
- .type = GF_OPTION_TYPE_STR,
- .value = {"off", "full", "incr"},
- .default_value = "off",
- .flags = OPT_FLAG_SETTABLE,
- .op_version = {GD_OP_VERSION_3_7_0},
- .tags = {}
- },
- { .key = {GFDB_SQL_PARAM_WAL_AUTOCHECK},
- .type = GF_OPTION_TYPE_INT,
- .default_value = "25000",
- .flags = OPT_FLAG_SETTABLE,
- .op_version = {GD_OP_VERSION_3_7_0},
- .tags = {}
- },
- { .key = {GFDB_SQL_PARAM_CACHE_SIZE},
- .type = GF_OPTION_TYPE_INT,
- .default_value = "12500",
- .flags = OPT_FLAG_SETTABLE,
- .op_version = {GD_OP_VERSION_3_7_0},
- .tags = {}
- },
- { .key = {GFDB_SQL_PARAM_PAGE_SIZE},
- .type = GF_OPTION_TYPE_INT,
- .default_value = "4096",
- .flags = OPT_FLAG_SETTABLE,
- .op_version = {GD_OP_VERSION_3_7_0},
- .tags = {}
- },
- { .key = {NULL} },
+ {.key =
+ {
+ "ctr-enabled",
+ },
+ .type = GF_OPTION_TYPE_BOOL,
+ .value = {"on", "off"},
+ .default_value = "off",
+ .description = "Enables the CTR",
+ .flags = OPT_FLAG_SETTABLE},
+ {.key = {"record-entry"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .value = {"on", "off"},
+ .default_value = "on"},
+ {.key = {"record-exit"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .value = {"on", "off"},
+ .default_value = "off"},
+ {.key = {"record-counters"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .value = {"on", "off"},
+ .default_value = "off",
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .flags = OPT_FLAG_SETTABLE,
+ .tags = {}},
+ {.key = {"ctr-record-metadata-heat"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .value = {"on", "off"},
+ .default_value = "off",
+ .flags = OPT_FLAG_SETTABLE,
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .tags = {}},
+ {.key = {"ctr_link_consistency"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .value = {"on", "off"},
+ .default_value = "off",
+ .flags = OPT_FLAG_SETTABLE,
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .tags = {}},
+ {.key = {"ctr_lookupheal_link_timeout"},
+ .type = GF_OPTION_TYPE_INT,
+ .default_value = "300",
+ .flags = OPT_FLAG_SETTABLE,
+ .op_version = {GD_OP_VERSION_3_7_2},
+ .tags = {}},
+ {.key = {"ctr_lookupheal_inode_timeout"},
+ .type = GF_OPTION_TYPE_INT,
+ .default_value = "300",
+ .flags = OPT_FLAG_SETTABLE,
+ .op_version = {GD_OP_VERSION_3_7_2},
+ .tags = {}},
+ {.key = {"hot-brick"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .value = {"on", "off"},
+ .default_value = "off"},
+ {.key = {"db-type"},
+ .type = GF_OPTION_TYPE_STR,
+ .value = {"hashfile", "rocksdb", "changelog", "sqlite3", "hyperdex"},
+ .default_value = "sqlite3",
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .flags = OPT_FLAG_SETTABLE,
+ .tags = {}},
+ {.key = {"db-sync"},
+ .type = GF_OPTION_TYPE_STR,
+ .value = {"sync", "async"},
+ .default_value = "sync"},
+ {.key = {"db-path"}, .type = GF_OPTION_TYPE_PATH},
+ {.key = {"db-name"}, .type = GF_OPTION_TYPE_STR},
+ {.key = {GFDB_SQL_PARAM_SYNC},
+ .type = GF_OPTION_TYPE_STR,
+ .value = {"off", "normal", "full"},
+ .default_value = "normal"},
+ {.key = {GFDB_SQL_PARAM_JOURNAL_MODE},
+ .type = GF_OPTION_TYPE_STR,
+ .value = {"delete", "truncate", "persist", "memory", "wal", "off"},
+ .default_value = "wal",
+ .flags = OPT_FLAG_SETTABLE,
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .tags = {}},
+ {.key = {GFDB_SQL_PARAM_AUTO_VACUUM},
+ .type = GF_OPTION_TYPE_STR,
+ .value = {"off", "full", "incr"},
+ .default_value = "off",
+ .flags = OPT_FLAG_SETTABLE,
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .tags = {}},
+ {.key = {GFDB_SQL_PARAM_WAL_AUTOCHECK},
+ .type = GF_OPTION_TYPE_INT,
+ .default_value = "25000",
+ .flags = OPT_FLAG_SETTABLE,
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .tags = {}},
+ {.key = {GFDB_SQL_PARAM_CACHE_SIZE},
+ .type = GF_OPTION_TYPE_INT,
+ .default_value = "12500",
+ .flags = OPT_FLAG_SETTABLE,
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .tags = {}},
+ {.key = {GFDB_SQL_PARAM_PAGE_SIZE},
+ .type = GF_OPTION_TYPE_INT,
+ .default_value = "4096",
+ .flags = OPT_FLAG_SETTABLE,
+ .op_version = {GD_OP_VERSION_3_7_0},
+ .tags = {}},
+ {.key = {NULL}},
};
diff --git a/xlators/features/changetimerecorder/src/ctr-helper.c b/xlators/features/changetimerecorder/src/ctr-helper.c
index 5a409c2b65e..e1e65735cef 100644
--- a/xlators/features/changetimerecorder/src/ctr-helper.c
+++ b/xlators/features/changetimerecorder/src/ctr-helper.c
@@ -18,146 +18,137 @@
*
******************************************************************************/
int
-fill_db_record_for_unwind(xlator_t *this,
- gf_ctr_local_t *ctr_local,
- gfdb_fop_type_t fop_type,
- gfdb_fop_path_t fop_path)
+fill_db_record_for_unwind(xlator_t *this, gf_ctr_local_t *ctr_local,
+ gfdb_fop_type_t fop_type, gfdb_fop_path_t fop_path)
{
- int ret = -1;
- gfdb_time_t *ctr_uwtime = NULL;
- gf_ctr_private_t *_priv = NULL;
-
- GF_ASSERT (this);
- _priv = this->private;
- GF_ASSERT (_priv);
-
- GF_ASSERT(ctr_local);
-
- /*If not unwind path error*/
- if (!isunwindpath(fop_path)) {
- gf_msg (this->name, GF_LOG_ERROR, 0, CTR_MSG_WRONG_FOP_PATH,
- "Wrong fop_path. Should be unwind");
- goto out;
- }
-
- ctr_uwtime = &CTR_DB_REC(ctr_local).gfdb_unwind_change_time;
- CTR_DB_REC(ctr_local).gfdb_fop_path = fop_path;
- CTR_DB_REC(ctr_local).gfdb_fop_type = fop_type;
-
- ret = gettimeofday (ctr_uwtime, NULL);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CTR_MSG_FILL_UNWIND_TIME_REC_ERROR, "Error "
- "filling unwind time record %s",
- strerror(errno));
- goto out;
- }
-
- /* Special case i.e if its a tier rebalance
- * + cold tier brick
- * + its a create/mknod FOP
- * we record unwind time as zero */
- if (ctr_local->client_pid == GF_CLIENT_PID_TIER_DEFRAG
- && (!_priv->ctr_hot_brick)
- && isdentrycreatefop(fop_type)) {
- memset(ctr_uwtime, 0, sizeof(*ctr_uwtime));
- }
- ret = 0;
+ int ret = -1;
+ gfdb_time_t *ctr_uwtime = NULL;
+ gf_ctr_private_t *_priv = NULL;
+
+ GF_ASSERT(this);
+ _priv = this->private;
+ GF_ASSERT(_priv);
+
+ GF_ASSERT(ctr_local);
+
+ /*If not unwind path error*/
+ if (!isunwindpath(fop_path)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_WRONG_FOP_PATH,
+ "Wrong fop_path. Should be unwind");
+ goto out;
+ }
+
+ ctr_uwtime = &CTR_DB_REC(ctr_local).gfdb_unwind_change_time;
+ CTR_DB_REC(ctr_local).gfdb_fop_path = fop_path;
+ CTR_DB_REC(ctr_local).gfdb_fop_type = fop_type;
+
+ ret = gettimeofday(ctr_uwtime, NULL);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CTR_MSG_FILL_UNWIND_TIME_REC_ERROR,
+ "Error "
+ "filling unwind time record %s",
+ strerror(errno));
+ goto out;
+ }
+
+ /* Special case i.e if its a tier rebalance
+ * + cold tier brick
+ * + its a create/mknod FOP
+ * we record unwind time as zero */
+ if (ctr_local->client_pid == GF_CLIENT_PID_TIER_DEFRAG &&
+ (!_priv->ctr_hot_brick) && isdentrycreatefop(fop_type)) {
+ memset(ctr_uwtime, 0, sizeof(*ctr_uwtime));
+ }
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
/*******************************************************************************
*
* Fill wind into db record
*
******************************************************************************/
int
-fill_db_record_for_wind (xlator_t *this,
- gf_ctr_local_t *ctr_local,
- gf_ctr_inode_context_t *ctr_inode_cx)
+fill_db_record_for_wind(xlator_t *this, gf_ctr_local_t *ctr_local,
+ gf_ctr_inode_context_t *ctr_inode_cx)
{
- int ret = -1;
- gfdb_time_t *ctr_wtime = NULL;
- gf_ctr_private_t *_priv = NULL;
-
- GF_ASSERT (this);
- _priv = this->private;
- GF_ASSERT (_priv);
- GF_ASSERT (ctr_local);
- IS_CTR_INODE_CX_SANE (ctr_inode_cx);
-
- /*if not wind path error!*/
- if (!iswindpath(ctr_inode_cx->fop_path)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_WRONG_FOP_PATH,
- "Wrong fop_path. Should be wind");
- goto out;
- }
-
- ctr_wtime = &CTR_DB_REC(ctr_local).gfdb_wind_change_time;
- CTR_DB_REC(ctr_local).gfdb_fop_path = ctr_inode_cx->fop_path;
- CTR_DB_REC(ctr_local).gfdb_fop_type = ctr_inode_cx->fop_type;
- CTR_DB_REC(ctr_local).link_consistency = _priv->ctr_link_consistency;
-
- ret = gettimeofday (ctr_wtime, NULL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- CTR_MSG_FILL_UNWIND_TIME_REC_ERROR,
- "Error filling wind time record %s",
- strerror(errno));
- goto out;
- }
-
- /* Special case i.e if its a tier rebalance
- * + cold tier brick
- * + its a create/mknod FOP
- * we record wind time as zero */
- if (ctr_local->client_pid == GF_CLIENT_PID_TIER_DEFRAG
- && (!_priv->ctr_hot_brick)
- && isdentrycreatefop(ctr_inode_cx->fop_type)) {
- memset(ctr_wtime, 0, sizeof(*ctr_wtime));
+ int ret = -1;
+ gfdb_time_t *ctr_wtime = NULL;
+ gf_ctr_private_t *_priv = NULL;
+
+ GF_ASSERT(this);
+ _priv = this->private;
+ GF_ASSERT(_priv);
+ GF_ASSERT(ctr_local);
+ IS_CTR_INODE_CX_SANE(ctr_inode_cx);
+
+ /*if not wind path error!*/
+ if (!iswindpath(ctr_inode_cx->fop_path)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_WRONG_FOP_PATH,
+ "Wrong fop_path. Should be wind");
+ goto out;
+ }
+
+ ctr_wtime = &CTR_DB_REC(ctr_local).gfdb_wind_change_time;
+ CTR_DB_REC(ctr_local).gfdb_fop_path = ctr_inode_cx->fop_path;
+ CTR_DB_REC(ctr_local).gfdb_fop_type = ctr_inode_cx->fop_type;
+ CTR_DB_REC(ctr_local).link_consistency = _priv->ctr_link_consistency;
+
+ ret = gettimeofday(ctr_wtime, NULL);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ CTR_MSG_FILL_UNWIND_TIME_REC_ERROR,
+ "Error filling wind time record %s", strerror(errno));
+ goto out;
+ }
+
+ /* Special case i.e if its a tier rebalance
+ * + cold tier brick
+ * + its a create/mknod FOP
+ * we record wind time as zero */
+ if (ctr_local->client_pid == GF_CLIENT_PID_TIER_DEFRAG &&
+ (!_priv->ctr_hot_brick) && isdentrycreatefop(ctr_inode_cx->fop_type)) {
+ memset(ctr_wtime, 0, sizeof(*ctr_wtime));
+ }
+
+ /* Copy gfid into db record */
+ gf_uuid_copy(CTR_DB_REC(ctr_local).gfid, *(ctr_inode_cx->gfid));
+
+ /* Copy older gfid if any */
+ if (ctr_inode_cx->old_gfid &&
+ (!gf_uuid_is_null(*(ctr_inode_cx->old_gfid)))) {
+ gf_uuid_copy(CTR_DB_REC(ctr_local).old_gfid, *(ctr_inode_cx->old_gfid));
+ }
+
+ /*Hard Links*/
+ if (isdentryfop(ctr_inode_cx->fop_type)) {
+ /*new link fop*/
+ if (NEW_LINK_CX(ctr_inode_cx)) {
+ gf_uuid_copy(CTR_DB_REC(ctr_local).pargfid,
+ *((NEW_LINK_CX(ctr_inode_cx))->pargfid));
+ strcpy(CTR_DB_REC(ctr_local).file_name,
+ NEW_LINK_CX(ctr_inode_cx)->basename);
}
-
- /* Copy gfid into db record */
- gf_uuid_copy (CTR_DB_REC(ctr_local).gfid, *(ctr_inode_cx->gfid));
-
- /* Copy older gfid if any */
- if (ctr_inode_cx->old_gfid &&
- (!gf_uuid_is_null (*(ctr_inode_cx->old_gfid)))) {
- gf_uuid_copy (CTR_DB_REC(ctr_local).old_gfid,
- *(ctr_inode_cx->old_gfid));
+ /*rename fop*/
+ if (OLD_LINK_CX(ctr_inode_cx)) {
+ gf_uuid_copy(CTR_DB_REC(ctr_local).old_pargfid,
+ *((OLD_LINK_CX(ctr_inode_cx))->pargfid));
+ strcpy(CTR_DB_REC(ctr_local).old_file_name,
+ OLD_LINK_CX(ctr_inode_cx)->basename);
}
+ }
- /*Hard Links*/
- if (isdentryfop(ctr_inode_cx->fop_type)) {
- /*new link fop*/
- if (NEW_LINK_CX(ctr_inode_cx)) {
- gf_uuid_copy (CTR_DB_REC(ctr_local).pargfid,
- *((NEW_LINK_CX(ctr_inode_cx))->pargfid));
- strcpy (CTR_DB_REC(ctr_local).file_name,
- NEW_LINK_CX(ctr_inode_cx)->basename);
- }
- /*rename fop*/
- if (OLD_LINK_CX(ctr_inode_cx)) {
- gf_uuid_copy (CTR_DB_REC(ctr_local).old_pargfid,
- *((OLD_LINK_CX(ctr_inode_cx))->pargfid));
- strcpy (CTR_DB_REC(ctr_local).old_file_name,
- OLD_LINK_CX(ctr_inode_cx)->basename);
- }
- }
-
- ret = 0;
+ ret = 0;
out:
- /*On error roll back and clean the record*/
- if (ret == -1) {
- CLEAR_CTR_DB_RECORD (ctr_local);
- }
- return ret;
+ /*On error roll back and clean the record*/
+ if (ret == -1) {
+ CLEAR_CTR_DB_RECORD(ctr_local);
+ }
+ return ret;
}
-
/******************************************************************************
*
* CTR xlator init related functions
@@ -167,141 +158,136 @@ out:
static int
extract_sql_params(xlator_t *this, dict_t *params_dict)
{
- int ret = -1;
- char *db_path = NULL;
- char *db_name = NULL;
- char *db_full_path = NULL;
-
- GF_ASSERT (this);
- GF_ASSERT (params_dict);
-
- /*Extract the path of the db*/
- db_path = NULL;
- GET_DB_PARAM_FROM_DICT_DEFAULT(this->name, this->options, "db-path",
- db_path, "/var/run/gluster/");
-
- /*Extract the name of the db*/
- db_name = NULL;
- GET_DB_PARAM_FROM_DICT_DEFAULT(this->name, this->options, "db-name",
- db_name, "gf_ctr_db.db");
-
- /*Construct full path of the db*/
- ret = gf_asprintf(&db_full_path, "%s/%s", db_path, db_name);
- if (ret < 0) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- CTR_MSG_CONSTRUCT_DB_PATH_FAILED,
- "Construction of full db path failed!");
- goto out;
- }
-
- /*Setting the SQL DB Path*/
- SET_DB_PARAM_TO_DICT(this->name, params_dict, GFDB_SQL_PARAM_DBPATH,
- db_full_path, ret, out);
-
- /*Extract rest of the sql params*/
- ret = gfdb_set_sql_params(this->name, this->options, params_dict);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- CTR_MSG_SET_VALUE_TO_SQL_PARAM_FAILED,
- "Failed setting values to sql param dict!");
- }
-
- ret = 0;
+ int ret = -1;
+ char *db_path = NULL;
+ char *db_name = NULL;
+ char *db_full_path = NULL;
+
+ GF_ASSERT(this);
+ GF_ASSERT(params_dict);
+
+ /*Extract the path of the db*/
+ db_path = NULL;
+ GET_DB_PARAM_FROM_DICT_DEFAULT(this->name, this->options, "db-path",
+ db_path, "/var/run/gluster/");
+
+ /*Extract the name of the db*/
+ db_name = NULL;
+ GET_DB_PARAM_FROM_DICT_DEFAULT(this->name, this->options, "db-name",
+ db_name, "gf_ctr_db.db");
+
+ /*Construct full path of the db*/
+ ret = gf_asprintf(&db_full_path, "%s/%s", db_path, db_name);
+ if (ret < 0) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0,
+ CTR_MSG_CONSTRUCT_DB_PATH_FAILED,
+ "Construction of full db path failed!");
+ goto out;
+ }
+
+ /*Setting the SQL DB Path*/
+ SET_DB_PARAM_TO_DICT(this->name, params_dict, GFDB_SQL_PARAM_DBPATH,
+ db_full_path, ret, out);
+
+ /*Extract rest of the sql params*/
+ ret = gfdb_set_sql_params(this->name, this->options, params_dict);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0,
+ CTR_MSG_SET_VALUE_TO_SQL_PARAM_FAILED,
+ "Failed setting values to sql param dict!");
+ }
+
+ ret = 0;
out:
- if (ret)
- GF_FREE (db_full_path);
- return ret;
+ if (ret)
+ GF_FREE(db_full_path);
+ return ret;
}
+int
+extract_db_params(xlator_t *this, dict_t *params_dict, gfdb_db_type_t db_type)
+{
+ int ret = -1;
+ GF_ASSERT(this);
+ GF_ASSERT(params_dict);
-int extract_db_params(xlator_t *this, dict_t *params_dict,
- gfdb_db_type_t db_type) {
-
- int ret = -1;
-
- GF_ASSERT (this);
- GF_ASSERT (params_dict);
-
- switch (db_type) {
+ switch (db_type) {
case GFDB_SQLITE3:
- ret = extract_sql_params(this, params_dict);
- if (ret)
- goto out;
- break;
+ ret = extract_sql_params(this, params_dict);
+ if (ret)
+ goto out;
+ break;
case GFDB_ROCKS_DB:
case GFDB_HYPERDEX:
case GFDB_HASH_FILE_STORE:
case GFDB_INVALID_DB:
case GFDB_DB_END:
- goto out;
- }
- ret = 0;
+ goto out;
+ }
+ ret = 0;
out:
- return ret;
+ return ret;
}
-int extract_ctr_options (xlator_t *this, gf_ctr_private_t *_priv) {
- int ret = -1;
- char *_val_str = NULL;
-
- GF_ASSERT (this);
- GF_ASSERT (_priv);
-
- /*Checking if the CTR Translator is enabled. By default its disabled*/
- _priv->enabled = _gf_false;
- GF_OPTION_INIT ("ctr-enabled", _priv->enabled, bool, out);
- if (!_priv->enabled) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_INFO, 0,
- CTR_MSG_XLATOR_DISABLED,
- "CTR Xlator is disabled.");
- ret = 0;
- goto out;
- }
+int
+extract_ctr_options(xlator_t *this, gf_ctr_private_t *_priv)
+{
+ int ret = -1;
+ char *_val_str = NULL;
+
+ GF_ASSERT(this);
+ GF_ASSERT(_priv);
+
+ /*Checking if the CTR Translator is enabled. By default its disabled*/
+ _priv->enabled = _gf_false;
+ GF_OPTION_INIT("ctr-enabled", _priv->enabled, bool, out);
+ if (!_priv->enabled) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_INFO, 0, CTR_MSG_XLATOR_DISABLED,
+ "CTR Xlator is disabled.");
+ ret = 0;
+ goto out;
+ }
- /*Extract db type*/
- GF_OPTION_INIT ("db-type", _val_str, str, out);
- _priv->gfdb_db_type = gf_string2gfdbdbtype(_val_str);
+ /*Extract db type*/
+ GF_OPTION_INIT("db-type", _val_str, str, out);
+ _priv->gfdb_db_type = gf_string2gfdbdbtype(_val_str);
- /*Extract flag for record on wind*/
- GF_OPTION_INIT ("record-entry", _priv->ctr_record_wind, bool, out);
+ /*Extract flag for record on wind*/
+ GF_OPTION_INIT("record-entry", _priv->ctr_record_wind, bool, out);
- /*Extract flag for record on unwind*/
- GF_OPTION_INIT ("record-exit", _priv->ctr_record_unwind, bool, out);
+ /*Extract flag for record on unwind*/
+ GF_OPTION_INIT("record-exit", _priv->ctr_record_unwind, bool, out);
- /*Extract flag for record on counters*/
- GF_OPTION_INIT ("record-counters", _priv->ctr_record_counter, bool,
- out);
+ /*Extract flag for record on counters*/
+ GF_OPTION_INIT("record-counters", _priv->ctr_record_counter, bool, out);
- /* Extract flag for record metadata heat */
- GF_OPTION_INIT ("ctr-record-metadata-heat",
- _priv->ctr_record_metadata_heat, bool,
- out);
+ /* Extract flag for record metadata heat */
+ GF_OPTION_INIT("ctr-record-metadata-heat", _priv->ctr_record_metadata_heat,
+ bool, out);
- /*Extract flag for link consistency*/
- GF_OPTION_INIT ("ctr_link_consistency", _priv->ctr_link_consistency,
- bool, out);
+ /*Extract flag for link consistency*/
+ GF_OPTION_INIT("ctr_link_consistency", _priv->ctr_link_consistency, bool,
+ out);
- /*Extract ctr_lookupheal_inode_timeout */
- GF_OPTION_INIT ("ctr_lookupheal_inode_timeout",
- _priv->ctr_lookupheal_inode_timeout,
- uint64, out);
+ /*Extract ctr_lookupheal_inode_timeout */
+ GF_OPTION_INIT("ctr_lookupheal_inode_timeout",
+ _priv->ctr_lookupheal_inode_timeout, uint64, out);
- /*Extract ctr_lookupheal_link_timeout*/
- GF_OPTION_INIT ("ctr_lookupheal_link_timeout",
- _priv->ctr_lookupheal_link_timeout,
- uint64, out);
+ /*Extract ctr_lookupheal_link_timeout*/
+ GF_OPTION_INIT("ctr_lookupheal_link_timeout",
+ _priv->ctr_lookupheal_link_timeout, uint64, out);
- /*Extract flag for hot tier brick*/
- GF_OPTION_INIT ("hot-brick", _priv->ctr_hot_brick, bool, out);
+ /*Extract flag for hot tier brick*/
+ GF_OPTION_INIT("hot-brick", _priv->ctr_hot_brick, bool, out);
- /*Extract flag for sync mode*/
- GF_OPTION_INIT ("db-sync", _val_str, str, out);
- _priv->gfdb_sync_type = gf_string2gfdbdbsync(_val_str);
+ /*Extract flag for sync mode*/
+ GF_OPTION_INIT("db-sync", _val_str, str, out);
+ _priv->gfdb_sync_type = gf_string2gfdbdbsync(_val_str);
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
diff --git a/xlators/features/changetimerecorder/src/ctr-xlator-ctx.c b/xlators/features/changetimerecorder/src/ctr-xlator-ctx.c
index 7700ad40ba6..b4afe74a31b 100644
--- a/xlators/features/changetimerecorder/src/ctr-xlator-ctx.c
+++ b/xlators/features/changetimerecorder/src/ctr-xlator-ctx.c
@@ -13,397 +13,350 @@
#include <time.h>
#include <sys/time.h>
-#define IS_THE_ONLY_HARDLINK(ctr_hard_link)\
- (ctr_hard_link->list.next == ctr_hard_link->list.prev)
-
+#define IS_THE_ONLY_HARDLINK(ctr_hard_link) \
+ (ctr_hard_link->list.next == ctr_hard_link->list.prev)
static void
-fini_ctr_hard_link (ctr_hard_link_t **ctr_hard_link) {
-
- GF_ASSERT (ctr_hard_link);
+fini_ctr_hard_link(ctr_hard_link_t **ctr_hard_link)
+{
+ GF_ASSERT(ctr_hard_link);
- if (*ctr_hard_link)
- return;
- GF_FREE ((*ctr_hard_link)->base_name);
- GF_FREE (*ctr_hard_link);
- *ctr_hard_link = NULL;
+ if (*ctr_hard_link)
+ return;
+ GF_FREE((*ctr_hard_link)->base_name);
+ GF_FREE(*ctr_hard_link);
+ *ctr_hard_link = NULL;
}
-
/* Please lock the ctr_xlator_ctx before using this function */
ctr_hard_link_t *
-ctr_search_hard_link_ctx (xlator_t *this,
- ctr_xlator_ctx_t *ctr_xlator_ctx,
- uuid_t pgfid,
- const char *base_name)
+ctr_search_hard_link_ctx(xlator_t *this, ctr_xlator_ctx_t *ctr_xlator_ctx,
+ uuid_t pgfid, const char *base_name)
{
- ctr_hard_link_t *_hard_link = NULL;
- ctr_hard_link_t *searched_hardlink = NULL;
-
- GF_ASSERT (this);
- GF_ASSERT (ctr_xlator_ctx);
-
- if (pgfid == NULL || base_name == NULL)
- goto out;
-
- /*linear search*/
- list_for_each_entry (_hard_link, &ctr_xlator_ctx->hardlink_list, list) {
- if (gf_uuid_compare (_hard_link->pgfid, pgfid) == 0
- && _hard_link->base_name
- && strcmp(_hard_link->base_name, base_name) == 0) {
- searched_hardlink = _hard_link;
- break;
- }
- }
+ ctr_hard_link_t *_hard_link = NULL;
+ ctr_hard_link_t *searched_hardlink = NULL;
-out:
- return searched_hardlink;
-}
+ GF_ASSERT(this);
+ GF_ASSERT(ctr_xlator_ctx);
+ if (pgfid == NULL || base_name == NULL)
+ goto out;
+ /*linear search*/
+ list_for_each_entry(_hard_link, &ctr_xlator_ctx->hardlink_list, list)
+ {
+ if (gf_uuid_compare(_hard_link->pgfid, pgfid) == 0 &&
+ _hard_link->base_name &&
+ strcmp(_hard_link->base_name, base_name) == 0) {
+ searched_hardlink = _hard_link;
+ break;
+ }
+ }
+out:
+ return searched_hardlink;
+}
/* Please lock the ctr_xlator_ctx before using this function */
int
-ctr_add_hard_link (xlator_t *this,
- ctr_xlator_ctx_t *ctr_xlator_ctx,
- uuid_t pgfid,
- const char *base_name)
+ctr_add_hard_link(xlator_t *this, ctr_xlator_ctx_t *ctr_xlator_ctx,
+ uuid_t pgfid, const char *base_name)
{
- int ret = -1;
- ctr_hard_link_t *ctr_hard_link = NULL;
- struct timeval current_time = {0};
-
- GF_ASSERT (this);
- GF_ASSERT (ctr_xlator_ctx);
-
- if (pgfid == NULL || base_name == NULL)
- goto out;
-
- ctr_hard_link = GF_CALLOC (1, sizeof (*ctr_hard_link),
- gf_ctr_mt_hard_link_t);
- if (!ctr_hard_link) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
- CTR_MSG_CALLOC_FAILED, "Failed allocating "
- "ctr_hard_link");
- goto out;
- }
+ int ret = -1;
+ ctr_hard_link_t *ctr_hard_link = NULL;
+ struct timeval current_time = {0};
- /*Initialize the ctr_hard_link object and
- * Assign the values : parent GFID and basename*/
- INIT_LIST_HEAD (&ctr_hard_link->list);
- gf_uuid_copy (ctr_hard_link->pgfid, pgfid);
- ret = gf_asprintf(&ctr_hard_link->base_name, "%s", base_name);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_COPY_FAILED, "Failed copying basename"
- "to ctr_hard_link");
- goto error;
- }
+ GF_ASSERT(this);
+ GF_ASSERT(ctr_xlator_ctx);
- ret = gettimeofday (&current_time, NULL);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "Failed to get current time");
- goto error;
- }
-
- /*Add the hard link to the list*/
- list_add_tail (&ctr_hard_link->list,
- &ctr_xlator_ctx->hardlink_list);
-
- ctr_hard_link->hardlink_heal_period = current_time.tv_sec;
+ if (pgfid == NULL || base_name == NULL)
+ goto out;
- /*aal izz well!*/
- ret = 0;
+ ctr_hard_link = GF_CALLOC(1, sizeof(*ctr_hard_link), gf_ctr_mt_hard_link_t);
+ if (!ctr_hard_link) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, CTR_MSG_CALLOC_FAILED,
+ "Failed allocating "
+ "ctr_hard_link");
goto out;
+ }
+
+ /*Initialize the ctr_hard_link object and
+ * Assign the values : parent GFID and basename*/
+ INIT_LIST_HEAD(&ctr_hard_link->list);
+ gf_uuid_copy(ctr_hard_link->pgfid, pgfid);
+ ret = gf_asprintf(&ctr_hard_link->base_name, "%s", base_name);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_COPY_FAILED,
+ "Failed copying basename"
+ "to ctr_hard_link");
+ goto error;
+ }
+
+ ret = gettimeofday(&current_time, NULL);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_ERROR, "Failed to get current time");
+ goto error;
+ }
+
+ /*Add the hard link to the list*/
+ list_add_tail(&ctr_hard_link->list, &ctr_xlator_ctx->hardlink_list);
+
+ ctr_hard_link->hardlink_heal_period = current_time.tv_sec;
+
+ /*aal izz well!*/
+ ret = 0;
+ goto out;
error:
- GF_FREE (ctr_hard_link);
+ GF_FREE(ctr_hard_link);
out:
- return ret;
+ return ret;
}
static void
-__delete_hard_link_from_list (ctr_hard_link_t **ctr_hard_link)
+__delete_hard_link_from_list(ctr_hard_link_t **ctr_hard_link)
{
- GF_ASSERT (ctr_hard_link);
- GF_ASSERT (*ctr_hard_link);
+ GF_ASSERT(ctr_hard_link);
+ GF_ASSERT(*ctr_hard_link);
- /*Remove hard link from list*/
- list_del(&(*ctr_hard_link)->list);
- fini_ctr_hard_link (ctr_hard_link);
+ /*Remove hard link from list*/
+ list_del(&(*ctr_hard_link)->list);
+ fini_ctr_hard_link(ctr_hard_link);
}
-
int
-ctr_delete_hard_link (xlator_t *this,
- ctr_xlator_ctx_t *ctr_xlator_ctx,
- uuid_t pgfid,
- const char *base_name)
+ctr_delete_hard_link(xlator_t *this, ctr_xlator_ctx_t *ctr_xlator_ctx,
+ uuid_t pgfid, const char *base_name)
{
- int ret = -1;
- ctr_hard_link_t *ctr_hard_link = NULL;
+ int ret = -1;
+ ctr_hard_link_t *ctr_hard_link = NULL;
- GF_ASSERT (this);
- GF_ASSERT (ctr_xlator_ctx);
+ GF_ASSERT(this);
+ GF_ASSERT(ctr_xlator_ctx);
+ LOCK(&ctr_xlator_ctx->lock);
- LOCK (&ctr_xlator_ctx->lock);
-
- /*Check if the hard link is present */
- ctr_hard_link = ctr_search_hard_link_ctx (this, ctr_xlator_ctx,
- pgfid, base_name);
- if (!ctr_hard_link) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_HARDLINK_MISSING_IN_LIST,
- "Hard link doesn't exist in the list");
- goto out;
- }
+ /*Check if the hard link is present */
+ ctr_hard_link = ctr_search_hard_link_ctx(this, ctr_xlator_ctx, pgfid,
+ base_name);
+ if (!ctr_hard_link) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_HARDLINK_MISSING_IN_LIST,
+ "Hard link doesn't exist in the list");
+ goto out;
+ }
- __delete_hard_link_from_list (&ctr_hard_link);
- ctr_hard_link = NULL;
+ __delete_hard_link_from_list(&ctr_hard_link);
+ ctr_hard_link = NULL;
- ret = 0;
+ ret = 0;
out:
- UNLOCK (&ctr_xlator_ctx->lock);
+ UNLOCK(&ctr_xlator_ctx->lock);
- return ret;
+ return ret;
}
-
-
-
int
-ctr_update_hard_link (xlator_t *this,
- ctr_xlator_ctx_t *ctr_xlator_ctx,
- uuid_t pgfid,
- const char *base_name,
- uuid_t old_pgfid,
- const char *old_base_name)
+ctr_update_hard_link(xlator_t *this, ctr_xlator_ctx_t *ctr_xlator_ctx,
+ uuid_t pgfid, const char *base_name, uuid_t old_pgfid,
+ const char *old_base_name)
{
- int ret = -1;
- ctr_hard_link_t *ctr_hard_link = NULL;
- struct timeval current_time = {0};
-
- GF_ASSERT (this);
- GF_ASSERT (ctr_xlator_ctx);
-
-
- LOCK (&ctr_xlator_ctx->lock);
-
- /*Check if the hard link is present */
- ctr_hard_link = ctr_search_hard_link_ctx (this, ctr_xlator_ctx,
- old_pgfid, old_base_name);
- if (!ctr_hard_link) {
- gf_msg_trace (this->name, 0, "Hard link doesn't exist"
- " in the list");
- /* Since the hard link is not present in the list
- * we add it to the list */
- ret = ctr_add_hard_link (this, ctr_xlator_ctx,
- pgfid, base_name);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_ADD_HARDLINK_TO_LIST_FAILED,
- "Failed adding hard link to the list");
- goto out;
- }
- ret = 0;
- goto out;
- }
-
- /* update the hard link */
- gf_uuid_copy (ctr_hard_link->pgfid, pgfid);
- GF_FREE (ctr_hard_link->base_name);
- ret = gf_asprintf(&ctr_hard_link->base_name, "%s", base_name);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- CTR_MSG_COPY_FAILED, "Failed copying basename"
- "to ctr_hard_link");
- /* delete the corrupted entry */
- __delete_hard_link_from_list (&ctr_hard_link);
- ctr_hard_link = NULL;
- goto out;
+ int ret = -1;
+ ctr_hard_link_t *ctr_hard_link = NULL;
+ struct timeval current_time = {0};
+
+ GF_ASSERT(this);
+ GF_ASSERT(ctr_xlator_ctx);
+
+ LOCK(&ctr_xlator_ctx->lock);
+
+ /*Check if the hard link is present */
+ ctr_hard_link = ctr_search_hard_link_ctx(this, ctr_xlator_ctx, old_pgfid,
+ old_base_name);
+ if (!ctr_hard_link) {
+ gf_msg_trace(this->name, 0,
+ "Hard link doesn't exist"
+ " in the list");
+ /* Since the hard link is not present in the list
+ * we add it to the list */
+ ret = ctr_add_hard_link(this, ctr_xlator_ctx, pgfid, base_name);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0,
+ CTR_MSG_ADD_HARDLINK_TO_LIST_FAILED,
+ "Failed adding hard link to the list");
+ goto out;
}
+ ret = 0;
+ goto out;
+ }
+
+ /* update the hard link */
+ gf_uuid_copy(ctr_hard_link->pgfid, pgfid);
+ GF_FREE(ctr_hard_link->base_name);
+ ret = gf_asprintf(&ctr_hard_link->base_name, "%s", base_name);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, CTR_MSG_COPY_FAILED,
+ "Failed copying basename"
+ "to ctr_hard_link");
+ /* delete the corrupted entry */
+ __delete_hard_link_from_list(&ctr_hard_link);
+ ctr_hard_link = NULL;
+ goto out;
+ }
- ret = gettimeofday (&current_time, NULL);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "Failed to get current time");
- ctr_hard_link->hardlink_heal_period = 0;
- } else {
- ctr_hard_link->hardlink_heal_period = current_time.tv_sec;
- }
+ ret = gettimeofday(&current_time, NULL);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_ERROR, "Failed to get current time");
+ ctr_hard_link->hardlink_heal_period = 0;
+ } else {
+ ctr_hard_link->hardlink_heal_period = current_time.tv_sec;
+ }
- ret = 0;
+ ret = 0;
out:
- UNLOCK (&ctr_xlator_ctx->lock);
+ UNLOCK(&ctr_xlator_ctx->lock);
- return ret;
+ return ret;
}
-
-
-
/* Delete all hardlinks */
static int
-ctr_delete_all_hard_link (xlator_t *this,
- ctr_xlator_ctx_t *ctr_xlator_ctx)
+ctr_delete_all_hard_link(xlator_t *this, ctr_xlator_ctx_t *ctr_xlator_ctx)
{
- int ret = -1;
- ctr_hard_link_t *ctr_hard_link = NULL;
- ctr_hard_link_t *tmp = NULL;
-
- GF_ASSERT (ctr_xlator_ctx);
+ int ret = -1;
+ ctr_hard_link_t *ctr_hard_link = NULL;
+ ctr_hard_link_t *tmp = NULL;
- LOCK (&ctr_xlator_ctx->lock);
+ GF_ASSERT(ctr_xlator_ctx);
- list_for_each_entry_safe(ctr_hard_link, tmp,
- &ctr_xlator_ctx->hardlink_list, list)
- {
- /*Remove hard link from list*/
- __delete_hard_link_from_list (&ctr_hard_link);
- ctr_hard_link = NULL;
-
- }
+ LOCK(&ctr_xlator_ctx->lock);
+ list_for_each_entry_safe(ctr_hard_link, tmp, &ctr_xlator_ctx->hardlink_list,
+ list)
+ {
+ /*Remove hard link from list*/
+ __delete_hard_link_from_list(&ctr_hard_link);
+ ctr_hard_link = NULL;
+ }
- UNLOCK (&ctr_xlator_ctx->lock);
+ UNLOCK(&ctr_xlator_ctx->lock);
- ret = 0;
+ ret = 0;
- return ret;
+ return ret;
}
-
/* Please lock the inode before using this function */
static ctr_xlator_ctx_t *
-__get_ctr_xlator_ctx (xlator_t *this,
- inode_t *inode)
+__get_ctr_xlator_ctx(xlator_t *this, inode_t *inode)
{
- int ret = 0;
- uint64_t _addr = 0;
- ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
-
- GF_ASSERT (this);
- GF_ASSERT (inode);
-
- ret = __inode_ctx_get (inode, this, &_addr);
- if (ret < 0)
- _addr = 0;
- if (_addr != 0) {
- ctr_xlator_ctx = (ctr_xlator_ctx_t *) (long)_addr;
- }
+ int ret = 0;
+ uint64_t _addr = 0;
+ ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
- return ctr_xlator_ctx;
-}
+ GF_ASSERT(this);
+ GF_ASSERT(inode);
+
+ ret = __inode_ctx_get(inode, this, &_addr);
+ if (ret < 0)
+ _addr = 0;
+ if (_addr != 0) {
+ ctr_xlator_ctx = (ctr_xlator_ctx_t *)(long)_addr;
+ }
+ return ctr_xlator_ctx;
+}
ctr_xlator_ctx_t *
-init_ctr_xlator_ctx (xlator_t *this,
- inode_t *inode)
+init_ctr_xlator_ctx(xlator_t *this, inode_t *inode)
{
- int ret = -1;
- uint64_t _addr = 0;
- ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
- struct timeval current_time = {0};
-
- GF_ASSERT (this);
- GF_ASSERT (inode);
-
- LOCK (&inode->lock);
- {
- ctr_xlator_ctx = __get_ctr_xlator_ctx (this, inode);
- if (ctr_xlator_ctx) {
- ret = 0;
- goto out;
- }
- ctr_xlator_ctx = GF_CALLOC (1, sizeof (*ctr_xlator_ctx),
- gf_ctr_mt_xlator_ctx);
- if (!ctr_xlator_ctx)
- goto out;
-
- ret = LOCK_INIT (&ctr_xlator_ctx->lock);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, ret,
- CTR_MSG_INIT_LOCK_FAILED,
- "Failed init lock %s", strerror(ret));
- goto out;
- }
- _addr = (uint64_t) ctr_xlator_ctx;
-
- ret = __inode_ctx_set (inode, this, &_addr);
- if (ret) {
- goto out;
- }
-
- INIT_LIST_HEAD (&ctr_xlator_ctx->hardlink_list);
-
- ret = gettimeofday (&current_time, NULL);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "Failed to get current time");
- goto out;
- }
-
- ctr_xlator_ctx->inode_heal_period = current_time.tv_sec;
+ int ret = -1;
+ uint64_t _addr = 0;
+ ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
+ struct timeval current_time = {0};
+
+ GF_ASSERT(this);
+ GF_ASSERT(inode);
+
+ LOCK(&inode->lock);
+ {
+ ctr_xlator_ctx = __get_ctr_xlator_ctx(this, inode);
+ if (ctr_xlator_ctx) {
+ ret = 0;
+ goto out;
}
- ret = 0;
-out:
+ ctr_xlator_ctx = GF_CALLOC(1, sizeof(*ctr_xlator_ctx),
+ gf_ctr_mt_xlator_ctx);
+ if (!ctr_xlator_ctx)
+ goto out;
+
+ ret = LOCK_INIT(&ctr_xlator_ctx->lock);
if (ret) {
- GF_FREE (ctr_xlator_ctx);
- ctr_xlator_ctx = NULL;
+ gf_msg(this->name, GF_LOG_ERROR, ret, CTR_MSG_INIT_LOCK_FAILED,
+ "Failed init lock %s", strerror(ret));
+ goto out;
}
+ _addr = (uint64_t)ctr_xlator_ctx;
- UNLOCK (&inode->lock);
+ ret = __inode_ctx_set(inode, this, &_addr);
+ if (ret) {
+ goto out;
+ }
- return ctr_xlator_ctx;
-}
+ INIT_LIST_HEAD(&ctr_xlator_ctx->hardlink_list);
+ ret = gettimeofday(&current_time, NULL);
+ if (ret == -1) {
+ gf_log(this->name, GF_LOG_ERROR, "Failed to get current time");
+ goto out;
+ }
+
+ ctr_xlator_ctx->inode_heal_period = current_time.tv_sec;
+ }
+ ret = 0;
+out:
+ if (ret) {
+ GF_FREE(ctr_xlator_ctx);
+ ctr_xlator_ctx = NULL;
+ }
+ UNLOCK(&inode->lock);
+ return ctr_xlator_ctx;
+}
void
-fini_ctr_xlator_ctx (xlator_t *this,
- inode_t *inode)
+fini_ctr_xlator_ctx(xlator_t *this, inode_t *inode)
{
- int ret = 0;
- uint64_t _addr = 0;
- ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
-
-
- inode_ctx_del (inode, this, &_addr);
- if (!_addr)
- return;
+ int ret = 0;
+ uint64_t _addr = 0;
+ ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
- ctr_xlator_ctx = (ctr_xlator_ctx_t *) (long) _addr;
+ inode_ctx_del(inode, this, &_addr);
+ if (!_addr)
+ return;
- ret = ctr_delete_all_hard_link (this, ctr_xlator_ctx);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING , 0,
- CTR_MSG_DELETE_HARDLINK_FAILED, "Failed deleting all "
- "hard links from inode context");
- }
+ ctr_xlator_ctx = (ctr_xlator_ctx_t *)(long)_addr;
- LOCK_DESTROY (&ctr_xlator_ctx->lock);
+ ret = ctr_delete_all_hard_link(this, ctr_xlator_ctx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, CTR_MSG_DELETE_HARDLINK_FAILED,
+ "Failed deleting all "
+ "hard links from inode context");
+ }
- GF_FREE (ctr_xlator_ctx);
+ LOCK_DESTROY(&ctr_xlator_ctx->lock);
+ GF_FREE(ctr_xlator_ctx);
}
-
-
-
ctr_xlator_ctx_t *
-get_ctr_xlator_ctx (xlator_t *this,
- inode_t *inode)
+get_ctr_xlator_ctx(xlator_t *this, inode_t *inode)
{
- ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
+ ctr_xlator_ctx_t *ctr_xlator_ctx = NULL;
- LOCK (&inode->lock);
- ctr_xlator_ctx = __get_ctr_xlator_ctx (this, inode);
- UNLOCK (&inode->lock);
+ LOCK(&inode->lock);
+ ctr_xlator_ctx = __get_ctr_xlator_ctx(this, inode);
+ UNLOCK(&inode->lock);
- return ctr_xlator_ctx;
+ return ctr_xlator_ctx;
}
-
diff --git a/xlators/features/cloudsync/src/cloudsync-common.c b/xlators/features/cloudsync/src/cloudsync-common.c
index d0d00decca3..aee1f06a82a 100644
--- a/xlators/features/cloudsync/src/cloudsync-common.c
+++ b/xlators/features/cloudsync/src/cloudsync-common.c
@@ -11,34 +11,34 @@
#include "cloudsync-common.h"
void
-cs_local_wipe (xlator_t *this, cs_local_t *local)
+cs_local_wipe(xlator_t *this, cs_local_t *local)
{
- if (!local)
- return;
+ if (!local)
+ return;
- loc_wipe (&local->loc);
+ loc_wipe(&local->loc);
- if (local->fd) {
- fd_unref (local->fd);
- local->fd = NULL;
- }
+ if (local->fd) {
+ fd_unref(local->fd);
+ local->fd = NULL;
+ }
- if (local->stub) {
- call_stub_destroy (local->stub);
- local->stub = NULL;
- }
+ if (local->stub) {
+ call_stub_destroy(local->stub);
+ local->stub = NULL;
+ }
- if (local->xattr_req)
- dict_unref (local->xattr_req);
+ if (local->xattr_req)
+ dict_unref(local->xattr_req);
- if (local->xattr_rsp)
- dict_unref (local->xattr_rsp);
+ if (local->xattr_rsp)
+ dict_unref(local->xattr_rsp);
- if (local->dlfd)
- fd_unref (local->dlfd);
+ if (local->dlfd)
+ fd_unref(local->dlfd);
- if (local->remotepath)
- GF_FREE (local->remotepath);
+ if (local->remotepath)
+ GF_FREE(local->remotepath);
- mem_put (local);
+ mem_put(local);
}
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c b/xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c
index e36bf71e4ae..dad29fc0e4f 100644
--- a/xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c
@@ -23,566 +23,560 @@
#define RESOURCE_SIZE 4096
store_methods_t store_ops = {
- .fop_download = aws_download_s3,
- .fop_init = aws_init,
- .fop_reconfigure = aws_reconfigure,
- .fop_fini = aws_fini,
+ .fop_download = aws_download_s3,
+ .fop_init = aws_init,
+ .fop_reconfigure = aws_reconfigure,
+ .fop_fini = aws_fini,
};
typedef struct aws_private {
- char *hostname;
- char *bucketid;
- char *awssekey;
- char *awskeyid;
- gf_boolean_t abortdl;
- pthread_spinlock_t lock;
+ char *hostname;
+ char *bucketid;
+ char *awssekey;
+ char *awskeyid;
+ gf_boolean_t abortdl;
+ pthread_spinlock_t lock;
} aws_private_t;
void *
-aws_init (xlator_t *this)
+aws_init(xlator_t *this)
{
- aws_private_t *priv = NULL;
- char *temp_str = NULL;
- int ret = 0;
-
- priv = GF_CALLOC (1, sizeof (aws_private_t),
- gf_libaws_mt_aws_private_t);
- if (!priv) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
- return NULL;
- }
-
- priv->abortdl = _gf_false;
-
- pthread_spin_init (&priv->lock, PTHREAD_PROCESS_PRIVATE);
-
- pthread_spin_lock (&(priv->lock));
- {
- if (dict_get_str (this->options, "s3plugin-seckey",
- &temp_str) == 0) {
- priv->awssekey = gf_strdup (temp_str);
- if (!priv->awssekey) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, 0,
- "initializing aws secret key failed");
- ret = -1;
- goto unlock;
- }
+ aws_private_t *priv = NULL;
+ char *temp_str = NULL;
+ int ret = 0;
+
+ priv = GF_CALLOC(1, sizeof(aws_private_t), gf_libaws_mt_aws_private_t);
+ if (!priv) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
+ return NULL;
+ }
+
+ priv->abortdl = _gf_false;
+
+ pthread_spin_init(&priv->lock, PTHREAD_PROCESS_PRIVATE);
+
+ pthread_spin_lock(&(priv->lock));
+ {
+ if (dict_get_str(this->options, "s3plugin-seckey", &temp_str) == 0) {
+ priv->awssekey = gf_strdup(temp_str);
+ if (!priv->awssekey) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, 0,
+ "initializing aws secret key failed");
+ ret = -1;
+ goto unlock;
+ }
}
- if (dict_get_str (this->options, "s3plugin-keyid",
- &temp_str) == 0) {
- priv->awskeyid = gf_strdup (temp_str);
- if (!priv->awskeyid) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, 0,
- "initializing aws key ID failed");
- ret = -1;
- goto unlock;
- }
+ if (dict_get_str(this->options, "s3plugin-keyid", &temp_str) == 0) {
+ priv->awskeyid = gf_strdup(temp_str);
+ if (!priv->awskeyid) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, 0,
+ "initializing aws key ID failed");
+ ret = -1;
+ goto unlock;
+ }
}
- if (dict_get_str (this->options, "s3plugin-bucketid",
- &temp_str) == 0) {
- priv->bucketid = gf_strdup (temp_str);
- if (!priv->bucketid) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, 0,
- "initializing aws bucketid failed");
+ if (dict_get_str(this->options, "s3plugin-bucketid", &temp_str) == 0) {
+ priv->bucketid = gf_strdup(temp_str);
+ if (!priv->bucketid) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, 0,
+ "initializing aws bucketid failed");
- ret = -1;
- goto unlock;
- }
+ ret = -1;
+ goto unlock;
+ }
}
- if (dict_get_str (this->options, "s3plugin-hostname",
- &temp_str) == 0) {
- priv->hostname = gf_strdup (temp_str);
- if (!priv->hostname) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, 0,
- "initializing aws hostname failed");
+ if (dict_get_str(this->options, "s3plugin-hostname", &temp_str) == 0) {
+ priv->hostname = gf_strdup(temp_str);
+ if (!priv->hostname) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, 0,
+ "initializing aws hostname failed");
- ret = -1;
- goto unlock;
- }
+ ret = -1;
+ goto unlock;
+ }
}
- gf_msg_debug (this->name, 0, "stored key: %s id: %s "
- "bucketid %s hostname: %s", priv->awssekey,
- priv->awskeyid, priv->bucketid, priv->hostname);
-
- }
+ gf_msg_debug(this->name, 0,
+ "stored key: %s id: %s "
+ "bucketid %s hostname: %s",
+ priv->awssekey, priv->awskeyid, priv->bucketid,
+ priv->hostname);
+ }
unlock:
- pthread_spin_unlock (&(priv->lock));
-
- if (ret == -1) {
- GF_FREE (priv->awskeyid);
- GF_FREE (priv->awssekey);
- GF_FREE (priv->bucketid);
- GF_FREE (priv->hostname);
- GF_FREE (priv);
- priv = NULL;
- }
-
- return (void *)priv;
+ pthread_spin_unlock(&(priv->lock));
+
+ if (ret == -1) {
+ GF_FREE(priv->awskeyid);
+ GF_FREE(priv->awssekey);
+ GF_FREE(priv->bucketid);
+ GF_FREE(priv->hostname);
+ GF_FREE(priv);
+ priv = NULL;
+ }
+
+ return (void *)priv;
}
int
-aws_reconfigure (xlator_t *this, dict_t *options)
+aws_reconfigure(xlator_t *this, dict_t *options)
{
- aws_private_t *priv = NULL;
- char *temp_str = NULL;
- int ret = 0;
- cs_private_t *cspriv = NULL;
-
- cspriv = this->private;
-
- priv = cspriv->stores->config;
-
- if (!priv) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "null priv");
- return -1;
- }
-
- pthread_spin_lock (&(priv->lock));
- {
- if (dict_get_str (options, "s3plugin-seckey",
- &temp_str) == 0) {
- priv->awssekey = gf_strdup (temp_str);
- if (!priv->awssekey) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, 0,
- "initializing aws secret key failed");
- ret = -1;
- goto out;
- }
- }
-
- if (dict_get_str (options, "s3plugin-keyid",
- &temp_str) == 0) {
- priv->awskeyid = gf_strdup (temp_str);
- if (!priv->awskeyid) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, 0,
- "initializing aws key ID failed");
- ret = -1;
- goto out;
- }
+ aws_private_t *priv = NULL;
+ char *temp_str = NULL;
+ int ret = 0;
+ cs_private_t *cspriv = NULL;
+
+ cspriv = this->private;
+
+ priv = cspriv->stores->config;
+
+ if (!priv) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "null priv");
+ return -1;
+ }
+
+ pthread_spin_lock(&(priv->lock));
+ {
+ if (dict_get_str(options, "s3plugin-seckey", &temp_str) == 0) {
+ priv->awssekey = gf_strdup(temp_str);
+ if (!priv->awssekey) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, 0,
+ "initializing aws secret key failed");
+ ret = -1;
+ goto out;
+ }
}
- if (dict_get_str (options, "s3plugin-bucketid",
- &temp_str) == 0) {
- priv->bucketid = gf_strdup (temp_str);
- if (!priv->bucketid) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, 0,
- "initializing aws bucketid failed");
- ret = -1;
- goto out;
- }
+ if (dict_get_str(options, "s3plugin-keyid", &temp_str) == 0) {
+ priv->awskeyid = gf_strdup(temp_str);
+ if (!priv->awskeyid) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, 0,
+ "initializing aws key ID failed");
+ ret = -1;
+ goto out;
+ }
}
- if (dict_get_str (options, "s3plugin-hostname",
- &temp_str) == 0) {
- priv->hostname = gf_strdup (temp_str);
- if (!priv->hostname) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM, 0,
- "initializing aws hostname failed");
- ret = -1;
- goto out;
- }
+ if (dict_get_str(options, "s3plugin-bucketid", &temp_str) == 0) {
+ priv->bucketid = gf_strdup(temp_str);
+ if (!priv->bucketid) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, 0,
+ "initializing aws bucketid failed");
+ ret = -1;
+ goto out;
+ }
}
+ if (dict_get_str(options, "s3plugin-hostname", &temp_str) == 0) {
+ priv->hostname = gf_strdup(temp_str);
+ if (!priv->hostname) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, 0,
+ "initializing aws hostname failed");
+ ret = -1;
+ goto out;
+ }
}
+ }
out:
- pthread_spin_unlock (&(priv->lock));
+ pthread_spin_unlock(&(priv->lock));
- gf_msg_debug (this->name, 0, "stored key: %s id: %s "
- "bucketid %s hostname: %s", priv->awssekey,
- priv->awskeyid, priv->bucketid, priv->hostname);
+ gf_msg_debug(this->name, 0,
+ "stored key: %s id: %s "
+ "bucketid %s hostname: %s",
+ priv->awssekey, priv->awskeyid, priv->bucketid,
+ priv->hostname);
- return ret;
+ return ret;
}
void
-aws_fini (void *config)
+aws_fini(void *config)
{
- aws_private_t *priv = NULL;
+ aws_private_t *priv = NULL;
- priv = (aws_private_t *)priv;
+ priv = (aws_private_t *)priv;
- if (priv) {
- GF_FREE (priv->hostname);
- GF_FREE (priv->bucketid);
- GF_FREE (priv->awssekey);
- GF_FREE (priv->awskeyid);
+ if (priv) {
+ GF_FREE(priv->hostname);
+ GF_FREE(priv->bucketid);
+ GF_FREE(priv->awssekey);
+ GF_FREE(priv->awskeyid);
- pthread_spin_destroy (&priv->lock);
- GF_FREE (priv);
- }
+ pthread_spin_destroy(&priv->lock);
+ GF_FREE(priv);
+ }
}
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int ret = -1;
+ int ret = -1;
- GF_VALIDATE_OR_GOTO ("dht", this, out);
+ GF_VALIDATE_OR_GOTO("dht", this, out);
- ret = xlator_mem_acct_init (this, gf_libaws_mt_end + 1);
+ ret = xlator_mem_acct_init(this, gf_libaws_mt_end + 1);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "Memory accounting init failed");
- return ret;
- }
-out:
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "Memory accounting init failed");
return ret;
+ }
+out:
+ return ret;
}
char *
-aws_form_request (char *resource, char **date, char *reqtype, char *bucketid,
- char *filepath)
+aws_form_request(char *resource, char **date, char *reqtype, char *bucketid,
+ char *filepath)
{
- char httpdate[256];
- time_t ctime;
- struct tm *gtime = NULL;
- char *sign_req = NULL;
- int signreq_len = -1;
- int date_len = -1;
- int res_len = -1;
-
- ctime = time(NULL);
- gtime = gmtime(&ctime);
-
- date_len = strftime (httpdate, sizeof(httpdate),
- "%a, %d %b %Y %H:%M:%S +0000", gtime);
-
- *date = gf_strndup (httpdate, date_len);
- if (*date == NULL) {
- gf_msg ("CS", GF_LOG_ERROR, ENOMEM, 0, "memory allocation "
- "failure for date");
- goto out;
- }
-
- res_len = snprintf(resource, RESOURCE_SIZE, "%s/%s", bucketid,
- filepath);
-
- gf_msg_debug ("CS", 0, "resource %s", resource);
-
- /* 6 accounts for the 4 new line chars, one forward slash and
- * one null char */
- signreq_len = res_len + date_len + strlen(reqtype) + 6;
-
- sign_req = GF_MALLOC (signreq_len, gf_common_mt_char);
- if (sign_req == NULL) {
- gf_msg ("CS", GF_LOG_ERROR, ENOMEM, 0, "memory allocation "
- "failure for sign_req");
- goto out;
- }
-
- snprintf(sign_req, signreq_len, "%s\n\n%s\n%s\n/%s",
- reqtype,
- "",
- *date,
- resource);
+ char httpdate[256];
+ time_t ctime;
+ struct tm *gtime = NULL;
+ char *sign_req = NULL;
+ int signreq_len = -1;
+ int date_len = -1;
+ int res_len = -1;
+
+ ctime = time(NULL);
+ gtime = gmtime(&ctime);
+
+ date_len = strftime(httpdate, sizeof(httpdate),
+ "%a, %d %b %Y %H:%M:%S +0000", gtime);
+
+ *date = gf_strndup(httpdate, date_len);
+ if (*date == NULL) {
+ gf_msg("CS", GF_LOG_ERROR, ENOMEM, 0,
+ "memory allocation "
+ "failure for date");
+ goto out;
+ }
+
+ res_len = snprintf(resource, RESOURCE_SIZE, "%s/%s", bucketid, filepath);
+
+ gf_msg_debug("CS", 0, "resource %s", resource);
+
+ /* 6 accounts for the 4 new line chars, one forward slash and
+ * one null char */
+ signreq_len = res_len + date_len + strlen(reqtype) + 6;
+
+ sign_req = GF_MALLOC(signreq_len, gf_common_mt_char);
+ if (sign_req == NULL) {
+ gf_msg("CS", GF_LOG_ERROR, ENOMEM, 0,
+ "memory allocation "
+ "failure for sign_req");
+ goto out;
+ }
+
+ snprintf(sign_req, signreq_len, "%s\n\n%s\n%s\n/%s", reqtype, "", *date,
+ resource);
out:
- return sign_req;
+ return sign_req;
}
-char*
+char *
aws_b64_encode(const unsigned char *input, int length)
{
- BIO *bio, *b64;
- BUF_MEM *bptr;
- char *buff = NULL;
+ BIO *bio, *b64;
+ BUF_MEM *bptr;
+ char *buff = NULL;
- b64 = BIO_new(BIO_f_base64());
- bio = BIO_new(BIO_s_mem());
- b64 = BIO_push(b64, bio);
- BIO_write(b64, input, length);
- BIO_flush(b64);
- BIO_get_mem_ptr(b64, &bptr);
+ b64 = BIO_new(BIO_f_base64());
+ bio = BIO_new(BIO_s_mem());
+ b64 = BIO_push(b64, bio);
+ BIO_write(b64, input, length);
+ BIO_flush(b64);
+ BIO_get_mem_ptr(b64, &bptr);
- buff = GF_MALLOC(bptr->length, gf_common_mt_char);
- memcpy(buff, bptr->data, bptr->length - 1);
- buff[bptr->length - 1] = 0;
+ buff = GF_MALLOC(bptr->length, gf_common_mt_char);
+ memcpy(buff, bptr->data, bptr->length - 1);
+ buff[bptr->length - 1] = 0;
- BIO_free_all(b64);
+ BIO_free_all(b64);
- return buff;
+ return buff;
}
char *
aws_sign_request(char *const str, char *awssekey)
{
#if (OPENSSL_VERSION_NUMBER < 0x1010002f)
- HMAC_CTX ctx;
+ HMAC_CTX ctx;
#endif
- HMAC_CTX *pctx = NULL;;
+ HMAC_CTX *pctx = NULL;
+ ;
- unsigned char md[256];
- unsigned len;
- char *base64 = NULL;
+ unsigned char md[256];
+ unsigned len;
+ char *base64 = NULL;
#if (OPENSSL_VERSION_NUMBER < 0x1010002f)
- HMAC_CTX_init (&ctx);
- pctx = &ctx;
+ HMAC_CTX_init(&ctx);
+ pctx = &ctx;
#else
- pctx = HMAC_CTX_new ();
+ pctx = HMAC_CTX_new();
#endif
- HMAC_Init_ex (pctx, awssekey, strlen(awssekey), EVP_sha1(), NULL);
- HMAC_Update (pctx, (unsigned char *)str, strlen(str));
- HMAC_Final (pctx, (unsigned char *)md, &len);
+ HMAC_Init_ex(pctx, awssekey, strlen(awssekey), EVP_sha1(), NULL);
+ HMAC_Update(pctx, (unsigned char *)str, strlen(str));
+ HMAC_Final(pctx, (unsigned char *)md, &len);
#if (OPENSSL_VERSION_NUMBER < 0x1010002f)
- HMAC_CTX_cleanup (pctx);
+ HMAC_CTX_cleanup(pctx);
#else
- HMAC_CTX_free (pctx);
+ HMAC_CTX_free(pctx);
#endif
- base64 = aws_b64_encode(md, len);
+ base64 = aws_b64_encode(md, len);
- return base64;
+ return base64;
}
int
-aws_dlwritev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+aws_dlwritev_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct iatt *prebuf, struct iatt *postbuf,
+ dict_t *xdata)
{
- aws_private_t *priv = NULL;
-
- if (op_ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0, op_errno, "write failed "
- ". Aborting Download");
-
- priv = this->private;
- pthread_spin_lock (&(priv->lock));
- {
- priv->abortdl = _gf_true;
- }
- pthread_spin_unlock (&(priv->lock));
+ aws_private_t *priv = NULL;
+
+ if (op_ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, op_errno,
+ "write failed "
+ ". Aborting Download");
+
+ priv = this->private;
+ pthread_spin_lock(&(priv->lock));
+ {
+ priv->abortdl = _gf_true;
}
+ pthread_spin_unlock(&(priv->lock));
+ }
- CS_STACK_DESTROY (frame);
+ CS_STACK_DESTROY(frame);
- return op_ret;
+ return op_ret;
}
size_t
-aws_write_callback (void *dlbuf, size_t size, size_t nitems, void *mainframe)
+aws_write_callback(void *dlbuf, size_t size, size_t nitems, void *mainframe)
{
- call_frame_t *frame = NULL;
- fd_t *dlfd = NULL;
- int ret = 0;
- cs_local_t *local = NULL;
- struct iovec iov = {0,};
- struct iobref *iobref = NULL;
- struct iobuf *iobuf = NULL;
- struct iovec dliov = {0, };
- size_t tsize = 0;
- xlator_t *this = NULL;
- cs_private_t *xl_priv = NULL;
- aws_private_t *priv = NULL;
- call_frame_t *dlframe = NULL;
-
- frame = (call_frame_t *)mainframe;
- this = frame->this;
- xl_priv = this->private;
- priv = xl_priv->stores->config;
-
- pthread_spin_lock (&(priv->lock));
- {
- /* returning size other than the size passed from curl will
- * abort further download*/
- if (priv->abortdl) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "aborting download");
- pthread_spin_unlock (&(priv->lock));
- return 0;
- }
+ call_frame_t *frame = NULL;
+ fd_t *dlfd = NULL;
+ int ret = 0;
+ cs_local_t *local = NULL;
+ struct iovec iov = {
+ 0,
+ };
+ struct iobref *iobref = NULL;
+ struct iobuf *iobuf = NULL;
+ struct iovec dliov = {
+ 0,
+ };
+ size_t tsize = 0;
+ xlator_t *this = NULL;
+ cs_private_t *xl_priv = NULL;
+ aws_private_t *priv = NULL;
+ call_frame_t *dlframe = NULL;
+
+ frame = (call_frame_t *)mainframe;
+ this = frame->this;
+ xl_priv = this->private;
+ priv = xl_priv->stores->config;
+
+ pthread_spin_lock(&(priv->lock));
+ {
+ /* returning size other than the size passed from curl will
+ * abort further download*/
+ if (priv->abortdl) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "aborting download");
+ pthread_spin_unlock(&(priv->lock));
+ return 0;
}
- pthread_spin_unlock (&(priv->lock));
+ }
+ pthread_spin_unlock(&(priv->lock));
- local = frame->local;
- dlfd = local->dlfd;
- tsize = size * nitems;
+ local = frame->local;
+ dlfd = local->dlfd;
+ tsize = size * nitems;
- dliov.iov_base = (void *)dlbuf;
- dliov.iov_len = tsize;
+ dliov.iov_base = (void *)dlbuf;
+ dliov.iov_len = tsize;
- ret = iobuf_copy (this->ctx->iobuf_pool, &dliov, 1, &iobref, &iobuf,
- &iov);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "iobuf_copy failed");
- goto out;
- }
+ ret = iobuf_copy(this->ctx->iobuf_pool, &dliov, 1, &iobref, &iobuf, &iov);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "iobuf_copy failed");
+ goto out;
+ }
- /* copy frame */
- dlframe = copy_frame (frame);
- if (!dlframe) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "copy_frame failed");
- tsize = 0;
- goto out;
- }
+ /* copy frame */
+ dlframe = copy_frame(frame);
+ if (!dlframe) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "copy_frame failed");
+ tsize = 0;
+ goto out;
+ }
- STACK_WIND (dlframe, aws_dlwritev_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->writev, dlfd,
- &iov, 1, local->dloffset, 0, iobref, NULL);
+ STACK_WIND(dlframe, aws_dlwritev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, dlfd, &iov, 1, local->dloffset,
+ 0, iobref, NULL);
- local->dloffset += tsize;
+ local->dloffset += tsize;
out:
- if (iobuf)
- iobuf_unref (iobuf);
- if (iobref)
- iobref_unref (iobref);
+ if (iobuf)
+ iobuf_unref(iobuf);
+ if (iobref)
+ iobref_unref(iobref);
- return tsize;
+ return tsize;
}
int
-aws_download_s3 (call_frame_t *frame, void *config)
+aws_download_s3(call_frame_t *frame, void *config)
{
- char *buf;
- int bufsize = -1;
- CURL *handle = NULL;
- struct curl_slist *slist = NULL;
- struct curl_slist *tmp = NULL;
- xlator_t *this = NULL;
- int ret = 0;
- int debug = 1;
- CURLcode res;
- char errbuf[CURL_ERROR_SIZE];
- size_t len = 0;
- long responsecode;
- char *sign_req = NULL;
- char *date = NULL;
- char *const reqtype = "GET";
- char *signature = NULL;
- cs_local_t *local = NULL;
- char resource[RESOURCE_SIZE] = {0,};
- aws_private_t *priv = NULL;
-
- local = frame->local;
-
- priv = (aws_private_t *)config;
-
- if (!priv->bucketid || !priv->hostname || !priv->awssekey ||
- !priv->awskeyid) {
- ret = -1;
- goto out;
- }
-
- sign_req = aws_form_request (resource, &date, reqtype, priv->bucketid,
- local->remotepath);
- if (!sign_req) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "null sign_req, "
- "aborting download");
- ret = -1;
- goto out;
+ char *buf;
+ int bufsize = -1;
+ CURL *handle = NULL;
+ struct curl_slist *slist = NULL;
+ struct curl_slist *tmp = NULL;
+ xlator_t *this = NULL;
+ int ret = 0;
+ int debug = 1;
+ CURLcode res;
+ char errbuf[CURL_ERROR_SIZE];
+ size_t len = 0;
+ long responsecode;
+ char *sign_req = NULL;
+ char *date = NULL;
+ char *const reqtype = "GET";
+ char *signature = NULL;
+ cs_local_t *local = NULL;
+ char resource[RESOURCE_SIZE] = {
+ 0,
+ };
+ aws_private_t *priv = NULL;
+
+ local = frame->local;
+
+ priv = (aws_private_t *)config;
+
+ if (!priv->bucketid || !priv->hostname || !priv->awssekey ||
+ !priv->awskeyid) {
+ ret = -1;
+ goto out;
+ }
+
+ sign_req = aws_form_request(resource, &date, reqtype, priv->bucketid,
+ local->remotepath);
+ if (!sign_req) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "null sign_req, "
+ "aborting download");
+ ret = -1;
+ goto out;
+ }
+
+ gf_msg_debug("CS", 0, "sign_req %s date %s", sign_req, date);
+
+ signature = aws_sign_request(sign_req, priv->awssekey);
+ if (!signature) {
+ gf_msg("CS", GF_LOG_ERROR, 0, 0,
+ "null signature, "
+ "aborting download");
+ ret = -1;
+ goto out;
+ }
+
+ handle = curl_easy_init();
+ this = frame->this;
+
+ /* special numbers 6, 20, 10 accounts for static characters in the
+ * below snprintf string format arguments*/
+ bufsize = strlen(date) + 6 + strlen(priv->awskeyid) + strlen(signature) +
+ 20 + strlen(priv->hostname) + 10;
+
+ buf = (char *)alloca(bufsize);
+ if (!buf) {
+ gf_msg("CS", GF_LOG_ERROR, ENOMEM, 0,
+ "mem allocation "
+ "failed for buf");
+ ret = -1;
+ goto out;
+ }
+
+ snprintf(buf, bufsize, "Date: %s", date);
+ slist = curl_slist_append(slist, buf);
+ snprintf(buf, bufsize, "Authorization: AWS %s:%s", priv->awskeyid,
+ signature);
+ slist = curl_slist_append(slist, buf);
+ snprintf(buf, bufsize, "https://%s/%s", priv->hostname, resource);
+
+ if (gf_log_get_loglevel() >= GF_LOG_DEBUG) {
+ tmp = slist;
+ while (tmp) {
+ gf_msg_debug(this->name, 0, "slist for curl - %s", tmp->data);
+ tmp = tmp->next;
}
-
- gf_msg_debug ("CS", 0, "sign_req %s date %s", sign_req, date);
-
- signature = aws_sign_request (sign_req, priv->awssekey);
- if (!signature) {
- gf_msg ("CS", GF_LOG_ERROR, 0, 0, "null signature, "
- "aborting download");
- ret = -1;
- goto out;
+ }
+
+ curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
+ curl_easy_setopt(handle, CURLOPT_URL, buf);
+ curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, aws_write_callback);
+ curl_easy_setopt(handle, CURLOPT_WRITEDATA, frame);
+ curl_easy_setopt(handle, CURLOPT_VERBOSE, debug);
+ curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errbuf);
+
+ res = curl_easy_perform(handle);
+ if (res != CURLE_OK) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "download failed. err: %s\n",
+ curl_easy_strerror(res));
+ ret = -1;
+ len = strlen(errbuf);
+ if (len) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "curl failure %s", errbuf);
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "curl error "
+ "%s\n",
+ curl_easy_strerror(res));
}
-
- handle = curl_easy_init();
- this = frame->this;
-
- /* special numbers 6, 20, 10 accounts for static characters in the
- * below snprintf string format arguments*/
- bufsize = strlen(date) + 6 + strlen(priv->awskeyid) + strlen(signature)
- + 20 + strlen(priv->hostname) + 10;
-
- buf = (char *)alloca(bufsize);
- if (!buf) {
- gf_msg ("CS", GF_LOG_ERROR, ENOMEM, 0, "mem allocation "
- "failed for buf");
- ret = -1;
- goto out;
+ }
+
+ if (res == CURLE_OK) {
+ curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &responsecode);
+ gf_msg_debug(this->name, 0, "response code %ld", responsecode);
+ if (responsecode != 200) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "curl download failed");
}
+ }
- snprintf (buf, bufsize, "Date: %s", date);
- slist = curl_slist_append(slist, buf);
- snprintf (buf, bufsize, "Authorization: AWS %s:%s", priv->awskeyid,
- signature);
- slist = curl_slist_append(slist, buf);
- snprintf(buf, bufsize, "https://%s/%s", priv->hostname, resource);
-
- if (gf_log_get_loglevel () >= GF_LOG_DEBUG) {
- tmp = slist;
- while (tmp) {
- gf_msg_debug (this->name, 0, "slist for curl - %s",
- tmp->data);
- tmp = tmp->next;
- }
- }
-
- curl_easy_setopt (handle, CURLOPT_HTTPHEADER, slist);
- curl_easy_setopt (handle, CURLOPT_URL, buf);
- curl_easy_setopt (handle, CURLOPT_WRITEFUNCTION, aws_write_callback);
- curl_easy_setopt (handle, CURLOPT_WRITEDATA, frame);
- curl_easy_setopt (handle, CURLOPT_VERBOSE, debug);
- curl_easy_setopt (handle, CURLOPT_ERRORBUFFER, errbuf);
-
- res = curl_easy_perform(handle);
- if (res != CURLE_OK) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "download failed. err: %s\n", curl_easy_strerror(res));
- ret = -1;
- len = strlen(errbuf);
- if (len) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "curl failure %s", errbuf);
- } else {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "curl error "
- "%s\n", curl_easy_strerror(res));
- }
- }
-
- if (res == CURLE_OK) {
- curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE,
- &responsecode);
- gf_msg_debug (this->name, 0, "response code %ld", responsecode);
- if (responsecode != 200) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "curl download failed");
- }
- }
-
- curl_slist_free_all(slist);
- curl_easy_cleanup(handle);
+ curl_slist_free_all(slist);
+ curl_easy_cleanup(handle);
out:
- if (sign_req)
- GF_FREE (sign_req);
- if (date)
- GF_FREE (date);
- if (signature)
- GF_FREE (signature);
-
- return ret;
+ if (sign_req)
+ GF_FREE(sign_req);
+ if (date)
+ GF_FREE(date);
+ if (signature)
+ GF_FREE(signature);
+
+ return ret;
}
struct volume_options cs_options[] = {
- { .key = {"s3plugin-seckey"},
- .type = GF_OPTION_TYPE_STR,
- .description = "aws secret key"
- },
- { .key = {"s3plugin-keyid"},
- .type = GF_OPTION_TYPE_STR,
- .description = "aws key ID"
-
- },
- { .key = {"s3plugin-bucketid"},
- .type = GF_OPTION_TYPE_STR,
- .description = "aws bucketid"
- },
- { .key = {"s3plugin-hostname"},
- .type = GF_OPTION_TYPE_STR,
- .description = "aws hostname e.g. s3.amazonaws.com"
- },
- { .key = {NULL} },
+ {.key = {"s3plugin-seckey"},
+ .type = GF_OPTION_TYPE_STR,
+ .description = "aws secret key"},
+ {.key = {"s3plugin-keyid"},
+ .type = GF_OPTION_TYPE_STR,
+ .description = "aws key ID"
+
+ },
+ {.key = {"s3plugin-bucketid"},
+ .type = GF_OPTION_TYPE_STR,
+ .description = "aws bucketid"},
+ {.key = {"s3plugin-hostname"},
+ .type = GF_OPTION_TYPE_STR,
+ .description = "aws hostname e.g. s3.amazonaws.com"},
+ {.key = {NULL}},
};
diff --git a/xlators/features/cloudsync/src/cloudsync.c b/xlators/features/cloudsync/src/cloudsync.c
index 3e1cd6a7111..00437aaf80c 100644
--- a/xlators/features/cloudsync/src/cloudsync.c
+++ b/xlators/features/cloudsync/src/cloudsync.c
@@ -19,1713 +19,1647 @@
#include <dlfcn.h>
void
-cs_cleanup_private (cs_private_t *priv)
+cs_cleanup_private(cs_private_t *priv)
{
- if (priv) {
- if (priv->stores) {
- priv->stores->fini (priv->stores->config);
- GF_FREE (priv->stores);
- }
-
- pthread_spin_destroy (&priv->lock);
- GF_FREE (priv);
+ if (priv) {
+ if (priv->stores) {
+ priv->stores->fini(priv->stores->config);
+ GF_FREE(priv->stores);
}
- return;
+ pthread_spin_destroy(&priv->lock);
+ GF_FREE(priv);
+ }
+
+ return;
}
struct cs_plugin plugins[] = {
- {
- .name = "cloudsyncs3",
- .library = "cloudsyncs3.so",
- .description = "cloudsync s3 store."
- },
+ {.name = "cloudsyncs3",
+ .library = "cloudsyncs3.so",
+ .description = "cloudsync s3 store."},
- {.name = NULL},
+ {.name = NULL},
};
int
-cs_init (xlator_t *this)
+cs_init(xlator_t *this)
{
- cs_private_t *priv = NULL;
- gf_boolean_t per_vol = _gf_false;
- int ret = 0;
- char *libpath = NULL;
- store_methods_t *store_methods = NULL;
- void *handle = NULL;
- char *temp_str = NULL;
- int index = 0;
- char *libname = NULL;
-
- priv = GF_CALLOC (1, sizeof (*priv), gf_cs_mt_cs_private_t);
- if (!priv) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
- goto out;
+ cs_private_t *priv = NULL;
+ gf_boolean_t per_vol = _gf_false;
+ int ret = 0;
+ char *libpath = NULL;
+ store_methods_t *store_methods = NULL;
+ void *handle = NULL;
+ char *temp_str = NULL;
+ int index = 0;
+ char *libname = NULL;
+
+ priv = GF_CALLOC(1, sizeof(*priv), gf_cs_mt_cs_private_t);
+ if (!priv) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
+ goto out;
+ }
+
+ priv->this = this;
+
+ this->local_pool = mem_pool_new(cs_local_t, 512);
+ if (!this->local_pool) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, ENOMEM, "initialisation failed.");
+ ret = -1;
+ goto out;
+ }
+
+ this->private = priv;
+
+ /* temp workaround. Should be configurable through glusterd*/
+ per_vol = _gf_true;
+
+ if (per_vol) {
+ if (dict_get_str(this->options, "cloudsync-storetype", &temp_str) ==
+ 0) {
+ for (index = 0; plugins[index].name; index++) {
+ if (!strcmp(temp_str, plugins[index].name)) {
+ libname = plugins[index].library;
+ break;
+ }
+ }
+ } else {
+ ret = 0;
}
- priv->this = this;
-
- this->local_pool = mem_pool_new (cs_local_t, 512);
- if (!this->local_pool) {
- gf_msg (this->name, GF_LOG_ERROR, 0, ENOMEM,
- "initialisation failed.");
- ret = -1;
- goto out;
+ if (!libname) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, 0, "no plugin enabled");
+ ret = 0;
+ goto out;
}
- this->private = priv;
-
- /* temp workaround. Should be configurable through glusterd*/
- per_vol = _gf_true;
-
- if (per_vol) {
- if (dict_get_str (this->options, "cloudsync-storetype",
- &temp_str) == 0) {
- for (index = 0; plugins[index].name; index++) {
- if (!strcmp (temp_str, plugins[index].name)) {
- libname = plugins[index].library;
- break;
- }
- }
- } else {
- ret = 0;
- }
-
- if (!libname) {
- gf_msg (this->name, GF_LOG_WARNING, 0, 0,
- "no plugin enabled");
- ret = 0;
- goto out;
- }
-
- ret = gf_asprintf (&libpath, "%s/%s", CS_PLUGINDIR, libname);
- if (ret == -1) {
- goto out;
- }
-
- handle = dlopen (libpath, RTLD_NOW);
- if (!handle) {
- gf_msg (this->name, GF_LOG_WARNING, 0, 0, "could not "
- "load the required library. %s", dlerror ());
- ret = 0;
- goto out;
- } else {
- gf_msg (this->name, GF_LOG_INFO, 0, 0,
- "loading library:%s successful", libname);
- }
+ ret = gf_asprintf(&libpath, "%s/%s", CS_PLUGINDIR, libname);
+ if (ret == -1) {
+ goto out;
+ }
+ handle = dlopen(libpath, RTLD_NOW);
+ if (!handle) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, 0,
+ "could not "
+ "load the required library. %s",
+ dlerror());
+ ret = 0;
+ goto out;
+ } else {
+ gf_msg(this->name, GF_LOG_INFO, 0, 0,
+ "loading library:%s successful", libname);
+ }
- priv->stores = GF_CALLOC (1, sizeof (struct cs_remote_stores),
- gf_cs_mt_cs_remote_stores_t);
- if (!priv->stores) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "Could not "
- "allocate memory for priv->stores");
- ret = -1;
- goto out;
- }
+ priv->stores = GF_CALLOC(1, sizeof(struct cs_remote_stores),
+ gf_cs_mt_cs_remote_stores_t);
+ if (!priv->stores) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "Could not "
+ "allocate memory for priv->stores");
+ ret = -1;
+ goto out;
+ }
- (void) dlerror (); /* clear out previous error string */
+ (void)dlerror(); /* clear out previous error string */
- /* load library methods */
- store_methods = (store_methods_t *) dlsym (handle, "store_ops");
- if (!store_methods) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "null store_methods %s", dlerror ());
- ret = -1;
- goto out;
- }
+ /* load library methods */
+ store_methods = (store_methods_t *)dlsym(handle, "store_ops");
+ if (!store_methods) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "null store_methods %s",
+ dlerror());
+ ret = -1;
+ goto out;
+ }
- (void) dlerror ();
+ (void)dlerror();
- priv->stores->dlfop = store_methods->fop_download;
- if (!priv->stores->dlfop) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "failed to get"
- " download fop %s", dlerror ());
- ret = -1;
- goto out;
- }
+ priv->stores->dlfop = store_methods->fop_download;
+ if (!priv->stores->dlfop) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "failed to get"
+ " download fop %s",
+ dlerror());
+ ret = -1;
+ goto out;
+ }
- (void) dlerror ();
- priv->stores->init = store_methods->fop_init;
- if (!priv->stores->init) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "failed to get"
- " init fop %s", dlerror ());
- ret = -1;
- goto out;
- }
+ (void)dlerror();
+ priv->stores->init = store_methods->fop_init;
+ if (!priv->stores->init) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "failed to get"
+ " init fop %s",
+ dlerror());
+ ret = -1;
+ goto out;
+ }
- (void) dlerror ();
- priv->stores->reconfigure = store_methods->fop_reconfigure;
- if (!priv->stores->reconfigure) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "failed to get"
- " reconfigure fop %s", dlerror ());
- ret = -1;
- goto out;
- }
+ (void)dlerror();
+ priv->stores->reconfigure = store_methods->fop_reconfigure;
+ if (!priv->stores->reconfigure) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "failed to get"
+ " reconfigure fop %s",
+ dlerror());
+ ret = -1;
+ goto out;
+ }
- priv->stores->handle = handle;
+ priv->stores->handle = handle;
- priv->stores->config = (void *) ((priv->stores->init) (this));
- if (!priv->stores->config) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "null config");
- ret = -1;
- goto out;
- }
+ priv->stores->config = (void *)((priv->stores->init)(this));
+ if (!priv->stores->config) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "null config");
+ ret = -1;
+ goto out;
}
+ }
- ret = 0;
+ ret = 0;
out:
- if (ret == -1) {
- if (this->local_pool)
- mem_pool_destroy (this->local_pool);
+ if (ret == -1) {
+ if (this->local_pool)
+ mem_pool_destroy(this->local_pool);
- cs_cleanup_private (priv);
+ cs_cleanup_private(priv);
- if (handle) {
- dlclose (handle);
- }
+ if (handle) {
+ dlclose(handle);
}
+ }
- GF_FREE (libpath);
+ GF_FREE(libpath);
- return ret;
+ return ret;
}
void
-cs_fini (xlator_t *this)
+cs_fini(xlator_t *this)
{
- cs_private_t *priv = NULL;
- priv = this->private;
+ cs_private_t *priv = NULL;
+ priv = this->private;
- cs_cleanup_private (priv);
+ cs_cleanup_private(priv);
}
int
-cs_reconfigure (xlator_t *this, dict_t *options)
+cs_reconfigure(xlator_t *this, dict_t *options)
{
- cs_private_t *priv = NULL;
- int ret = 0;
+ cs_private_t *priv = NULL;
+ int ret = 0;
- priv = this->private;
- if (!priv) {
- ret = -1;
- goto out;
- }
+ priv = this->private;
+ if (!priv) {
+ ret = -1;
+ goto out;
+ }
- /* needed only for per volume configuration*/
- ret = priv->stores->reconfigure (this, options);
+ /* needed only for per volume configuration*/
+ ret = priv->stores->reconfigure(this, options);
out:
- return ret;
+ return ret;
}
int32_t
-cs_mem_acct_init (xlator_t *this)
+cs_mem_acct_init(xlator_t *this)
{
- int ret = -1;
+ int ret = -1;
- GF_VALIDATE_OR_GOTO ("cloudsync", this, out);
+ GF_VALIDATE_OR_GOTO("cloudsync", this, out);
- ret = xlator_mem_acct_init (this, gf_cs_mt_end + 1);
+ ret = xlator_mem_acct_init(this, gf_cs_mt_end + 1);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "Memory accounting init failed");
- return ret;
- }
-out:
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "Memory accounting init failed");
return ret;
+ }
+out:
+ return ret;
}
int32_t
-cs_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
- dict_t *xdata)
+cs_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
+ dict_t *xdata)
{
- gf_dirent_t *tmp = NULL;
- char *sxattr = NULL;
- uint64_t ia_size = 0;
- int ret = 0;
-
- list_for_each_entry (tmp, &entries->list, list) {
- ret = dict_get_str (tmp->dict, GF_CS_OBJECT_SIZE, &sxattr);
- if (ret) {
- gf_msg_trace (this->name, 0, "size xattr found");
- continue;
- }
-
- ia_size = atoll (sxattr);
- tmp->d_stat.ia_size = ia_size;
+ gf_dirent_t *tmp = NULL;
+ char *sxattr = NULL;
+ uint64_t ia_size = 0;
+ int ret = 0;
+
+ list_for_each_entry(tmp, &entries->list, list)
+ {
+ ret = dict_get_str(tmp->dict, GF_CS_OBJECT_SIZE, &sxattr);
+ if (ret) {
+ gf_msg_trace(this->name, 0, "size xattr found");
+ continue;
}
- STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno,
- entries, xdata);
- return 0;
-}
+ ia_size = atoll(sxattr);
+ tmp->d_stat.ia_size = ia_size;
+ }
+ STACK_UNWIND_STRICT(readdirp, frame, op_ret, op_errno, entries, xdata);
+ return 0;
+}
int32_t
-cs_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
- off_t off, dict_t *xdata)
+cs_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t off, dict_t *xdata)
{
- int ret = 0;
- int op_errno = ENOMEM;
+ int ret = 0;
+ int op_errno = ENOMEM;
+ if (!xdata) {
+ xdata = dict_new();
if (!xdata) {
- xdata = dict_new ();
- if (!xdata) {
- goto err;
- }
+ goto err;
}
+ }
- ret = dict_set_int32 (xdata, GF_CS_OBJECT_SIZE, 1);
- if (ret) {
- goto err;
- }
+ ret = dict_set_int32(xdata, GF_CS_OBJECT_SIZE, 1);
+ if (ret) {
+ goto err;
+ }
- STACK_WIND (frame, cs_readdirp_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->readdirp,
- fd, size, off, xdata);
- return 0;
+ STACK_WIND(frame, cs_readdirp_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readdirp, fd, size, off, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (readdirp, frame, -1, op_errno,
- NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(readdirp, frame, -1, op_errno, NULL, NULL);
+ return 0;
}
-
int32_t
-cs_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+cs_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- cs_local_t *local = NULL;
- int ret = 0;
- uint64_t val = 0;
-
- local = frame->local;
-
- /* Do we need lock here? */
- local->call_cnt++;
-
- if (op_ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "truncate failed");
- ret = dict_get_uint64 (xdata, GF_CS_OBJECT_STATUS, &val);
- if (ret == 0) {
- if (val == GF_CS_ERROR) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "could not get file state, unwinding");
- op_ret = -1;
- op_errno = EIO;
- goto unwind;
- } else {
- __cs_inode_ctx_update (this, local->loc.inode,
- val);
- gf_msg (this->name, GF_LOG_INFO, 0, 0,
- " state = %ld", val);
-
- if (local->call_cnt == 1 &&
- (val == GF_CS_REMOTE ||
- val == GF_CS_DOWNLOADING)) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- 0, "will repair and download "
- "the file, current state : %ld",
- val);
- goto repair;
- } else {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "second truncate, Unwinding");
- goto unwind;
- }
- }
+ cs_local_t *local = NULL;
+ int ret = 0;
+ uint64_t val = 0;
+
+ local = frame->local;
+
+ /* Do we need lock here? */
+ local->call_cnt++;
+
+ if (op_ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "truncate failed");
+ ret = dict_get_uint64(xdata, GF_CS_OBJECT_STATUS, &val);
+ if (ret == 0) {
+ if (val == GF_CS_ERROR) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "could not get file state, unwinding");
+ op_ret = -1;
+ op_errno = EIO;
+ goto unwind;
+ } else {
+ __cs_inode_ctx_update(this, local->loc.inode, val);
+ gf_msg(this->name, GF_LOG_INFO, 0, 0, " state = %ld", val);
+
+ if (local->call_cnt == 1 &&
+ (val == GF_CS_REMOTE || val == GF_CS_DOWNLOADING)) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, 0,
+ "will repair and download "
+ "the file, current state : %ld",
+ val);
+ goto repair;
} else {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "file state "
- "could not be figured, unwinding");
- goto unwind;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "second truncate, Unwinding");
+ goto unwind;
}
+ }
} else {
- /* successful write => file is local */
- __cs_inode_ctx_update (this, local->loc.inode, GF_CS_LOCAL);
- gf_msg (this->name, GF_LOG_INFO, 0, 0, "state : GF_CS_LOCAL"
- ", truncate successful");
-
- goto unwind;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "file state "
+ "could not be figured, unwinding");
+ goto unwind;
}
+ } else {
+ /* successful write => file is local */
+ __cs_inode_ctx_update(this, local->loc.inode, GF_CS_LOCAL);
+ gf_msg(this->name, GF_LOG_INFO, 0, 0,
+ "state : GF_CS_LOCAL"
+ ", truncate successful");
+
+ goto unwind;
+ }
repair:
- ret = locate_and_execute (frame);
- if (ret) {
- goto unwind;
- }
+ ret = locate_and_execute(frame);
+ if (ret) {
+ goto unwind;
+ }
- return 0;
+ return 0;
unwind:
- CS_STACK_UNWIND (truncate, frame, op_ret, op_errno, prebuf, postbuf,
- xdata);
- return 0;
+ CS_STACK_UNWIND(truncate, frame, op_ret, op_errno, prebuf, postbuf, xdata);
+ return 0;
}
-
int32_t
-cs_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
- dict_t *xdata)
+cs_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
+ dict_t *xdata)
{
- int op_errno = -1;
- cs_local_t *local = NULL;
- int ret = 0;
- cs_inode_ctx_t *ctx = NULL;
- gf_cs_obj_state state = -1;
-
- VALIDATE_OR_GOTO (frame, err);
- VALIDATE_OR_GOTO (this, err);
- VALIDATE_OR_GOTO (loc, err);
-
- local = cs_local_init (this, frame, loc, NULL, GF_FOP_TRUNCATE);
- if (!local) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "local init failed");
- op_errno = ENOMEM;
- goto err;
- }
-
- __cs_inode_ctx_get (this, loc->inode, &ctx);
-
- if (ctx)
- state = __cs_get_file_state (this, loc->inode, ctx);
- else
- state = GF_CS_LOCAL;
-
- local->xattr_req = xdata ? dict_ref (xdata) : (xdata = dict_new ());
-
- ret = dict_set_uint32 (local->xattr_req, GF_CS_OBJECT_STATUS, 1);
+ int op_errno = -1;
+ cs_local_t *local = NULL;
+ int ret = 0;
+ cs_inode_ctx_t *ctx = NULL;
+ gf_cs_obj_state state = -1;
+
+ VALIDATE_OR_GOTO(frame, err);
+ VALIDATE_OR_GOTO(this, err);
+ VALIDATE_OR_GOTO(loc, err);
+
+ local = cs_local_init(this, frame, loc, NULL, GF_FOP_TRUNCATE);
+ if (!local) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "local init failed");
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ __cs_inode_ctx_get(this, loc->inode, &ctx);
+
+ if (ctx)
+ state = __cs_get_file_state(this, loc->inode, ctx);
+ else
+ state = GF_CS_LOCAL;
+
+ local->xattr_req = xdata ? dict_ref(xdata) : (xdata = dict_new());
+
+ ret = dict_set_uint32(local->xattr_req, GF_CS_OBJECT_STATUS, 1);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "dict_set failed key:"
+ " %s",
+ GF_CS_OBJECT_STATUS);
+ goto err;
+ }
+
+ local->stub = fop_truncate_stub(frame, cs_resume_truncate, loc, offset,
+ xdata);
+ if (!local->stub) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ if (state == GF_CS_LOCAL) {
+ STACK_WIND(frame, cs_truncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
+
+ } else {
+ local->call_cnt++;
+ ret = locate_and_execute(frame);
if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "dict_set failed key:"
- " %s", GF_CS_OBJECT_STATUS);
- goto err;
+ op_errno = ENOMEM;
+ goto err;
}
+ }
- local->stub = fop_truncate_stub (frame, cs_resume_truncate, loc, offset,
- xdata);
- if (!local->stub) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
- op_errno = ENOMEM;
- goto err;
- }
-
- if (state == GF_CS_LOCAL) {
- STACK_WIND (frame, cs_truncate_cbk,
- FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->truncate,
- loc, offset, xdata);
-
- } else {
- local->call_cnt++;
- ret = locate_and_execute (frame);
- if (ret) {
- op_errno = ENOMEM;
- goto err;
- }
- }
-
- return 0;
+ return 0;
err:
- CS_STACK_UNWIND (truncate, frame, -1, op_errno, NULL, NULL, NULL);
- return 0;
+ CS_STACK_UNWIND(truncate, frame, -1, op_errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-cs_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct statvfs *buf,
- dict_t *xdata)
+cs_statfs_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct statvfs *buf, dict_t *xdata)
{
- STACK_UNWIND_STRICT (statfs, frame, op_ret, op_errno,
- buf, xdata);
- return 0;
+ STACK_UNWIND_STRICT(statfs, frame, op_ret, op_errno, buf, xdata);
+ return 0;
}
-
int32_t
-cs_statfs (call_frame_t *frame, xlator_t *this,
- loc_t *loc,
- dict_t *xdata)
+cs_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- STACK_WIND (frame, cs_statfs_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->statfs,
- loc, xdata);
- return 0;
+ STACK_WIND(frame, cs_statfs_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->statfs, loc, xdata);
+ return 0;
}
-
int32_t
-cs_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *dict,
- dict_t *xdata)
+cs_getxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata)
{
- STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno,
- dict, xdata);
- return 0;
+ STACK_UNWIND_STRICT(getxattr, frame, op_ret, op_errno, dict, xdata);
+ return 0;
}
-
int32_t
-cs_getxattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc,
- const char *name,
- dict_t *xattr_req)
+cs_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name,
+ dict_t *xattr_req)
{
- STACK_WIND (frame, cs_getxattr_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->getxattr,
- loc, name, xattr_req);
- return 0;
+ STACK_WIND(frame, cs_getxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->getxattr, loc, name, xattr_req);
+ return 0;
}
int32_t
-cs_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+cs_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- cs_local_t *local = NULL;
+ cs_local_t *local = NULL;
- local = frame->local;
+ local = frame->local;
- if (local->locked)
- cs_inodelk_unlock (frame);
+ if (local->locked)
+ cs_inodelk_unlock(frame);
- CS_STACK_UNWIND (setxattr, frame, op_ret, op_errno, xdata);
+ CS_STACK_UNWIND(setxattr, frame, op_ret, op_errno, xdata);
- return 0;
+ return 0;
}
-
int32_t
-cs_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
- int32_t flags, dict_t *xdata)
+cs_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
+ int32_t flags, dict_t *xdata)
{
- data_t *tmp = NULL;
- cs_local_t *local = NULL;
- int ret = 0;
+ data_t *tmp = NULL;
+ cs_local_t *local = NULL;
+ int ret = 0;
- VALIDATE_OR_GOTO (frame, err);
- VALIDATE_OR_GOTO (this, err);
-
- local = cs_local_init (this, frame, loc, NULL, GF_FOP_SETXATTR);
- if (!local) {
- ret = -1;
- goto err;
- }
+ VALIDATE_OR_GOTO(frame, err);
+ VALIDATE_OR_GOTO(this, err);
- local->xattr_req = xdata ? dict_ref (xdata) : (xdata = dict_new ());
+ local = cs_local_init(this, frame, loc, NULL, GF_FOP_SETXATTR);
+ if (!local) {
+ ret = -1;
+ goto err;
+ }
- tmp = dict_get (dict, GF_CS_OBJECT_UPLOAD_COMPLETE);
- if (tmp) {
- /* Value of key should be the atime */
- local->stub = fop_setxattr_stub (frame, cs_resume_setxattr,
- loc, dict, flags, xdata);
+ local->xattr_req = xdata ? dict_ref(xdata) : (xdata = dict_new());
- if (!local->stub)
- goto err;
+ tmp = dict_get(dict, GF_CS_OBJECT_UPLOAD_COMPLETE);
+ if (tmp) {
+ /* Value of key should be the atime */
+ local->stub = fop_setxattr_stub(frame, cs_resume_setxattr, loc, dict,
+ flags, xdata);
- ret = locate_and_execute (frame);
- if (ret) {
- goto err;
- }
+ if (!local->stub)
+ goto err;
- return 0;
+ ret = locate_and_execute(frame);
+ if (ret) {
+ goto err;
}
- STACK_WIND (frame, cs_setxattr_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->setxattr,
- loc, dict, flags, xdata);
return 0;
+ }
+
+ STACK_WIND(frame, cs_setxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, loc, dict, flags, xdata);
+ return 0;
err:
- CS_STACK_UNWIND (setxattr, frame, -1, errno, NULL);
- return 0;
+ CS_STACK_UNWIND(setxattr, frame, -1, errno, NULL);
+ return 0;
}
-
int32_t
-cs_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *dict,
- dict_t *xdata)
+cs_fgetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata)
{
- STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno,
- dict, xdata);
- return 0;
+ STACK_UNWIND_STRICT(fgetxattr, frame, op_ret, op_errno, dict, xdata);
+ return 0;
}
-
int32_t
-cs_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name,
- dict_t *xdata)
+cs_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name,
+ dict_t *xdata)
{
- STACK_WIND (frame, cs_fgetxattr_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->fgetxattr,
- fd, name, xdata);
- return 0;
+ STACK_WIND(frame, cs_fgetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fgetxattr, fd, name, xdata);
+ return 0;
}
-
-
int32_t
-cs_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+cs_fsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno,
- xdata);
- return 0;
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, xdata);
+ return 0;
}
-
int32_t
-cs_fsetxattr (call_frame_t *frame, xlator_t *this,
- fd_t *fd,
- dict_t *dict,
- int32_t flags,
- dict_t *xdata)
+cs_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
+ int32_t flags, dict_t *xdata)
{
- STACK_WIND (frame, cs_fsetxattr_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsetxattr,
- fd, dict, flags, xdata);
- return 0;
+ STACK_WIND(frame, cs_fsetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata);
+ return 0;
}
int32_t
-cs_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *preparent,
- struct iatt *postparent,
- dict_t *xdata)
+cs_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct iatt *preparent, struct iatt *postparent,
+ dict_t *xdata)
{
- STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno,
- preparent, postparent, xdata);
- return 0;
+ STACK_UNWIND_STRICT(unlink, frame, op_ret, op_errno, preparent, postparent,
+ xdata);
+ return 0;
}
-
int32_t
-cs_unlink (call_frame_t *frame, xlator_t *this,
- loc_t *loc,
- int32_t flags,
- dict_t *xattr_req)
+cs_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ dict_t *xattr_req)
{
- cs_local_t *local = NULL;
- int ret = 0;
-
- local = cs_local_init (this, frame, loc, NULL, GF_FOP_UNLINK);
- if (!local)
- goto err;
-
- local->xattr_req = xattr_req ? dict_ref (xattr_req) : dict_new ();
-
- ret = dict_set_uint32 (local->xattr_req, GF_CS_OBJECT_STATUS, 1);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "dict_set failed key:"
- " %s", GF_CS_OBJECT_STATUS);
- goto err;
- }
- STACK_WIND (frame, cs_unlink_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->unlink,
- loc, flags, local->xattr_req);
- return 0;
+ cs_local_t *local = NULL;
+ int ret = 0;
+
+ local = cs_local_init(this, frame, loc, NULL, GF_FOP_UNLINK);
+ if (!local)
+ goto err;
+
+ local->xattr_req = xattr_req ? dict_ref(xattr_req) : dict_new();
+
+ ret = dict_set_uint32(local->xattr_req, GF_CS_OBJECT_STATUS, 1);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "dict_set failed key:"
+ " %s",
+ GF_CS_OBJECT_STATUS);
+ goto err;
+ }
+ STACK_WIND(frame, cs_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, loc, flags, local->xattr_req);
+ return 0;
err:
- CS_STACK_UNWIND (unlink, frame, -1, errno, NULL, NULL, NULL);
- return 0;
+ CS_STACK_UNWIND(unlink, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
-
int32_t
-cs_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, fd_t *fd,
- dict_t *xdata)
+cs_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, fd_t *fd, dict_t *xdata)
{
- int ret = 0;
- uint64_t val = 0;
-
- if (op_ret == 0) {
- ret = dict_get_uint64 (xdata, GF_CS_OBJECT_STATUS, &val);
- if (!ret) {
- ret = __cs_inode_ctx_update (this, fd->inode, val);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "ctx update failed");
- }
- }
- } else {
- cs_inode_ctx_reset (this, fd->inode);
+ int ret = 0;
+ uint64_t val = 0;
+
+ if (op_ret == 0) {
+ ret = dict_get_uint64(xdata, GF_CS_OBJECT_STATUS, &val);
+ if (!ret) {
+ ret = __cs_inode_ctx_update(this, fd->inode, val);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "ctx update failed");
+ }
}
+ } else {
+ cs_inode_ctx_reset(this, fd->inode);
+ }
- CS_STACK_UNWIND (open, frame, op_ret, op_errno, fd, xdata);
- return 0;
+ CS_STACK_UNWIND(open, frame, op_ret, op_errno, fd, xdata);
+ return 0;
}
-
int32_t
-cs_open (call_frame_t *frame, xlator_t *this,
- loc_t *loc,
- int32_t flags,
- fd_t *fd,
- dict_t *xattr_req)
+cs_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ fd_t *fd, dict_t *xattr_req)
{
- cs_local_t *local = NULL;
- int ret = 0;
-
- local = cs_local_init (this, frame, NULL, fd, GF_FOP_OPEN);
- if (!local)
- goto err;
-
- local->xattr_req = xattr_req ? dict_ref (xattr_req) : dict_new ();
-
- ret = dict_set_uint32 (local->xattr_req, GF_CS_OBJECT_STATUS, 1);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "dict_set failed key:"
- " %s", GF_CS_OBJECT_STATUS);
- goto err;
- }
-
- STACK_WIND (frame, cs_open_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->open,
- loc, flags, fd, local->xattr_req);
- return 0;
+ cs_local_t *local = NULL;
+ int ret = 0;
+
+ local = cs_local_init(this, frame, NULL, fd, GF_FOP_OPEN);
+ if (!local)
+ goto err;
+
+ local->xattr_req = xattr_req ? dict_ref(xattr_req) : dict_new();
+
+ ret = dict_set_uint32(local->xattr_req, GF_CS_OBJECT_STATUS, 1);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "dict_set failed key:"
+ " %s",
+ GF_CS_OBJECT_STATUS);
+ goto err;
+ }
+
+ STACK_WIND(frame, cs_open_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->open, loc, flags, fd, local->xattr_req);
+ return 0;
err:
- CS_STACK_UNWIND (open, frame, -1, errno, NULL, NULL);
- return 0;
+ CS_STACK_UNWIND(open, frame, -1, errno, NULL, NULL);
+ return 0;
}
-
int32_t
-cs_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *buf,
- dict_t *xdata)
+cs_fstat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct iatt *buf, dict_t *xdata)
{
- int ret = 0;
- uint64_t val = 0;
- fd_t *fd = NULL;
- cs_local_t *local = NULL;
-
- local = frame->local;
-
- fd = local->fd;
-
- if (op_ret == 0) {
- ret = dict_get_uint64 (xdata, GF_CS_OBJECT_STATUS, &val);
- if (!ret) {
- gf_msg_debug (this->name, 0, "state %ld", val);
- ret = __cs_inode_ctx_update (this, fd->inode, val);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "ctx update failed");
- }
- }
- } else {
- cs_inode_ctx_reset (this, fd->inode);
+ int ret = 0;
+ uint64_t val = 0;
+ fd_t *fd = NULL;
+ cs_local_t *local = NULL;
+
+ local = frame->local;
+
+ fd = local->fd;
+
+ if (op_ret == 0) {
+ ret = dict_get_uint64(xdata, GF_CS_OBJECT_STATUS, &val);
+ if (!ret) {
+ gf_msg_debug(this->name, 0, "state %ld", val);
+ ret = __cs_inode_ctx_update(this, fd->inode, val);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "ctx update failed");
+ }
}
+ } else {
+ cs_inode_ctx_reset(this, fd->inode);
+ }
- CS_STACK_UNWIND (fstat, frame, op_ret, op_errno, buf, xdata);
+ CS_STACK_UNWIND(fstat, frame, op_ret, op_errno, buf, xdata);
- return 0;
+ return 0;
}
-
int32_t
-cs_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xattr_req)
+cs_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xattr_req)
{
- cs_local_t *local = NULL;
- int ret = 0;
+ cs_local_t *local = NULL;
+ int ret = 0;
- local = cs_local_init (this, frame, NULL, fd, GF_FOP_FSTAT);
- if (!local)
- goto err;
+ local = cs_local_init(this, frame, NULL, fd, GF_FOP_FSTAT);
+ if (!local)
+ goto err;
- if (fd->inode->ia_type == IA_IFDIR)
- goto wind;
+ if (fd->inode->ia_type == IA_IFDIR)
+ goto wind;
- local->xattr_req = xattr_req ? dict_ref (xattr_req) : dict_new ();
+ local->xattr_req = xattr_req ? dict_ref(xattr_req) : dict_new();
- ret = dict_set_uint32 (local->xattr_req, GF_CS_OBJECT_STATUS, 1);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "dict_set failed key:"
- " %s", GF_CS_OBJECT_STATUS);
- goto err;
- }
+ ret = dict_set_uint32(local->xattr_req, GF_CS_OBJECT_STATUS, 1);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "dict_set failed key:"
+ " %s",
+ GF_CS_OBJECT_STATUS);
+ goto err;
+ }
wind:
- STACK_WIND (frame, cs_fstat_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->fstat,
- fd, local->xattr_req);
- return 0;
+ STACK_WIND(frame, cs_fstat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, fd, local->xattr_req);
+ return 0;
err:
- CS_STACK_UNWIND (fstat, frame, -1, errno, NULL, NULL);
- return 0;
+ CS_STACK_UNWIND(fstat, frame, -1, errno, NULL, NULL);
+ return 0;
}
cs_local_t *
-cs_local_init (xlator_t *this, call_frame_t *frame, loc_t *loc, fd_t *fd,
- glusterfs_fop_t fop)
+cs_local_init(xlator_t *this, call_frame_t *frame, loc_t *loc, fd_t *fd,
+ glusterfs_fop_t fop)
{
- cs_local_t *local = NULL;
- int ret = 0;
-
- local = mem_get0 (this->local_pool);
- if (!local)
- goto out;
-
- if (loc) {
- ret = loc_copy (&local->loc, loc);
- if (ret)
- goto out;
- }
+ cs_local_t *local = NULL;
+ int ret = 0;
- if (fd) {
- local->fd = fd_ref (fd);
- }
+ local = mem_get0(this->local_pool);
+ if (!local)
+ goto out;
- local->op_ret = -1;
- local->op_errno = EUCLEAN;
- local->fop = fop;
- local->dloffset = 0;
- frame->local = local;
- local->locked = _gf_false;
- local->call_cnt = 0;
+ if (loc) {
+ ret = loc_copy(&local->loc, loc);
+ if (ret)
+ goto out;
+ }
+
+ if (fd) {
+ local->fd = fd_ref(fd);
+ }
+
+ local->op_ret = -1;
+ local->op_errno = EUCLEAN;
+ local->fop = fop;
+ local->dloffset = 0;
+ frame->local = local;
+ local->locked = _gf_false;
+ local->call_cnt = 0;
out:
- if (ret) {
- if (local)
- mem_put (local);
- local = NULL;
- }
+ if (ret) {
+ if (local)
+ mem_put(local);
+ local = NULL;
+ }
- return local;
+ return local;
}
call_frame_t *
-cs_lock_frame (call_frame_t *parent_frame)
+cs_lock_frame(call_frame_t *parent_frame)
{
- call_frame_t *lock_frame = NULL;
+ call_frame_t *lock_frame = NULL;
- lock_frame = copy_frame (parent_frame);
+ lock_frame = copy_frame(parent_frame);
- if (lock_frame == NULL)
- goto out;
+ if (lock_frame == NULL)
+ goto out;
- set_lk_owner_from_ptr (&lock_frame->root->lk_owner, parent_frame->root);
+ set_lk_owner_from_ptr(&lock_frame->root->lk_owner, parent_frame->root);
out:
- return lock_frame;
-
+ return lock_frame;
}
void
-cs_lock_wipe (call_frame_t *lock_frame)
+cs_lock_wipe(call_frame_t *lock_frame)
{
- CS_STACK_DESTROY (lock_frame);
+ CS_STACK_DESTROY(lock_frame);
}
-
int32_t
-cs_inodelk_unlock_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+cs_inodelk_unlock_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- cs_lock_wipe (frame);
+ cs_lock_wipe(frame);
- return 0;
+ return 0;
}
int
-cs_inodelk_unlock (call_frame_t *main_frame)
+cs_inodelk_unlock(call_frame_t *main_frame)
{
- xlator_t *this = NULL;
- struct gf_flock flock = {0,};
- call_frame_t *lock_frame = NULL;
- cs_local_t *lock_local = NULL;
- cs_local_t *main_local = NULL;
- int ret = 0;
-
- this = main_frame->this;
- main_local = main_frame->local;
-
- lock_frame = cs_lock_frame (main_frame);
- if (!lock_frame)
- goto out;
+ xlator_t *this = NULL;
+ struct gf_flock flock = {
+ 0,
+ };
+ call_frame_t *lock_frame = NULL;
+ cs_local_t *lock_local = NULL;
+ cs_local_t *main_local = NULL;
+ int ret = 0;
- lock_local = cs_local_init (this, lock_frame, NULL, NULL, 0);
- if (!lock_local)
- goto out;
+ this = main_frame->this;
+ main_local = main_frame->local;
- ret = cs_build_loc (&lock_local->loc, main_frame);
- if (ret) {
- goto out;
- }
+ lock_frame = cs_lock_frame(main_frame);
+ if (!lock_frame)
+ goto out;
- flock.l_type = F_UNLCK;
+ lock_local = cs_local_init(this, lock_frame, NULL, NULL, 0);
+ if (!lock_local)
+ goto out;
- main_local->locked = _gf_false;
+ ret = cs_build_loc(&lock_local->loc, main_frame);
+ if (ret) {
+ goto out;
+ }
- STACK_WIND (lock_frame, cs_inodelk_unlock_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->inodelk, CS_LOCK_DOMAIN,
- &lock_local->loc, F_SETLKW, &flock, NULL);
+ flock.l_type = F_UNLCK;
- return 0;
+ main_local->locked = _gf_false;
+
+ STACK_WIND(lock_frame, cs_inodelk_unlock_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->inodelk, CS_LOCK_DOMAIN,
+ &lock_local->loc, F_SETLKW, &flock, NULL);
+
+ return 0;
out:
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "Stale lock would be found on"
- " server");
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "Stale lock would be found on"
+ " server");
- if (lock_frame)
- cs_lock_wipe (lock_frame);
+ if (lock_frame)
+ cs_lock_wipe(lock_frame);
- return 0;
+ return 0;
}
void *
-cs_download_task (void *arg)
+cs_download_task(void *arg)
{
- call_frame_t *frame = NULL;
- xlator_t *this = NULL;
- cs_private_t *priv = NULL;
- int ret = -1;
- char *sign_req = NULL;
- fd_t *fd = NULL;
- cs_local_t *local = NULL;
- dict_t *dict = NULL;
- int *retval = NULL;
-
- frame = (call_frame_t *)arg;
-
- this = frame->this;
-
- priv = this->private;
-
- retval = GF_CALLOC (1, sizeof(int), gf_common_mt_int);
- if (!retval) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
- ret = -1;
- goto out;
- }
-
- if (!priv->stores) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "No remote store "
- "plugins found");
- ret = -1;
- goto out;
- }
-
- local = frame->local;
-
-
- if (local->fd)
- fd = fd_anonymous (local->fd->inode);
- else
- fd = fd_anonymous (local->loc.inode);
-
- if (!fd) {
- gf_msg ("CS", GF_LOG_ERROR, 0, 0, "fd creation failed");
- ret = -1;
- goto out;
+ call_frame_t *frame = NULL;
+ xlator_t *this = NULL;
+ cs_private_t *priv = NULL;
+ int ret = -1;
+ char *sign_req = NULL;
+ fd_t *fd = NULL;
+ cs_local_t *local = NULL;
+ dict_t *dict = NULL;
+ int *retval = NULL;
+
+ frame = (call_frame_t *)arg;
+
+ this = frame->this;
+
+ priv = this->private;
+
+ retval = GF_CALLOC(1, sizeof(int), gf_common_mt_int);
+ if (!retval) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
+ ret = -1;
+ goto out;
+ }
+
+ if (!priv->stores) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "No remote store "
+ "plugins found");
+ ret = -1;
+ goto out;
+ }
+
+ local = frame->local;
+
+ if (local->fd)
+ fd = fd_anonymous(local->fd->inode);
+ else
+ fd = fd_anonymous(local->loc.inode);
+
+ if (!fd) {
+ gf_msg("CS", GF_LOG_ERROR, 0, 0, "fd creation failed");
+ ret = -1;
+ goto out;
+ }
+
+ local->dlfd = fd;
+ local->dloffset = 0;
+
+ dict = dict_new();
+ if (!dict) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, ENOMEM,
+ "failed to create "
+ "dict");
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_set_uint32(dict, GF_CS_OBJECT_DOWNLOADING, 1);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "dict_set failed");
+ ret = -1;
+ goto out;
+ }
+
+ ret = syncop_fsetxattr(this, local->fd, dict, 0, NULL, NULL);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "fsetxattr failed "
+ "key %s",
+ GF_CS_OBJECT_DOWNLOADING);
+ ret = -1;
+ goto out;
+ }
+ /*this calling method is for per volume setting */
+ ret = priv->stores->dlfop(frame, priv->stores->config);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "download failed"
+ ", remotepath: %s",
+ local->remotepath);
+
+ /*using dlfd as it is anonymous and have RDWR flag*/
+ ret = syncop_ftruncate(FIRST_CHILD(this), local->dlfd, 0, NULL, NULL,
+ NULL, NULL);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, -ret, "ftruncate failed");
+ } else {
+ gf_msg_debug(this->name, 0, "ftruncate succeed");
}
- local->dlfd = fd;
- local->dloffset = 0;
-
- dict = dict_new ();
- if (!dict) {
- gf_msg (this->name, GF_LOG_ERROR, 0, ENOMEM, "failed to create "
- "dict");
- ret = -1;
- goto out;
- }
+ ret = -1;
+ goto out;
+ } else {
+ gf_msg(this->name, GF_LOG_INFO, 0, 0,
+ "download success, path"
+ " : %s",
+ local->remotepath);
- ret = dict_set_uint32 (dict, GF_CS_OBJECT_DOWNLOADING, 1);
+ ret = syncop_fremovexattr(this, local->fd, GF_CS_OBJECT_REMOTE, NULL,
+ NULL);
if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "dict_set failed");
- ret = -1;
- goto out;
+ gf_msg(this->name, GF_LOG_ERROR, 0, -ret,
+ "removexattr failed, remotexattr");
+ ret = -1;
+ goto out;
+ } else {
+ gf_msg_debug(this->name, 0,
+ "fremovexattr success, "
+ "path : %s",
+ local->remotepath);
}
- ret = syncop_fsetxattr (this, local->fd, dict, 0, NULL, NULL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "fsetxattr failed "
- "key %s", GF_CS_OBJECT_DOWNLOADING);
- ret = -1;
- goto out;
- }
- /*this calling method is for per volume setting */
- ret = priv->stores->dlfop (frame, priv->stores->config);
+ ret = syncop_fremovexattr(this, local->fd, GF_CS_OBJECT_DOWNLOADING,
+ NULL, NULL);
if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "download failed"
- ", remotepath: %s", local->remotepath);
-
- /*using dlfd as it is anonymous and have RDWR flag*/
- ret = syncop_ftruncate (FIRST_CHILD (this), local->dlfd, 0,
- NULL, NULL, NULL, NULL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, -ret,
- "ftruncate failed");
- } else {
- gf_msg_debug (this->name, 0, "ftruncate succeed");
- }
-
- ret = -1;
- goto out;
+ gf_msg(this->name, GF_LOG_ERROR, 0, -ret,
+ "removexattr failed, downloading xattr, path %s",
+ local->remotepath);
+ ret = -1;
+ goto out;
} else {
- gf_msg (this->name, GF_LOG_INFO, 0, 0, "download success, path"
- " : %s", local->remotepath);
-
- ret = syncop_fremovexattr (this, local->fd,
- GF_CS_OBJECT_REMOTE, NULL, NULL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, -ret,
- "removexattr failed, remotexattr");
- ret = -1;
- goto out;
- } else {
- gf_msg_debug (this->name, 0, "fremovexattr success, "
- "path : %s", local->remotepath);
- }
-
- ret = syncop_fremovexattr (this, local->fd,
- GF_CS_OBJECT_DOWNLOADING, NULL,
- NULL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, -ret,
- "removexattr failed, downloading xattr, path %s"
- , local->remotepath);
- ret = -1;
- goto out;
- } else {
- gf_msg_debug (this->name, 0, "fremovexattr success"
- " path %s", local->remotepath);
- }
+ gf_msg_debug(this->name, 0,
+ "fremovexattr success"
+ " path %s",
+ local->remotepath);
}
+ }
out:
- GF_FREE (sign_req);
-
- if (dict)
- dict_unref (dict);
-
- if (fd) {
- fd_unref (fd);
- local->dlfd = NULL;
- }
-
- if (retval) {
- *retval = ret;
- pthread_exit (retval);
- } else {
- pthread_exit (&ret);
- }
+ GF_FREE(sign_req);
+
+ if (dict)
+ dict_unref(dict);
+
+ if (fd) {
+ fd_unref(fd);
+ local->dlfd = NULL;
+ }
+
+ if (retval) {
+ *retval = ret;
+ pthread_exit(retval);
+ } else {
+ pthread_exit(&ret);
+ }
}
int
-cs_download (call_frame_t *frame)
+cs_download(call_frame_t *frame)
{
- int *retval = NULL;
- int ret = 0;
- pthread_t dthread;
- cs_local_t *local = NULL;
- xlator_t *this = NULL;
+ int *retval = NULL;
+ int ret = 0;
+ pthread_t dthread;
+ cs_local_t *local = NULL;
+ xlator_t *this = NULL;
- local = frame->local;
- this = frame->this;
+ local = frame->local;
+ this = frame->this;
- if (!local->remotepath) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "remote path not"
- " available. Check posix logs to resolve");
- goto out;
- }
+ if (!local->remotepath) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "remote path not"
+ " available. Check posix logs to resolve");
+ goto out;
+ }
- ret = gf_thread_create (&dthread, NULL, &cs_download_task,
- (void *)frame, "downloadthread");
+ ret = gf_thread_create(&dthread, NULL, &cs_download_task, (void *)frame,
+ "downloadthread");
- pthread_join (dthread, (void **)&retval);
+ pthread_join(dthread, (void **)&retval);
- ret = *retval;
+ ret = *retval;
out:
- if (retval)
- GF_FREE (retval);
+ if (retval)
+ GF_FREE(retval);
- return ret;
+ return ret;
}
int
-cs_stat_check_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, struct iatt *stbuf, dict_t *xdata)
+cs_stat_check_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct iatt *stbuf, dict_t *xdata)
{
- cs_local_t *local = NULL;
- call_stub_t *stub = NULL;
- char *filepath = NULL;
- int ret = 0;
- inode_t *inode = NULL;
- uint64_t val = 0;
-
- local = frame->local;
-
- if (op_ret == -1) {
- local->op_ret = op_ret;
- local->op_errno = op_errno;
- gf_msg (this->name, GF_LOG_ERROR, 0, op_errno,
- "stat check failed");
- goto err;
- } else {
- if (local->fd)
- inode = local->fd->inode;
- else
- inode = local->loc.inode;
-
- if (!inode) {
- local->op_ret = -1;
- local->op_errno = EINVAL;
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "null inode "
- "returned");
- goto err;
- }
-
- ret = dict_get_uint64 (xdata, GF_CS_OBJECT_STATUS, &val);
- if (ret == 0) {
- if (val == GF_CS_ERROR) {
- cs_inode_ctx_reset (this, inode);
- local->op_ret = -1;
- local->op_errno = EIO;
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "status = GF_CS_ERROR. failed to get "
- " file state");
- goto err;
- } else {
- ret = __cs_inode_ctx_update (this, inode, val);
- gf_msg_debug (this->name, 0, "status : %lu",
- val);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "ctx update failed");
- local->op_ret = -1;
- local->op_errno = ENOMEM;
- goto err;
- }
- }
- } else {
- gf_msg_debug (this->name, 0,
- "status not found in dict");
- local->op_ret = -1;
- local->op_errno = ENOMEM;
- goto err;
- }
+ cs_local_t *local = NULL;
+ call_stub_t *stub = NULL;
+ char *filepath = NULL;
+ int ret = 0;
+ inode_t *inode = NULL;
+ uint64_t val = 0;
+
+ local = frame->local;
+
+ if (op_ret == -1) {
+ local->op_ret = op_ret;
+ local->op_errno = op_errno;
+ gf_msg(this->name, GF_LOG_ERROR, 0, op_errno, "stat check failed");
+ goto err;
+ } else {
+ if (local->fd)
+ inode = local->fd->inode;
+ else
+ inode = local->loc.inode;
+
+ if (!inode) {
+ local->op_ret = -1;
+ local->op_errno = EINVAL;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "null inode "
+ "returned");
+ goto err;
+ }
- ret = dict_get_str (xdata, GF_CS_OBJECT_REMOTE, &filepath);
- if (filepath) {
- gf_msg_debug (this->name, 0, "filepath returned %s",
- filepath);
- local->remotepath = gf_strdup (filepath);
- if (!local->remotepath) {
- local->op_ret = -1;
- local->op_errno = ENOMEM;
- goto err;
- }
- } else {
- gf_msg_debug (this->name, 0, "NULL filepath");
+ ret = dict_get_uint64(xdata, GF_CS_OBJECT_STATUS, &val);
+ if (ret == 0) {
+ if (val == GF_CS_ERROR) {
+ cs_inode_ctx_reset(this, inode);
+ local->op_ret = -1;
+ local->op_errno = EIO;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "status = GF_CS_ERROR. failed to get "
+ " file state");
+ goto err;
+ } else {
+ ret = __cs_inode_ctx_update(this, inode, val);
+ gf_msg_debug(this->name, 0, "status : %lu", val);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "ctx update failed");
+ local->op_ret = -1;
+ local->op_errno = ENOMEM;
+ goto err;
}
+ }
+ } else {
+ gf_msg_debug(this->name, 0, "status not found in dict");
+ local->op_ret = -1;
+ local->op_errno = ENOMEM;
+ goto err;
+ }
- local->op_ret = 0;
- local->xattr_rsp = dict_ref (xdata);
- memcpy (&local->stbuf, stbuf, sizeof (struct iatt));
+ ret = dict_get_str(xdata, GF_CS_OBJECT_REMOTE, &filepath);
+ if (filepath) {
+ gf_msg_debug(this->name, 0, "filepath returned %s", filepath);
+ local->remotepath = gf_strdup(filepath);
+ if (!local->remotepath) {
+ local->op_ret = -1;
+ local->op_errno = ENOMEM;
+ goto err;
+ }
+ } else {
+ gf_msg_debug(this->name, 0, "NULL filepath");
}
- stub = local->stub;
- local->stub = NULL;
- call_resume (stub);
+ local->op_ret = 0;
+ local->xattr_rsp = dict_ref(xdata);
+ memcpy(&local->stbuf, stbuf, sizeof(struct iatt));
+ }
- return 0;
+ stub = local->stub;
+ local->stub = NULL;
+ call_resume(stub);
+
+ return 0;
err:
- cs_inodelk_unlock (frame);
+ cs_inodelk_unlock(frame);
- cs_common_cbk (frame);
+ cs_common_cbk(frame);
- return 0;
+ return 0;
}
int
-cs_do_stat_check (call_frame_t *main_frame)
+cs_do_stat_check(call_frame_t *main_frame)
{
- cs_local_t *local = NULL;
- xlator_t *this = NULL;
- int ret = 0;
-
- local = main_frame->local;
- this = main_frame->this;
-
- ret = dict_set_uint32 (local->xattr_req, GF_CS_OBJECT_REPAIR, 256);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "dict_set failed");
- goto err;
- }
-
- if (local->fd) {
- STACK_WIND (main_frame, cs_stat_check_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->fstat, local->fd,
- local->xattr_req);
- } else {
- STACK_WIND (main_frame, cs_stat_check_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->stat, &local->loc,
- local->xattr_req);
- }
-
- return 0;
+ cs_local_t *local = NULL;
+ xlator_t *this = NULL;
+ int ret = 0;
+
+ local = main_frame->local;
+ this = main_frame->this;
+
+ ret = dict_set_uint32(local->xattr_req, GF_CS_OBJECT_REPAIR, 256);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "dict_set failed");
+ goto err;
+ }
+
+ if (local->fd) {
+ STACK_WIND(main_frame, cs_stat_check_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, local->fd, local->xattr_req);
+ } else {
+ STACK_WIND(main_frame, cs_stat_check_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->stat, &local->loc,
+ local->xattr_req);
+ }
+
+ return 0;
err:
- cs_inodelk_unlock (main_frame);
+ cs_inodelk_unlock(main_frame);
- cs_common_cbk (main_frame);
+ cs_common_cbk(main_frame);
- return 0;
+ return 0;
}
void
-cs_common_cbk (call_frame_t *frame)
+cs_common_cbk(call_frame_t *frame)
{
- glusterfs_fop_t fop = -1;
- cs_local_t *local = NULL;
+ glusterfs_fop_t fop = -1;
+ cs_local_t *local = NULL;
- local = frame->local;
+ local = frame->local;
- fop = local->fop;
+ fop = local->fop;
- /*Note: Only the failure case needs to be handled here. Since for
- * successful stat check the fop will resume anyway. The unwind can
- * happen from the fop_cbk and each cbk can unlock the inodelk in case
- * a lock was taken before. The lock status can be stored in frame */
+ /*Note: Only the failure case needs to be handled here. Since for
+ * successful stat check the fop will resume anyway. The unwind can
+ * happen from the fop_cbk and each cbk can unlock the inodelk in case
+ * a lock was taken before. The lock status can be stored in frame */
- /* for failure case */
+ /* for failure case */
- /*TODO: add other fops*/
- switch (fop) {
+ /*TODO: add other fops*/
+ switch (fop) {
case GF_FOP_WRITE:
- CS_STACK_UNWIND (writev, frame, local->op_ret,
- local->op_errno, NULL, NULL, NULL);
- break;
+ CS_STACK_UNWIND(writev, frame, local->op_ret, local->op_errno, NULL,
+ NULL, NULL);
+ break;
case GF_FOP_SETXATTR:
- CS_STACK_UNWIND (setxattr, frame, local->op_ret,
- local->op_errno, NULL);
- break;
+ CS_STACK_UNWIND(setxattr, frame, local->op_ret, local->op_errno,
+ NULL);
+ break;
case GF_FOP_READ:
- CS_STACK_UNWIND (readv, frame, local->op_ret,
- local->op_errno, NULL, 0, NULL, NULL,
- NULL);
- break;
+ CS_STACK_UNWIND(readv, frame, local->op_ret, local->op_errno, NULL,
+ 0, NULL, NULL, NULL);
+ break;
case GF_FOP_FTRUNCATE:
- CS_STACK_UNWIND (ftruncate, frame, local->op_ret,
- local->op_errno, NULL, NULL, NULL);
- break;
-
+ CS_STACK_UNWIND(ftruncate, frame, local->op_ret, local->op_errno,
+ NULL, NULL, NULL);
+ break;
default:
- break;
- }
+ break;
+ }
- return;
+ return;
}
int
-cs_blocking_inodelk_cbk (call_frame_t *lock_frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+cs_blocking_inodelk_cbk(call_frame_t *lock_frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- cs_local_t *main_local = NULL;
- call_frame_t *main_frame = NULL;
- cs_local_t *lock_local = NULL;
+ cs_local_t *main_local = NULL;
+ call_frame_t *main_frame = NULL;
+ cs_local_t *lock_local = NULL;
- lock_local = lock_frame->local;
+ lock_local = lock_frame->local;
- main_frame = lock_local->main_frame;
- main_local = main_frame->local;
+ main_frame = lock_local->main_frame;
+ main_local = main_frame->local;
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "inodelk failed");
- main_local->op_errno = op_errno;
- main_local->op_ret = op_ret;
- goto err;
- }
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "inodelk failed");
+ main_local->op_errno = op_errno;
+ main_local->op_ret = op_ret;
+ goto err;
+ }
- main_local->locked = _gf_true;
+ main_local->locked = _gf_true;
- cs_lock_wipe (lock_frame);
+ cs_lock_wipe(lock_frame);
- cs_do_stat_check (main_frame);
+ cs_do_stat_check(main_frame);
- return 0;
+ return 0;
err:
- cs_common_cbk (main_frame);
+ cs_common_cbk(main_frame);
- cs_lock_wipe (lock_frame);
+ cs_lock_wipe(lock_frame);
- return 0;
+ return 0;
}
int
-cs_build_loc (loc_t *loc, call_frame_t *frame)
+cs_build_loc(loc_t *loc, call_frame_t *frame)
{
- cs_local_t *local = NULL;
- int ret = -1;
+ cs_local_t *local = NULL;
+ int ret = -1;
- local = frame->local;
+ local = frame->local;
- if (local->fd) {
- loc->inode = inode_ref (local->fd->inode);
- if (loc->inode) {
- gf_uuid_copy (loc->gfid, loc->inode->gfid);
- ret = 0;
- goto out;
- } else {
- ret = -1;
- goto out;
- }
+ if (local->fd) {
+ loc->inode = inode_ref(local->fd->inode);
+ if (loc->inode) {
+ gf_uuid_copy(loc->gfid, loc->inode->gfid);
+ ret = 0;
+ goto out;
} else {
- loc->inode = inode_ref (local->loc.inode);
- if (loc->inode) {
- gf_uuid_copy (loc->gfid, loc->inode->gfid);
- ret = 0;
- goto out;
- } else {
- ret = -1;
- goto out;
- }
+ ret = -1;
+ goto out;
+ }
+ } else {
+ loc->inode = inode_ref(local->loc.inode);
+ if (loc->inode) {
+ gf_uuid_copy(loc->gfid, loc->inode->gfid);
+ ret = 0;
+ goto out;
+ } else {
+ ret = -1;
+ goto out;
}
+ }
out:
- return ret;
+ return ret;
}
int
-cs_blocking_inodelk (call_frame_t *parent_frame)
+cs_blocking_inodelk(call_frame_t *parent_frame)
{
- call_frame_t *lock_frame = NULL;
- cs_local_t *lock_local = NULL;
- xlator_t *this = NULL;
- struct gf_flock flock = {0,};
- int ret = 0;
-
- lock_frame = cs_lock_frame (parent_frame);
- if (!lock_frame) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "insuffcient memory");
- goto err;
- }
-
- this = parent_frame->this;
-
- lock_local = cs_local_init (this, lock_frame, NULL, NULL, 0);
- if (!lock_local) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "local init failed");
- goto err;
- }
-
- lock_local->main_frame = parent_frame;
-
- flock.l_type = F_WRLCK;
-
- ret = cs_build_loc (&lock_local->loc, parent_frame);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "build_loc failed");
- goto err;
- }
-
- STACK_WIND (lock_frame, cs_blocking_inodelk_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->inodelk, CS_LOCK_DOMAIN,
- &lock_local->loc, F_SETLKW, &flock, NULL);
-
- return 0;
+ call_frame_t *lock_frame = NULL;
+ cs_local_t *lock_local = NULL;
+ xlator_t *this = NULL;
+ struct gf_flock flock = {
+ 0,
+ };
+ int ret = 0;
+
+ lock_frame = cs_lock_frame(parent_frame);
+ if (!lock_frame) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "insuffcient memory");
+ goto err;
+ }
+
+ this = parent_frame->this;
+
+ lock_local = cs_local_init(this, lock_frame, NULL, NULL, 0);
+ if (!lock_local) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "local init failed");
+ goto err;
+ }
+
+ lock_local->main_frame = parent_frame;
+
+ flock.l_type = F_WRLCK;
+
+ ret = cs_build_loc(&lock_local->loc, parent_frame);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "build_loc failed");
+ goto err;
+ }
+
+ STACK_WIND(lock_frame, cs_blocking_inodelk_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->inodelk, CS_LOCK_DOMAIN,
+ &lock_local->loc, F_SETLKW, &flock, NULL);
+
+ return 0;
err:
- if (lock_frame)
- cs_lock_wipe (lock_frame);
+ if (lock_frame)
+ cs_lock_wipe(lock_frame);
- return -1;
+ return -1;
}
int
-locate_and_execute (call_frame_t *frame)
+locate_and_execute(call_frame_t *frame)
{
- int ret = 0;
+ int ret = 0;
- ret = cs_blocking_inodelk (frame);
+ ret = cs_blocking_inodelk(frame);
- if (ret)
- return -1;
- else
- return 0;
+ if (ret)
+ return -1;
+ else
+ return 0;
}
int32_t
-cs_resume_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc,
- off_t offset, dict_t *xattr_req)
+cs_resume_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ off_t offset, dict_t *xattr_req)
{
- cs_local_t *local = NULL;
- int ret = 0;
+ cs_local_t *local = NULL;
+ int ret = 0;
- local = frame->local;
+ local = frame->local;
- ret = cs_resume_postprocess (this, frame, loc->inode);
- if (ret) {
- goto unwind;
- }
+ ret = cs_resume_postprocess(this, frame, loc->inode);
+ if (ret) {
+ goto unwind;
+ }
- cs_inodelk_unlock (frame);
+ cs_inodelk_unlock(frame);
- STACK_WIND (frame, cs_truncate_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->truncate,
- loc, offset, local->xattr_req);
+ STACK_WIND(frame, cs_truncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->truncate, loc, offset,
+ local->xattr_req);
- return 0;
+ return 0;
unwind:
- cs_inodelk_unlock (frame);
+ cs_inodelk_unlock(frame);
- cs_common_cbk (frame);
+ cs_common_cbk(frame);
- return 0;
+ return 0;
}
-
int32_t
-cs_resume_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- dict_t *dict, int32_t flags, dict_t *xdata)
+cs_resume_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ dict_t *dict, int32_t flags, dict_t *xdata)
{
- cs_local_t *local = NULL;
- cs_inode_ctx_t *ctx = NULL;
- gf_cs_obj_state state = GF_CS_ERROR;
-
- local = frame->local;
-
- __cs_inode_ctx_get (this, loc->inode, &ctx);
-
- state = __cs_get_file_state (this, loc->inode, ctx);
-
- if (state == GF_CS_ERROR) {
- /* file is already remote */
- local->op_ret = -1;
- local->op_errno = EINVAL;
- gf_msg (this->name, GF_LOG_WARNING, 0, 0,
- "file %s , could not figure file state", loc->path);
- goto unwind;
- }
-
-
- if (state == GF_CS_REMOTE) {
- /* file is already remote */
- local->op_ret = -1;
- local->op_errno = EINVAL;
- gf_msg (this->name, GF_LOG_WARNING, 0, EINVAL,
- "file %s is already remote", loc->path);
- goto unwind;
- }
-
- if (state == GF_CS_DOWNLOADING) {
- gf_msg (this->name, GF_LOG_WARNING, 0, 0,
- " file is in downloading state.");
- local->op_ret = -1;
- local->op_errno = EINVAL;
- goto unwind;
- }
-
- STACK_WIND (frame, cs_setxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setxattr, loc, dict, flags,
- local->xattr_req);
-
- return 0;
+ cs_local_t *local = NULL;
+ cs_inode_ctx_t *ctx = NULL;
+ gf_cs_obj_state state = GF_CS_ERROR;
+
+ local = frame->local;
+
+ __cs_inode_ctx_get(this, loc->inode, &ctx);
+
+ state = __cs_get_file_state(this, loc->inode, ctx);
+
+ if (state == GF_CS_ERROR) {
+ /* file is already remote */
+ local->op_ret = -1;
+ local->op_errno = EINVAL;
+ gf_msg(this->name, GF_LOG_WARNING, 0, 0,
+ "file %s , could not figure file state", loc->path);
+ goto unwind;
+ }
+
+ if (state == GF_CS_REMOTE) {
+ /* file is already remote */
+ local->op_ret = -1;
+ local->op_errno = EINVAL;
+ gf_msg(this->name, GF_LOG_WARNING, 0, EINVAL,
+ "file %s is already remote", loc->path);
+ goto unwind;
+ }
+
+ if (state == GF_CS_DOWNLOADING) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, 0,
+ " file is in downloading state.");
+ local->op_ret = -1;
+ local->op_errno = EINVAL;
+ goto unwind;
+ }
+
+ STACK_WIND(frame, cs_setxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, loc, dict, flags,
+ local->xattr_req);
+
+ return 0;
unwind:
- cs_inodelk_unlock (frame);
+ cs_inodelk_unlock(frame);
- cs_common_cbk (frame);
+ cs_common_cbk(frame);
- return 0;
+ return 0;
}
-
-
-
gf_cs_obj_state
-__cs_get_file_state (xlator_t *this, inode_t *inode, cs_inode_ctx_t *ctx)
+__cs_get_file_state(xlator_t *this, inode_t *inode, cs_inode_ctx_t *ctx)
{
- gf_cs_obj_state state = -1;
+ gf_cs_obj_state state = -1;
- if (!ctx)
- return GF_CS_ERROR;
+ if (!ctx)
+ return GF_CS_ERROR;
- LOCK (&inode->lock);
- {
- state = ctx->state;
- }
- UNLOCK (&inode->lock);
+ LOCK(&inode->lock);
+ {
+ state = ctx->state;
+ }
+ UNLOCK(&inode->lock);
- return state;
+ return state;
}
void
-__cs_inode_ctx_get (xlator_t *this, inode_t *inode, cs_inode_ctx_t **ctx)
+__cs_inode_ctx_get(xlator_t *this, inode_t *inode, cs_inode_ctx_t **ctx)
{
- uint64_t ctxint = 0;
- int ret = 0;
+ uint64_t ctxint = 0;
+ int ret = 0;
- LOCK (&inode->lock);
- {
- ret = __inode_ctx_get (inode, this, &ctxint);
- }
- UNLOCK (&inode->lock);
+ LOCK(&inode->lock);
+ {
+ ret = __inode_ctx_get(inode, this, &ctxint);
+ }
+ UNLOCK(&inode->lock);
- if (ret)
- *ctx = NULL;
- else
- *ctx = (cs_inode_ctx_t *)ctxint;
+ if (ret)
+ *ctx = NULL;
+ else
+ *ctx = (cs_inode_ctx_t *)ctxint;
- return;
+ return;
}
int
-__cs_inode_ctx_update (xlator_t *this, inode_t *inode, uint64_t val)
+__cs_inode_ctx_update(xlator_t *this, inode_t *inode, uint64_t val)
{
- cs_inode_ctx_t *ctx = NULL;
- uint64_t ctxint = 0;
- int ret = 0;
+ cs_inode_ctx_t *ctx = NULL;
+ uint64_t ctxint = 0;
+ int ret = 0;
- LOCK (&inode->lock);
- {
- ret = __inode_ctx_get (inode, this, &ctxint);
+ LOCK(&inode->lock);
+ {
+ ret = __inode_ctx_get(inode, this, &ctxint);
if (ret) {
- ctx = GF_CALLOC (1, sizeof (*ctx), gf_cs_mt_cs_inode_ctx_t);
- if (!ctx) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "ctx allocation failed");
- ret = -1;
- goto out;
- }
+ ctx = GF_CALLOC(1, sizeof(*ctx), gf_cs_mt_cs_inode_ctx_t);
+ if (!ctx) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "ctx allocation failed");
+ ret = -1;
+ goto out;
+ }
- ctx->state = val;
+ ctx->state = val;
- ctxint = (uint64_t) ctx;
+ ctxint = (uint64_t)ctx;
- ret = __inode_ctx_set (inode, this, &ctxint);
- if (ret) {
- GF_FREE (ctx);
- goto out;
- }
+ ret = __inode_ctx_set(inode, this, &ctxint);
+ if (ret) {
+ GF_FREE(ctx);
+ goto out;
+ }
} else {
- ctx = (cs_inode_ctx_t *) ctxint;
-
- ctx->state = val;
- }
+ ctx = (cs_inode_ctx_t *)ctxint;
+ ctx->state = val;
}
+ }
out:
- UNLOCK (&inode->lock);
+ UNLOCK(&inode->lock);
- return ret;
+ return ret;
}
int
-cs_inode_ctx_reset (xlator_t *this, inode_t *inode)
+cs_inode_ctx_reset(xlator_t *this, inode_t *inode)
{
- cs_inode_ctx_t *ctx = NULL;
- uint64_t ctxint = 0;
+ cs_inode_ctx_t *ctx = NULL;
+ uint64_t ctxint = 0;
- inode_ctx_del (inode, this, &ctxint);
- if (!ctxint) {
- return 0;
- }
+ inode_ctx_del(inode, this, &ctxint);
+ if (!ctxint) {
+ return 0;
+ }
- ctx = (cs_inode_ctx_t *)ctxint;
+ ctx = (cs_inode_ctx_t *)ctxint;
- GF_FREE (ctx);
- return 0;
+ GF_FREE(ctx);
+ return 0;
}
int
-cs_resume_postprocess (xlator_t *this, call_frame_t *frame, inode_t *inode)
+cs_resume_postprocess(xlator_t *this, call_frame_t *frame, inode_t *inode)
{
- cs_local_t *local = NULL;
- gf_cs_obj_state state = -1;
- cs_inode_ctx_t *ctx = NULL;
- int ret = 0;
-
- local = frame->local;
- if (!local) {
- ret = -1;
- goto out;
- }
-
- __cs_inode_ctx_get (this, inode, &ctx);
-
- state = __cs_get_file_state (this, inode, ctx);
- if (state == GF_CS_ERROR) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "status is GF_CS_ERROR."
- " Aborting write");
- local->op_ret = -1;
- local->op_errno = EREMOTE;
- ret = -1;
- goto out;
- }
-
- if (state == GF_CS_REMOTE || state == GF_CS_DOWNLOADING) {
- gf_msg_debug (this->name, 0, "status is %d", state);
- ret = cs_download (frame);
- if (ret == 0) {
- gf_msg_debug (this->name, 0, "Winding for Final Write");
- } else {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- " download failed, unwinding writev");
- local->op_ret = -1;
- local->op_errno = EREMOTE;
- ret = -1;
- }
+ cs_local_t *local = NULL;
+ gf_cs_obj_state state = -1;
+ cs_inode_ctx_t *ctx = NULL;
+ int ret = 0;
+
+ local = frame->local;
+ if (!local) {
+ ret = -1;
+ goto out;
+ }
+
+ __cs_inode_ctx_get(this, inode, &ctx);
+
+ state = __cs_get_file_state(this, inode, ctx);
+ if (state == GF_CS_ERROR) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "status is GF_CS_ERROR."
+ " Aborting write");
+ local->op_ret = -1;
+ local->op_errno = EREMOTE;
+ ret = -1;
+ goto out;
+ }
+
+ if (state == GF_CS_REMOTE || state == GF_CS_DOWNLOADING) {
+ gf_msg_debug(this->name, 0, "status is %d", state);
+ ret = cs_download(frame);
+ if (ret == 0) {
+ gf_msg_debug(this->name, 0, "Winding for Final Write");
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ " download failed, unwinding writev");
+ local->op_ret = -1;
+ local->op_errno = EREMOTE;
+ ret = -1;
}
+ }
out:
- return ret;
+ return ret;
}
int32_t
-cs_fdctx_to_dict (xlator_t *this,
- fd_t *fd,
- dict_t *dict)
+cs_fdctx_to_dict(xlator_t *this, fd_t *fd, dict_t *dict)
{
- return 0;
+ return 0;
}
-
int32_t
-cs_inode (xlator_t *this)
+cs_inode(xlator_t *this)
{
- return 0;
+ return 0;
}
-
int32_t
-cs_inode_to_dict (xlator_t *this,
- dict_t *dict)
+cs_inode_to_dict(xlator_t *this, dict_t *dict)
{
- return 0;
+ return 0;
}
-
int32_t
-cs_history (xlator_t *this)
+cs_history(xlator_t *this)
{
- return 0;
+ return 0;
}
-
int32_t
-cs_fd (xlator_t *this)
+cs_fd(xlator_t *this)
{
- return 0;
+ return 0;
}
-
int32_t
-cs_fd_to_dict (xlator_t *this,
- dict_t *dict)
+cs_fd_to_dict(xlator_t *this, dict_t *dict)
{
- return 0;
+ return 0;
}
-
int32_t
-cs_fdctx (xlator_t *this,
- fd_t *fd)
+cs_fdctx(xlator_t *this, fd_t *fd)
{
- return 0;
+ return 0;
}
-
int32_t
-cs_inodectx (xlator_t *this,
- inode_t *ino)
+cs_inodectx(xlator_t *this, inode_t *ino)
{
- return 0;
+ return 0;
}
-
int32_t
-cs_inodectx_to_dict (xlator_t *this,
- inode_t *ino,
- dict_t *dict)
+cs_inodectx_to_dict(xlator_t *this, inode_t *ino, dict_t *dict)
{
- return 0;
+ return 0;
}
-
int32_t
-cs_priv_to_dict (xlator_t *this,
- dict_t *dict, char *brickname)
+cs_priv_to_dict(xlator_t *this, dict_t *dict, char *brickname)
{
- return 0;
+ return 0;
}
-
int32_t
-cs_priv (xlator_t *this)
+cs_priv(xlator_t *this)
{
- return 0;
+ return 0;
}
int
-cs_notify (xlator_t *this, int event, void *data, ...)
+cs_notify(xlator_t *this, int event, void *data, ...)
{
- return default_notify (this, event, data);
+ return default_notify(this, event, data);
}
-
struct xlator_fops cs_fops = {
- .stat = cs_stat,
- .readdirp = cs_readdirp,
- .truncate = cs_truncate,
- .seek = cs_seek,
- .statfs = cs_statfs,
- .fallocate = cs_fallocate,
- .discard = cs_discard,
- .getxattr = cs_getxattr,
- .writev = cs_writev,
- .setxattr = cs_setxattr,
- .fgetxattr = cs_fgetxattr,
- .lookup = cs_lookup,
- .fsetxattr = cs_fsetxattr,
- .readv = cs_readv,
- .ftruncate = cs_ftruncate,
- .rchecksum = cs_rchecksum,
- .unlink = cs_unlink,
- .open = cs_open,
- .fstat = cs_fstat,
- .zerofill = cs_zerofill,
+ .stat = cs_stat,
+ .readdirp = cs_readdirp,
+ .truncate = cs_truncate,
+ .seek = cs_seek,
+ .statfs = cs_statfs,
+ .fallocate = cs_fallocate,
+ .discard = cs_discard,
+ .getxattr = cs_getxattr,
+ .writev = cs_writev,
+ .setxattr = cs_setxattr,
+ .fgetxattr = cs_fgetxattr,
+ .lookup = cs_lookup,
+ .fsetxattr = cs_fsetxattr,
+ .readv = cs_readv,
+ .ftruncate = cs_ftruncate,
+ .rchecksum = cs_rchecksum,
+ .unlink = cs_unlink,
+ .open = cs_open,
+ .fstat = cs_fstat,
+ .zerofill = cs_zerofill,
};
-struct xlator_cbks cs_cbks = {
-};
+struct xlator_cbks cs_cbks = {};
struct xlator_dumpops cs_dumpops = {
- .fdctx_to_dict = cs_fdctx_to_dict,
- .inode = cs_inode,
- .inode_to_dict = cs_inode_to_dict,
- .history = cs_history,
- .fd = cs_fd,
- .fd_to_dict = cs_fd_to_dict,
- .fdctx = cs_fdctx,
- .inodectx = cs_inodectx,
- .inodectx_to_dict = cs_inodectx_to_dict,
- .priv_to_dict = cs_priv_to_dict,
- .priv = cs_priv,
+ .fdctx_to_dict = cs_fdctx_to_dict,
+ .inode = cs_inode,
+ .inode_to_dict = cs_inode_to_dict,
+ .history = cs_history,
+ .fd = cs_fd,
+ .fd_to_dict = cs_fd_to_dict,
+ .fdctx = cs_fdctx,
+ .inodectx = cs_inodectx,
+ .inodectx_to_dict = cs_inodectx_to_dict,
+ .priv_to_dict = cs_priv_to_dict,
+ .priv = cs_priv,
};
struct volume_options cs_options[] = {
- { .key = {"cloudsync-storetype"},
- .type = GF_OPTION_TYPE_STR,
- .description = "Defines which remote store is enabled"
- },
- { .key = {NULL} },
+ {.key = {"cloudsync-storetype"},
+ .type = GF_OPTION_TYPE_STR,
+ .description = "Defines which remote store is enabled"},
+ {.key = {NULL}},
};
xlator_api_t xlator_api = {
- .init = cs_init,
- .fini = cs_fini,
- .notify = cs_notify,
- .reconfigure = cs_reconfigure,
- .mem_acct_init = cs_mem_acct_init,
- .dumpops = &cs_dumpops,
- .fops = &cs_fops,
- .cbks = &cs_cbks,
- .options = cs_options,
- .identifier = "cloudsync",
- .category = GF_TECH_PREVIEW,
+ .init = cs_init,
+ .fini = cs_fini,
+ .notify = cs_notify,
+ .reconfigure = cs_reconfigure,
+ .mem_acct_init = cs_mem_acct_init,
+ .dumpops = &cs_dumpops,
+ .fops = &cs_fops,
+ .cbks = &cs_cbks,
+ .options = cs_options,
+ .identifier = "cloudsync",
+ .category = GF_TECH_PREVIEW,
};
diff --git a/xlators/features/compress/src/cdc-helper.c b/xlators/features/compress/src/cdc-helper.c
index 7baccb0cd3d..71f446d51cd 100644
--- a/xlators/features/compress/src/cdc-helper.c
+++ b/xlators/features/compress/src/cdc-helper.c
@@ -34,118 +34,110 @@
* gzip_header is added only during debugging.
* Refer to the function cdc_dump_iovec_to_disk
*/
-static const char gzip_header[10] =
- {
- '\037', '\213', Z_DEFLATED, 0,
- 0, 0, 0, 0,
- 0, GF_CDC_OS_ID
- };
+static const char gzip_header[10] = {'\037', '\213', Z_DEFLATED, 0, 0, 0, 0,
+ 0, 0, GF_CDC_OS_ID};
static int32_t
-cdc_next_iovec (xlator_t *this, cdc_info_t *ci)
+cdc_next_iovec(xlator_t *this, cdc_info_t *ci)
{
- int ret = -1;
-
- ci->ncount++;
- /* check for iovec overflow -- should not happen */
- if (ci->ncount == MAX_IOVEC) {
- gf_log (this->name, GF_LOG_ERROR,
- "Zlib output buffer overflow"
- " ->ncount (%d) | ->MAX_IOVEC (%d)",
- ci->ncount, MAX_IOVEC);
- goto out;
- }
-
- ret = 0;
-
- out:
- return ret;
+ int ret = -1;
+
+ ci->ncount++;
+ /* check for iovec overflow -- should not happen */
+ if (ci->ncount == MAX_IOVEC) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "Zlib output buffer overflow"
+ " ->ncount (%d) | ->MAX_IOVEC (%d)",
+ ci->ncount, MAX_IOVEC);
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ return ret;
}
static void
-cdc_put_long (unsigned char *string, unsigned long x)
+cdc_put_long(unsigned char *string, unsigned long x)
{
- string[0] = (unsigned char) (x & 0xff);
- string[1] = (unsigned char) ((x & 0xff00) >> 8);
- string[2] = (unsigned char) ((x & 0xff0000) >> 16);
- string[3] = (unsigned char) ((x & 0xff000000) >> 24);
+ string[0] = (unsigned char)(x & 0xff);
+ string[1] = (unsigned char)((x & 0xff00) >> 8);
+ string[2] = (unsigned char)((x & 0xff0000) >> 16);
+ string[3] = (unsigned char)((x & 0xff000000) >> 24);
}
static unsigned long
-cdc_get_long (unsigned char *buf)
+cdc_get_long(unsigned char *buf)
{
- return ((unsigned long) buf[0])
- | (((unsigned long) buf[1]) << 8)
- | (((unsigned long) buf[2]) << 16)
- | (((unsigned long) buf[3]) << 24);
+ return ((unsigned long)buf[0]) | (((unsigned long)buf[1]) << 8) |
+ (((unsigned long)buf[2]) << 16) | (((unsigned long)buf[3]) << 24);
}
static int32_t
-cdc_init_gzip_trailer (xlator_t *this, cdc_priv_t *priv, cdc_info_t *ci)
+cdc_init_gzip_trailer(xlator_t *this, cdc_priv_t *priv, cdc_info_t *ci)
{
- int ret = -1;
- char *buf = NULL;
+ int ret = -1;
+ char *buf = NULL;
- ret = cdc_next_iovec (this, ci);
- if (ret)
- goto out;
+ ret = cdc_next_iovec(this, ci);
+ if (ret)
+ goto out;
- buf = CURR_VEC(ci).iov_base =
- (char *) GF_CALLOC (1, GF_CDC_VALIDATION_SIZE,
- gf_cdc_mt_gzip_trailer_t);
+ buf = CURR_VEC(ci).iov_base = (char *)GF_CALLOC(1, GF_CDC_VALIDATION_SIZE,
+ gf_cdc_mt_gzip_trailer_t);
- if (!CURR_VEC(ci).iov_base)
- goto out;
+ if (!CURR_VEC(ci).iov_base)
+ goto out;
- CURR_VEC(ci).iov_len = GF_CDC_VALIDATION_SIZE;
+ CURR_VEC(ci).iov_len = GF_CDC_VALIDATION_SIZE;
- cdc_put_long ((unsigned char *)&buf[0], ci->crc);
- cdc_put_long ((unsigned char *)&buf[4], ci->stream.total_in);
+ cdc_put_long((unsigned char *)&buf[0], ci->crc);
+ cdc_put_long((unsigned char *)&buf[4], ci->stream.total_in);
- ret = 0;
+ ret = 0;
- out:
- return ret;
+out:
+ return ret;
}
static int32_t
-cdc_alloc_iobuf_and_init_vec (xlator_t *this,
- cdc_priv_t *priv, cdc_info_t *ci,
- int size)
+cdc_alloc_iobuf_and_init_vec(xlator_t *this, cdc_priv_t *priv, cdc_info_t *ci,
+ int size)
{
- int ret = -1;
- int alloc_len = 0;
- struct iobuf *iobuf = NULL;
+ int ret = -1;
+ int alloc_len = 0;
+ struct iobuf *iobuf = NULL;
- ret = cdc_next_iovec (this, ci);
- if (ret)
- goto out;
+ ret = cdc_next_iovec(this, ci);
+ if (ret)
+ goto out;
- alloc_len = size ? size : ci->buffer_size;
+ alloc_len = size ? size : ci->buffer_size;
- iobuf = iobuf_get2 (this->ctx->iobuf_pool, alloc_len);
- if (!iobuf)
- goto out;
+ iobuf = iobuf_get2(this->ctx->iobuf_pool, alloc_len);
+ if (!iobuf)
+ goto out;
- ret = iobref_add (ci->iobref, iobuf);
- if (ret)
- goto out;
+ ret = iobref_add(ci->iobref, iobuf);
+ if (ret)
+ goto out;
- /* Initialize this iovec */
- CURR_VEC(ci).iov_base = iobuf->ptr;
- CURR_VEC(ci).iov_len = alloc_len;
+ /* Initialize this iovec */
+ CURR_VEC(ci).iov_base = iobuf->ptr;
+ CURR_VEC(ci).iov_len = alloc_len;
- ret = 0;
+ ret = 0;
- out:
- return ret;
+out:
+ return ret;
}
static void
-cdc_init_zlib_output_stream (cdc_priv_t *priv, cdc_info_t *ci, int size)
+cdc_init_zlib_output_stream(cdc_priv_t *priv, cdc_info_t *ci, int size)
{
- ci->stream.next_out = (unsigned char *) CURR_VEC(ci).iov_base;
- ci->stream.avail_out = size ? size : ci->buffer_size;
+ ci->stream.next_out = (unsigned char *)CURR_VEC(ci).iov_base;
+ ci->stream.avail_out = size ? size : ci->buffer_size;
}
/* This routine is for testing and debugging only.
@@ -153,391 +145,383 @@ cdc_init_zlib_output_stream (cdc_priv_t *priv, cdc_info_t *ci, int size)
* So each gzip dump file is at least 18 bytes in size.
*/
void
-cdc_dump_iovec_to_disk (xlator_t *this, cdc_info_t *ci, const char *file)
+cdc_dump_iovec_to_disk(xlator_t *this, cdc_info_t *ci, const char *file)
{
- int i = 0;
- int fd = 0;
- size_t written = 0;
- size_t total_written = 0;
-
- fd = open (file, O_WRONLY|O_CREAT|O_TRUNC, 0777 );
- if (fd < 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "Cannot open file: %s", file);
- return;
- }
-
- written = sys_write (fd, (char *) gzip_header, 10);
+ int i = 0;
+ int fd = 0;
+ size_t written = 0;
+ size_t total_written = 0;
+
+ fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0777);
+ if (fd < 0) {
+ gf_log(this->name, GF_LOG_ERROR, "Cannot open file: %s", file);
+ return;
+ }
+
+ written = sys_write(fd, (char *)gzip_header, 10);
+ total_written += written;
+ for (i = 0; i < ci->ncount; i++) {
+ written = sys_write(fd, (char *)ci->vec[i].iov_base,
+ ci->vec[i].iov_len);
total_written += written;
- for (i = 0; i < ci->ncount; i++) {
- written = sys_write (fd, (char *) ci->vec[i].iov_base, ci->vec[i].iov_len);
- total_written += written;
- }
+ }
- gf_log (this->name, GF_LOG_DEBUG,
- "dump'd %zu bytes to %s", total_written, GF_CDC_DEBUG_DUMP_FILE );
+ gf_log(this->name, GF_LOG_DEBUG, "dump'd %zu bytes to %s", total_written,
+ GF_CDC_DEBUG_DUMP_FILE);
- sys_close (fd);
+ sys_close(fd);
}
static int32_t
-cdc_flush_libz_buffer (cdc_priv_t *priv, xlator_t *this, cdc_info_t *ci,
- int (*libz_func)(z_streamp, int),
- int flush)
+cdc_flush_libz_buffer(cdc_priv_t *priv, xlator_t *this, cdc_info_t *ci,
+ int (*libz_func)(z_streamp, int), int flush)
{
- int32_t ret = Z_OK;
- int done = 0;
- unsigned int deflate_len = 0;
+ int32_t ret = Z_OK;
+ int done = 0;
+ unsigned int deflate_len = 0;
- for (;;) {
- deflate_len = ci->buffer_size - ci->stream.avail_out;
+ for (;;) {
+ deflate_len = ci->buffer_size - ci->stream.avail_out;
- if (deflate_len != 0) {
- CURR_VEC(ci).iov_len = deflate_len;
+ if (deflate_len != 0) {
+ CURR_VEC(ci).iov_len = deflate_len;
- ret = cdc_alloc_iobuf_and_init_vec (this, priv, ci, 0);
- if (ret) {
- ret = Z_MEM_ERROR;
- break;
- }
+ ret = cdc_alloc_iobuf_and_init_vec(this, priv, ci, 0);
+ if (ret) {
+ ret = Z_MEM_ERROR;
+ break;
+ }
- /* Re-position Zlib output buffer */
- cdc_init_zlib_output_stream (priv, ci, 0);
- }
+ /* Re-position Zlib output buffer */
+ cdc_init_zlib_output_stream(priv, ci, 0);
+ }
- if (done) {
- ci->ncount--;
- break;
- }
+ if (done) {
+ ci->ncount--;
+ break;
+ }
- ret = libz_func (&ci->stream, flush);
+ ret = libz_func(&ci->stream, flush);
- if (ret == Z_BUF_ERROR) {
- ret = Z_OK;
- ci->ncount--;
- break;
- }
+ if (ret == Z_BUF_ERROR) {
+ ret = Z_OK;
+ ci->ncount--;
+ break;
+ }
- done = (ci->stream.avail_out != 0 || ret == Z_STREAM_END);
+ done = (ci->stream.avail_out != 0 || ret == Z_STREAM_END);
- if (ret != Z_OK && ret != Z_STREAM_END)
- break;
- }
+ if (ret != Z_OK && ret != Z_STREAM_END)
+ break;
+ }
- return ret;
+ return ret;
}
static int32_t
-do_cdc_compress (struct iovec *vec, xlator_t *this, cdc_priv_t *priv,
- cdc_info_t *ci)
+do_cdc_compress(struct iovec *vec, xlator_t *this, cdc_priv_t *priv,
+ cdc_info_t *ci)
{
- int ret = -1;
+ int ret = -1;
- /* Initialize defalte */
- ret = deflateInit2 (&ci->stream, priv->cdc_level, Z_DEFLATED,
- priv->window_size, priv->mem_level,
- Z_DEFAULT_STRATEGY);
+ /* Initialize defalte */
+ ret = deflateInit2(&ci->stream, priv->cdc_level, Z_DEFLATED,
+ priv->window_size, priv->mem_level, Z_DEFAULT_STRATEGY);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "unable to init Zlib (retval: %d)", ret);
- goto out;
- }
+ if (ret) {
+ gf_log(this->name, GF_LOG_ERROR, "unable to init Zlib (retval: %d)",
+ ret);
+ goto out;
+ }
- ret = cdc_alloc_iobuf_and_init_vec (this, priv, ci, 0);
- if (ret)
- goto out;
+ ret = cdc_alloc_iobuf_and_init_vec(this, priv, ci, 0);
+ if (ret)
+ goto out;
- /* setup output buffer */
- cdc_init_zlib_output_stream (priv, ci, 0);
+ /* setup output buffer */
+ cdc_init_zlib_output_stream(priv, ci, 0);
- /* setup input buffer */
- ci->stream.next_in = (unsigned char *) vec->iov_base;
- ci->stream.avail_in = vec->iov_len;
+ /* setup input buffer */
+ ci->stream.next_in = (unsigned char *)vec->iov_base;
+ ci->stream.avail_in = vec->iov_len;
- ci->crc = crc32 (ci->crc, (const Bytef *) vec->iov_base, vec->iov_len);
+ ci->crc = crc32(ci->crc, (const Bytef *)vec->iov_base, vec->iov_len);
- gf_log (this->name, GF_LOG_DEBUG, "crc=%lu len=%d buffer_size=%d",
- ci->crc, ci->stream.avail_in, ci->buffer_size);
+ gf_log(this->name, GF_LOG_DEBUG, "crc=%lu len=%d buffer_size=%d", ci->crc,
+ ci->stream.avail_in, ci->buffer_size);
- /* compress !! */
- while (ci->stream.avail_in != 0) {
- if (ci->stream.avail_out == 0) {
+ /* compress !! */
+ while (ci->stream.avail_in != 0) {
+ if (ci->stream.avail_out == 0) {
+ CURR_VEC(ci).iov_len = ci->buffer_size;
- CURR_VEC(ci).iov_len = ci->buffer_size;
+ ret = cdc_alloc_iobuf_and_init_vec(this, priv, ci, 0);
+ if (ret)
+ break;
- ret = cdc_alloc_iobuf_and_init_vec (this, priv, ci, 0);
- if (ret)
- break;
-
- /* Re-position Zlib output buffer */
- cdc_init_zlib_output_stream (priv, ci, 0);
- }
-
- ret = deflate (&ci->stream, Z_NO_FLUSH);
- if (ret != Z_OK)
- break;
+ /* Re-position Zlib output buffer */
+ cdc_init_zlib_output_stream(priv, ci, 0);
}
- out:
- return ret;
+ ret = deflate(&ci->stream, Z_NO_FLUSH);
+ if (ret != Z_OK)
+ break;
+ }
+
+out:
+ return ret;
}
int32_t
-cdc_compress (xlator_t *this, cdc_priv_t *priv, cdc_info_t *ci,
- dict_t **xdata)
+cdc_compress(xlator_t *this, cdc_priv_t *priv, cdc_info_t *ci, dict_t **xdata)
{
- int ret = -1;
- int i = 0;
+ int ret = -1;
+ int i = 0;
- ci->iobref = iobref_new ();
- if (!ci->iobref)
- goto out;
+ ci->iobref = iobref_new();
+ if (!ci->iobref)
+ goto out;
+ if (!*xdata) {
+ *xdata = dict_new();
if (!*xdata) {
- *xdata = dict_new ();
- if (!*xdata) {
- gf_log (this->name, GF_LOG_ERROR, "Cannot allocate xdata"
- " dict");
- goto out;
- }
- }
-
- /* data */
- for (i = 0; i < ci->count; i++) {
- ret = do_cdc_compress (&ci->vector[i], this, priv, ci);
- if (ret != Z_OK)
- goto deflate_cleanup_out;
- }
-
- /* flush zlib buffer */
- ret = cdc_flush_libz_buffer (priv, this, ci, deflate, Z_FINISH);
- if (!(ret == Z_OK || ret == Z_STREAM_END)) {
- gf_log (this->name, GF_LOG_ERROR,
- "Compression Error: ret (%d)", ret);
- ret = -1;
- goto deflate_cleanup_out;
- }
-
- /* trailer */
- ret = cdc_init_gzip_trailer (this, priv, ci);
- if (ret)
- goto deflate_cleanup_out;
-
- gf_log (this->name, GF_LOG_DEBUG,
- "Compressed %ld to %ld bytes",
- ci->stream.total_in, ci->stream.total_out);
-
- ci->nbytes = ci->stream.total_out + GF_CDC_VALIDATION_SIZE;
-
- /* set deflated canary value for identification */
- ret = dict_set_int32 (*xdata, GF_CDC_DEFLATE_CANARY_VAL, 1);
- if (ret) {
- /* Send uncompressed data if we can't _tell_ the client
- * that deflated data is on it's way. So, we just log
- * the failure and continue as usual.
- */
- gf_log (this->name, GF_LOG_ERROR,
- "Data deflated, but could not set canary"
- " value in dict for identification");
+ gf_log(this->name, GF_LOG_ERROR,
+ "Cannot allocate xdata"
+ " dict");
+ goto out;
}
+ }
+
+ /* data */
+ for (i = 0; i < ci->count; i++) {
+ ret = do_cdc_compress(&ci->vector[i], this, priv, ci);
+ if (ret != Z_OK)
+ goto deflate_cleanup_out;
+ }
+
+ /* flush zlib buffer */
+ ret = cdc_flush_libz_buffer(priv, this, ci, deflate, Z_FINISH);
+ if (!(ret == Z_OK || ret == Z_STREAM_END)) {
+ gf_log(this->name, GF_LOG_ERROR, "Compression Error: ret (%d)", ret);
+ ret = -1;
+ goto deflate_cleanup_out;
+ }
+
+ /* trailer */
+ ret = cdc_init_gzip_trailer(this, priv, ci);
+ if (ret)
+ goto deflate_cleanup_out;
+
+ gf_log(this->name, GF_LOG_DEBUG, "Compressed %ld to %ld bytes",
+ ci->stream.total_in, ci->stream.total_out);
+
+ ci->nbytes = ci->stream.total_out + GF_CDC_VALIDATION_SIZE;
+
+ /* set deflated canary value for identification */
+ ret = dict_set_int32(*xdata, GF_CDC_DEFLATE_CANARY_VAL, 1);
+ if (ret) {
+ /* Send uncompressed data if we can't _tell_ the client
+ * that deflated data is on it's way. So, we just log
+ * the failure and continue as usual.
+ */
+ gf_log(this->name, GF_LOG_ERROR,
+ "Data deflated, but could not set canary"
+ " value in dict for identification");
+ }
- /* This is to be used in testing */
- if ( priv->debug ) {
- cdc_dump_iovec_to_disk (this, ci, GF_CDC_DEBUG_DUMP_FILE );
- }
+ /* This is to be used in testing */
+ if (priv->debug) {
+ cdc_dump_iovec_to_disk(this, ci, GF_CDC_DEBUG_DUMP_FILE);
+ }
- deflate_cleanup_out:
- (void) deflateEnd(&ci->stream);
+deflate_cleanup_out:
+ (void)deflateEnd(&ci->stream);
- out:
- return ret;
+out:
+ return ret;
}
-
/* deflate content is checked by the presence of a canary
* value in the dict as the key
*/
static int32_t
-cdc_check_content_for_deflate (dict_t *xdata)
+cdc_check_content_for_deflate(dict_t *xdata)
{
- return dict_get (xdata, GF_CDC_DEFLATE_CANARY_VAL) ? -1 : 0;
+ return dict_get(xdata, GF_CDC_DEFLATE_CANARY_VAL) ? -1 : 0;
}
static unsigned long
-cdc_extract_crc (char *trailer)
+cdc_extract_crc(char *trailer)
{
- return cdc_get_long ((unsigned char *) &trailer[0]);
+ return cdc_get_long((unsigned char *)&trailer[0]);
}
static unsigned long
-cdc_extract_size (char *trailer)
+cdc_extract_size(char *trailer)
{
- return cdc_get_long ((unsigned char *) &trailer[4]);
+ return cdc_get_long((unsigned char *)&trailer[4]);
}
static int32_t
-cdc_validate_inflate (cdc_info_t *ci, unsigned long crc,
- unsigned long len)
+cdc_validate_inflate(cdc_info_t *ci, unsigned long crc, unsigned long len)
{
- return !((crc == ci->crc)
- /* inflated length is hidden inside
- * Zlib stream struct */
- && (len == ci->stream.total_out));
+ return !((crc == ci->crc)
+ /* inflated length is hidden inside
+ * Zlib stream struct */
+ && (len == ci->stream.total_out));
}
static int32_t
-do_cdc_decompress (xlator_t *this, cdc_priv_t *priv, cdc_info_t *ci)
+do_cdc_decompress(xlator_t *this, cdc_priv_t *priv, cdc_info_t *ci)
{
- int ret = -1;
- int i = 0;
- int len = 0;
- char *inflte = NULL;
- char *trailer = NULL;
- struct iovec vec = {0,};
- unsigned long computed_crc = 0;
- unsigned long computed_len = 0;
-
- ret = inflateInit2 (&ci->stream, priv->window_size);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "Zlib: Unable to initialize inflate");
- goto out;
+ int ret = -1;
+ int i = 0;
+ int len = 0;
+ char *inflte = NULL;
+ char *trailer = NULL;
+ struct iovec vec = {
+ 0,
+ };
+ unsigned long computed_crc = 0;
+ unsigned long computed_len = 0;
+
+ ret = inflateInit2(&ci->stream, priv->window_size);
+ if (ret) {
+ gf_log(this->name, GF_LOG_ERROR, "Zlib: Unable to initialize inflate");
+ goto out;
+ }
+
+ vec = THIS_VEC(ci, 0);
+
+ trailer = (char *)(((char *)vec.iov_base) + vec.iov_len -
+ GF_CDC_VALIDATION_SIZE);
+
+ /* CRC of uncompressed data */
+ computed_crc = cdc_extract_crc(trailer);
+
+ /* size of uncomrpessed data */
+ computed_len = cdc_extract_size(trailer);
+
+ gf_log(this->name, GF_LOG_DEBUG, "crc=%lu len=%lu buffer_size=%d",
+ computed_crc, computed_len, ci->buffer_size);
+
+ inflte = vec.iov_base;
+ len = vec.iov_len - GF_CDC_VALIDATION_SIZE;
+
+ /* allocate buffer of the original length of the data */
+ ret = cdc_alloc_iobuf_and_init_vec(this, priv, ci, 0);
+ if (ret)
+ goto out;
+
+ /* setup output buffer */
+ cdc_init_zlib_output_stream(priv, ci, 0);
+
+ /* setup input buffer */
+ ci->stream.next_in = (unsigned char *)inflte;
+ ci->stream.avail_in = len;
+
+ while (ci->stream.avail_in != 0) {
+ if (ci->stream.avail_out == 0) {
+ CURR_VEC(ci).iov_len = ci->buffer_size;
+
+ ret = cdc_alloc_iobuf_and_init_vec(this, priv, ci, 0);
+ if (ret)
+ break;
+
+ /* Re-position Zlib output buffer */
+ cdc_init_zlib_output_stream(priv, ci, 0);
}
- vec = THIS_VEC(ci, 0);
-
- trailer = (char *) (((char *) vec.iov_base) + vec.iov_len
- - GF_CDC_VALIDATION_SIZE);
-
- /* CRC of uncompressed data */
- computed_crc = cdc_extract_crc (trailer);
-
- /* size of uncomrpessed data */
- computed_len = cdc_extract_size (trailer);
-
- gf_log (this->name, GF_LOG_DEBUG, "crc=%lu len=%lu buffer_size=%d",
- computed_crc, computed_len, ci->buffer_size);
-
- inflte = vec.iov_base ;
- len = vec.iov_len - GF_CDC_VALIDATION_SIZE;
-
- /* allocate buffer of the original length of the data */
- ret = cdc_alloc_iobuf_and_init_vec (this, priv, ci, 0);
- if (ret)
- goto out;
-
- /* setup output buffer */
- cdc_init_zlib_output_stream (priv, ci, 0);
-
- /* setup input buffer */
- ci->stream.next_in = (unsigned char *) inflte;
- ci->stream.avail_in = len;
-
- while (ci->stream.avail_in != 0) {
- if (ci->stream.avail_out == 0) {
- CURR_VEC(ci).iov_len = ci->buffer_size;
-
- ret = cdc_alloc_iobuf_and_init_vec (this, priv, ci, 0);
- if (ret)
- break;
-
- /* Re-position Zlib output buffer */
- cdc_init_zlib_output_stream (priv, ci, 0);
- }
-
- ret = inflate (&ci->stream, Z_NO_FLUSH);
- if (ret == Z_STREAM_ERROR)
- break;
- }
-
- /* flush zlib buffer */
- ret = cdc_flush_libz_buffer (priv, this, ci, inflate, Z_SYNC_FLUSH);
- if (!(ret == Z_OK || ret == Z_STREAM_END)) {
- gf_log (this->name, GF_LOG_ERROR,
- "Decompression Error: ret (%d)", ret);
- ret = -1;
- goto out;
- }
-
- /* compute CRC of the uncompresses data to check for
- * correctness */
-
- for (i = 0; i < ci->ncount; i++) {
- ci->crc = crc32 (ci->crc,
- (const Bytef *) ci->vec[i].iov_base,
- ci->vec[i].iov_len);
- }
-
- /* validate inflated data */
- ret = cdc_validate_inflate (ci, computed_crc, computed_len);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "Checksum or length mismatched in inflated data");
- }
-
- out:
- return ret;
+ ret = inflate(&ci->stream, Z_NO_FLUSH);
+ if (ret == Z_STREAM_ERROR)
+ break;
+ }
+
+ /* flush zlib buffer */
+ ret = cdc_flush_libz_buffer(priv, this, ci, inflate, Z_SYNC_FLUSH);
+ if (!(ret == Z_OK || ret == Z_STREAM_END)) {
+ gf_log(this->name, GF_LOG_ERROR, "Decompression Error: ret (%d)", ret);
+ ret = -1;
+ goto out;
+ }
+
+ /* compute CRC of the uncompresses data to check for
+ * correctness */
+
+ for (i = 0; i < ci->ncount; i++) {
+ ci->crc = crc32(ci->crc, (const Bytef *)ci->vec[i].iov_base,
+ ci->vec[i].iov_len);
+ }
+
+ /* validate inflated data */
+ ret = cdc_validate_inflate(ci, computed_crc, computed_len);
+ if (ret) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "Checksum or length mismatched in inflated data");
+ }
+
+out:
+ return ret;
}
int32_t
-cdc_decompress (xlator_t *this, cdc_priv_t *priv, cdc_info_t *ci,
- dict_t *xdata)
+cdc_decompress(xlator_t *this, cdc_priv_t *priv, cdc_info_t *ci, dict_t *xdata)
{
- int32_t ret = -1;
-
- /* check for deflate content */
- if (!cdc_check_content_for_deflate (xdata)) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Content not deflated, passing through ...");
- goto passthrough_out;
- }
-
- ci->iobref = iobref_new ();
- if (!ci->iobref)
- goto passthrough_out;
-
- /* do we need to do this? can we assume that one iovec
- * will hold per request data every time?
- *
- * server/client protocol seems to deal with a single
- * iovec even if op_ret > 1M. So, it looks ok to
- * assume that a single iovec will contain all the
- * data (This saves us a lot from finding the trailer
- * and the data since it could have been split-up onto
- * two adjacent iovec's.
- *
- * But, in case this translator is loaded above quick-read
- * for some reason, then it's entirely possible that we get
- * multiple iovec's...
- *
- * This case (handled below) is not tested. (by loading the
- * xlator below quick-read)
- */
-
- /* @@ I_HOPE_THIS_IS_NEVER_HIT */
- if (ci->count > 1) {
- gf_log (this->name, GF_LOG_WARNING, "unable to handle"
- " multiple iovecs (%d in number)", ci->count);
- goto inflate_cleanup_out;
- /* TODO: coallate all iovecs in one */
- }
-
- ret = do_cdc_decompress (this, priv, ci);
- if (ret)
- goto inflate_cleanup_out;
-
- ci->nbytes = ci->stream.total_out;
-
- gf_log (this->name, GF_LOG_DEBUG,
- "Inflated %ld to %ld bytes",
- ci->stream.total_in, ci->stream.total_out);
-
- inflate_cleanup_out:
- (void) inflateEnd (&ci->stream);
-
- passthrough_out:
- return ret;
+ int32_t ret = -1;
+
+ /* check for deflate content */
+ if (!cdc_check_content_for_deflate(xdata)) {
+ gf_log(this->name, GF_LOG_DEBUG,
+ "Content not deflated, passing through ...");
+ goto passthrough_out;
+ }
+
+ ci->iobref = iobref_new();
+ if (!ci->iobref)
+ goto passthrough_out;
+
+ /* do we need to do this? can we assume that one iovec
+ * will hold per request data every time?
+ *
+ * server/client protocol seems to deal with a single
+ * iovec even if op_ret > 1M. So, it looks ok to
+ * assume that a single iovec will contain all the
+ * data (This saves us a lot from finding the trailer
+ * and the data since it could have been split-up onto
+ * two adjacent iovec's.
+ *
+ * But, in case this translator is loaded above quick-read
+ * for some reason, then it's entirely possible that we get
+ * multiple iovec's...
+ *
+ * This case (handled below) is not tested. (by loading the
+ * xlator below quick-read)
+ */
+
+ /* @@ I_HOPE_THIS_IS_NEVER_HIT */
+ if (ci->count > 1) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "unable to handle"
+ " multiple iovecs (%d in number)",
+ ci->count);
+ goto inflate_cleanup_out;
+ /* TODO: coallate all iovecs in one */
+ }
+
+ ret = do_cdc_decompress(this, priv, ci);
+ if (ret)
+ goto inflate_cleanup_out;
+
+ ci->nbytes = ci->stream.total_out;
+
+ gf_log(this->name, GF_LOG_DEBUG, "Inflated %ld to %ld bytes",
+ ci->stream.total_in, ci->stream.total_out);
+
+inflate_cleanup_out:
+ (void)inflateEnd(&ci->stream);
+
+passthrough_out:
+ return ret;
}
#endif
diff --git a/xlators/features/compress/src/cdc.c b/xlators/features/compress/src/cdc.c
index e33d4efc1a1..25ea6dc1846 100644
--- a/xlators/features/compress/src/cdc.c
+++ b/xlators/features/compress/src/cdc.c
@@ -18,339 +18,316 @@
#include "cdc-mem-types.h"
static void
-cdc_cleanup_iobref (cdc_info_t *ci)
+cdc_cleanup_iobref(cdc_info_t *ci)
{
- assert(ci->iobref != NULL);
- iobref_clear (ci->iobref);
+ assert(ci->iobref != NULL);
+ iobref_clear(ci->iobref);
}
int32_t
-cdc_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iovec *vector, int32_t count,
- struct iatt *stbuf, struct iobref *iobref,
- dict_t *xdata)
+cdc_readv_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct iovec *vector, int32_t count,
+ struct iatt *stbuf, struct iobref *iobref, dict_t *xdata)
{
- int ret = -1;
- cdc_priv_t *priv = NULL;
- cdc_info_t ci = {0,};
-
- GF_VALIDATE_OR_GOTO ("cdc", this, default_out);
- GF_VALIDATE_OR_GOTO (this->name, frame, default_out);
-
- priv = this->private;
-
- if (op_ret <= 0)
- goto default_out;
-
- if ( (priv->min_file_size != 0)
- && (op_ret < priv->min_file_size) )
- goto default_out;
-
- ci.count = count;
- ci.ibytes = op_ret;
- ci.vector = vector;
- ci.buf = NULL;
- ci.iobref = NULL;
- ci.ncount = 0;
- ci.crc = 0;
- ci.buffer_size = GF_CDC_DEF_BUFFERSIZE;
-
-/* A readv compresses on the server side and decompresses on the client side
- */
- if (priv->op_mode == GF_CDC_MODE_SERVER) {
- ret = cdc_compress (this, priv, &ci, &xdata);
- } else if (priv->op_mode == GF_CDC_MODE_CLIENT) {
- ret = cdc_decompress (this, priv, &ci, xdata);
- } else {
- gf_log (this->name, GF_LOG_ERROR,
- "Invalid operation mode (%d)", priv->op_mode);
- }
-
- if (ret)
- goto default_out;
-
- STACK_UNWIND_STRICT (readv, frame, ci.nbytes, op_errno,
- ci.vec, ci.ncount, stbuf, iobref,
- xdata);
- cdc_cleanup_iobref (&ci);
- return 0;
-
- default_out:
- STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno,
- vector, count, stbuf, iobref, xdata);
- return 0;
+ int ret = -1;
+ cdc_priv_t *priv = NULL;
+ cdc_info_t ci = {
+ 0,
+ };
+
+ GF_VALIDATE_OR_GOTO("cdc", this, default_out);
+ GF_VALIDATE_OR_GOTO(this->name, frame, default_out);
+
+ priv = this->private;
+
+ if (op_ret <= 0)
+ goto default_out;
+
+ if ((priv->min_file_size != 0) && (op_ret < priv->min_file_size))
+ goto default_out;
+
+ ci.count = count;
+ ci.ibytes = op_ret;
+ ci.vector = vector;
+ ci.buf = NULL;
+ ci.iobref = NULL;
+ ci.ncount = 0;
+ ci.crc = 0;
+ ci.buffer_size = GF_CDC_DEF_BUFFERSIZE;
+
+ /* A readv compresses on the server side and decompresses on the client side
+ */
+ if (priv->op_mode == GF_CDC_MODE_SERVER) {
+ ret = cdc_compress(this, priv, &ci, &xdata);
+ } else if (priv->op_mode == GF_CDC_MODE_CLIENT) {
+ ret = cdc_decompress(this, priv, &ci, xdata);
+ } else {
+ gf_log(this->name, GF_LOG_ERROR, "Invalid operation mode (%d)",
+ priv->op_mode);
+ }
+
+ if (ret)
+ goto default_out;
+
+ STACK_UNWIND_STRICT(readv, frame, ci.nbytes, op_errno, ci.vec, ci.ncount,
+ stbuf, iobref, xdata);
+ cdc_cleanup_iobref(&ci);
+ return 0;
+
+default_out:
+ STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, vector, count, stbuf,
+ iobref, xdata);
+ return 0;
}
int32_t
-cdc_readv (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t offset, uint32_t flags,
- dict_t *xdata)
+cdc_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset, uint32_t flags, dict_t *xdata)
{
- fop_readv_cbk_t cbk = NULL;
+ fop_readv_cbk_t cbk = NULL;
#ifdef HAVE_LIB_Z
- cbk = cdc_readv_cbk;
+ cbk = cdc_readv_cbk;
#else
- cbk = default_readv_cbk;
+ cbk = default_readv_cbk;
#endif
- STACK_WIND (frame, cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->readv,
- fd, size, offset, flags, xdata);
- return 0;
+ STACK_WIND(frame, cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readv,
+ fd, size, offset, flags, xdata);
+ return 0;
}
int32_t
-cdc_writev_cbk (call_frame_t *frame,
- void *cookie,
- xlator_t *this,
- int32_t op_ret,
- int32_t op_errno,
- struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+cdc_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
-
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf, xdata);
- return 0;
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ return 0;
}
int32_t
-cdc_writev (call_frame_t *frame,
- xlator_t *this,
- fd_t *fd,
- struct iovec *vector,
- int32_t count,
- off_t offset,
- uint32_t flags,
- struct iobref *iobref, dict_t *xdata)
+cdc_writev(call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector,
+ int32_t count, off_t offset, uint32_t flags, struct iobref *iobref,
+ dict_t *xdata)
{
- int ret = -1;
- cdc_priv_t *priv = NULL;
- cdc_info_t ci = {0,};
- size_t isize = 0;
-
- GF_VALIDATE_OR_GOTO ("cdc", this, default_out);
- GF_VALIDATE_OR_GOTO (this->name, frame, default_out);
-
- priv = this->private;
-
- isize = iov_length(vector, count);
-
- if (isize <= 0)
- goto default_out;
-
- if ( (priv->min_file_size != 0) && (isize < priv->min_file_size) )
- goto default_out;
-
- ci.count = count;
- ci.ibytes = isize;
- ci.vector = vector;
- ci.buf = NULL;
- ci.iobref = NULL;
- ci.ncount = 0;
- ci.crc = 0;
- ci.buffer_size = GF_CDC_DEF_BUFFERSIZE;
-
-/* A writev compresses on the client side and decompresses on the server side
- */
- if (priv->op_mode == GF_CDC_MODE_CLIENT) {
- ret = cdc_compress (this, priv, &ci, &xdata);
- } else if (priv->op_mode == GF_CDC_MODE_SERVER) {
- ret = cdc_decompress (this, priv, &ci, xdata);
- } else {
- gf_log (this->name, GF_LOG_ERROR, "Invalid operation mode (%d) ", priv->op_mode);
- }
-
- if (ret)
- goto default_out;
-
- STACK_WIND (frame,
- cdc_writev_cbk,
- FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->writev,
- fd, ci.vec, ci.ncount, offset, flags,
- iobref, xdata);
-
- cdc_cleanup_iobref (&ci);
- return 0;
-
- default_out:
- STACK_WIND (frame,
- cdc_writev_cbk,
- FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->writev,
- fd, vector, count, offset, flags,
- iobref, xdata);
- return 0;
+ int ret = -1;
+ cdc_priv_t *priv = NULL;
+ cdc_info_t ci = {
+ 0,
+ };
+ size_t isize = 0;
+
+ GF_VALIDATE_OR_GOTO("cdc", this, default_out);
+ GF_VALIDATE_OR_GOTO(this->name, frame, default_out);
+
+ priv = this->private;
+
+ isize = iov_length(vector, count);
+
+ if (isize <= 0)
+ goto default_out;
+
+ if ((priv->min_file_size != 0) && (isize < priv->min_file_size))
+ goto default_out;
+
+ ci.count = count;
+ ci.ibytes = isize;
+ ci.vector = vector;
+ ci.buf = NULL;
+ ci.iobref = NULL;
+ ci.ncount = 0;
+ ci.crc = 0;
+ ci.buffer_size = GF_CDC_DEF_BUFFERSIZE;
+
+ /* A writev compresses on the client side and decompresses on the server
+ * side
+ */
+ if (priv->op_mode == GF_CDC_MODE_CLIENT) {
+ ret = cdc_compress(this, priv, &ci, &xdata);
+ } else if (priv->op_mode == GF_CDC_MODE_SERVER) {
+ ret = cdc_decompress(this, priv, &ci, xdata);
+ } else {
+ gf_log(this->name, GF_LOG_ERROR, "Invalid operation mode (%d) ",
+ priv->op_mode);
+ }
+
+ if (ret)
+ goto default_out;
+
+ STACK_WIND(frame, cdc_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, ci.vec, ci.ncount, offset,
+ flags, iobref, xdata);
+
+ cdc_cleanup_iobref(&ci);
+ return 0;
+
+default_out:
+ STACK_WIND(frame, cdc_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, vector, count, offset,
+ flags, iobref, xdata);
+ return 0;
}
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int ret = -1;
-
- if (!this)
- return ret;
+ int ret = -1;
- ret = xlator_mem_acct_init (this, gf_cdc_mt_end);
+ if (!this)
+ return ret;
- if (ret != 0) {
- gf_log(this->name, GF_LOG_ERROR, "Memory accounting init"
- "failed");
- return ret;
- }
+ ret = xlator_mem_acct_init(this, gf_cdc_mt_end);
+ if (ret != 0) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "Memory accounting init"
+ "failed");
return ret;
+ }
+
+ return ret;
}
int32_t
-init (xlator_t *this)
+init(xlator_t *this)
{
- int ret = -1;
- char *temp_str = NULL;
- cdc_priv_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO ("cdc", this, err);
-
- if (!this->children || this->children->next) {
- gf_log (this->name, GF_LOG_ERROR,
- "Need subvolume == 1");
- goto err;
- }
-
- if (!this->parents) {
- gf_log (this->name, GF_LOG_WARNING,
- "Dangling volume. Check volfile");
- }
-
- priv = GF_CALLOC (1, sizeof (*priv), gf_cdc_mt_priv_t);
- if (!priv) {
- goto err;
- }
-
- /* Check if debug mode is turned on */
- GF_OPTION_INIT ("debug", priv->debug, bool, err);
- if( priv->debug ) {
- gf_log (this->name, GF_LOG_DEBUG, "CDC debug option turned on");
- }
-
- /* Set Gzip Window Size */
- GF_OPTION_INIT ("window-size", priv->window_size, int32, err);
- if ( (priv->window_size > GF_CDC_MAX_WINDOWSIZE)
- || (priv->window_size < GF_CDC_DEF_WINDOWSIZE) ) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid gzip window size (%d), using default",
- priv->window_size);
- priv->window_size = GF_CDC_DEF_WINDOWSIZE;
- }
-
- /* Set Gzip (De)Compression Level */
- GF_OPTION_INIT ("compression-level", priv->cdc_level, int32, err);
- if ( ((priv->cdc_level < 1) || (priv->cdc_level > 9))
- && (priv->cdc_level != GF_CDC_DEF_COMPRESSION) ) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid gzip (de)compression level (%d),"
- " using default", priv->cdc_level);
- priv->cdc_level = GF_CDC_DEF_COMPRESSION;
- }
-
- /* Set Gzip Memory Level */
- GF_OPTION_INIT ("mem-level", priv->mem_level, int32, err);
- if ( (priv->mem_level < 1) || (priv->mem_level > 9) ) {
- gf_log (this->name, GF_LOG_WARNING,
- "Invalid gzip memory level, using the default");
- priv->mem_level = GF_CDC_DEF_MEMLEVEL;
- }
-
- /* Set min file size to enable compression */
- GF_OPTION_INIT ("min-size", priv->min_file_size, int32, err);
-
- /* Mode of operation - Server/Client */
- ret = dict_get_str (this->options, "mode", &temp_str);
- if (ret) {
- gf_log (this->name, GF_LOG_CRITICAL,
- "Operation mode not specified !!");
- goto err;
- }
-
- if (GF_CDC_MODE_IS_CLIENT (temp_str)) {
- priv->op_mode = GF_CDC_MODE_CLIENT;
- } else if (GF_CDC_MODE_IS_SERVER (temp_str)) {
- priv->op_mode = GF_CDC_MODE_SERVER;
- } else {
- gf_log (this->name, GF_LOG_CRITICAL,
- "Bogus operation mode (%s) specified", temp_str);
- goto err;
- }
-
- this->private = priv;
- gf_log (this->name, GF_LOG_DEBUG, "CDC xlator loaded in (%s) mode",temp_str);
- return 0;
-
- err:
- if (priv)
- GF_FREE (priv);
-
- return -1;
+ int ret = -1;
+ char *temp_str = NULL;
+ cdc_priv_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO("cdc", this, err);
+
+ if (!this->children || this->children->next) {
+ gf_log(this->name, GF_LOG_ERROR, "Need subvolume == 1");
+ goto err;
+ }
+
+ if (!this->parents) {
+ gf_log(this->name, GF_LOG_WARNING, "Dangling volume. Check volfile");
+ }
+
+ priv = GF_CALLOC(1, sizeof(*priv), gf_cdc_mt_priv_t);
+ if (!priv) {
+ goto err;
+ }
+
+ /* Check if debug mode is turned on */
+ GF_OPTION_INIT("debug", priv->debug, bool, err);
+ if (priv->debug) {
+ gf_log(this->name, GF_LOG_DEBUG, "CDC debug option turned on");
+ }
+
+ /* Set Gzip Window Size */
+ GF_OPTION_INIT("window-size", priv->window_size, int32, err);
+ if ((priv->window_size > GF_CDC_MAX_WINDOWSIZE) ||
+ (priv->window_size < GF_CDC_DEF_WINDOWSIZE)) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "Invalid gzip window size (%d), using default",
+ priv->window_size);
+ priv->window_size = GF_CDC_DEF_WINDOWSIZE;
+ }
+
+ /* Set Gzip (De)Compression Level */
+ GF_OPTION_INIT("compression-level", priv->cdc_level, int32, err);
+ if (((priv->cdc_level < 1) || (priv->cdc_level > 9)) &&
+ (priv->cdc_level != GF_CDC_DEF_COMPRESSION)) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "Invalid gzip (de)compression level (%d),"
+ " using default",
+ priv->cdc_level);
+ priv->cdc_level = GF_CDC_DEF_COMPRESSION;
+ }
+
+ /* Set Gzip Memory Level */
+ GF_OPTION_INIT("mem-level", priv->mem_level, int32, err);
+ if ((priv->mem_level < 1) || (priv->mem_level > 9)) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "Invalid gzip memory level, using the default");
+ priv->mem_level = GF_CDC_DEF_MEMLEVEL;
+ }
+
+ /* Set min file size to enable compression */
+ GF_OPTION_INIT("min-size", priv->min_file_size, int32, err);
+
+ /* Mode of operation - Server/Client */
+ ret = dict_get_str(this->options, "mode", &temp_str);
+ if (ret) {
+ gf_log(this->name, GF_LOG_CRITICAL, "Operation mode not specified !!");
+ goto err;
+ }
+
+ if (GF_CDC_MODE_IS_CLIENT(temp_str)) {
+ priv->op_mode = GF_CDC_MODE_CLIENT;
+ } else if (GF_CDC_MODE_IS_SERVER(temp_str)) {
+ priv->op_mode = GF_CDC_MODE_SERVER;
+ } else {
+ gf_log(this->name, GF_LOG_CRITICAL,
+ "Bogus operation mode (%s) specified", temp_str);
+ goto err;
+ }
+
+ this->private = priv;
+ gf_log(this->name, GF_LOG_DEBUG, "CDC xlator loaded in (%s) mode",
+ temp_str);
+ return 0;
+
+err:
+ if (priv)
+ GF_FREE(priv);
+
+ return -1;
}
void
-fini (xlator_t *this)
+fini(xlator_t *this)
{
- cdc_priv_t *priv = this->private;
+ cdc_priv_t *priv = this->private;
- if (priv)
- GF_FREE (priv);
- this->private = NULL;
- return;
+ if (priv)
+ GF_FREE(priv);
+ this->private = NULL;
+ return;
}
struct xlator_fops fops = {
- .readv = cdc_readv,
- .writev = cdc_writev,
+ .readv = cdc_readv,
+ .writev = cdc_writev,
};
-struct xlator_cbks cbks = {
-};
+struct xlator_cbks cbks = {};
struct volume_options options[] = {
- { .key = {"window-size"},
- .default_value = "-15",
- .type = GF_OPTION_TYPE_INT,
- .description = "Size of the zlib history buffer."
- },
- { .key = {"mem-level"},
- .default_value = "8",
- .type = GF_OPTION_TYPE_INT,
- .description = "Memory allocated for internal compression state. "
- "1 uses minimum memory but is slow and reduces "
- "compression ratio; memLevel=9 uses maximum memory "
- "for optimal speed. The default value is 8."
- },
- { .key = {"compression-level"},
- .default_value = "-1",
- .type = GF_OPTION_TYPE_INT,
- .description = "Compression levels \n"
- "0 : no compression, 1 : best speed, \n"
- "9 : best compression, -1 : default compression "
- },
- { .key = {"min-size"},
- .default_value = "0",
- .type = GF_OPTION_TYPE_INT,
- .description = "Data is compressed only when its size exceeds this."
- },
- { .key = {"mode"},
- .value = {"server", "client"},
- .type = GF_OPTION_TYPE_STR,
- .description = "Set on the basis of where the xlator is loaded. "
- "This option should NOT be configured by user."
- },
- { .key = {"debug"},
- .default_value = "false",
- .type = GF_OPTION_TYPE_BOOL,
- .description = "This is used in testing. Will dump compressed data "
- "to disk as a gzip file."
- },
- { .key = {NULL}
- },
+ {.key = {"window-size"},
+ .default_value = "-15",
+ .type = GF_OPTION_TYPE_INT,
+ .description = "Size of the zlib history buffer."},
+ {.key = {"mem-level"},
+ .default_value = "8",
+ .type = GF_OPTION_TYPE_INT,
+ .description = "Memory allocated for internal compression state. "
+ "1 uses minimum memory but is slow and reduces "
+ "compression ratio; memLevel=9 uses maximum memory "
+ "for optimal speed. The default value is 8."},
+ {.key = {"compression-level"},
+ .default_value = "-1",
+ .type = GF_OPTION_TYPE_INT,
+ .description = "Compression levels \n"
+ "0 : no compression, 1 : best speed, \n"
+ "9 : best compression, -1 : default compression "},
+ {.key = {"min-size"},
+ .default_value = "0",
+ .type = GF_OPTION_TYPE_INT,
+ .description = "Data is compressed only when its size exceeds this."},
+ {.key = {"mode"},
+ .value = {"server", "client"},
+ .type = GF_OPTION_TYPE_STR,
+ .description = "Set on the basis of where the xlator is loaded. "
+ "This option should NOT be configured by user."},
+ {.key = {"debug"},
+ .default_value = "false",
+ .type = GF_OPTION_TYPE_BOOL,
+ .description = "This is used in testing. Will dump compressed data "
+ "to disk as a gzip file."},
+ {.key = {NULL}},
};
diff --git a/xlators/features/gfid-access/src/gfid-access.c b/xlators/features/gfid-access/src/gfid-access.c
index 79c2ee911cd..3d5008666f6 100644
--- a/xlators/features/gfid-access/src/gfid-access.c
+++ b/xlators/features/gfid-access/src/gfid-access.c
@@ -12,1418 +12,1399 @@
#include "byte-order.h"
#include "statedump.h"
-
int
-ga_valid_inode_loc_copy (loc_t *dst, loc_t *src, xlator_t *this)
+ga_valid_inode_loc_copy(loc_t *dst, loc_t *src, xlator_t *this)
{
- int ret = 0;
- uint64_t value = 0;
-
- /* if its an entry operation, on the virtual */
- /* directory inode as parent, we need to handle */
- /* it properly */
- ret = loc_copy (dst, src);
- if (ret < 0)
- goto out;
-
- /*
- * Change ALL virtual inodes with real-inodes in loc
- */
- if (dst->parent) {
- ret = inode_ctx_get (dst->parent, this, &value);
- if (ret < 0) {
- ret = 0; //real-inode
- goto out;
- }
- inode_unref (dst->parent);
- dst->parent = inode_ref ((inode_t*)value);
- gf_uuid_copy (dst->pargfid, dst->parent->gfid);
+ int ret = 0;
+ uint64_t value = 0;
+
+ /* if its an entry operation, on the virtual */
+ /* directory inode as parent, we need to handle */
+ /* it properly */
+ ret = loc_copy(dst, src);
+ if (ret < 0)
+ goto out;
+
+ /*
+ * Change ALL virtual inodes with real-inodes in loc
+ */
+ if (dst->parent) {
+ ret = inode_ctx_get(dst->parent, this, &value);
+ if (ret < 0) {
+ ret = 0; // real-inode
+ goto out;
}
+ inode_unref(dst->parent);
+ dst->parent = inode_ref((inode_t *)value);
+ gf_uuid_copy(dst->pargfid, dst->parent->gfid);
+ }
- if (dst->inode) {
- ret = inode_ctx_get (dst->inode, this, &value);
- if (ret < 0) {
- ret = 0; //real-inode
- goto out;
- }
- inode_unref (dst->inode);
- dst->inode = inode_ref ((inode_t*)value);
- gf_uuid_copy (dst->gfid, dst->inode->gfid);
+ if (dst->inode) {
+ ret = inode_ctx_get(dst->inode, this, &value);
+ if (ret < 0) {
+ ret = 0; // real-inode
+ goto out;
}
+ inode_unref(dst->inode);
+ dst->inode = inode_ref((inode_t *)value);
+ gf_uuid_copy(dst->gfid, dst->inode->gfid);
+ }
out:
- return ret;
+ return ret;
}
void
-ga_newfile_args_free (ga_newfile_args_t *args)
+ga_newfile_args_free(ga_newfile_args_t *args)
{
- if (!args)
- goto out;
+ if (!args)
+ goto out;
- GF_FREE (args->bname);
+ GF_FREE(args->bname);
- if (S_ISLNK (args->st_mode) && args->args.symlink.linkpath) {
- GF_FREE (args->args.symlink.linkpath);
- args->args.symlink.linkpath = NULL;
- }
+ if (S_ISLNK(args->st_mode) && args->args.symlink.linkpath) {
+ GF_FREE(args->args.symlink.linkpath);
+ args->args.symlink.linkpath = NULL;
+ }
- mem_put (args);
+ mem_put(args);
out:
- return;
+ return;
}
-
void
-ga_heal_args_free (ga_heal_args_t *args)
+ga_heal_args_free(ga_heal_args_t *args)
{
- if (!args)
- goto out;
+ if (!args)
+ goto out;
- GF_FREE (args->bname);
+ GF_FREE(args->bname);
- mem_put (args);
+ mem_put(args);
out:
- return;
+ return;
}
-
ga_newfile_args_t *
-ga_newfile_parse_args (xlator_t *this, data_t *data)
+ga_newfile_parse_args(xlator_t *this, data_t *data)
{
- ga_newfile_args_t *args = NULL;
- ga_private_t *priv = NULL;
- int len = 0;
- int blob_len = 0;
- int min_len = 0;
- void *blob = NULL;
-
- priv = this->private;
-
- blob = data->data;
- blob_len = data->len;
-
- min_len = sizeof (args->uid) + sizeof (args->gid) + sizeof (args->gfid)
- + sizeof (args->st_mode) + 2 + 2;
- if (blob_len < min_len) {
- gf_log (this->name, GF_LOG_ERROR,
- "Invalid length: Total length is less "
- "than minimum length.");
- goto err;
+ ga_newfile_args_t *args = NULL;
+ ga_private_t *priv = NULL;
+ int len = 0;
+ int blob_len = 0;
+ int min_len = 0;
+ void *blob = NULL;
+
+ priv = this->private;
+
+ blob = data->data;
+ blob_len = data->len;
+
+ min_len = sizeof(args->uid) + sizeof(args->gid) + sizeof(args->gfid) +
+ sizeof(args->st_mode) + 2 + 2;
+ if (blob_len < min_len) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "Invalid length: Total length is less "
+ "than minimum length.");
+ goto err;
+ }
+
+ args = mem_get0(priv->newfile_args_pool);
+ if (args == NULL)
+ goto err;
+
+ args->uid = ntoh32(*(uint32_t *)blob);
+ blob += sizeof(uint32_t);
+ blob_len -= sizeof(uint32_t);
+
+ args->gid = ntoh32(*(uint32_t *)blob);
+ blob += sizeof(uint32_t);
+ blob_len -= sizeof(uint32_t);
+
+ memcpy(args->gfid, blob, sizeof(args->gfid));
+ blob += sizeof(args->gfid);
+ blob_len -= sizeof(args->gfid);
+
+ args->st_mode = ntoh32(*(uint32_t *)blob);
+ blob += sizeof(uint32_t);
+ blob_len -= sizeof(uint32_t);
+
+ len = strnlen(blob, blob_len);
+ if (len == blob_len) {
+ gf_log(this->name, GF_LOG_ERROR, "gfid: %s. No null byte present.",
+ args->gfid);
+ goto err;
+ }
+
+ args->bname = GF_MALLOC(len + 1, gf_common_mt_char);
+ if (args->bname == NULL)
+ goto err;
+
+ memcpy(args->bname, blob, (len + 1));
+ blob += (len + 1);
+ blob_len -= (len + 1);
+
+ if (S_ISDIR(args->st_mode)) {
+ if (blob_len < sizeof(uint32_t)) {
+ gf_log(this->name, GF_LOG_ERROR, "gfid: %s. Invalid length",
+ args->gfid);
+ goto err;
}
-
- args = mem_get0 (priv->newfile_args_pool);
- if (args == NULL)
- goto err;
-
- args->uid = ntoh32 (*(uint32_t *)blob);
- blob += sizeof (uint32_t);
- blob_len -= sizeof (uint32_t);
-
- args->gid = ntoh32 (*(uint32_t *)blob);
- blob += sizeof (uint32_t);
- blob_len -= sizeof (uint32_t);
-
- memcpy (args->gfid, blob, sizeof (args->gfid));
- blob += sizeof (args->gfid);
- blob_len -= sizeof (args->gfid);
-
- args->st_mode = ntoh32 (*(uint32_t *)blob);
- blob += sizeof (uint32_t);
- blob_len -= sizeof (uint32_t);
-
- len = strnlen (blob, blob_len);
+ args->args.mkdir.mode = ntoh32(*(uint32_t *)blob);
+ blob += sizeof(uint32_t);
+ blob_len -= sizeof(uint32_t);
+
+ if (blob_len < sizeof(uint32_t)) {
+ gf_log(this->name, GF_LOG_ERROR, "gfid: %s. Invalid length",
+ args->gfid);
+ goto err;
+ }
+ args->args.mkdir.umask = ntoh32(*(uint32_t *)blob);
+ blob_len -= sizeof(uint32_t);
+ if (blob_len < 0) {
+ gf_log(this->name, GF_LOG_ERROR, "gfid: %s. Invalid length",
+ args->gfid);
+ goto err;
+ }
+ } else if (S_ISLNK(args->st_mode)) {
+ len = strnlen(blob, blob_len);
if (len == blob_len) {
- gf_log (this->name, GF_LOG_ERROR,
- "gfid: %s. No null byte present.",
- args->gfid);
- goto err;
+ gf_log(this->name, GF_LOG_ERROR, "gfid: %s. Invalid length",
+ args->gfid);
+ goto err;
}
+ args->args.symlink.linkpath = GF_MALLOC(len + 1, gf_common_mt_char);
+ if (args->args.symlink.linkpath == NULL)
+ goto err;
- args->bname = GF_MALLOC (len + 1, gf_common_mt_char);
- if (args->bname == NULL)
- goto err;
-
- memcpy (args->bname, blob, (len + 1));
- blob += (len + 1);
+ memcpy(args->args.symlink.linkpath, blob, (len + 1));
blob_len -= (len + 1);
-
- if (S_ISDIR (args->st_mode)) {
- if (blob_len < sizeof (uint32_t)) {
- gf_log (this->name, GF_LOG_ERROR,
- "gfid: %s. Invalid length",
- args->gfid);
- goto err;
- }
- args->args.mkdir.mode = ntoh32 (*(uint32_t *)blob);
- blob += sizeof (uint32_t);
- blob_len -= sizeof (uint32_t);
-
- if (blob_len < sizeof (uint32_t)) {
- gf_log (this->name, GF_LOG_ERROR,
- "gfid: %s. Invalid length",
- args->gfid);
- goto err;
- }
- args->args.mkdir.umask = ntoh32 (*(uint32_t *)blob);
- blob_len -= sizeof (uint32_t);
- if (blob_len < 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "gfid: %s. Invalid length",
- args->gfid);
- goto err;
- }
- } else if (S_ISLNK (args->st_mode)) {
- len = strnlen (blob, blob_len);
- if (len == blob_len) {
- gf_log (this->name, GF_LOG_ERROR,
- "gfid: %s. Invalid length",
- args->gfid);
- goto err;
- }
- args->args.symlink.linkpath = GF_MALLOC (len + 1,
- gf_common_mt_char);
- if (args->args.symlink.linkpath == NULL)
- goto err;
-
- memcpy (args->args.symlink.linkpath, blob, (len + 1));
- blob_len -= (len + 1);
- } else {
- if (blob_len < sizeof (uint32_t)) {
- gf_log (this->name, GF_LOG_ERROR,
- "gfid: %s. Invalid length",
- args->gfid);
- goto err;
- }
- args->args.mknod.mode = ntoh32 (*(uint32_t *)blob);
- blob += sizeof (uint32_t);
- blob_len -= sizeof (uint32_t);
-
- if (blob_len < sizeof (uint32_t)) {
- gf_log (this->name, GF_LOG_ERROR,
- "gfid: %s. Invalid length",
- args->gfid);
- goto err;
- }
- args->args.mknod.rdev = ntoh32 (*(uint32_t *)blob);
- blob += sizeof (uint32_t);
- blob_len -= sizeof (uint32_t);
-
- if (blob_len < sizeof (uint32_t)) {
- gf_log (this->name, GF_LOG_ERROR,
- "gfid: %s. Invalid length",
- args->gfid);
- goto err;
- }
- args->args.mknod.umask = ntoh32 (*(uint32_t *)blob);
- blob_len -= sizeof (uint32_t);
+ } else {
+ if (blob_len < sizeof(uint32_t)) {
+ gf_log(this->name, GF_LOG_ERROR, "gfid: %s. Invalid length",
+ args->gfid);
+ goto err;
}
-
- if (blob_len) {
- gf_log (this->name, GF_LOG_ERROR,
- "gfid: %s. Invalid length",
- args->gfid);
- goto err;
+ args->args.mknod.mode = ntoh32(*(uint32_t *)blob);
+ blob += sizeof(uint32_t);
+ blob_len -= sizeof(uint32_t);
+
+ if (blob_len < sizeof(uint32_t)) {
+ gf_log(this->name, GF_LOG_ERROR, "gfid: %s. Invalid length",
+ args->gfid);
+ goto err;
+ }
+ args->args.mknod.rdev = ntoh32(*(uint32_t *)blob);
+ blob += sizeof(uint32_t);
+ blob_len -= sizeof(uint32_t);
+
+ if (blob_len < sizeof(uint32_t)) {
+ gf_log(this->name, GF_LOG_ERROR, "gfid: %s. Invalid length",
+ args->gfid);
+ goto err;
}
+ args->args.mknod.umask = ntoh32(*(uint32_t *)blob);
+ blob_len -= sizeof(uint32_t);
+ }
+
+ if (blob_len) {
+ gf_log(this->name, GF_LOG_ERROR, "gfid: %s. Invalid length",
+ args->gfid);
+ goto err;
+ }
- return args;
+ return args;
err:
- if (args)
- ga_newfile_args_free (args);
+ if (args)
+ ga_newfile_args_free(args);
- return NULL;
+ return NULL;
}
ga_heal_args_t *
-ga_heal_parse_args (xlator_t *this, data_t *data)
+ga_heal_parse_args(xlator_t *this, data_t *data)
{
- ga_heal_args_t *args = NULL;
- ga_private_t *priv = NULL;
- void *blob = NULL;
- int len = 0;
- int blob_len = 0;
+ ga_heal_args_t *args = NULL;
+ ga_private_t *priv = NULL;
+ void *blob = NULL;
+ int len = 0;
+ int blob_len = 0;
- blob = data->data;
- blob_len = data->len;
+ blob = data->data;
+ blob_len = data->len;
- priv = this->private;
+ priv = this->private;
- /* bname should at least contain a character */
- if (blob_len < (sizeof (args->gfid) + 2))
- goto err;
+ /* bname should at least contain a character */
+ if (blob_len < (sizeof(args->gfid) + 2))
+ goto err;
- args = mem_get0 (priv->heal_args_pool);
- if (!args)
- goto err;
+ args = mem_get0(priv->heal_args_pool);
+ if (!args)
+ goto err;
- memcpy (args->gfid, blob, sizeof (args->gfid));
- blob += sizeof (args->gfid);
- blob_len -= sizeof (args->gfid);
+ memcpy(args->gfid, blob, sizeof(args->gfid));
+ blob += sizeof(args->gfid);
+ blob_len -= sizeof(args->gfid);
- len = strnlen (blob, blob_len);
- if (len == blob_len)
- goto err;
+ len = strnlen(blob, blob_len);
+ if (len == blob_len)
+ goto err;
- args->bname = GF_MALLOC (len + 1, gf_common_mt_char);
- if (!args->bname)
- goto err;
+ args->bname = GF_MALLOC(len + 1, gf_common_mt_char);
+ if (!args->bname)
+ goto err;
- memcpy (args->bname, blob, len);
- args->bname[len] = '\0';
- blob_len -= (len + 1);
+ memcpy(args->bname, blob, len);
+ args->bname[len] = '\0';
+ blob_len -= (len + 1);
- if (blob_len)
- goto err;
+ if (blob_len)
+ goto err;
- return args;
+ return args;
err:
- if (args)
- ga_heal_args_free (args);
+ if (args)
+ ga_heal_args_free(args);
- return NULL;
+ return NULL;
}
static int32_t
-ga_fill_tmp_loc (loc_t *loc, xlator_t *this, uuid_t gfid,
- char *bname, dict_t *xdata, loc_t *new_loc)
+ga_fill_tmp_loc(loc_t *loc, xlator_t *this, uuid_t gfid, char *bname,
+ dict_t *xdata, loc_t *new_loc)
{
- int ret = -1;
- uint64_t value = 0;
- inode_t *parent = NULL;
- unsigned char *gfid_ptr = NULL;
-
- parent = loc->inode;
- ret = inode_ctx_get (loc->inode, this, &value);
- if (!ret) {
- parent = (void *)value;
- if (gf_uuid_is_null (parent->gfid))
- parent = loc->inode;
- }
-
- /* parent itself should be looked up */
- gf_uuid_copy (new_loc->pargfid, parent->gfid);
- new_loc->parent = inode_ref (parent);
-
- new_loc->inode = inode_grep (parent->table, parent, bname);
- if (!new_loc->inode) {
- new_loc->inode = inode_new (parent->table);
- gf_uuid_copy (new_loc->inode->gfid, gfid);
- }
-
- loc_path (new_loc, bname);
- if (new_loc->path) {
- new_loc->name = strrchr (new_loc->path, '/');
- if (new_loc->name)
- new_loc->name++;
- }
-
- gfid_ptr = GF_MALLOC (sizeof(uuid_t), gf_common_mt_uuid_t);
- if (!gfid_ptr) {
- ret = -1;
- goto out;
- }
- gf_uuid_copy (gfid_ptr, gfid);
- ret = dict_set_gfuuid (xdata, "gfid-req", gfid_ptr, false);
- if (ret < 0)
- goto out;
-
- ret = 0;
+ int ret = -1;
+ uint64_t value = 0;
+ inode_t *parent = NULL;
+ unsigned char *gfid_ptr = NULL;
+
+ parent = loc->inode;
+ ret = inode_ctx_get(loc->inode, this, &value);
+ if (!ret) {
+ parent = (void *)value;
+ if (gf_uuid_is_null(parent->gfid))
+ parent = loc->inode;
+ }
+
+ /* parent itself should be looked up */
+ gf_uuid_copy(new_loc->pargfid, parent->gfid);
+ new_loc->parent = inode_ref(parent);
+
+ new_loc->inode = inode_grep(parent->table, parent, bname);
+ if (!new_loc->inode) {
+ new_loc->inode = inode_new(parent->table);
+ gf_uuid_copy(new_loc->inode->gfid, gfid);
+ }
+
+ loc_path(new_loc, bname);
+ if (new_loc->path) {
+ new_loc->name = strrchr(new_loc->path, '/');
+ if (new_loc->name)
+ new_loc->name++;
+ }
+
+ gfid_ptr = GF_MALLOC(sizeof(uuid_t), gf_common_mt_uuid_t);
+ if (!gfid_ptr) {
+ ret = -1;
+ goto out;
+ }
+ gf_uuid_copy(gfid_ptr, gfid);
+ ret = dict_set_gfuuid(xdata, "gfid-req", gfid_ptr, false);
+ if (ret < 0)
+ goto out;
+
+ ret = 0;
out:
- if (ret && gfid_ptr)
- GF_FREE (gfid_ptr);
- return ret;
+ if (ret && gfid_ptr)
+ GF_FREE(gfid_ptr);
+ return ret;
}
-
-
static gf_boolean_t
-__is_gfid_access_dir (uuid_t gfid)
+__is_gfid_access_dir(uuid_t gfid)
{
- uuid_t aux_gfid;
+ uuid_t aux_gfid;
- memset (aux_gfid, 0, 16);
- aux_gfid[15] = GF_AUX_GFID;
+ memset(aux_gfid, 0, 16);
+ aux_gfid[15] = GF_AUX_GFID;
- if (gf_uuid_compare (gfid, aux_gfid) == 0)
- return _gf_true;
+ if (gf_uuid_compare(gfid, aux_gfid) == 0)
+ return _gf_true;
- return _gf_false;
+ return _gf_false;
}
int32_t
-ga_forget (xlator_t *this, inode_t *inode)
+ga_forget(xlator_t *this, inode_t *inode)
{
- int ret = -1;
- uint64_t value = 0;
- inode_t *tmp_inode = NULL;
+ int ret = -1;
+ uint64_t value = 0;
+ inode_t *tmp_inode = NULL;
- ret = inode_ctx_del (inode, this, &value);
- if (ret)
- goto out;
+ ret = inode_ctx_del(inode, this, &value);
+ if (ret)
+ goto out;
- tmp_inode = (void *)value;
- inode_unref (tmp_inode);
+ tmp_inode = (void *)value;
+ inode_unref(tmp_inode);
out:
- return 0;
+ return 0;
}
-
static int
-ga_heal_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- inode_t *inode, struct iatt *stat, dict_t *dict,
- struct iatt *postparent)
+ga_heal_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, inode_t *inode, struct iatt *stat, dict_t *dict,
+ struct iatt *postparent)
{
- call_frame_t *orig_frame = NULL;
+ call_frame_t *orig_frame = NULL;
- orig_frame = frame->local;
- frame->local = NULL;
+ orig_frame = frame->local;
+ frame->local = NULL;
- /* don't worry about inode linking and other stuff. They'll happen on
- * the next lookup.
- */
- STACK_DESTROY (frame->root);
+ /* don't worry about inode linking and other stuff. They'll happen on
+ * the next lookup.
+ */
+ STACK_DESTROY(frame->root);
- STACK_UNWIND_STRICT (setxattr, orig_frame, op_ret, op_errno, dict);
+ STACK_UNWIND_STRICT(setxattr, orig_frame, op_ret, op_errno, dict);
- return 0;
+ return 0;
}
static int
-ga_newentry_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- inode_t *inode, struct iatt *buf,
- struct iatt *preparent, struct iatt *postparent,
- dict_t *xdata)
+ga_newentry_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- ga_local_t *local = NULL;
+ ga_local_t *local = NULL;
- local = frame->local;
+ local = frame->local;
- /* don't worry about inode linking and other stuff. They'll happen on
- * the next lookup.
- */
- frame->local = NULL;
- STACK_DESTROY (frame->root);
+ /* don't worry about inode linking and other stuff. They'll happen on
+ * the next lookup.
+ */
+ frame->local = NULL;
+ STACK_DESTROY(frame->root);
- STACK_UNWIND_STRICT (setxattr, local->orig_frame, op_ret,
- op_errno, xdata);
+ STACK_UNWIND_STRICT(setxattr, local->orig_frame, op_ret, op_errno, xdata);
- if (local->xdata)
- dict_unref (local->xdata);
- loc_wipe (&local->loc);
- mem_put (local);
+ if (local->xdata)
+ dict_unref(local->xdata);
+ loc_wipe(&local->loc);
+ mem_put(local);
- return 0;
+ return 0;
}
static int
-ga_newentry_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *stat, dict_t *xdata,
- struct iatt *postparent)
+ga_newentry_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *stat, dict_t *xdata,
+ struct iatt *postparent)
{
- ga_local_t *local = NULL;
+ ga_local_t *local = NULL;
- local = frame->local;
+ local = frame->local;
- if ((op_ret < 0) && ((op_errno != ENOENT) && (op_errno != ESTALE)))
- goto err;
+ if ((op_ret < 0) && ((op_errno != ENOENT) && (op_errno != ESTALE)))
+ goto err;
- STACK_WIND (frame, ga_newentry_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->mknod, &local->loc, local->mode,
- local->rdev, local->umask, local->xdata);
- return 0;
+ STACK_WIND(frame, ga_newentry_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mknod, &local->loc, local->mode,
+ local->rdev, local->umask, local->xdata);
+ return 0;
err:
- frame->local = NULL;
- STACK_DESTROY (frame->root);
- STACK_UNWIND_STRICT (setxattr, local->orig_frame, op_ret, op_errno,
- xdata);
- if (local->xdata)
- dict_unref (local->xdata);
- loc_wipe (&local->loc);
- mem_put (local);
-
- return 0;
+ frame->local = NULL;
+ STACK_DESTROY(frame->root);
+ STACK_UNWIND_STRICT(setxattr, local->orig_frame, op_ret, op_errno, xdata);
+ if (local->xdata)
+ dict_unref(local->xdata);
+ loc_wipe(&local->loc);
+ mem_put(local);
+
+ return 0;
}
int32_t
-ga_new_entry (call_frame_t *frame, xlator_t *this, loc_t *loc, data_t *data,
- dict_t *xdata)
+ga_new_entry(call_frame_t *frame, xlator_t *this, loc_t *loc, data_t *data,
+ dict_t *xdata)
{
- int ret = -1;
- ga_newfile_args_t *args = NULL;
- loc_t tmp_loc = {0,};
- call_frame_t *new_frame = NULL;
- ga_local_t *local = NULL;
- uuid_t gfid = {0,};
-
- args = ga_newfile_parse_args (this, data);
- if (!args)
- goto out;
-
- ret = gf_uuid_parse (args->gfid, gfid);
- if (ret)
- goto out;
-
- if (!xdata) {
- xdata = dict_new ();
- } else {
- xdata = dict_ref (xdata);
- }
-
- if (!xdata) {
- ret = -1;
- goto out;
- }
-
- ret = ga_fill_tmp_loc (loc, this, gfid,
- args->bname, xdata, &tmp_loc);
- if (ret)
- goto out;
-
- new_frame = copy_frame (frame);
- if (!new_frame)
- goto out;
-
- local = mem_get0 (this->local_pool);
- local->orig_frame = frame;
-
- loc_copy (&local->loc, &tmp_loc);
-
- new_frame->local = local;
- new_frame->root->uid = args->uid;
- new_frame->root->gid = args->gid;
-
- if (S_ISDIR (args->st_mode)) {
- STACK_WIND (new_frame, ga_newentry_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->mkdir,
- &tmp_loc, args->args.mkdir.mode,
- args->args.mkdir.umask, xdata);
- } else if (S_ISLNK (args->st_mode)) {
- STACK_WIND (new_frame, ga_newentry_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->symlink,
- args->args.symlink.linkpath,
- &tmp_loc, 0, xdata);
- } else {
- /* use 07777 (4 7s) for considering the Sticky bits etc) */
- ((ga_local_t *)new_frame->local)->mode =
- (S_IFMT & args->st_mode) | (07777 & args->args.mknod.mode);
-
- ((ga_local_t *)new_frame->local)->umask =
- args->args.mknod.umask;
- ((ga_local_t *)new_frame->local)->rdev = args->args.mknod.rdev;
- ((ga_local_t *)new_frame->local)->xdata = dict_ref (xdata);
-
- /* send a named lookup, so that dht can cleanup up stale linkto
- * files etc.
- */
- STACK_WIND (new_frame, ga_newentry_lookup_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->lookup,
- &tmp_loc, NULL);
- }
+ int ret = -1;
+ ga_newfile_args_t *args = NULL;
+ loc_t tmp_loc = {
+ 0,
+ };
+ call_frame_t *new_frame = NULL;
+ ga_local_t *local = NULL;
+ uuid_t gfid = {
+ 0,
+ };
+
+ args = ga_newfile_parse_args(this, data);
+ if (!args)
+ goto out;
+
+ ret = gf_uuid_parse(args->gfid, gfid);
+ if (ret)
+ goto out;
+
+ if (!xdata) {
+ xdata = dict_new();
+ } else {
+ xdata = dict_ref(xdata);
+ }
+
+ if (!xdata) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = ga_fill_tmp_loc(loc, this, gfid, args->bname, xdata, &tmp_loc);
+ if (ret)
+ goto out;
+
+ new_frame = copy_frame(frame);
+ if (!new_frame)
+ goto out;
+
+ local = mem_get0(this->local_pool);
+ local->orig_frame = frame;
+
+ loc_copy(&local->loc, &tmp_loc);
+
+ new_frame->local = local;
+ new_frame->root->uid = args->uid;
+ new_frame->root->gid = args->gid;
+
+ if (S_ISDIR(args->st_mode)) {
+ STACK_WIND(new_frame, ga_newentry_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mkdir, &tmp_loc,
+ args->args.mkdir.mode, args->args.mkdir.umask, xdata);
+ } else if (S_ISLNK(args->st_mode)) {
+ STACK_WIND(new_frame, ga_newentry_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->symlink,
+ args->args.symlink.linkpath, &tmp_loc, 0, xdata);
+ } else {
+ /* use 07777 (4 7s) for considering the Sticky bits etc) */
+ ((ga_local_t *)new_frame->local)->mode = (S_IFMT & args->st_mode) |
+ (07777 &
+ args->args.mknod.mode);
+
+ ((ga_local_t *)new_frame->local)->umask = args->args.mknod.umask;
+ ((ga_local_t *)new_frame->local)->rdev = args->args.mknod.rdev;
+ ((ga_local_t *)new_frame->local)->xdata = dict_ref(xdata);
+
+ /* send a named lookup, so that dht can cleanup up stale linkto
+ * files etc.
+ */
+ STACK_WIND(new_frame, ga_newentry_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, &tmp_loc, NULL);
+ }
- ret = 0;
+ ret = 0;
out:
- ga_newfile_args_free (args);
+ ga_newfile_args_free(args);
- if (xdata)
- dict_unref (xdata);
+ if (xdata)
+ dict_unref(xdata);
- loc_wipe (&tmp_loc);
+ loc_wipe(&tmp_loc);
- return ret;
+ return ret;
}
int32_t
-ga_heal_entry (call_frame_t *frame, xlator_t *this, loc_t *loc, data_t *data,
- dict_t *xdata)
+ga_heal_entry(call_frame_t *frame, xlator_t *this, loc_t *loc, data_t *data,
+ dict_t *xdata)
{
- int ret = -1;
- ga_heal_args_t *args = NULL;
- loc_t tmp_loc = {0,};
- call_frame_t *new_frame = NULL;
- uuid_t gfid = {0,};
-
- args = ga_heal_parse_args (this, data);
- if (!args)
- goto out;
-
- ret = gf_uuid_parse (args->gfid, gfid);
- if (ret)
- goto out;
-
- if (!xdata)
- xdata = dict_new ();
- else
- xdata = dict_ref (xdata);
-
- if (!xdata) {
- ret = -1;
- goto out;
- }
-
- ret = ga_fill_tmp_loc (loc, this, gfid, args->bname,
- xdata, &tmp_loc);
- if (ret)
- goto out;
-
- new_frame = copy_frame (frame);
- if (!new_frame)
- goto out;
-
- new_frame->local = (void *)frame;
-
- STACK_WIND (new_frame, ga_heal_cbk, FIRST_CHILD (this),
- FIRST_CHILD(this)->fops->lookup,
- &tmp_loc, xdata);
-
- ret = 0;
+ int ret = -1;
+ ga_heal_args_t *args = NULL;
+ loc_t tmp_loc = {
+ 0,
+ };
+ call_frame_t *new_frame = NULL;
+ uuid_t gfid = {
+ 0,
+ };
+
+ args = ga_heal_parse_args(this, data);
+ if (!args)
+ goto out;
+
+ ret = gf_uuid_parse(args->gfid, gfid);
+ if (ret)
+ goto out;
+
+ if (!xdata)
+ xdata = dict_new();
+ else
+ xdata = dict_ref(xdata);
+
+ if (!xdata) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = ga_fill_tmp_loc(loc, this, gfid, args->bname, xdata, &tmp_loc);
+ if (ret)
+ goto out;
+
+ new_frame = copy_frame(frame);
+ if (!new_frame)
+ goto out;
+
+ new_frame->local = (void *)frame;
+
+ STACK_WIND(new_frame, ga_heal_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, &tmp_loc, xdata);
+
+ ret = 0;
out:
- if (args)
- ga_heal_args_free (args);
+ if (args)
+ ga_heal_args_free(args);
- loc_wipe (&tmp_loc);
+ loc_wipe(&tmp_loc);
- if (xdata)
- dict_unref (xdata);
+ if (xdata)
+ dict_unref(xdata);
- return ret;
+ return ret;
}
int32_t
-ga_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- dict_t *xdata)
+ga_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata);
- return 0;
+ STACK_UNWIND_STRICT(setxattr, frame, op_ret, op_errno, xdata);
+ return 0;
}
int32_t
-ga_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
- int32_t flags, dict_t *xdata)
+ga_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
+ int32_t flags, dict_t *xdata)
{
- data_t *data = NULL;
- int op_errno = ENOMEM;
- int ret = 0;
- loc_t ga_loc = {0, };
-
- GFID_ACCESS_INODE_OP_CHECK (loc, op_errno, err);
-
- data = dict_get (dict, GF_FUSE_AUX_GFID_NEWFILE);
- if (data) {
- ret = ga_new_entry (frame, this, loc, data, xdata);
- if (ret)
- goto err;
- return 0;
- }
+ data_t *data = NULL;
+ int op_errno = ENOMEM;
+ int ret = 0;
+ loc_t ga_loc = {
+ 0,
+ };
+
+ GFID_ACCESS_INODE_OP_CHECK(loc, op_errno, err);
+
+ data = dict_get(dict, GF_FUSE_AUX_GFID_NEWFILE);
+ if (data) {
+ ret = ga_new_entry(frame, this, loc, data, xdata);
+ if (ret)
+ goto err;
+ return 0;
+ }
- data = dict_get (dict, GF_FUSE_AUX_GFID_HEAL);
- if (data) {
- ret = ga_heal_entry (frame, this, loc, data, xdata);
- if (ret)
- goto err;
- return 0;
- }
+ data = dict_get(dict, GF_FUSE_AUX_GFID_HEAL);
+ if (data) {
+ ret = ga_heal_entry(frame, this, loc, data, xdata);
+ if (ret)
+ goto err;
+ return 0;
+ }
- //If the inode is a virtual inode change the inode otherwise perform
- //the operation on same inode
- ret = ga_valid_inode_loc_copy (&ga_loc, loc, this);
- if (ret < 0)
- goto err;
+ // If the inode is a virtual inode change the inode otherwise perform
+ // the operation on same inode
+ ret = ga_valid_inode_loc_copy(&ga_loc, loc, this);
+ if (ret < 0)
+ goto err;
- STACK_WIND (frame, ga_setxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setxattr, &ga_loc, dict, flags,
- xdata);
+ STACK_WIND(frame, ga_setxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, &ga_loc, dict, flags, xdata);
- loc_wipe (&ga_loc);
- return 0;
+ loc_wipe(&ga_loc);
+ return 0;
err:
- STACK_UNWIND_STRICT (setxattr, frame, -1, op_errno, xdata);
- return 0;
+ STACK_UNWIND_STRICT(setxattr, frame, -1, op_errno, xdata);
+ return 0;
}
-
int32_t
-ga_virtual_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, dict_t *xdata, struct iatt *postparent)
+ga_virtual_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, dict_t *xdata, struct iatt *postparent)
{
- int ret = 0;
- inode_t *cbk_inode = NULL;
- inode_t *true_inode = NULL;
- uuid_t random_gfid = {0,};
- inode_t *linked_inode = NULL;
-
- if (frame->local)
- cbk_inode = frame->local;
- else
- cbk_inode = inode_ref (inode);
-
- frame->local = NULL;
- if (op_ret)
- goto unwind;
-
- if (!IA_ISDIR (buf->ia_type))
+ int ret = 0;
+ inode_t *cbk_inode = NULL;
+ inode_t *true_inode = NULL;
+ uuid_t random_gfid = {
+ 0,
+ };
+ inode_t *linked_inode = NULL;
+
+ if (frame->local)
+ cbk_inode = frame->local;
+ else
+ cbk_inode = inode_ref(inode);
+
+ frame->local = NULL;
+ if (op_ret)
+ goto unwind;
+
+ if (!IA_ISDIR(buf->ia_type))
+ goto unwind;
+
+ /* need to send back a different inode for linking in itable */
+ if (cbk_inode == inode) {
+ /* check if the inode is in the 'itable' or
+ if its just previously discover()'d inode */
+ true_inode = inode_find(inode->table, buf->ia_gfid);
+ if (!true_inode) {
+ /* This unref is for 'inode_ref()' done in beginning.
+ This is needed as cbk_inode is allocated new inode
+ whose unref is taken at the end*/
+ inode_unref(cbk_inode);
+ cbk_inode = inode_new(inode->table);
+
+ if (!cbk_inode) {
+ op_ret = -1;
+ op_errno = ENOMEM;
goto unwind;
+ }
+ /* the inode is not present in itable, ie, the actual
+ path is not yet looked up. Use the current inode
+ itself for now */
- /* need to send back a different inode for linking in itable */
- if (cbk_inode == inode) {
- /* check if the inode is in the 'itable' or
- if its just previously discover()'d inode */
- true_inode = inode_find (inode->table, buf->ia_gfid);
- if (!true_inode) {
- /* This unref is for 'inode_ref()' done in beginning.
- This is needed as cbk_inode is allocated new inode
- whose unref is taken at the end*/
- inode_unref (cbk_inode);
- cbk_inode = inode_new (inode->table);
-
- if (!cbk_inode) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
- /* the inode is not present in itable, ie, the actual
- path is not yet looked up. Use the current inode
- itself for now */
-
- linked_inode = inode_link (inode, NULL, NULL, buf);
- inode = linked_inode;
- } else {
- /* 'inode_ref()' has been done in inode_find() */
- inode = true_inode;
- }
-
- ret = inode_ctx_put (cbk_inode, this, (uint64_t)inode);
- if (ret) {
- gf_log (this->name, GF_LOG_WARNING,
- "failed to set the inode ctx with"
- "the actual inode");
- if (inode)
- inode_unref (inode);
- }
- inode = NULL;
+ linked_inode = inode_link(inode, NULL, NULL, buf);
+ inode = linked_inode;
+ } else {
+ /* 'inode_ref()' has been done in inode_find() */
+ inode = true_inode;
}
- if (!gf_uuid_is_null (cbk_inode->gfid)) {
- /* if the previous linked inode is used, use the
- same gfid */
- gf_uuid_copy (random_gfid, cbk_inode->gfid);
- } else {
- /* replace the buf->ia_gfid to a random gfid
- for directory, for files, what we received is fine */
- gf_uuid_generate (random_gfid);
+ ret = inode_ctx_put(cbk_inode, this, (uint64_t)inode);
+ if (ret) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "failed to set the inode ctx with"
+ "the actual inode");
+ if (inode)
+ inode_unref(inode);
}
+ inode = NULL;
+ }
- gf_uuid_copy (buf->ia_gfid, random_gfid);
+ if (!gf_uuid_is_null(cbk_inode->gfid)) {
+ /* if the previous linked inode is used, use the
+ same gfid */
+ gf_uuid_copy(random_gfid, cbk_inode->gfid);
+ } else {
+ /* replace the buf->ia_gfid to a random gfid
+ for directory, for files, what we received is fine */
+ gf_uuid_generate(random_gfid);
+ }
- buf->ia_ino = gfid_to_ino (buf->ia_gfid);
+ gf_uuid_copy(buf->ia_gfid, random_gfid);
+
+ buf->ia_ino = gfid_to_ino(buf->ia_gfid);
unwind:
- /* Lookup on non-existing gfid returns ESTALE.
- Convert into ENOENT for virtual lookup*/
- if (op_errno == ESTALE)
- op_errno = ENOENT;
+ /* Lookup on non-existing gfid returns ESTALE.
+ Convert into ENOENT for virtual lookup*/
+ if (op_errno == ESTALE)
+ op_errno = ENOENT;
- STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, cbk_inode, buf,
- xdata, postparent);
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, cbk_inode, buf, xdata,
+ postparent);
- /* Also handles inode_unref of frame->local if done in ga_lookup */
- if (cbk_inode)
- inode_unref (cbk_inode);
+ /* Also handles inode_unref of frame->local if done in ga_lookup */
+ if (cbk_inode)
+ inode_unref(cbk_inode);
- return 0;
+ return 0;
}
int32_t
-ga_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, dict_t *xdata, struct iatt *postparent)
+ga_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, inode_t *inode, struct iatt *buf, dict_t *xdata,
+ struct iatt *postparent)
{
- ga_private_t *priv = NULL;
+ ga_private_t *priv = NULL;
- /* if the entry in question is not 'root',
- then follow the normal path */
- if (op_ret || !__is_root_gfid(buf->ia_gfid))
- goto unwind;
+ /* if the entry in question is not 'root',
+ then follow the normal path */
+ if (op_ret || !__is_root_gfid(buf->ia_gfid))
+ goto unwind;
- priv = this->private;
+ priv = this->private;
- /* do we need to copy root stbuf every time? */
- /* mostly yes, as we want to have the 'stat' info show latest
- in every _cbk() */
+ /* do we need to copy root stbuf every time? */
+ /* mostly yes, as we want to have the 'stat' info show latest
+ in every _cbk() */
- /* keep the reference for root stat buf */
- priv->root_stbuf = *buf;
- priv->gfiddir_stbuf = priv->root_stbuf;
- priv->gfiddir_stbuf.ia_gfid[15] = GF_AUX_GFID;
- priv->gfiddir_stbuf.ia_ino = GF_AUX_GFID;
+ /* keep the reference for root stat buf */
+ priv->root_stbuf = *buf;
+ priv->gfiddir_stbuf = priv->root_stbuf;
+ priv->gfiddir_stbuf.ia_gfid[15] = GF_AUX_GFID;
+ priv->gfiddir_stbuf.ia_ino = GF_AUX_GFID;
unwind:
- STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf,
- xdata, postparent);
- return 0;
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, buf, xdata,
+ postparent);
+ return 0;
}
int32_t
-ga_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
+ga_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- ga_private_t *priv = NULL;
- int ret = -1;
- uuid_t tmp_gfid = {0,};
- loc_t tmp_loc = {0,};
- uint64_t value = 0;
- inode_t *inode = NULL;
- inode_t *true_inode = NULL;
- int32_t op_errno = ENOENT;
-
- priv = this->private;
-
- /* Handle nameless lookup on ".gfid" */
- if (!loc->parent && __is_gfid_access_dir(loc->gfid)) {
- STACK_UNWIND_STRICT (lookup, frame, 0, 0, loc->inode,
- &priv->gfiddir_stbuf, xdata,
- &priv->root_stbuf);
- return 0;
- }
-
- /* if its discover(), no need for any action here */
- if (!loc->name)
- goto wind;
-
- /* if its revalidate, and inode is not of type directory,
- proceed with 'wind' */
- if (loc->inode && loc->inode->ia_type &&
- !IA_ISDIR (loc->inode->ia_type)) {
-
- /* a revalidate on ".gfid/<dentry>" is possible, check for it */
- if (((loc->parent &&
- __is_gfid_access_dir (loc->parent->gfid)) ||
- __is_gfid_access_dir (loc->pargfid))) {
-
- /* here, just send 'loc->gfid' and 'loc->inode' */
- tmp_loc.inode = inode_ref (loc->inode);
- gf_uuid_copy (tmp_loc.gfid, loc->inode->gfid);
+ ga_private_t *priv = NULL;
+ int ret = -1;
+ uuid_t tmp_gfid = {
+ 0,
+ };
+ loc_t tmp_loc = {
+ 0,
+ };
+ uint64_t value = 0;
+ inode_t *inode = NULL;
+ inode_t *true_inode = NULL;
+ int32_t op_errno = ENOENT;
+
+ priv = this->private;
+
+ /* Handle nameless lookup on ".gfid" */
+ if (!loc->parent && __is_gfid_access_dir(loc->gfid)) {
+ STACK_UNWIND_STRICT(lookup, frame, 0, 0, loc->inode,
+ &priv->gfiddir_stbuf, xdata, &priv->root_stbuf);
+ return 0;
+ }
- STACK_WIND (frame, default_lookup_cbk,
- FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->lookup,
- &tmp_loc, xdata);
+ /* if its discover(), no need for any action here */
+ if (!loc->name)
+ goto wind;
- inode_unref (tmp_loc.inode);
+ /* if its revalidate, and inode is not of type directory,
+ proceed with 'wind' */
+ if (loc->inode && loc->inode->ia_type && !IA_ISDIR(loc->inode->ia_type)) {
+ /* a revalidate on ".gfid/<dentry>" is possible, check for it */
+ if (((loc->parent && __is_gfid_access_dir(loc->parent->gfid)) ||
+ __is_gfid_access_dir(loc->pargfid))) {
+ /* here, just send 'loc->gfid' and 'loc->inode' */
+ tmp_loc.inode = inode_ref(loc->inode);
+ gf_uuid_copy(tmp_loc.gfid, loc->inode->gfid);
- return 0;
- }
+ STACK_WIND(frame, default_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, &tmp_loc, xdata);
- /* not something to bother, continue the flow */
- goto wind;
- }
+ inode_unref(tmp_loc.inode);
- /* need to check if the lookup is on virtual dir */
- if ((loc->name && !strcmp (GF_GFID_DIR, loc->name)) &&
- ((loc->parent && __is_root_gfid (loc->parent->gfid)) ||
- __is_root_gfid (loc->pargfid))) {
- /* this means, the query is on '/.gfid', return the fake stat,
- and say success */
-
- STACK_UNWIND_STRICT (lookup, frame, 0, 0, loc->inode,
- &priv->gfiddir_stbuf, xdata,
- &priv->root_stbuf);
- return 0;
+ return 0;
}
- /* now, check if the lookup() is on an existing entry,
- but on gfid-path */
- if (!((loc->parent && __is_gfid_access_dir (loc->parent->gfid)) ||
- __is_gfid_access_dir (loc->pargfid))) {
- if (!loc->parent)
- goto wind;
-
- ret = inode_ctx_get (loc->parent, this, &value);
- if (ret)
- goto wind;
-
- inode = (inode_t *) value;
+ /* not something to bother, continue the flow */
+ goto wind;
+ }
- ret = loc_copy_overload_parent (&tmp_loc, loc, inode);
- if (ret)
- goto err;
+ /* need to check if the lookup is on virtual dir */
+ if ((loc->name && !strcmp(GF_GFID_DIR, loc->name)) &&
+ ((loc->parent && __is_root_gfid(loc->parent->gfid)) ||
+ __is_root_gfid(loc->pargfid))) {
+ /* this means, the query is on '/.gfid', return the fake stat,
+ and say success */
- STACK_WIND (frame, ga_lookup_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->lookup, &tmp_loc, xdata);
+ STACK_UNWIND_STRICT(lookup, frame, 0, 0, loc->inode,
+ &priv->gfiddir_stbuf, xdata, &priv->root_stbuf);
+ return 0;
+ }
- loc_wipe (&tmp_loc);
- return 0;
- }
+ /* now, check if the lookup() is on an existing entry,
+ but on gfid-path */
+ if (!((loc->parent && __is_gfid_access_dir(loc->parent->gfid)) ||
+ __is_gfid_access_dir(loc->pargfid))) {
+ if (!loc->parent)
+ goto wind;
- /* make sure the 'basename' is actually a 'canonical-gfid',
- otherwise, return error */
- ret = gf_uuid_parse (loc->name, tmp_gfid);
+ ret = inode_ctx_get(loc->parent, this, &value);
if (ret)
- goto err;
+ goto wind;
- /* if its fresh lookup, go ahead and send it down, if not,
- for directory, we need indirection to actual dir inode */
- if (!(loc->inode && loc->inode->ia_type))
- goto discover;
+ inode = (inode_t *)value;
- /* revalidate on directory */
- ret = inode_ctx_get (loc->inode, this, &value);
+ ret = loc_copy_overload_parent(&tmp_loc, loc, inode);
if (ret)
- goto err;
-
- inode = (void *)value;
+ goto err;
- /* valid inode, already looked up, work on that */
- if (inode->ia_type)
- goto discover;
+ STACK_WIND(frame, ga_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, &tmp_loc, xdata);
- /* check if the inode is in the 'itable' or
- if its just previously discover()'d inode */
- true_inode = inode_find (loc->inode->table, tmp_gfid);
- if (true_inode) {
- /* time do another lookup and update the context
- with proper inode */
- op_errno = ESTALE;
- /* 'inode_ref()' done in inode_find */
- inode_unref (true_inode);
- goto err;
- }
+ loc_wipe(&tmp_loc);
+ return 0;
+ }
+
+ /* make sure the 'basename' is actually a 'canonical-gfid',
+ otherwise, return error */
+ ret = gf_uuid_parse(loc->name, tmp_gfid);
+ if (ret)
+ goto err;
+
+ /* if its fresh lookup, go ahead and send it down, if not,
+ for directory, we need indirection to actual dir inode */
+ if (!(loc->inode && loc->inode->ia_type))
+ goto discover;
+
+ /* revalidate on directory */
+ ret = inode_ctx_get(loc->inode, this, &value);
+ if (ret)
+ goto err;
+
+ inode = (void *)value;
+
+ /* valid inode, already looked up, work on that */
+ if (inode->ia_type)
+ goto discover;
+
+ /* check if the inode is in the 'itable' or
+ if its just previously discover()'d inode */
+ true_inode = inode_find(loc->inode->table, tmp_gfid);
+ if (true_inode) {
+ /* time do another lookup and update the context
+ with proper inode */
+ op_errno = ESTALE;
+ /* 'inode_ref()' done in inode_find */
+ inode_unref(true_inode);
+ goto err;
+ }
discover:
- /* for the virtual entries, we don't need to send 'gfid-req' key, as
- for these entries, we don't want to 'set' a new gfid */
- if (xdata)
- dict_del (xdata, "gfid-req");
+ /* for the virtual entries, we don't need to send 'gfid-req' key, as
+ for these entries, we don't want to 'set' a new gfid */
+ if (xdata)
+ dict_del(xdata, "gfid-req");
- gf_uuid_copy (tmp_loc.gfid, tmp_gfid);
+ gf_uuid_copy(tmp_loc.gfid, tmp_gfid);
- /* if revalidate, then we need to have the proper reference */
- if (inode) {
- tmp_loc.inode = inode_ref (inode);
- frame->local = inode_ref (loc->inode);
- } else {
- tmp_loc.inode = inode_ref (loc->inode);
- }
+ /* if revalidate, then we need to have the proper reference */
+ if (inode) {
+ tmp_loc.inode = inode_ref(inode);
+ frame->local = inode_ref(loc->inode);
+ } else {
+ tmp_loc.inode = inode_ref(loc->inode);
+ }
- STACK_WIND (frame, ga_virtual_lookup_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->lookup, &tmp_loc, xdata);
+ STACK_WIND(frame, ga_virtual_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, &tmp_loc, xdata);
- inode_unref (tmp_loc.inode);
+ inode_unref(tmp_loc.inode);
- return 0;
+ return 0;
wind:
- /* used for all the normal lookup path */
- STACK_WIND (frame, ga_lookup_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->lookup, loc, xdata);
+ /* used for all the normal lookup path */
+ STACK_WIND(frame, ga_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, loc, xdata);
- return 0;
+ return 0;
err:
- STACK_UNWIND_STRICT (lookup, frame, -1, op_errno, loc->inode,
- &priv->gfiddir_stbuf, xdata,
- &priv->root_stbuf);
- return 0;
+ STACK_UNWIND_STRICT(lookup, frame, -1, op_errno, loc->inode,
+ &priv->gfiddir_stbuf, xdata, &priv->root_stbuf);
+ return 0;
}
int
-ga_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
- mode_t umask, dict_t *xdata)
+ga_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ mode_t umask, dict_t *xdata)
{
- int op_errno = ENOMEM;
+ int op_errno = ENOMEM;
- GFID_ACCESS_ENTRY_OP_CHECK (loc, op_errno, err);
+ GFID_ACCESS_ENTRY_OP_CHECK(loc, op_errno, err);
- STACK_WIND (frame, default_mkdir_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->mkdir, loc, mode, umask,
- xdata);
+ STACK_WIND(frame, default_mkdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mkdir, loc, mode, umask, xdata);
- return 0;
+ return 0;
err:
- STACK_UNWIND_STRICT (mkdir, frame, -1, op_errno, loc->inode,
- NULL, NULL, NULL, xdata);
- return 0;
+ STACK_UNWIND_STRICT(mkdir, frame, -1, op_errno, loc->inode, NULL, NULL,
+ NULL, xdata);
+ return 0;
}
-
int
-ga_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
- mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
+ga_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
+ mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
{
- int op_errno = ENOMEM;
+ int op_errno = ENOMEM;
- GFID_ACCESS_ENTRY_OP_CHECK (loc, op_errno, err);
+ GFID_ACCESS_ENTRY_OP_CHECK(loc, op_errno, err);
- STACK_WIND (frame, default_create_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->create,
- loc, flags, mode, umask, fd, xdata);
- return 0;
+ STACK_WIND(frame, default_create_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->create, loc, flags, mode, umask, fd,
+ xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (create, frame, -1, op_errno, NULL,
- NULL, NULL, NULL, NULL, xdata);
-
- return 0;
+ STACK_UNWIND_STRICT(create, frame, -1, op_errno, NULL, NULL, NULL, NULL,
+ NULL, xdata);
+ return 0;
}
int
-ga_symlink (call_frame_t *frame, xlator_t *this, const char *linkname,
- loc_t *loc, mode_t umask, dict_t *xdata)
+ga_symlink(call_frame_t *frame, xlator_t *this, const char *linkname,
+ loc_t *loc, mode_t umask, dict_t *xdata)
{
- int op_errno = ENOMEM;
+ int op_errno = ENOMEM;
- GFID_ACCESS_ENTRY_OP_CHECK (loc, op_errno, err);
+ GFID_ACCESS_ENTRY_OP_CHECK(loc, op_errno, err);
- STACK_WIND (frame, default_symlink_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->symlink,
- linkname, loc, umask, xdata);
- return 0;
+ STACK_WIND(frame, default_symlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->symlink, linkname, loc, umask, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (symlink, frame, -1, op_errno, NULL,
- NULL, NULL, NULL, xdata);
+ STACK_UNWIND_STRICT(symlink, frame, -1, op_errno, NULL, NULL, NULL, NULL,
+ xdata);
- return 0;
+ return 0;
}
int
-ga_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
- dev_t rdev, mode_t umask, dict_t *xdata)
+ga_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ dev_t rdev, mode_t umask, dict_t *xdata)
{
- int op_errno = ENOMEM;
+ int op_errno = ENOMEM;
- GFID_ACCESS_ENTRY_OP_CHECK (loc, op_errno, err);
+ GFID_ACCESS_ENTRY_OP_CHECK(loc, op_errno, err);
- STACK_WIND (frame, default_mknod_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->mknod, loc, mode, rdev,
- umask, xdata);
+ STACK_WIND(frame, default_mknod_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mknod, loc, mode, rdev, umask, xdata);
- return 0;
+ return 0;
err:
- STACK_UNWIND_STRICT (mknod, frame, -1, op_errno, NULL,
- NULL, NULL, NULL, xdata);
+ STACK_UNWIND_STRICT(mknod, frame, -1, op_errno, NULL, NULL, NULL, NULL,
+ xdata);
- return 0;
+ return 0;
}
int
-ga_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flag,
- dict_t *xdata)
+ga_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int flag,
+ dict_t *xdata)
{
- int op_errno = ENOMEM;
- int ret = -1;
- loc_t ga_loc = {0, };
+ int op_errno = ENOMEM;
+ int ret = -1;
+ loc_t ga_loc = {
+ 0,
+ };
- GFID_ACCESS_ENTRY_OP_CHECK (loc, op_errno, err);
+ GFID_ACCESS_ENTRY_OP_CHECK(loc, op_errno, err);
- ret = ga_valid_inode_loc_copy (&ga_loc, loc, this);
- if (ret < 0)
- goto err;
+ ret = ga_valid_inode_loc_copy(&ga_loc, loc, this);
+ if (ret < 0)
+ goto err;
- STACK_WIND (frame, default_rmdir_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->rmdir,
- &ga_loc, flag, xdata);
+ STACK_WIND(frame, default_rmdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rmdir, &ga_loc, flag, xdata);
- loc_wipe (&ga_loc);
- return 0;
+ loc_wipe(&ga_loc);
+ return 0;
err:
- STACK_UNWIND_STRICT (rmdir, frame, -1, op_errno, NULL,
- NULL, xdata);
+ STACK_UNWIND_STRICT(rmdir, frame, -1, op_errno, NULL, NULL, xdata);
- return 0;
+ return 0;
}
int
-ga_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t xflag,
- dict_t *xdata)
+ga_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t xflag,
+ dict_t *xdata)
{
- int op_errno = ENOMEM;
- int ret = -1;
- loc_t ga_loc = {0, };
+ int op_errno = ENOMEM;
+ int ret = -1;
+ loc_t ga_loc = {
+ 0,
+ };
- GFID_ACCESS_ENTRY_OP_CHECK (loc, op_errno, err);
+ GFID_ACCESS_ENTRY_OP_CHECK(loc, op_errno, err);
- ret = ga_valid_inode_loc_copy (&ga_loc, loc, this);
- if (ret < 0)
- goto err;
+ ret = ga_valid_inode_loc_copy(&ga_loc, loc, this);
+ if (ret < 0)
+ goto err;
- STACK_WIND (frame, default_unlink_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->unlink,
- &ga_loc, xflag, xdata);
+ STACK_WIND(frame, default_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, &ga_loc, xflag, xdata);
- loc_wipe (&ga_loc);
- return 0;
+ loc_wipe(&ga_loc);
+ return 0;
err:
- STACK_UNWIND_STRICT (unlink, frame, -1, op_errno, NULL,
- NULL, xdata);
+ STACK_UNWIND_STRICT(unlink, frame, -1, op_errno, NULL, NULL, xdata);
- return 0;
+ return 0;
}
int
-ga_rename (call_frame_t *frame, xlator_t *this,
- loc_t *oldloc, loc_t *newloc, dict_t *xdata)
+ga_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
+ dict_t *xdata)
{
- int op_errno = ENOMEM;
- int ret = 0;
- loc_t ga_oldloc = {0, };
- loc_t ga_newloc = {0, };
-
- GFID_ACCESS_ENTRY_OP_CHECK (oldloc, op_errno, err);
- GFID_ACCESS_ENTRY_OP_CHECK (newloc, op_errno, err);
-
- ret = ga_valid_inode_loc_copy (&ga_oldloc, oldloc, this);
- if (ret < 0)
- goto err;
-
- ret = ga_valid_inode_loc_copy (&ga_newloc, newloc, this);
- if (ret < 0) {
- loc_wipe (&ga_oldloc);
- goto err;
- }
-
- STACK_WIND (frame, default_rename_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->rename,
- &ga_oldloc, &ga_newloc, xdata);
-
- loc_wipe (&ga_newloc);
- loc_wipe (&ga_oldloc);
- return 0;
+ int op_errno = ENOMEM;
+ int ret = 0;
+ loc_t ga_oldloc = {
+ 0,
+ };
+ loc_t ga_newloc = {
+ 0,
+ };
+
+ GFID_ACCESS_ENTRY_OP_CHECK(oldloc, op_errno, err);
+ GFID_ACCESS_ENTRY_OP_CHECK(newloc, op_errno, err);
+
+ ret = ga_valid_inode_loc_copy(&ga_oldloc, oldloc, this);
+ if (ret < 0)
+ goto err;
+
+ ret = ga_valid_inode_loc_copy(&ga_newloc, newloc, this);
+ if (ret < 0) {
+ loc_wipe(&ga_oldloc);
+ goto err;
+ }
+
+ STACK_WIND(frame, default_rename_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rename, &ga_oldloc, &ga_newloc, xdata);
+
+ loc_wipe(&ga_newloc);
+ loc_wipe(&ga_oldloc);
+ return 0;
err:
- STACK_UNWIND_STRICT (rename, frame, -1, op_errno, NULL,
- NULL, NULL, NULL, NULL, xdata);
+ STACK_UNWIND_STRICT(rename, frame, -1, op_errno, NULL, NULL, NULL, NULL,
+ NULL, xdata);
- return 0;
+ return 0;
}
-
int
-ga_link (call_frame_t *frame, xlator_t *this,
- loc_t *oldloc, loc_t *newloc, dict_t *xdata)
+ga_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
+ dict_t *xdata)
{
- int op_errno = ENOMEM;
- int ret = 0;
- loc_t ga_oldloc = {0, };
- loc_t ga_newloc = {0, };
-
- GFID_ACCESS_ENTRY_OP_CHECK (oldloc, op_errno, err);
- GFID_ACCESS_ENTRY_OP_CHECK (newloc, op_errno, err);
-
- ret = ga_valid_inode_loc_copy (&ga_oldloc, oldloc, this);
- if (ret < 0)
- goto err;
-
- ret = ga_valid_inode_loc_copy (&ga_newloc, newloc, this);
- if (ret < 0) {
- loc_wipe (&ga_oldloc);
- goto err;
- }
-
- STACK_WIND (frame, default_link_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->link,
- &ga_oldloc, &ga_newloc, xdata);
-
- loc_wipe (&ga_newloc);
- loc_wipe (&ga_oldloc);
- return 0;
+ int op_errno = ENOMEM;
+ int ret = 0;
+ loc_t ga_oldloc = {
+ 0,
+ };
+ loc_t ga_newloc = {
+ 0,
+ };
+
+ GFID_ACCESS_ENTRY_OP_CHECK(oldloc, op_errno, err);
+ GFID_ACCESS_ENTRY_OP_CHECK(newloc, op_errno, err);
+
+ ret = ga_valid_inode_loc_copy(&ga_oldloc, oldloc, this);
+ if (ret < 0)
+ goto err;
+
+ ret = ga_valid_inode_loc_copy(&ga_newloc, newloc, this);
+ if (ret < 0) {
+ loc_wipe(&ga_oldloc);
+ goto err;
+ }
+
+ STACK_WIND(frame, default_link_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->link, &ga_oldloc, &ga_newloc, xdata);
+
+ loc_wipe(&ga_newloc);
+ loc_wipe(&ga_oldloc);
+ return 0;
err:
- STACK_UNWIND_STRICT (link, frame, -1, op_errno, NULL,
- NULL, NULL, NULL, xdata);
+ STACK_UNWIND_STRICT(link, frame, -1, op_errno, NULL, NULL, NULL, NULL,
+ xdata);
- return 0;
+ return 0;
}
int32_t
-ga_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc,
- fd_t *fd, dict_t *xdata)
+ga_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
+ dict_t *xdata)
{
- int op_errno = ENOMEM;
+ int op_errno = ENOMEM;
- GFID_ACCESS_INODE_OP_CHECK (loc, op_errno, err);
+ GFID_ACCESS_INODE_OP_CHECK(loc, op_errno, err);
- /* also check if the loc->inode itself is virtual
- inode, if yes, return with failure, mainly because we
- can't handle all the readdirp and other things on it. */
- if (inode_ctx_get (loc->inode, this, NULL) == 0) {
- op_errno = ENOTSUP;
- goto err;
- }
+ /* also check if the loc->inode itself is virtual
+ inode, if yes, return with failure, mainly because we
+ can't handle all the readdirp and other things on it. */
+ if (inode_ctx_get(loc->inode, this, NULL) == 0) {
+ op_errno = ENOTSUP;
+ goto err;
+ }
- STACK_WIND (frame, default_opendir_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->opendir,
- loc, fd, xdata);
- return 0;
+ STACK_WIND(frame, default_opendir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->opendir, loc, fd, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (opendir, frame, -1, op_errno, NULL, xdata);
+ STACK_UNWIND_STRICT(opendir, frame, -1, op_errno, NULL, xdata);
- return 0;
+ return 0;
}
int32_t
-ga_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- const char *name, dict_t *xdata)
+ga_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name,
+ dict_t *xdata)
{
- int op_errno = ENOMEM;
- int ret = -1;
- loc_t ga_loc = {0, };
+ int op_errno = ENOMEM;
+ int ret = -1;
+ loc_t ga_loc = {
+ 0,
+ };
- GFID_ACCESS_INODE_OP_CHECK (loc, op_errno, err);
- ret = ga_valid_inode_loc_copy (&ga_loc, loc, this);
- if (ret < 0)
- goto err;
+ GFID_ACCESS_INODE_OP_CHECK(loc, op_errno, err);
+ ret = ga_valid_inode_loc_copy(&ga_loc, loc, this);
+ if (ret < 0)
+ goto err;
- STACK_WIND (frame, default_getxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->getxattr, &ga_loc, name, xdata);
+ STACK_WIND(frame, default_getxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->getxattr, &ga_loc, name, xdata);
- loc_wipe (&ga_loc);
+ loc_wipe(&ga_loc);
- return 0;
+ return 0;
err:
- STACK_UNWIND_STRICT (getxattr, frame, -1, op_errno, NULL, xdata);
+ STACK_UNWIND_STRICT(getxattr, frame, -1, op_errno, NULL, xdata);
- return 0;
+ return 0;
}
int32_t
-ga_stat (call_frame_t *frame, xlator_t *this, loc_t *loc,
- dict_t *xdata)
+ga_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- int op_errno = ENOMEM;
- int ret = -1;
- loc_t ga_loc = {0, };
- ga_private_t *priv = NULL;
-
- priv = this->private;
- /* If stat is on ".gfid" itself, do not wind further,
- * return fake stat and return success.
- */
- if (__is_gfid_access_dir(loc->gfid))
- goto out;
-
- ret = ga_valid_inode_loc_copy (&ga_loc, loc, this);
- if (ret < 0)
- goto err;
-
- STACK_WIND (frame, default_stat_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->stat, &ga_loc, xdata);
-
- loc_wipe (&ga_loc);
- return 0;
+ int op_errno = ENOMEM;
+ int ret = -1;
+ loc_t ga_loc = {
+ 0,
+ };
+ ga_private_t *priv = NULL;
+
+ priv = this->private;
+ /* If stat is on ".gfid" itself, do not wind further,
+ * return fake stat and return success.
+ */
+ if (__is_gfid_access_dir(loc->gfid))
+ goto out;
+
+ ret = ga_valid_inode_loc_copy(&ga_loc, loc, this);
+ if (ret < 0)
+ goto err;
+
+ STACK_WIND(frame, default_stat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->stat, &ga_loc, xdata);
+
+ loc_wipe(&ga_loc);
+ return 0;
err:
- STACK_UNWIND_STRICT (stat, frame, -1, op_errno, NULL, xdata);
+ STACK_UNWIND_STRICT(stat, frame, -1, op_errno, NULL, xdata);
- return 0;
+ return 0;
out:
- STACK_UNWIND_STRICT (stat, frame, 0, 0, &priv->gfiddir_stbuf, xdata);
- return 0;
+ STACK_UNWIND_STRICT(stat, frame, 0, 0, &priv->gfiddir_stbuf, xdata);
+ return 0;
}
int32_t
-ga_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- struct iatt *stbuf, int32_t valid,
- dict_t *xdata)
+ga_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc, struct iatt *stbuf,
+ int32_t valid, dict_t *xdata)
{
- int op_errno = ENOMEM;
- int ret = -1;
- loc_t ga_loc = {0, };
-
- GFID_ACCESS_INODE_OP_CHECK (loc, op_errno, err);
- ret = ga_valid_inode_loc_copy (&ga_loc, loc, this);
- if (ret < 0)
- goto err;
-
- STACK_WIND (frame, default_setattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->setattr, &ga_loc, stbuf, valid,
- xdata);
-
- loc_wipe (&ga_loc);
- return 0;
+ int op_errno = ENOMEM;
+ int ret = -1;
+ loc_t ga_loc = {
+ 0,
+ };
+
+ GFID_ACCESS_INODE_OP_CHECK(loc, op_errno, err);
+ ret = ga_valid_inode_loc_copy(&ga_loc, loc, this);
+ if (ret < 0)
+ goto err;
+
+ STACK_WIND(frame, default_setattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setattr, &ga_loc, stbuf, valid, xdata);
+
+ loc_wipe(&ga_loc);
+ return 0;
err:
- STACK_UNWIND_STRICT (setattr, frame, -1, op_errno, NULL, NULL, xdata);
+ STACK_UNWIND_STRICT(setattr, frame, -1, op_errno, NULL, NULL, xdata);
- return 0;
+ return 0;
}
int32_t
-ga_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- const char *name, dict_t *xdata)
+ga_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
{
- int op_errno = ENOMEM;
- int ret = -1;
- loc_t ga_loc = {0, };
+ int op_errno = ENOMEM;
+ int ret = -1;
+ loc_t ga_loc = {
+ 0,
+ };
- GFID_ACCESS_INODE_OP_CHECK (loc, op_errno, err);
- ret = ga_valid_inode_loc_copy (&ga_loc, loc, this);
- if (ret < 0)
- goto err;
+ GFID_ACCESS_INODE_OP_CHECK(loc, op_errno, err);
+ ret = ga_valid_inode_loc_copy(&ga_loc, loc, this);
+ if (ret < 0)
+ goto err;
- STACK_WIND (frame, default_removexattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->removexattr, &ga_loc, name,
- xdata);
+ STACK_WIND(frame, default_removexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr, &ga_loc, name, xdata);
- loc_wipe (&ga_loc);
- return 0;
+ loc_wipe(&ga_loc);
+ return 0;
err:
- STACK_UNWIND_STRICT (removexattr, frame, -1, op_errno, xdata);
+ STACK_UNWIND_STRICT(removexattr, frame, -1, op_errno, xdata);
- return 0;
+ return 0;
}
-
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int ret = -1;
-
- if (!this)
- return ret;
+ int ret = -1;
- ret = xlator_mem_acct_init (this, gf_gfid_access_mt_end + 1);
+ if (!this)
+ return ret;
- if (ret != 0) {
- gf_log (this->name, GF_LOG_WARNING, "Memory accounting"
- " init failed");
- return ret;
- }
+ ret = xlator_mem_acct_init(this, gf_gfid_access_mt_end + 1);
+ if (ret != 0) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "Memory accounting"
+ " init failed");
return ret;
+ }
+
+ return ret;
}
int32_t
-init (xlator_t *this)
+init(xlator_t *this)
{
- ga_private_t *priv = NULL;
- int ret = -1;
-
- if (!this->children || this->children->next) {
- gf_log (this->name, GF_LOG_ERROR,
- "not configured with exactly one child. exiting");
- goto out;
- }
-
- /* This can be the top of graph in certain cases */
- if (!this->parents) {
- gf_log (this->name, GF_LOG_DEBUG,
- "dangling volume. check volfile ");
- }
-
- /* TODO: define a mem-type structure */
- priv = GF_CALLOC (1, sizeof (*priv), gf_gfid_access_mt_priv_t);
- if (!priv)
- goto out;
-
- priv->newfile_args_pool = mem_pool_new (ga_newfile_args_t, 512);
- if (!priv->newfile_args_pool)
- goto out;
-
- priv->heal_args_pool = mem_pool_new (ga_heal_args_t, 512);
- if (!priv->heal_args_pool)
- goto out;
-
- this->local_pool = mem_pool_new (ga_local_t, 16);
- if (!this->local_pool) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to create local_t's memory pool");
- goto out;
- }
-
- this->private = priv;
-
- ret = 0;
+ ga_private_t *priv = NULL;
+ int ret = -1;
+
+ if (!this->children || this->children->next) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "not configured with exactly one child. exiting");
+ goto out;
+ }
+
+ /* This can be the top of graph in certain cases */
+ if (!this->parents) {
+ gf_log(this->name, GF_LOG_DEBUG, "dangling volume. check volfile ");
+ }
+
+ /* TODO: define a mem-type structure */
+ priv = GF_CALLOC(1, sizeof(*priv), gf_gfid_access_mt_priv_t);
+ if (!priv)
+ goto out;
+
+ priv->newfile_args_pool = mem_pool_new(ga_newfile_args_t, 512);
+ if (!priv->newfile_args_pool)
+ goto out;
+
+ priv->heal_args_pool = mem_pool_new(ga_heal_args_t, 512);
+ if (!priv->heal_args_pool)
+ goto out;
+
+ this->local_pool = mem_pool_new(ga_local_t, 16);
+ if (!this->local_pool) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "failed to create local_t's memory pool");
+ goto out;
+ }
+
+ this->private = priv;
+
+ ret = 0;
out:
- if (ret && priv) {
- if (priv->newfile_args_pool)
- mem_pool_destroy (priv->newfile_args_pool);
- GF_FREE (priv);
- }
+ if (ret && priv) {
+ if (priv->newfile_args_pool)
+ mem_pool_destroy(priv->newfile_args_pool);
+ GF_FREE(priv);
+ }
- return ret;
+ return ret;
}
void
-fini (xlator_t *this)
+fini(xlator_t *this)
{
- ga_private_t *priv = NULL;
- priv = this->private;
- this->private = NULL;
-
- if (priv) {
- if (priv->newfile_args_pool)
- mem_pool_destroy (priv->newfile_args_pool);
- if (priv->heal_args_pool)
- mem_pool_destroy (priv->heal_args_pool);
- GF_FREE (priv);
- }
-
- return;
+ ga_private_t *priv = NULL;
+ priv = this->private;
+ this->private = NULL;
+
+ if (priv) {
+ if (priv->newfile_args_pool)
+ mem_pool_destroy(priv->newfile_args_pool);
+ if (priv->heal_args_pool)
+ mem_pool_destroy(priv->heal_args_pool);
+ GF_FREE(priv);
+ }
+
+ return;
}
int32_t
-ga_dump_inodectx (xlator_t *this, inode_t *inode)
+ga_dump_inodectx(xlator_t *this, inode_t *inode)
{
- int ret = -1;
- uint64_t value = 0;
- inode_t *tmp_inode = NULL;
- char key_prefix[GF_DUMP_MAX_BUF_LEN] = {0, };
-
- ret = inode_ctx_get (inode, this, &value);
- if (ret == 0) {
- tmp_inode = (void*) value;
- gf_proc_dump_build_key (key_prefix, this->name, "inode");
- gf_proc_dump_add_section (key_prefix);
- gf_proc_dump_write ("real-gfid", "%s",
- uuid_utoa (tmp_inode->gfid));
- }
+ int ret = -1;
+ uint64_t value = 0;
+ inode_t *tmp_inode = NULL;
+ char key_prefix[GF_DUMP_MAX_BUF_LEN] = {
+ 0,
+ };
+
+ ret = inode_ctx_get(inode, this, &value);
+ if (ret == 0) {
+ tmp_inode = (void *)value;
+ gf_proc_dump_build_key(key_prefix, this->name, "inode");
+ gf_proc_dump_add_section(key_prefix);
+ gf_proc_dump_write("real-gfid", "%s", uuid_utoa(tmp_inode->gfid));
+ }
- return 0;
+ return 0;
}
struct xlator_fops fops = {
- .lookup = ga_lookup,
-
- /* entry fops */
- .mkdir = ga_mkdir,
- .mknod = ga_mknod,
- .create = ga_create,
- .symlink = ga_symlink,
- .link = ga_link,
- .unlink = ga_unlink,
- .rmdir = ga_rmdir,
- .rename = ga_rename,
-
- /* handle any other directory operations here */
- .opendir = ga_opendir,
- .stat = ga_stat,
- .setattr = ga_setattr,
- .getxattr = ga_getxattr,
- .removexattr = ga_removexattr,
-
- /* special fop to handle more entry creations */
- .setxattr = ga_setxattr,
+ .lookup = ga_lookup,
+
+ /* entry fops */
+ .mkdir = ga_mkdir,
+ .mknod = ga_mknod,
+ .create = ga_create,
+ .symlink = ga_symlink,
+ .link = ga_link,
+ .unlink = ga_unlink,
+ .rmdir = ga_rmdir,
+ .rename = ga_rename,
+
+ /* handle any other directory operations here */
+ .opendir = ga_opendir,
+ .stat = ga_stat,
+ .setattr = ga_setattr,
+ .getxattr = ga_getxattr,
+ .removexattr = ga_removexattr,
+
+ /* special fop to handle more entry creations */
+ .setxattr = ga_setxattr,
};
struct xlator_cbks cbks = {
- .forget = ga_forget,
+ .forget = ga_forget,
};
struct xlator_dumpops dumpops = {
- .inodectx = ga_dump_inodectx,
+ .inodectx = ga_dump_inodectx,
};
struct volume_options options[] = {
- /* This translator doesn't take any options, or provide any options */
- { .key = {NULL} },
+ /* This translator doesn't take any options, or provide any options */
+ {.key = {NULL}},
};
diff --git a/xlators/features/glupy/src/glupy.c b/xlators/features/glupy/src/glupy.c
index bacccfef686..d1a111eab4a 100644
--- a/xlators/features/glupy/src/glupy.c
+++ b/xlators/features/glupy/src/glupy.c
@@ -25,2521 +25,2422 @@
pthread_key_t gil_init_key;
PyGILState_STATE
-glupy_enter (void)
+glupy_enter(void)
{
- if (!pthread_getspecific(gil_init_key)) {
- PyEval_ReleaseLock();
- (void)pthread_setspecific(gil_init_key,(void *)1);
- }
+ if (!pthread_getspecific(gil_init_key)) {
+ PyEval_ReleaseLock();
+ (void)pthread_setspecific(gil_init_key, (void *)1);
+ }
- return PyGILState_Ensure();
+ return PyGILState_Ensure();
}
void
-glupy_leave (PyGILState_STATE gstate)
+glupy_leave(PyGILState_STATE gstate)
{
- PyGILState_Release(gstate);
+ PyGILState_Release(gstate);
}
/* FOP: LOOKUP */
int32_t
-glupy_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, dict_t *xdata, struct iatt *postparent)
+glupy_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, dict_t *xdata, struct iatt *postparent)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_LOOKUP]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_LOOKUP]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_lookup_cbk_t)(priv->cbks[GLUPY_LOOKUP]))(
- frame, cookie, this, op_ret, op_errno,
- inode, buf, xdata, postparent);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_lookup_cbk_t)(priv->cbks[GLUPY_LOOKUP]))(
+ frame, cookie, this, op_ret, op_errno, inode, buf, xdata, postparent);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf,
- xdata, postparent);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, buf, xdata,
+ postparent);
+ return 0;
}
int32_t
-glupy_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc,
- dict_t *xdata)
+glupy_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_LOOKUP]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_LOOKUP]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_lookup_t)(priv->fops[GLUPY_LOOKUP]))(
- frame, this, loc, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_lookup_t)(priv->fops[GLUPY_LOOKUP]))(frame, this, loc, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_lookup_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->lookup, loc, xdata);
- return 0;
+ STACK_WIND(frame, glupy_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, loc, xdata);
+ return 0;
}
void
-wind_lookup (call_frame_t *frame, xlator_t *xl, loc_t *loc, dict_t *xdata)
+wind_lookup(call_frame_t *frame, xlator_t *xl, loc_t *loc, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND(frame,glupy_lookup_cbk,xl,xl->fops->lookup,loc,xdata);
+ STACK_WIND(frame, glupy_lookup_cbk, xl, xl->fops->lookup, loc, xdata);
}
void
-unwind_lookup (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, dict_t *xdata, struct iatt *postparent)
+unwind_lookup(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, inode_t *inode, struct iatt *buf, dict_t *xdata,
+ struct iatt *postparent)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT(lookup,frame,op_ret,op_errno,
- inode,buf,xdata,postparent);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, buf, xdata,
+ postparent);
}
void
-set_lookup_fop (long py_this, fop_lookup_t fop)
+set_lookup_fop(long py_this, fop_lookup_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_LOOKUP] = (long)fop;
+ priv->fops[GLUPY_LOOKUP] = (long)fop;
}
void
-set_lookup_cbk (long py_this, fop_lookup_cbk_t cbk)
+set_lookup_cbk(long py_this, fop_lookup_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_LOOKUP] = (long)cbk;
+ priv->cbks[GLUPY_LOOKUP] = (long)cbk;
}
/* FOP: CREATE */
int32_t
-glupy_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+glupy_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode,
+ struct iatt *buf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_CREATE]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_CREATE]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_create_cbk_t)(priv->cbks[GLUPY_CREATE]))(
- frame, cookie, this, op_ret, op_errno,
- fd, inode, buf, preparent, postparent, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_create_cbk_t)(priv->cbks[GLUPY_CREATE]))(
+ frame, cookie, this, op_ret, op_errno, fd, inode, buf, preparent,
+ postparent, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf,
- preparent, postparent, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(create, frame, op_ret, op_errno, fd, inode, buf,
+ preparent, postparent, xdata);
+ return 0;
}
int32_t
-glupy_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
- mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
+glupy_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_CREATE]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_CREATE]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_create_t)(priv->fops[GLUPY_CREATE]))(
- frame, this, loc, flags, mode, umask, fd, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_create_t)(priv->fops[GLUPY_CREATE]))(frame, this, loc, flags,
+ mode, umask, fd, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_create_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->create, loc, flags, mode, umask,
- fd, xdata);
- return 0;
+ STACK_WIND(frame, glupy_create_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->create, loc, flags, mode, umask, fd,
+ xdata);
+ return 0;
}
void
-wind_create (call_frame_t *frame, xlator_t *xl, loc_t *loc, int32_t flags,
- mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
+wind_create(call_frame_t *frame, xlator_t *xl, loc_t *loc, int32_t flags,
+ mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_create_cbk,xl, xl->fops->create,
- loc, flags, mode, umask, fd, xdata);
+ STACK_WIND(frame, glupy_create_cbk, xl, xl->fops->create, loc, flags, mode,
+ umask, fd, xdata);
}
void
-unwind_create (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+unwind_create(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, fd_t *fd, inode_t *inode, struct iatt *buf,
+ struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf,
- preparent, postparent, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(create, frame, op_ret, op_errno, fd, inode, buf,
+ preparent, postparent, xdata);
}
void
-set_create_fop (long py_this, fop_create_t fop)
+set_create_fop(long py_this, fop_create_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_CREATE] = (long)fop;
+ priv->fops[GLUPY_CREATE] = (long)fop;
}
void
-set_create_cbk (long py_this, fop_create_cbk_t cbk)
+set_create_cbk(long py_this, fop_create_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_CREATE] = (long)cbk;
+ priv->cbks[GLUPY_CREATE] = (long)cbk;
}
/* FOP: OPEN */
int32_t
-glupy_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)
+glupy_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_OPEN]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_OPEN]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_open_cbk_t)(priv->cbks[GLUPY_OPEN]))(
- frame, cookie, this, op_ret, op_errno,
- fd, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_open_cbk_t)(priv->cbks[GLUPY_OPEN]))(
+ frame, cookie, this, op_ret, op_errno, fd, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(open, frame, op_ret, op_errno, fd, xdata);
+ return 0;
}
int32_t
-glupy_open (call_frame_t *frame, xlator_t *this, loc_t *loc,
- int32_t flags, fd_t *fd, dict_t *xdata)
+glupy_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ fd_t *fd, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_OPEN]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_OPEN]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_open_t)(priv->fops[GLUPY_OPEN]))(
- frame, this, loc, flags, fd, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_open_t)(priv->fops[GLUPY_OPEN]))(frame, this, loc, flags, fd,
+ xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_open_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata);
- return 0;
+ STACK_WIND(frame, glupy_open_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata);
+ return 0;
}
void
-wind_open (call_frame_t *frame, xlator_t *xl, loc_t *loc, int32_t flags,
- fd_t *fd, dict_t *xdata)
+wind_open(call_frame_t *frame, xlator_t *xl, loc_t *loc, int32_t flags,
+ fd_t *fd, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_open_cbk, xl, xl->fops->open, loc, flags,
- fd, xdata);
+ STACK_WIND(frame, glupy_open_cbk, xl, xl->fops->open, loc, flags, fd,
+ xdata);
}
void
-unwind_open (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)
+unwind_open(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, fd_t *fd, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(open, frame, op_ret, op_errno, fd, xdata);
}
void
-set_open_fop (long py_this, fop_open_t fop)
+set_open_fop(long py_this, fop_open_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_OPEN] = (long)fop;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ priv->fops[GLUPY_OPEN] = (long)fop;
}
void
-set_open_cbk (long py_this, fop_open_cbk_t cbk)
+set_open_cbk(long py_this, fop_open_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_OPEN] = (long)cbk;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ priv->cbks[GLUPY_OPEN] = (long)cbk;
}
/* FOP: READV */
int32_t
-glupy_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iovec *vector,
- int32_t count, struct iatt *stbuf, struct iobref *iobref,
- dict_t *xdata)
+glupy_readv_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iovec *vector,
+ int32_t count, struct iatt *stbuf, struct iobref *iobref,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_READV]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_READV]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_readv_cbk_t)(priv->cbks[GLUPY_READV]))(
- frame, cookie, this, op_ret, op_errno,
- vector, count, stbuf, iobref, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_readv_cbk_t)(priv->cbks[GLUPY_READV]))(
+ frame, cookie, this, op_ret, op_errno, vector, count, stbuf, iobref,
+ xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector,
- count, stbuf, iobref, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, vector, count, stbuf,
+ iobref, xdata);
+ return 0;
}
int32_t
-glupy_readv (call_frame_t *frame, xlator_t *this, fd_t *fd,
- size_t size, off_t offset, uint32_t flags, dict_t *xdata)
+glupy_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset, uint32_t flags, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_READV]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_READV]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_readv_t)(priv->fops[GLUPY_READV]))(
- frame, this, fd, size, offset, flags, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_readv_t)(priv->fops[GLUPY_READV]))(frame, this, fd, size,
+ offset, flags, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_readv_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->readv, fd, size, offset,
- flags, xdata);
- return 0;
+ STACK_WIND(frame, glupy_readv_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readv, fd, size, offset, flags, xdata);
+ return 0;
}
void
-wind_readv (call_frame_t *frame, xlator_t *xl, fd_t *fd, size_t size,
- off_t offset, uint32_t flags, dict_t *xdata)
+wind_readv(call_frame_t *frame, xlator_t *xl, fd_t *fd, size_t size,
+ off_t offset, uint32_t flags, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_readv_cbk, xl, xl->fops->readv, fd, size,
- offset, flags, xdata);
+ STACK_WIND(frame, glupy_readv_cbk, xl, xl->fops->readv, fd, size, offset,
+ flags, xdata);
}
void
-unwind_readv (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iovec *vector,
- int32_t count, struct iatt *stbuf, struct iobref *iobref,
- dict_t *xdata)
+unwind_readv(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct iovec *vector, int32_t count,
+ struct iatt *stbuf, struct iobref *iobref, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector,
- count, stbuf, iobref, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, vector, count, stbuf,
+ iobref, xdata);
}
void
-set_readv_fop (long py_this, fop_readv_t fop)
+set_readv_fop(long py_this, fop_readv_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_READV] = (long)fop;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ priv->fops[GLUPY_READV] = (long)fop;
}
void
-set_readv_cbk (long py_this, fop_readv_cbk_t cbk)
+set_readv_cbk(long py_this, fop_readv_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_READV] = (long)cbk;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ priv->cbks[GLUPY_READV] = (long)cbk;
}
/* FOP: WRITEV */
int32_t
-glupy_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+glupy_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_WRITEV]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_WRITEV]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_writev_cbk_t)(priv->cbks[GLUPY_WRITEV]))(
- frame, cookie, this, op_ret, op_errno,
- prebuf, postbuf, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_writev_cbk_t)(priv->cbks[GLUPY_WRITEV]))(
+ frame, cookie, this, op_ret, op_errno, prebuf, postbuf, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf,
- postbuf, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ return 0;
}
int32_t
-glupy_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *vector, int32_t count, off_t offset,
- uint32_t flags, struct iobref *iobref, dict_t *xdata)
+glupy_writev(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *vector, int32_t count, off_t offset, uint32_t flags,
+ struct iobref *iobref, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_WRITEV]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_WRITEV]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_writev_t)(priv->fops[GLUPY_WRITEV]))(
- frame, this, fd, vector, count, offset, flags,
- iobref, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_writev_t)(priv->fops[GLUPY_WRITEV]))(
+ frame, this, fd, vector, count, offset, flags, iobref, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_writev_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->writev, fd, vector, count,
- offset, flags, iobref, xdata);
- return 0;
+ STACK_WIND(frame, glupy_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, vector, count, offset,
+ flags, iobref, xdata);
+ return 0;
}
void
-wind_writev (call_frame_t *frame, xlator_t *xl, fd_t *fd, struct iovec *vector,
- int32_t count, off_t offset, uint32_t flags, struct iobref *iobref,
- dict_t *xdata)
+wind_writev(call_frame_t *frame, xlator_t *xl, fd_t *fd, struct iovec *vector,
+ int32_t count, off_t offset, uint32_t flags, struct iobref *iobref,
+ dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_writev_cbk, xl, xl->fops->writev, fd, vector,
- count, offset, flags, iobref, xdata);
+ STACK_WIND(frame, glupy_writev_cbk, xl, xl->fops->writev, fd, vector, count,
+ offset, flags, iobref, xdata);
}
void
-unwind_writev (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+unwind_writev(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct iatt *prebuf, struct iatt *postbuf,
+ dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf,
- postbuf, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
}
void
-set_writev_fop (long py_this, fop_writev_t fop)
+set_writev_fop(long py_this, fop_writev_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_WRITEV] = (long)fop;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ priv->fops[GLUPY_WRITEV] = (long)fop;
}
void
-set_writev_cbk (long py_this, fop_writev_cbk_t cbk)
+set_writev_cbk(long py_this, fop_writev_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_WRITEV] = (long)cbk;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ priv->cbks[GLUPY_WRITEV] = (long)cbk;
}
-
/* FOP: OPENDIR */
int32_t
-glupy_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, fd_t *fd,
- dict_t *xdata)
+glupy_opendir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_OPENDIR]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_OPENDIR]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_opendir_cbk_t)(priv->cbks[GLUPY_OPENDIR]))(
- frame, cookie, this, op_ret, op_errno,
- fd, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_opendir_cbk_t)(priv->cbks[GLUPY_OPENDIR]))(
+ frame, cookie, this, op_ret, op_errno, fd, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (opendir, frame, op_ret, op_errno, fd, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(opendir, frame, op_ret, op_errno, fd, xdata);
+ return 0;
}
int32_t
-glupy_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc,
- fd_t *fd, dict_t *xdata)
+glupy_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_OPENDIR]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_OPENDIR]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_opendir_t)(priv->fops[GLUPY_OPENDIR]))(
- frame, this, loc, fd, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_opendir_t)(priv->fops[GLUPY_OPENDIR]))(frame, this, loc, fd,
+ xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_opendir_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->opendir, loc, fd, xdata);
- return 0;
+ STACK_WIND(frame, glupy_opendir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->opendir, loc, fd, xdata);
+ return 0;
}
void
-wind_opendir (call_frame_t *frame, xlator_t *xl, loc_t *loc, fd_t *fd, dict_t *xdata)
+wind_opendir(call_frame_t *frame, xlator_t *xl, loc_t *loc, fd_t *fd,
+ dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND(frame,glupy_opendir_cbk,xl,xl->fops->opendir,loc,fd,xdata);
+ STACK_WIND(frame, glupy_opendir_cbk, xl, xl->fops->opendir, loc, fd, xdata);
}
void
-unwind_opendir (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)
+unwind_opendir(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, fd_t *fd, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT(opendir,frame,op_ret,op_errno,
- fd,xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(opendir, frame, op_ret, op_errno, fd, xdata);
}
void
-set_opendir_fop (long py_this, fop_opendir_t fop)
+set_opendir_fop(long py_this, fop_opendir_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_OPENDIR] = (long)fop;
+ priv->fops[GLUPY_OPENDIR] = (long)fop;
}
void
-set_opendir_cbk (long py_this, fop_opendir_cbk_t cbk)
+set_opendir_cbk(long py_this, fop_opendir_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_OPENDIR] = (long)cbk;
+ priv->cbks[GLUPY_OPENDIR] = (long)cbk;
}
/* FOP: READDIR */
int32_t
-glupy_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
- dict_t *xdata)
+glupy_readdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_READDIR]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_READDIR]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_readdir_cbk_t)(priv->cbks[GLUPY_READDIR]))(
- frame, cookie, this, op_ret, op_errno,
- entries, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_readdir_cbk_t)(priv->cbks[GLUPY_READDIR]))(
+ frame, cookie, this, op_ret, op_errno, entries, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, entries,
- xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(readdir, frame, op_ret, op_errno, entries, xdata);
+ return 0;
}
int32_t
-glupy_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd,
- size_t size, off_t offset, dict_t *xdata)
+glupy_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_READDIR]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_READDIR]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_readdir_t)(priv->fops[GLUPY_READDIR]))(
- frame, this, fd, size, offset, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_readdir_t)(priv->fops[GLUPY_READDIR]))(frame, this, fd, size,
+ offset, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_readdir_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->readdir,fd, size, offset, xdata);
- return 0;
+ STACK_WIND(frame, glupy_readdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readdir, fd, size, offset, xdata);
+ return 0;
}
void
wind_readdir(call_frame_t *frame, xlator_t *xl, fd_t *fd, size_t size,
off_t offset, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND(frame,glupy_readdir_cbk,xl,xl->fops->readdir,fd,size,offset,xdata);
+ STACK_WIND(frame, glupy_readdir_cbk, xl, xl->fops->readdir, fd, size,
+ offset, xdata);
}
void
-unwind_readdir (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
- dict_t *xdata)
+unwind_readdir(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, gf_dirent_t *entries, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT(readdir,frame,op_ret,op_errno,
- entries, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(readdir, frame, op_ret, op_errno, entries, xdata);
}
void
-set_readdir_fop (long py_this, fop_readdir_t fop)
+set_readdir_fop(long py_this, fop_readdir_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_READDIR] = (long)fop;
+ priv->fops[GLUPY_READDIR] = (long)fop;
}
void
-set_readdir_cbk (long py_this, fop_readdir_cbk_t cbk)
+set_readdir_cbk(long py_this, fop_readdir_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_READDIR] = (long)cbk;
+ priv->cbks[GLUPY_READDIR] = (long)cbk;
}
-
/* FOP: READDIRP */
int32_t
-glupy_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
- dict_t *xdata)
+glupy_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_READDIRP]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_READDIRP]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_readdirp_cbk_t)(priv->cbks[GLUPY_READDIRP]))(
- frame, cookie, this, op_ret, op_errno,
- entries, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_readdirp_cbk_t)(priv->cbks[GLUPY_READDIRP]))(
+ frame, cookie, this, op_ret, op_errno, entries, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno, entries,
- xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(readdirp, frame, op_ret, op_errno, entries, xdata);
+ return 0;
}
int32_t
-glupy_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd,
- size_t size, off_t offset, dict_t *xdata)
+glupy_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_READDIRP]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_READDIRP]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_readdirp_t)(priv->fops[GLUPY_READDIRP]))(
- frame, this, fd, size, offset, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_readdirp_t)(priv->fops[GLUPY_READDIRP]))(frame, this, fd, size,
+ offset, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_readdirp_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->readdirp,fd, size, offset, xdata);
- return 0;
+ STACK_WIND(frame, glupy_readdirp_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readdirp, fd, size, offset, xdata);
+ return 0;
}
void
-wind_readdirp (call_frame_t *frame, xlator_t *xl, fd_t *fd, size_t size,
- off_t offset, dict_t *xdata)
+wind_readdirp(call_frame_t *frame, xlator_t *xl, fd_t *fd, size_t size,
+ off_t offset, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND(frame,glupy_readdirp_cbk,xl,xl->fops->readdirp,fd,size,offset,xdata);
+ STACK_WIND(frame, glupy_readdirp_cbk, xl, xl->fops->readdirp, fd, size,
+ offset, xdata);
}
void
-unwind_readdirp (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
- dict_t *xdata)
+unwind_readdirp(call_frame_t *frame, long cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
+ dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT(readdirp,frame,op_ret,op_errno,
- entries, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(readdirp, frame, op_ret, op_errno, entries, xdata);
}
void
-set_readdirp_fop (long py_this, fop_readdirp_t fop)
+set_readdirp_fop(long py_this, fop_readdirp_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_READDIRP] = (long)fop;
+ priv->fops[GLUPY_READDIRP] = (long)fop;
}
void
-set_readdirp_cbk (long py_this, fop_readdirp_cbk_t cbk)
+set_readdirp_cbk(long py_this, fop_readdirp_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_READDIRP] = (long)cbk;
+ priv->cbks[GLUPY_READDIRP] = (long)cbk;
}
-
/* FOP:STAT */
int32_t
-glupy_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *buf, dict_t *xdata)
+glupy_stat_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_STAT]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_STAT]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_stat_cbk_t)(priv->cbks[GLUPY_STAT]))(
- frame, cookie, this, op_ret, op_errno,
- buf, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_stat_cbk_t)(priv->cbks[GLUPY_STAT]))(
+ frame, cookie, this, op_ret, op_errno, buf, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, buf, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(stat, frame, op_ret, op_errno, buf, xdata);
+ return 0;
}
int32_t
-glupy_stat (call_frame_t *frame, xlator_t *this, loc_t *loc,
- dict_t *xdata)
+glupy_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_STAT]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_STAT]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_stat_t)(priv->fops[GLUPY_STAT]))(
- frame, this, loc, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_stat_t)(priv->fops[GLUPY_STAT]))(frame, this, loc, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_stat_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->stat, loc, xdata);
- return 0;
+ STACK_WIND(frame, glupy_stat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->stat, loc, xdata);
+ return 0;
}
void
-wind_stat (call_frame_t *frame, xlator_t *xl, loc_t *loc, dict_t *xdata)
+wind_stat(call_frame_t *frame, xlator_t *xl, loc_t *loc, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND(frame,glupy_stat_cbk,xl,xl->fops->stat,loc,xdata);
+ STACK_WIND(frame, glupy_stat_cbk, xl, xl->fops->stat, loc, xdata);
}
void
-unwind_stat (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *buf,
- dict_t *xdata)
+unwind_stat(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct iatt *buf, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT(stat,frame,op_ret,op_errno,
- buf,xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(stat, frame, op_ret, op_errno, buf, xdata);
}
void
-set_stat_fop (long py_this, fop_stat_t fop)
+set_stat_fop(long py_this, fop_stat_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_STAT] = (long)fop;
+ priv->fops[GLUPY_STAT] = (long)fop;
}
void
-set_stat_cbk (long py_this, fop_stat_cbk_t cbk)
+set_stat_cbk(long py_this, fop_stat_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_STAT] = (long)cbk;
+ priv->cbks[GLUPY_STAT] = (long)cbk;
}
-
/* FOP: FSTAT */
int32_t
-glupy_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *buf, dict_t *xdata)
+glupy_fstat_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_FSTAT]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_FSTAT]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_fstat_cbk_t)(priv->cbks[GLUPY_FSTAT]))(
- frame, cookie, this, op_ret, op_errno,
- buf, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_fstat_cbk_t)(priv->cbks[GLUPY_FSTAT]))(
+ frame, cookie, this, op_ret, op_errno, buf, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(fstat, frame, op_ret, op_errno, buf, xdata);
+ return 0;
}
int32_t
-glupy_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd,
- dict_t *xdata)
+glupy_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_FSTAT]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_FSTAT]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_fstat_t)(priv->fops[GLUPY_FSTAT]))(
- frame, this, fd, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_fstat_t)(priv->fops[GLUPY_FSTAT]))(frame, this, fd, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_fstat_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fstat, fd, xdata);
- return 0;
+ STACK_WIND(frame, glupy_fstat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, fd, xdata);
+ return 0;
}
void
-wind_fstat (call_frame_t *frame, xlator_t *xl, fd_t *fd, dict_t *xdata)
+wind_fstat(call_frame_t *frame, xlator_t *xl, fd_t *fd, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND(frame,glupy_fstat_cbk,xl,xl->fops->fstat,fd,xdata);
+ STACK_WIND(frame, glupy_fstat_cbk, xl, xl->fops->fstat, fd, xdata);
}
void
-unwind_fstat (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *buf,
- dict_t *xdata)
+unwind_fstat(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct iatt *buf, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT(fstat,frame,op_ret,op_errno,
- buf,xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(fstat, frame, op_ret, op_errno, buf, xdata);
}
void
-set_fstat_fop (long py_this, fop_fstat_t fop)
+set_fstat_fop(long py_this, fop_fstat_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_FSTAT] = (long)fop;
+ priv->fops[GLUPY_FSTAT] = (long)fop;
}
void
-set_fstat_cbk (long py_this, fop_fstat_cbk_t cbk)
+set_fstat_cbk(long py_this, fop_fstat_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_FSTAT] = (long)cbk;
+ priv->cbks[GLUPY_FSTAT] = (long)cbk;
}
/* FOP:STATFS */
int32_t
-glupy_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct statvfs *buf, dict_t *xdata)
+glupy_statfs_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct statvfs *buf,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_STATFS]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_STATFS]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_statfs_cbk_t)(priv->cbks[GLUPY_STATFS]))(
- frame, cookie, this, op_ret, op_errno,
- buf, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_statfs_cbk_t)(priv->cbks[GLUPY_STATFS]))(
+ frame, cookie, this, op_ret, op_errno, buf, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (statfs, frame, op_ret, op_errno, buf, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(statfs, frame, op_ret, op_errno, buf, xdata);
+ return 0;
}
int32_t
-glupy_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc,
- dict_t *xdata)
+glupy_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_STATFS]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_STATFS]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_statfs_t)(priv->fops[GLUPY_STATFS]))(
- frame, this, loc, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_statfs_t)(priv->fops[GLUPY_STATFS]))(frame, this, loc, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_statfs_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->statfs, loc, xdata);
- return 0;
+ STACK_WIND(frame, glupy_statfs_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->statfs, loc, xdata);
+ return 0;
}
void
-wind_statfs (call_frame_t *frame, xlator_t *xl, loc_t *loc, dict_t *xdata)
+wind_statfs(call_frame_t *frame, xlator_t *xl, loc_t *loc, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND(frame,glupy_statfs_cbk,xl,xl->fops->statfs,loc,xdata);
+ STACK_WIND(frame, glupy_statfs_cbk, xl, xl->fops->statfs, loc, xdata);
}
void
-unwind_statfs (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct statvfs *buf,
- dict_t *xdata)
+unwind_statfs(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct statvfs *buf, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT(statfs,frame,op_ret,op_errno,
- buf,xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(statfs, frame, op_ret, op_errno, buf, xdata);
}
void
-set_statfs_fop (long py_this, fop_statfs_t fop)
+set_statfs_fop(long py_this, fop_statfs_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_STATFS] = (long)fop;
+ priv->fops[GLUPY_STATFS] = (long)fop;
}
void
-set_statfs_cbk (long py_this, fop_statfs_cbk_t cbk)
+set_statfs_cbk(long py_this, fop_statfs_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_STATFS] = (long)cbk;
+ priv->cbks[GLUPY_STATFS] = (long)cbk;
}
-
/* FOP: SETXATTR */
int32_t
-glupy_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+glupy_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_SETXATTR]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_SETXATTR]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_setxattr_cbk_t)(priv->cbks[GLUPY_SETXATTR]))(
- frame, cookie, this, op_ret, op_errno,
- xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_setxattr_cbk_t)(priv->cbks[GLUPY_SETXATTR]))(
+ frame, cookie, this, op_ret, op_errno, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(setxattr, frame, op_ret, op_errno, xdata);
+ return 0;
}
int32_t
-glupy_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- dict_t *dict, int32_t flags, dict_t *xdata)
+glupy_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
+ int32_t flags, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_SETXATTR]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_SETXATTR]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_setxattr_t)(priv->fops[GLUPY_SETXATTR]))(
- frame, this, loc, dict, flags, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_setxattr_t)(priv->fops[GLUPY_SETXATTR]))(frame, this, loc, dict,
+ flags, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_setxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setxattr, loc, dict,
- flags, xdata);
- return 0;
+ STACK_WIND(frame, glupy_setxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, loc, dict, flags, xdata);
+ return 0;
}
void
-wind_setxattr (call_frame_t *frame, xlator_t *xl, loc_t *loc,
- dict_t *dict, int32_t flags, dict_t *xdata)
+wind_setxattr(call_frame_t *frame, xlator_t *xl, loc_t *loc, dict_t *dict,
+ int32_t flags, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_setxattr_cbk, xl, xl->fops->setxattr,
- loc, dict, flags, xdata);
+ STACK_WIND(frame, glupy_setxattr_cbk, xl, xl->fops->setxattr, loc, dict,
+ flags, xdata);
}
-
void
-unwind_setxattr (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+unwind_setxattr(call_frame_t *frame, long cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata);
-
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(setxattr, frame, op_ret, op_errno, xdata);
}
void
-set_setxattr_fop (long py_this, fop_setxattr_t fop)
+set_setxattr_fop(long py_this, fop_setxattr_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_SETXATTR] = (long)fop;
+ priv->fops[GLUPY_SETXATTR] = (long)fop;
}
void
-set_setxattr_cbk (long py_this, fop_setxattr_cbk_t cbk)
+set_setxattr_cbk(long py_this, fop_setxattr_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_SETXATTR] = (long)cbk;
+ priv->cbks[GLUPY_SETXATTR] = (long)cbk;
}
/* FOP: GETXATTR */
int32_t
-glupy_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *dict,
- dict_t *xdata)
+glupy_getxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *dict,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_GETXATTR]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_GETXATTR]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_getxattr_cbk_t)(priv->cbks[GLUPY_GETXATTR]))(
- frame, cookie, this, op_ret, op_errno, dict,
- xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_getxattr_cbk_t)(priv->cbks[GLUPY_GETXATTR]))(
+ frame, cookie, this, op_ret, op_errno, dict, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict,
- xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(getxattr, frame, op_ret, op_errno, dict, xdata);
+ return 0;
}
int32_t
-glupy_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- const char *name, dict_t *xdata)
+glupy_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_GETXATTR]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_GETXATTR]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_getxattr_t)(priv->fops[GLUPY_GETXATTR]))(
- frame, this, loc, name, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_getxattr_t)(priv->fops[GLUPY_GETXATTR]))(frame, this, loc, name,
+ xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_getxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->getxattr, loc, name,
- xdata);
- return 0;
+ STACK_WIND(frame, glupy_getxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->getxattr, loc, name, xdata);
+ return 0;
}
void
-wind_getxattr (call_frame_t *frame, xlator_t *xl, loc_t *loc,
- const char *name, dict_t *xdata)
+wind_getxattr(call_frame_t *frame, xlator_t *xl, loc_t *loc, const char *name,
+ dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_getxattr_cbk, xl, xl->fops->getxattr,
- loc, name, xdata);
+ STACK_WIND(frame, glupy_getxattr_cbk, xl, xl->fops->getxattr, loc, name,
+ xdata);
}
-
void
-unwind_getxattr (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *dict,
- dict_t *xdata)
+unwind_getxattr(call_frame_t *frame, long cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict,
- xdata);
-
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(getxattr, frame, op_ret, op_errno, dict, xdata);
}
-
void
-set_getxattr_fop (long py_this, fop_getxattr_t fop)
+set_getxattr_fop(long py_this, fop_getxattr_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_GETXATTR] = (long)fop;
+ priv->fops[GLUPY_GETXATTR] = (long)fop;
}
-
void
-set_getxattr_cbk (long py_this, fop_getxattr_cbk_t cbk)
+set_getxattr_cbk(long py_this, fop_getxattr_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_GETXATTR] = (long)cbk;
+ priv->cbks[GLUPY_GETXATTR] = (long)cbk;
}
/* FOP: FSETXATTR */
int32_t
-glupy_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+glupy_fsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_FSETXATTR]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_FSETXATTR]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_fsetxattr_cbk_t)(priv->cbks[GLUPY_FSETXATTR]))(
- frame, cookie, this, op_ret, op_errno,
- xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_fsetxattr_cbk_t)(priv->cbks[GLUPY_FSETXATTR]))(
+ frame, cookie, this, op_ret, op_errno, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, xdata);
+ return 0;
}
int32_t
-glupy_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
- dict_t *dict, int32_t flags, dict_t *xdata)
+glupy_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
+ int32_t flags, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_FSETXATTR]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_FSETXATTR]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_fsetxattr_t)(priv->fops[GLUPY_FSETXATTR]))(
- frame, this, fd, dict, flags, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_fsetxattr_t)(priv->fops[GLUPY_FSETXATTR]))(frame, this, fd,
+ dict, flags, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_fsetxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fsetxattr, fd, dict,
- flags, xdata);
- return 0;
+ STACK_WIND(frame, glupy_fsetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata);
+ return 0;
}
void
-wind_fsetxattr (call_frame_t *frame, xlator_t *xl, fd_t *fd,
- dict_t *dict, int32_t flags, dict_t *xdata)
+wind_fsetxattr(call_frame_t *frame, xlator_t *xl, fd_t *fd, dict_t *dict,
+ int32_t flags, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_fsetxattr_cbk, xl, xl->fops->fsetxattr,
- fd, dict, flags, xdata);
+ STACK_WIND(frame, glupy_fsetxattr_cbk, xl, xl->fops->fsetxattr, fd, dict,
+ flags, xdata);
}
-
void
-unwind_fsetxattr (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+unwind_fsetxattr(call_frame_t *frame, long cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno, xdata);
-
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(fsetxattr, frame, op_ret, op_errno, xdata);
}
void
-set_fsetxattr_fop (long py_this, fop_fsetxattr_t fop)
+set_fsetxattr_fop(long py_this, fop_fsetxattr_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_FSETXATTR] = (long)fop;
+ priv->fops[GLUPY_FSETXATTR] = (long)fop;
}
void
-set_fsetxattr_cbk (long py_this, fop_fsetxattr_cbk_t cbk)
+set_fsetxattr_cbk(long py_this, fop_fsetxattr_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_FSETXATTR] = (long)cbk;
+ priv->cbks[GLUPY_FSETXATTR] = (long)cbk;
}
/* FOP: FGETXATTR */
int32_t
-glupy_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *dict,
- dict_t *xdata)
+glupy_fgetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *dict,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_FGETXATTR]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_FGETXATTR]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_fgetxattr_cbk_t)(priv->cbks[GLUPY_FGETXATTR]))(
- frame, cookie, this, op_ret, op_errno, dict,
- xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_fgetxattr_cbk_t)(priv->cbks[GLUPY_FGETXATTR]))(
+ frame, cookie, this, op_ret, op_errno, dict, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, dict,
- xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(fgetxattr, frame, op_ret, op_errno, dict, xdata);
+ return 0;
}
int32_t
-glupy_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
- const char *name, dict_t *xdata)
+glupy_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_FGETXATTR]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_FGETXATTR]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_fgetxattr_t)(priv->fops[GLUPY_FGETXATTR]))(
- frame, this, fd, name, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_fgetxattr_t)(priv->fops[GLUPY_FGETXATTR]))(frame, this, fd,
+ name, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_fgetxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fgetxattr, fd, name,
- xdata);
- return 0;
+ STACK_WIND(frame, glupy_fgetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fgetxattr, fd, name, xdata);
+ return 0;
}
void
-wind_fgetxattr (call_frame_t *frame, xlator_t *xl, fd_t *fd,
- const char *name, dict_t *xdata)
+wind_fgetxattr(call_frame_t *frame, xlator_t *xl, fd_t *fd, const char *name,
+ dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_fgetxattr_cbk, xl, xl->fops->fgetxattr,
- fd, name, xdata);
+ STACK_WIND(frame, glupy_fgetxattr_cbk, xl, xl->fops->fgetxattr, fd, name,
+ xdata);
}
-
void
-unwind_fgetxattr (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *dict,
- dict_t *xdata)
+unwind_fgetxattr(call_frame_t *frame, long cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, dict,
- xdata);
-
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(fgetxattr, frame, op_ret, op_errno, dict, xdata);
}
-
void
-set_fgetxattr_fop (long py_this, fop_fgetxattr_t fop)
+set_fgetxattr_fop(long py_this, fop_fgetxattr_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_FGETXATTR] = (long)fop;
+ priv->fops[GLUPY_FGETXATTR] = (long)fop;
}
-
void
-set_fgetxattr_cbk (long py_this, fop_fgetxattr_cbk_t cbk)
+set_fgetxattr_cbk(long py_this, fop_fgetxattr_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_FGETXATTR] = (long)cbk;
+ priv->cbks[GLUPY_FGETXATTR] = (long)cbk;
}
/* FOP:REMOVEXATTR */
int32_t
-glupy_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+glupy_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_REMOVEXATTR]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_REMOVEXATTR]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_removexattr_cbk_t)(priv->cbks[GLUPY_REMOVEXATTR]))(
- frame, cookie, this, op_ret, op_errno, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_removexattr_cbk_t)(priv->cbks[GLUPY_REMOVEXATTR]))(
+ frame, cookie, this, op_ret, op_errno, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(removexattr, frame, op_ret, op_errno, xdata);
+ return 0;
}
int32_t
-glupy_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- const char *name, dict_t *xdata)
+glupy_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_REMOVEXATTR]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_REMOVEXATTR]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_removexattr_t)(priv->fops[GLUPY_REMOVEXATTR]))(
- frame, this, loc, name, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_removexattr_t)(priv->fops[GLUPY_REMOVEXATTR]))(frame, this, loc,
+ name, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_removexattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->removexattr, loc, name,
- xdata);
- return 0;
+ STACK_WIND(frame, glupy_removexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr, loc, name, xdata);
+ return 0;
}
void
-wind_removexattr (call_frame_t *frame, xlator_t *xl, loc_t *loc,
- const char *name, dict_t *xdata)
+wind_removexattr(call_frame_t *frame, xlator_t *xl, loc_t *loc,
+ const char *name, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_removexattr_cbk, xl, xl->fops->removexattr,
- loc, name, xdata);
+ STACK_WIND(frame, glupy_removexattr_cbk, xl, xl->fops->removexattr, loc,
+ name, xdata);
}
-
void
-unwind_removexattr (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+unwind_removexattr(call_frame_t *frame, long cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (removexattr, frame, op_ret, op_errno, xdata);
-
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(removexattr, frame, op_ret, op_errno, xdata);
}
void
-set_removexattr_fop (long py_this, fop_removexattr_t fop)
+set_removexattr_fop(long py_this, fop_removexattr_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_REMOVEXATTR] = (long)fop;
+ priv->fops[GLUPY_REMOVEXATTR] = (long)fop;
}
void
-set_removexattr_cbk (long py_this, fop_removexattr_cbk_t cbk)
+set_removexattr_cbk(long py_this, fop_removexattr_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_REMOVEXATTR] = (long)cbk;
+ priv->cbks[GLUPY_REMOVEXATTR] = (long)cbk;
}
-
/* FOP:FREMOVEXATTR */
int32_t
-glupy_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+glupy_fremovexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_FREMOVEXATTR]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_FREMOVEXATTR]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_fremovexattr_cbk_t)(priv->cbks[GLUPY_FREMOVEXATTR]))(
- frame, cookie, this, op_ret, op_errno, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_fremovexattr_cbk_t)(priv->cbks[GLUPY_FREMOVEXATTR]))(
+ frame, cookie, this, op_ret, op_errno, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (fremovexattr, frame, op_ret, op_errno, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(fremovexattr, frame, op_ret, op_errno, xdata);
+ return 0;
}
int32_t
-glupy_fremovexattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
+glupy_fremovexattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
const char *name, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_FREMOVEXATTR]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_FREMOVEXATTR]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_fremovexattr_t)(priv->fops[GLUPY_FREMOVEXATTR]))(
- frame, this, fd, name, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_fremovexattr_t)(priv->fops[GLUPY_FREMOVEXATTR]))(
+ frame, this, fd, name, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_fremovexattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fremovexattr, fd, name,
- xdata);
- return 0;
+ STACK_WIND(frame, glupy_fremovexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fremovexattr, fd, name, xdata);
+ return 0;
}
void
-wind_fremovexattr (call_frame_t *frame, xlator_t *xl, fd_t *fd,
- const char *name, dict_t *xdata)
+wind_fremovexattr(call_frame_t *frame, xlator_t *xl, fd_t *fd, const char *name,
+ dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_fremovexattr_cbk, xl, xl->fops->fremovexattr,
- fd, name, xdata);
+ STACK_WIND(frame, glupy_fremovexattr_cbk, xl, xl->fops->fremovexattr, fd,
+ name, xdata);
}
-
void
-unwind_fremovexattr (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+unwind_fremovexattr(call_frame_t *frame, long cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (fremovexattr, frame, op_ret, op_errno, xdata);
-
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(fremovexattr, frame, op_ret, op_errno, xdata);
}
void
-set_fremovexattr_fop (long py_this, fop_fremovexattr_t fop)
+set_fremovexattr_fop(long py_this, fop_fremovexattr_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_FREMOVEXATTR] = (long)fop;
+ priv->fops[GLUPY_FREMOVEXATTR] = (long)fop;
}
void
-set_fremovexattr_cbk (long py_this, fop_fremovexattr_cbk_t cbk)
+set_fremovexattr_cbk(long py_this, fop_fremovexattr_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_FREMOVEXATTR] = (long)cbk;
+ priv->cbks[GLUPY_FREMOVEXATTR] = (long)cbk;
}
-
/* FOP: LINK*/
int32_t
-glupy_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+glupy_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_LINK]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_LINK]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_link_cbk_t)(priv->cbks[GLUPY_LINK]))(
- frame, cookie, this, op_ret, op_errno,
- inode, buf, preparent, postparent, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_link_cbk_t)(priv->cbks[GLUPY_LINK]))(
+ frame, cookie, this, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (link, frame, op_ret, op_errno, inode, buf,
- preparent, postparent, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(link, frame, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
+ return 0;
}
int32_t
glupy_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_LINK]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_LINK]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_link_t)(priv->fops[GLUPY_LINK]))(
- frame, this, oldloc, newloc, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_link_t)(priv->fops[GLUPY_LINK]))(frame, this, oldloc, newloc,
+ xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_link_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->link, oldloc, newloc,
- xdata);
- return 0;
+ STACK_WIND(frame, glupy_link_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata);
+ return 0;
}
void
-wind_link (call_frame_t *frame, xlator_t *xl, loc_t *oldloc, loc_t *newloc,
- dict_t *xdata)
+wind_link(call_frame_t *frame, xlator_t *xl, loc_t *oldloc, loc_t *newloc,
+ dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_link_cbk, xl, xl->fops->link,
- oldloc, newloc, xdata);
+ STACK_WIND(frame, glupy_link_cbk, xl, xl->fops->link, oldloc, newloc,
+ xdata);
}
void
-unwind_link (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+unwind_link(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, inode_t *inode, struct iatt *buf,
+ struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (link, frame, op_ret, op_errno, inode, buf,
- preparent, postparent, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(link, frame, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
}
void
-set_link_fop (long py_this, fop_link_t fop)
+set_link_fop(long py_this, fop_link_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_LINK] = (long)fop;
+ priv->fops[GLUPY_LINK] = (long)fop;
}
void
-set_link_cbk (long py_this, fop_link_cbk_t cbk)
+set_link_cbk(long py_this, fop_link_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_LINK] = (long)cbk;
+ priv->cbks[GLUPY_LINK] = (long)cbk;
}
/* FOP: SYMLINK*/
int32_t
-glupy_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+glupy_symlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_SYMLINK]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_SYMLINK]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_symlink_cbk_t)(priv->cbks[GLUPY_SYMLINK]))(
- frame, cookie, this, op_ret, op_errno,
- inode, buf, preparent, postparent, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_symlink_cbk_t)(priv->cbks[GLUPY_SYMLINK]))(
+ frame, cookie, this, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (symlink, frame, op_ret, op_errno, inode, buf,
- preparent, postparent, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(symlink, frame, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
+ return 0;
}
int32_t
glupy_symlink(call_frame_t *frame, xlator_t *this, const char *linkname,
loc_t *loc, mode_t umask, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_SYMLINK]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_SYMLINK]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_symlink_t)(priv->fops[GLUPY_SYMLINK]))(
- frame, this, linkname, loc, umask, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_symlink_t)(priv->fops[GLUPY_SYMLINK]))(frame, this, linkname,
+ loc, umask, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_symlink_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->symlink, linkname, loc,
- umask, xdata);
- return 0;
+ STACK_WIND(frame, glupy_symlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->symlink, linkname, loc, umask, xdata);
+ return 0;
}
void
-wind_symlink (call_frame_t *frame, xlator_t *xl, const char *linkname,
- loc_t *loc, mode_t umask, dict_t *xdata)
+wind_symlink(call_frame_t *frame, xlator_t *xl, const char *linkname,
+ loc_t *loc, mode_t umask, dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_symlink_cbk, xl, xl->fops->symlink,
- linkname, loc, umask, xdata);
+ STACK_WIND(frame, glupy_symlink_cbk, xl, xl->fops->symlink, linkname, loc,
+ umask, xdata);
}
void
-unwind_symlink (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+unwind_symlink(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, inode_t *inode, struct iatt *buf,
+ struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (symlink, frame, op_ret, op_errno, inode, buf,
- preparent, postparent, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(symlink, frame, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
}
void
-set_symlink_fop (long py_this, fop_symlink_t fop)
+set_symlink_fop(long py_this, fop_symlink_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_SYMLINK] = (long)fop;
+ priv->fops[GLUPY_SYMLINK] = (long)fop;
}
void
-set_symlink_cbk (long py_this, fop_symlink_cbk_t cbk)
+set_symlink_cbk(long py_this, fop_symlink_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_SYMLINK] = (long)cbk;
+ priv->cbks[GLUPY_SYMLINK] = (long)cbk;
}
-
/* FOP: READLINK */
int32_t
-glupy_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, const char *path,
- struct iatt *buf, dict_t *xdata)
+glupy_readlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, const char *path,
+ struct iatt *buf, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_READLINK]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_READLINK]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_readlink_cbk_t)(priv->cbks[GLUPY_READLINK]))(
- frame, cookie, this, op_ret, op_errno,
- path, buf, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_readlink_cbk_t)(priv->cbks[GLUPY_READLINK]))(
+ frame, cookie, this, op_ret, op_errno, path, buf, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (readlink, frame, op_ret, op_errno, path,
- buf, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(readlink, frame, op_ret, op_errno, path, buf, xdata);
+ return 0;
}
int32_t
-glupy_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc,
- size_t size, dict_t *xdata)
+glupy_readlink(call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_READLINK]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_READLINK]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_readlink_t)(priv->fops[GLUPY_READLINK]))(
- frame, this, loc, size, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_readlink_t)(priv->fops[GLUPY_READLINK]))(frame, this, loc, size,
+ xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_readlink_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->readlink, loc,
- size, xdata);
- return 0;
+ STACK_WIND(frame, glupy_readlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readlink, loc, size, xdata);
+ return 0;
}
void
-wind_readlink (call_frame_t *frame, xlator_t *xl, loc_t *loc,
- size_t size, dict_t *xdata)
+wind_readlink(call_frame_t *frame, xlator_t *xl, loc_t *loc, size_t size,
+ dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_readlink_cbk, xl, xl->fops->readlink,
- loc, size, xdata);
+ STACK_WIND(frame, glupy_readlink_cbk, xl, xl->fops->readlink, loc, size,
+ xdata);
}
void
-unwind_readlink (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, const char *path,
- struct iatt *buf, dict_t *xdata)
+unwind_readlink(call_frame_t *frame, long cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, const char *path,
+ struct iatt *buf, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (readlink, frame, op_ret, op_errno, path, buf,
- xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(readlink, frame, op_ret, op_errno, path, buf, xdata);
}
void
-set_readlink_fop (long py_this, fop_readlink_t fop)
+set_readlink_fop(long py_this, fop_readlink_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_READLINK] = (long)fop;
+ priv->fops[GLUPY_READLINK] = (long)fop;
}
void
-set_readlink_cbk (long py_this, fop_readlink_cbk_t cbk)
+set_readlink_cbk(long py_this, fop_readlink_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_READLINK] = (long)cbk;
+ priv->cbks[GLUPY_READLINK] = (long)cbk;
}
-
/* FOP: UNLINK */
int32_t
-glupy_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iatt *preparent, struct iatt *postparent,
- dict_t *xdata)
+glupy_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_UNLINK]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_UNLINK]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_unlink_cbk_t)(priv->cbks[GLUPY_UNLINK]))(
- frame, cookie, this, op_ret, op_errno,
- preparent, postparent, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_unlink_cbk_t)(priv->cbks[GLUPY_UNLINK]))(
+ frame, cookie, this, op_ret, op_errno, preparent, postparent, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, preparent,
- postparent, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(unlink, frame, op_ret, op_errno, preparent, postparent,
+ xdata);
+ return 0;
}
int32_t
-glupy_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc,
- int xflags, dict_t *xdata)
+glupy_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflags,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_UNLINK]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_UNLINK]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_unlink_t)(priv->fops[GLUPY_UNLINK]))(
- frame, this, loc, xflags, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_unlink_t)(priv->fops[GLUPY_UNLINK]))(frame, this, loc, xflags,
+ xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_unlink_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->unlink, loc,
- xflags, xdata);
- return 0;
+ STACK_WIND(frame, glupy_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, loc, xflags, xdata);
+ return 0;
}
void
-wind_unlink (call_frame_t *frame, xlator_t *xl, loc_t *loc,
- int xflags, dict_t *xdata)
+wind_unlink(call_frame_t *frame, xlator_t *xl, loc_t *loc, int xflags,
+ dict_t *xdata)
{
- xlator_t *this = THIS;
+ xlator_t *this = THIS;
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_unlink_cbk, xl, xl->fops->unlink,
- loc, xflags, xdata);
+ STACK_WIND(frame, glupy_unlink_cbk, xl, xl->fops->unlink, loc, xflags,
+ xdata);
}
void
-unwind_unlink (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iatt *preparent, struct iatt *postparent,
- dict_t *xdata)
+unwind_unlink(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct iatt *preparent, struct iatt *postparent,
+ dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno,
- preparent, postparent, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(unlink, frame, op_ret, op_errno, preparent, postparent,
+ xdata);
}
void
-set_unlink_fop (long py_this, fop_unlink_t fop)
+set_unlink_fop(long py_this, fop_unlink_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_UNLINK] = (long)fop;
+ priv->fops[GLUPY_UNLINK] = (long)fop;
}
void
-set_unlink_cbk (long py_this, fop_unlink_cbk_t cbk)
+set_unlink_cbk(long py_this, fop_unlink_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_UNLINK] = (long)cbk;
+ priv->cbks[GLUPY_UNLINK] = (long)cbk;
}
-
/* FOP: MKDIR */
int32_t
-glupy_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+glupy_mkdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_MKDIR]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_MKDIR]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_mkdir_cbk_t)(priv->cbks[GLUPY_MKDIR]))(
- frame, cookie, this, op_ret, op_errno,
- inode, buf, preparent, postparent, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_mkdir_cbk_t)(priv->cbks[GLUPY_MKDIR]))(
+ frame, cookie, this, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (mkdir, frame, op_ret, op_errno, inode, buf,
- preparent, postparent, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(mkdir, frame, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
+ return 0;
}
int32_t
-glupy_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
- mode_t umask, dict_t *xdata)
+glupy_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ mode_t umask, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_MKDIR]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_MKDIR]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_mkdir_t)(priv->fops[GLUPY_MKDIR]))(
- frame, this, loc, mode, umask, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_mkdir_t)(priv->fops[GLUPY_MKDIR]))(frame, this, loc, mode,
+ umask, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_mkdir_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->mkdir, loc, mode, umask,
- xdata);
- return 0;
+ STACK_WIND(frame, glupy_mkdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mkdir, loc, mode, umask, xdata);
+ return 0;
}
void
-wind_mkdir (call_frame_t *frame, xlator_t *xl, loc_t *loc, mode_t mode,
- mode_t umask, dict_t *xdata)
+wind_mkdir(call_frame_t *frame, xlator_t *xl, loc_t *loc, mode_t mode,
+ mode_t umask, dict_t *xdata)
{
+ xlator_t *this = THIS;
- xlator_t *this = THIS;
-
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- STACK_WIND (frame, glupy_mkdir_cbk, xl, xl->fops->mkdir,
- loc, mode, umask, xdata);
+ STACK_WIND(frame, glupy_mkdir_cbk, xl, xl->fops->mkdir, loc, mode, umask,
+ xdata);
}
void
-unwind_mkdir (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+unwind_mkdir(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, inode_t *inode, struct iatt *buf,
+ struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (mkdir, frame, op_ret, op_errno, inode, buf,
- preparent, postparent, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(mkdir, frame, op_ret, op_errno, inode, buf, preparent,
+ postparent, xdata);
}
void
-set_mkdir_fop (long py_this, fop_mkdir_t fop)
+set_mkdir_fop(long py_this, fop_mkdir_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_MKDIR] = (long)fop;
+ priv->fops[GLUPY_MKDIR] = (long)fop;
}
void
-set_mkdir_cbk (long py_this, fop_mkdir_cbk_t cbk)
+set_mkdir_cbk(long py_this, fop_mkdir_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_MKDIR] = (long)cbk;
+ priv->cbks[GLUPY_MKDIR] = (long)cbk;
}
-
/* FOP: RMDIR */
int32_t
-glupy_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iatt *preparent, struct iatt *postparent,
- dict_t *xdata)
+glupy_rmdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *preparent,
+ struct iatt *postparent, dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
- if (!priv->cbks[GLUPY_RMDIR]) {
- goto unwind;
- }
+ if (!priv->cbks[GLUPY_RMDIR]) {
+ goto unwind;
+ }
- gstate = glupy_enter();
- ret = ((fop_rmdir_cbk_t)(priv->cbks[GLUPY_RMDIR]))(
- frame, cookie, this, op_ret, op_errno,
- preparent, postparent, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ ret = ((fop_rmdir_cbk_t)(priv->cbks[GLUPY_RMDIR]))(
+ frame, cookie, this, op_ret, op_errno, preparent, postparent, xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
unwind:
- frame->local = NULL;
- STACK_UNWIND_STRICT (rmdir, frame, op_ret, op_errno, preparent,
- postparent, xdata);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(rmdir, frame, op_ret, op_errno, preparent, postparent,
+ xdata);
+ return 0;
}
int32_t
-glupy_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc,
- int xflags, dict_t *xdata)
+glupy_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflags,
+ dict_t *xdata)
{
- glupy_private_t *priv = this->private;
- PyGILState_STATE gstate;
- int32_t ret;
- static long next_id = 0;
+ glupy_private_t *priv = this->private;
+ PyGILState_STATE gstate;
+ int32_t ret;
+ static long next_id = 0;
- if (!priv->fops[GLUPY_RMDIR]) {
- goto wind;
- }
+ if (!priv->fops[GLUPY_RMDIR]) {
+ goto wind;
+ }
- gstate = glupy_enter();
- frame->local = (void *)++next_id;
- ret = ((fop_rmdir_t)(priv->fops[GLUPY_RMDIR]))(
- frame, this, loc, xflags, xdata);
- glupy_leave(gstate);
+ gstate = glupy_enter();
+ frame->local = (void *)++next_id;
+ ret = ((fop_rmdir_t)(priv->fops[GLUPY_RMDIR]))(frame, this, loc, xflags,
+ xdata);
+ glupy_leave(gstate);
- return ret;
+ return ret;
wind:
- STACK_WIND (frame, glupy_rmdir_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->rmdir, loc,
- xflags, xdata);
- return 0;
+ STACK_WIND(frame, glupy_rmdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rmdir, loc, xflags, xdata);
+ return 0;
}
void
-wind_rmdir (call_frame_t *frame, xlator_t *xl, loc_t *loc,
- int xflags, dict_t *xdata)
+wind_rmdir(call_frame_t *frame, xlator_t *xl, loc_t *loc, int xflags,
+ dict_t *xdata)
{
+ xlator_t *this = THIS;
- xlator_t *this = THIS;
+ if (!xl || (xl == this)) {
+ xl = FIRST_CHILD(this);
+ }
- if (!xl || (xl == this)) {
- xl = FIRST_CHILD(this);
- }
-
- STACK_WIND (frame, glupy_rmdir_cbk, xl, xl->fops->rmdir,
- loc, xflags, xdata);
+ STACK_WIND(frame, glupy_rmdir_cbk, xl, xl->fops->rmdir, loc, xflags, xdata);
}
void
-unwind_rmdir (call_frame_t *frame, long cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iatt *preparent, struct iatt *postparent,
- dict_t *xdata)
+unwind_rmdir(call_frame_t *frame, long cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct iatt *preparent, struct iatt *postparent,
+ dict_t *xdata)
{
- frame->local = NULL;
- STACK_UNWIND_STRICT (rmdir, frame, op_ret, op_errno,
- preparent, postparent, xdata);
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(rmdir, frame, op_ret, op_errno, preparent, postparent,
+ xdata);
}
void
-set_rmdir_fop (long py_this, fop_rmdir_t fop)
+set_rmdir_fop(long py_this, fop_rmdir_t fop)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->fops[GLUPY_RMDIR] = (long)fop;
+ priv->fops[GLUPY_RMDIR] = (long)fop;
}
void
-set_rmdir_cbk (long py_this, fop_rmdir_cbk_t cbk)
+set_rmdir_cbk(long py_this, fop_rmdir_cbk_t cbk)
{
- glupy_private_t *priv = ((xlator_t *)py_this)->private;
+ glupy_private_t *priv = ((xlator_t *)py_this)->private;
- priv->cbks[GLUPY_RMDIR] = (long)cbk;
+ priv->cbks[GLUPY_RMDIR] = (long)cbk;
}
-
/* NON-FOP-SPECIFIC CODE */
-
long
-get_id (call_frame_t *frame)
+get_id(call_frame_t *frame)
{
- return (long)(frame->local);
+ return (long)(frame->local);
}
uint64_t
-get_rootunique (call_frame_t *frame)
+get_rootunique(call_frame_t *frame)
{
- return frame->root->unique;
+ return frame->root->unique;
}
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int ret = -1;
+ int ret = -1;
- if (!this)
- return ret;
+ if (!this)
+ return ret;
- ret = xlator_mem_acct_init (this, gf_glupy_mt_end);
-
- if (ret != 0) {
- gf_log(this->name, GF_LOG_ERROR, "Memory accounting init"
- " failed");
- return ret;
- }
+ ret = xlator_mem_acct_init(this, gf_glupy_mt_end);
+ if (ret != 0) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "Memory accounting init"
+ " failed");
return ret;
+ }
+
+ return ret;
}
static void
py_error_log(const char *name, PyObject *pystr)
{
#if PY_MAJOR_VERSION > 2
- char scr[256];
- if (PyUnicode_Check(pystr)) {
- PyObject *tmp =
- PyUnicode_AsEncodedString(pystr, "UTF-8", "strict");
- if (tmp != NULL) {
- strncpy(scr, PyBytes_AS_STRING(pystr), sizeof(scr));
- Py_DECREF(tmp);
- } else {
- strncpy(scr, "string encoding error", sizeof(scr));
- }
- } else if (PyBytes_Check(pystr)) {
- strncpy(scr, PyBytes_AS_STRING(pystr), sizeof(scr));
+ char scr[256];
+ if (PyUnicode_Check(pystr)) {
+ PyObject *tmp = PyUnicode_AsEncodedString(pystr, "UTF-8", "strict");
+ if (tmp != NULL) {
+ strncpy(scr, PyBytes_AS_STRING(pystr), sizeof(scr));
+ Py_DECREF(tmp);
} else {
- strncpy(scr, "string encoding error", sizeof(scr));
- }
- gf_log (name, GF_LOG_ERROR, "Python error: %s", scr);
+ strncpy(scr, "string encoding error", sizeof(scr));
+ }
+ } else if (PyBytes_Check(pystr)) {
+ strncpy(scr, PyBytes_AS_STRING(pystr), sizeof(scr));
+ } else {
+ strncpy(scr, "string encoding error", sizeof(scr));
+ }
+ gf_log(name, GF_LOG_ERROR, "Python error: %s", scr);
#else
- gf_log (name, GF_LOG_ERROR, "Python error: %s", PyString_AsString(pystr));
+ gf_log(name, GF_LOG_ERROR, "Python error: %s", PyString_AsString(pystr));
#endif
}
static PyObject *
-encode (const char *str)
+encode(const char *str)
{
#if PY_MAJOR_VERSION > 2
- return PyUnicode_FromString(str);
+ return PyUnicode_FromString(str);
#else
- return PyString_FromString(str);
+ return PyString_FromString(str);
#endif
}
int32_t
-init (xlator_t *this)
-{
- glupy_private_t *priv = NULL;
- char *module_name = NULL;
- PyObject *py_mod_name = NULL;
- PyObject *py_init_func = NULL;
- PyObject *py_args = NULL;
- PyObject *syspath = NULL;
- PyObject *path = NULL;
- PyObject *error_type = NULL;
- PyObject *error_msg = NULL;
- PyObject *error_bt = NULL;
- static gf_boolean_t py_inited = _gf_false;
- void * err_cleanup = &&err_return;
- char libpython[16];
-
- if (dict_get_str(this->options,"module-name",&module_name) != 0) {
- gf_log (this->name, GF_LOG_ERROR, "missing module-name");
- return -1;
- }
-
- priv = GF_CALLOC (1, sizeof (glupy_private_t), gf_glupy_mt_priv);
- if (!priv) {
- goto *err_cleanup;
- }
- this->private = priv;
- err_cleanup = &&err_free_priv;
-
- if (!py_inited) {
- /* FIXME:
- * This hack is necessary because glusterfs (rightly) loads
- * glupy.so with RTLD_LOCAL but glupy needs libpython to be
- * loaded with RTLD_GLOBAL even though glupy is correctly
- * linked with libpython.
- * This is needed because one of the internal modules of
- * python 2.x (lib-dynload/_struct.so) does not explicitly
- * link with libpython.
- */
- snprintf(libpython, sizeof(libpython), "libpython%d.%d.so",
- PY_MAJOR_VERSION, PY_MINOR_VERSION);
- if (!dlopen (libpython, RTLD_NOW|RTLD_GLOBAL)) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- LG_MSG_DLOPEN_FAILED, "dlopen(%s) failed: %s",
- libpython, dlerror ());
- }
-
- /*
- * This must be done before Py_Initialize(),
- * because it will duplicate the environment,
- * and fail to see later environment updates.
- */
- setenv("PATH_GLUSTERFS_GLUPY_MODULE",
- PATH_GLUSTERFS_GLUPY_MODULE, 1);
-
- Py_Initialize();
- PyEval_InitThreads();
-
- (void)pthread_key_create(&gil_init_key,NULL);
- (void)pthread_setspecific(gil_init_key,(void *)1);
-
- /* PyEval_InitThreads takes this "for" us. No thanks. */
- PyEval_ReleaseLock();
- py_inited = _gf_true;
- }
-
- /* Adjust python's path */
- syspath = PySys_GetObject("path");
- path = encode(GLUSTER_PYTHON_PATH);
- PyList_Append(syspath, path);
- Py_DECREF(path);
-
- py_mod_name = encode(module_name);
- if (!py_mod_name) {
- gf_log (this->name, GF_LOG_ERROR, "could not create name");
- if (PyErr_Occurred()) {
- PyErr_Fetch (&error_type, &error_msg, &error_bt);
- py_error_log(this->name, error_msg);
- }
- goto *err_cleanup;
- }
-
- gf_log (this->name, GF_LOG_DEBUG, "py_mod_name = %s", module_name);
- priv->py_module = PyImport_Import(py_mod_name);
- Py_DECREF(py_mod_name);
- if (!priv->py_module) {
- gf_log (this->name, GF_LOG_ERROR, "Python import of %s failed",
- module_name);
- if (PyErr_Occurred()) {
- PyErr_Fetch (&error_type, &error_msg, &error_bt);
- py_error_log (this->name, error_msg);
- }
- goto *err_cleanup;
- }
- gf_log (this->name, GF_LOG_INFO, "Import of %s succeeded", module_name);
- err_cleanup = &&err_deref_module;
-
- py_init_func = PyObject_GetAttrString(priv->py_module, "xlator");
- if (!py_init_func || !PyCallable_Check(py_init_func)) {
- gf_log (this->name, GF_LOG_ERROR, "missing init func");
- if (PyErr_Occurred()) {
- PyErr_Fetch (&error_type, &error_msg, &error_bt);
- py_error_log (this->name, error_msg);
- }
- goto *err_cleanup;
- }
- err_cleanup = &&err_deref_init;
-
- py_args = PyTuple_New(1);
- if (!py_args) {
- gf_log (this->name, GF_LOG_ERROR, "could not create args");
- if (PyErr_Occurred()) {
- PyErr_Fetch (&error_type, &error_msg, &error_bt);
- py_error_log (this->name, error_msg);
- }
- goto *err_cleanup;
- }
- PyTuple_SetItem(py_args,0,PyLong_FromLong((long)this));
-
- /* TBD: pass in list of children */
- priv->py_xlator = PyObject_CallObject(py_init_func, py_args);
- Py_DECREF(py_args);
- if (!priv->py_xlator) {
- gf_log (this->name, GF_LOG_ERROR, "Python init failed");
- if (PyErr_Occurred()) {
- PyErr_Fetch (&error_type, &error_msg, &error_bt);
- py_error_log (this->name, error_msg);
- }
- goto *err_cleanup;
- }
- gf_log (this->name, GF_LOG_DEBUG, "init returned %p", priv->py_xlator);
-
- return 0;
+init(xlator_t *this)
+{
+ glupy_private_t *priv = NULL;
+ char *module_name = NULL;
+ PyObject *py_mod_name = NULL;
+ PyObject *py_init_func = NULL;
+ PyObject *py_args = NULL;
+ PyObject *syspath = NULL;
+ PyObject *path = NULL;
+ PyObject *error_type = NULL;
+ PyObject *error_msg = NULL;
+ PyObject *error_bt = NULL;
+ static gf_boolean_t py_inited = _gf_false;
+ void *err_cleanup = &&err_return;
+ char libpython[16];
+
+ if (dict_get_str(this->options, "module-name", &module_name) != 0) {
+ gf_log(this->name, GF_LOG_ERROR, "missing module-name");
+ return -1;
+ }
+
+ priv = GF_CALLOC(1, sizeof(glupy_private_t), gf_glupy_mt_priv);
+ if (!priv) {
+ goto *err_cleanup;
+ }
+ this->private = priv;
+ err_cleanup = &&err_free_priv;
+
+ if (!py_inited) {
+ /* FIXME:
+ * This hack is necessary because glusterfs (rightly) loads
+ * glupy.so with RTLD_LOCAL but glupy needs libpython to be
+ * loaded with RTLD_GLOBAL even though glupy is correctly
+ * linked with libpython.
+ * This is needed because one of the internal modules of
+ * python 2.x (lib-dynload/_struct.so) does not explicitly
+ * link with libpython.
+ */
+ snprintf(libpython, sizeof(libpython), "libpython%d.%d.so",
+ PY_MAJOR_VERSION, PY_MINOR_VERSION);
+ if (!dlopen(libpython, RTLD_NOW | RTLD_GLOBAL)) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, LG_MSG_DLOPEN_FAILED,
+ "dlopen(%s) failed: %s", libpython, dlerror());
+ }
+
+ /*
+ * This must be done before Py_Initialize(),
+ * because it will duplicate the environment,
+ * and fail to see later environment updates.
+ */
+ setenv("PATH_GLUSTERFS_GLUPY_MODULE", PATH_GLUSTERFS_GLUPY_MODULE, 1);
+
+ Py_Initialize();
+ PyEval_InitThreads();
+
+ (void)pthread_key_create(&gil_init_key, NULL);
+ (void)pthread_setspecific(gil_init_key, (void *)1);
+
+ /* PyEval_InitThreads takes this "for" us. No thanks. */
+ PyEval_ReleaseLock();
+ py_inited = _gf_true;
+ }
+
+ /* Adjust python's path */
+ syspath = PySys_GetObject("path");
+ path = encode(GLUSTER_PYTHON_PATH);
+ PyList_Append(syspath, path);
+ Py_DECREF(path);
+
+ py_mod_name = encode(module_name);
+ if (!py_mod_name) {
+ gf_log(this->name, GF_LOG_ERROR, "could not create name");
+ if (PyErr_Occurred()) {
+ PyErr_Fetch(&error_type, &error_msg, &error_bt);
+ py_error_log(this->name, error_msg);
+ }
+ goto *err_cleanup;
+ }
+
+ gf_log(this->name, GF_LOG_DEBUG, "py_mod_name = %s", module_name);
+ priv->py_module = PyImport_Import(py_mod_name);
+ Py_DECREF(py_mod_name);
+ if (!priv->py_module) {
+ gf_log(this->name, GF_LOG_ERROR, "Python import of %s failed",
+ module_name);
+ if (PyErr_Occurred()) {
+ PyErr_Fetch(&error_type, &error_msg, &error_bt);
+ py_error_log(this->name, error_msg);
+ }
+ goto *err_cleanup;
+ }
+ gf_log(this->name, GF_LOG_INFO, "Import of %s succeeded", module_name);
+ err_cleanup = &&err_deref_module;
+
+ py_init_func = PyObject_GetAttrString(priv->py_module, "xlator");
+ if (!py_init_func || !PyCallable_Check(py_init_func)) {
+ gf_log(this->name, GF_LOG_ERROR, "missing init func");
+ if (PyErr_Occurred()) {
+ PyErr_Fetch(&error_type, &error_msg, &error_bt);
+ py_error_log(this->name, error_msg);
+ }
+ goto *err_cleanup;
+ }
+ err_cleanup = &&err_deref_init;
+
+ py_args = PyTuple_New(1);
+ if (!py_args) {
+ gf_log(this->name, GF_LOG_ERROR, "could not create args");
+ if (PyErr_Occurred()) {
+ PyErr_Fetch(&error_type, &error_msg, &error_bt);
+ py_error_log(this->name, error_msg);
+ }
+ goto *err_cleanup;
+ }
+ PyTuple_SetItem(py_args, 0, PyLong_FromLong((long)this));
+
+ /* TBD: pass in list of children */
+ priv->py_xlator = PyObject_CallObject(py_init_func, py_args);
+ Py_DECREF(py_args);
+ if (!priv->py_xlator) {
+ gf_log(this->name, GF_LOG_ERROR, "Python init failed");
+ if (PyErr_Occurred()) {
+ PyErr_Fetch(&error_type, &error_msg, &error_bt);
+ py_error_log(this->name, error_msg);
+ }
+ goto *err_cleanup;
+ }
+ gf_log(this->name, GF_LOG_DEBUG, "init returned %p", priv->py_xlator);
+
+ return 0;
err_deref_init:
- Py_DECREF(py_init_func);
+ Py_DECREF(py_init_func);
err_deref_module:
- Py_DECREF(priv->py_module);
+ Py_DECREF(priv->py_module);
err_free_priv:
- GF_FREE(priv);
+ GF_FREE(priv);
err_return:
- return -1;
+ return -1;
}
void
-fini (xlator_t *this)
+fini(xlator_t *this)
{
- glupy_private_t *priv = this->private;
-
- if (!priv)
- return;
- Py_DECREF(priv->py_xlator);
- Py_DECREF(priv->py_module);
- this->private = NULL;
- GF_FREE (priv);
+ glupy_private_t *priv = this->private;
+ if (!priv)
return;
-}
-
-struct xlator_fops fops = {
- .lookup = glupy_lookup,
- .create = glupy_create,
- .open = glupy_open,
- .readv = glupy_readv,
- .writev = glupy_writev,
- .opendir = glupy_opendir,
- .readdir = glupy_readdir,
- .stat = glupy_stat,
- .fstat = glupy_fstat,
- .setxattr = glupy_setxattr,
- .getxattr = glupy_getxattr,
- .fsetxattr = glupy_fsetxattr,
- .fgetxattr = glupy_fgetxattr,
- .removexattr = glupy_removexattr,
- .fremovexattr = glupy_fremovexattr,
- .link = glupy_link,
- .unlink = glupy_unlink,
- .readlink = glupy_readlink,
- .symlink = glupy_symlink,
- .mkdir = glupy_mkdir,
- .rmdir = glupy_rmdir,
- .statfs = glupy_statfs,
- .readdirp = glupy_readdirp
-};
-
-struct xlator_cbks cbks = {
-};
+ Py_DECREF(priv->py_xlator);
+ Py_DECREF(priv->py_module);
+ this->private = NULL;
+ GF_FREE(priv);
+
+ return;
+}
+
+struct xlator_fops fops = {.lookup = glupy_lookup,
+ .create = glupy_create,
+ .open = glupy_open,
+ .readv = glupy_readv,
+ .writev = glupy_writev,
+ .opendir = glupy_opendir,
+ .readdir = glupy_readdir,
+ .stat = glupy_stat,
+ .fstat = glupy_fstat,
+ .setxattr = glupy_setxattr,
+ .getxattr = glupy_getxattr,
+ .fsetxattr = glupy_fsetxattr,
+ .fgetxattr = glupy_fgetxattr,
+ .removexattr = glupy_removexattr,
+ .fremovexattr = glupy_fremovexattr,
+ .link = glupy_link,
+ .unlink = glupy_unlink,
+ .readlink = glupy_readlink,
+ .symlink = glupy_symlink,
+ .mkdir = glupy_mkdir,
+ .rmdir = glupy_rmdir,
+ .statfs = glupy_statfs,
+ .readdirp = glupy_readdirp};
+
+struct xlator_cbks cbks = {};
struct volume_options options[] = {
- { .key = {NULL} },
+ {.key = {NULL}},
};
diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c
index 3a518248c13..08785f21a2a 100644
--- a/xlators/features/index/src/index.c
+++ b/xlators/features/index/src/index.c
@@ -23,2583 +23,2567 @@
#define ENTRY_CHANGES_SUBDIR "entry-changes"
struct index_syncop_args {
- inode_t *parent;
- gf_dirent_t *entries;
- char *path;
+ inode_t *parent;
+ gf_dirent_t *entries;
+ char *path;
};
static char *index_vgfid_xattrs[XATTROP_TYPE_END] = {
- [XATTROP] = GF_XATTROP_INDEX_GFID,
- [DIRTY] = GF_XATTROP_DIRTY_GFID,
- [ENTRY_CHANGES] = GF_XATTROP_ENTRY_CHANGES_GFID
-};
+ [XATTROP] = GF_XATTROP_INDEX_GFID,
+ [DIRTY] = GF_XATTROP_DIRTY_GFID,
+ [ENTRY_CHANGES] = GF_XATTROP_ENTRY_CHANGES_GFID};
static char *index_subdirs[XATTROP_TYPE_END] = {
- [XATTROP] = XATTROP_SUBDIR,
- [DIRTY] = DIRTY_SUBDIR,
- [ENTRY_CHANGES] = ENTRY_CHANGES_SUBDIR
-};
+ [XATTROP] = XATTROP_SUBDIR,
+ [DIRTY] = DIRTY_SUBDIR,
+ [ENTRY_CHANGES] = ENTRY_CHANGES_SUBDIR};
int
-index_get_type_from_vgfid (index_priv_t *priv, uuid_t vgfid)
+index_get_type_from_vgfid(index_priv_t *priv, uuid_t vgfid)
{
- int i = 0;
+ int i = 0;
- for (i = 0; i < XATTROP_TYPE_END; i++) {
- if (gf_uuid_compare (priv->internal_vgfid[i], vgfid) == 0)
- return i;
- }
- return -1;
+ for (i = 0; i < XATTROP_TYPE_END; i++) {
+ if (gf_uuid_compare(priv->internal_vgfid[i], vgfid) == 0)
+ return i;
+ }
+ return -1;
}
gf_boolean_t
-index_is_virtual_gfid (index_priv_t *priv, uuid_t vgfid)
+index_is_virtual_gfid(index_priv_t *priv, uuid_t vgfid)
{
- if (index_get_type_from_vgfid (priv, vgfid) < 0)
- return _gf_false;
- return _gf_true;
+ if (index_get_type_from_vgfid(priv, vgfid) < 0)
+ return _gf_false;
+ return _gf_true;
}
static int
-__index_inode_ctx_get (inode_t *inode, xlator_t *this, index_inode_ctx_t **ctx)
-{
- int ret = 0;
- index_inode_ctx_t *ictx = NULL;
- uint64_t tmpctx = 0;
-
- ret = __inode_ctx_get (inode, this, &tmpctx);
- if (!ret) {
- ictx = (index_inode_ctx_t *) (long) tmpctx;
- goto out;
- }
- ictx = GF_CALLOC (1, sizeof (*ictx), gf_index_inode_ctx_t);
- if (!ictx) {
- ret = -1;
- goto out;
- }
-
- INIT_LIST_HEAD (&ictx->callstubs);
- ret = __inode_ctx_put (inode, this, (uint64_t)ictx);
- if (ret) {
- GF_FREE (ictx);
- ictx = NULL;
- goto out;
- }
+__index_inode_ctx_get(inode_t *inode, xlator_t *this, index_inode_ctx_t **ctx)
+{
+ int ret = 0;
+ index_inode_ctx_t *ictx = NULL;
+ uint64_t tmpctx = 0;
+
+ ret = __inode_ctx_get(inode, this, &tmpctx);
+ if (!ret) {
+ ictx = (index_inode_ctx_t *)(long)tmpctx;
+ goto out;
+ }
+ ictx = GF_CALLOC(1, sizeof(*ictx), gf_index_inode_ctx_t);
+ if (!ictx) {
+ ret = -1;
+ goto out;
+ }
+
+ INIT_LIST_HEAD(&ictx->callstubs);
+ ret = __inode_ctx_put(inode, this, (uint64_t)ictx);
+ if (ret) {
+ GF_FREE(ictx);
+ ictx = NULL;
+ goto out;
+ }
out:
- if (ictx)
- *ctx = ictx;
- return ret;
+ if (ictx)
+ *ctx = ictx;
+ return ret;
}
static int
-index_inode_ctx_get (inode_t *inode, xlator_t *this, index_inode_ctx_t **ctx)
+index_inode_ctx_get(inode_t *inode, xlator_t *this, index_inode_ctx_t **ctx)
{
- int ret = 0;
+ int ret = 0;
- LOCK (&inode->lock);
- {
- ret = __index_inode_ctx_get (inode, this, ctx);
- }
- UNLOCK (&inode->lock);
+ LOCK(&inode->lock);
+ {
+ ret = __index_inode_ctx_get(inode, this, ctx);
+ }
+ UNLOCK(&inode->lock);
- return ret;
+ return ret;
}
static gf_boolean_t
-index_is_subdir_of_entry_changes (xlator_t *this, inode_t *inode)
+index_is_subdir_of_entry_changes(xlator_t *this, inode_t *inode)
{
- index_inode_ctx_t *ctx = NULL;
- int ret = 0;
+ index_inode_ctx_t *ctx = NULL;
+ int ret = 0;
- if (!inode)
- return _gf_false;
-
- ret = index_inode_ctx_get (inode, this, &ctx);
- if ((ret == 0) && !gf_uuid_is_null (ctx->virtual_pargfid))
- return _gf_true;
+ if (!inode)
return _gf_false;
+
+ ret = index_inode_ctx_get(inode, this, &ctx);
+ if ((ret == 0) && !gf_uuid_is_null(ctx->virtual_pargfid))
+ return _gf_true;
+ return _gf_false;
}
static int
-index_get_type_from_vgfid_xattr (const char *name)
+index_get_type_from_vgfid_xattr(const char *name)
{
- int i = 0;
+ int i = 0;
- for (i = 0; i < XATTROP_TYPE_END; i++) {
- if (strcmp (name, index_vgfid_xattrs[i]) == 0)
- return i;
- }
- return -1;
+ for (i = 0; i < XATTROP_TYPE_END; i++) {
+ if (strcmp(name, index_vgfid_xattrs[i]) == 0)
+ return i;
+ }
+ return -1;
}
gf_boolean_t
-index_is_fop_on_internal_inode (xlator_t *this, inode_t *inode, uuid_t gfid)
+index_is_fop_on_internal_inode(xlator_t *this, inode_t *inode, uuid_t gfid)
{
- index_priv_t *priv = this->private;
- uuid_t vgfid = {0};
+ index_priv_t *priv = this->private;
+ uuid_t vgfid = {0};
- if (!inode)
- return _gf_false;
+ if (!inode)
+ return _gf_false;
- if (gfid && !gf_uuid_is_null (gfid))
- gf_uuid_copy (vgfid, gfid);
- else
- gf_uuid_copy (vgfid, inode->gfid);
+ if (gfid && !gf_uuid_is_null(gfid))
+ gf_uuid_copy(vgfid, gfid);
+ else
+ gf_uuid_copy(vgfid, inode->gfid);
- if (index_is_virtual_gfid (priv, vgfid))
- return _gf_true;
- if (index_is_subdir_of_entry_changes (this, inode))
- return _gf_true;
- return _gf_false;
+ if (index_is_virtual_gfid(priv, vgfid))
+ return _gf_true;
+ if (index_is_subdir_of_entry_changes(this, inode))
+ return _gf_true;
+ return _gf_false;
}
static gf_boolean_t
-index_is_vgfid_xattr (const char *name)
+index_is_vgfid_xattr(const char *name)
{
- if (index_get_type_from_vgfid_xattr (name) < 0)
- return _gf_false;
- return _gf_true;
+ if (index_get_type_from_vgfid_xattr(name) < 0)
+ return _gf_false;
+ return _gf_true;
}
call_stub_t *
-__index_dequeue (struct list_head *callstubs)
+__index_dequeue(struct list_head *callstubs)
{
- call_stub_t *stub = NULL;
+ call_stub_t *stub = NULL;
- if (!list_empty (callstubs)) {
- stub = list_entry (callstubs->next, call_stub_t, list);
- list_del_init (&stub->list);
- }
+ if (!list_empty(callstubs)) {
+ stub = list_entry(callstubs->next, call_stub_t, list);
+ list_del_init(&stub->list);
+ }
- return stub;
+ return stub;
}
static void
-__index_enqueue (struct list_head *callstubs, call_stub_t *stub)
+__index_enqueue(struct list_head *callstubs, call_stub_t *stub)
{
- list_add_tail (&stub->list, callstubs);
+ list_add_tail(&stub->list, callstubs);
}
static void
-worker_enqueue (xlator_t *this, call_stub_t *stub)
+worker_enqueue(xlator_t *this, call_stub_t *stub)
{
- index_priv_t *priv = NULL;
+ index_priv_t *priv = NULL;
- priv = this->private;
- pthread_mutex_lock (&priv->mutex);
- {
- __index_enqueue (&priv->callstubs, stub);
- pthread_cond_signal (&priv->cond);
- }
- pthread_mutex_unlock (&priv->mutex);
+ priv = this->private;
+ pthread_mutex_lock(&priv->mutex);
+ {
+ __index_enqueue(&priv->callstubs, stub);
+ pthread_cond_signal(&priv->cond);
+ }
+ pthread_mutex_unlock(&priv->mutex);
}
void *
-index_worker (void *data)
-{
- index_priv_t *priv = NULL;
- xlator_t *this = NULL;
- call_stub_t *stub = NULL;
- gf_boolean_t bye = _gf_false;
-
-
- THIS = data;
- this = data;
- priv = this->private;
-
- for (;;) {
- pthread_mutex_lock (&priv->mutex);
- {
- while (list_empty (&priv->callstubs)) {
- if (priv->down) {
- bye = _gf_true;/*Avoid wait*/
- break;
- }
- (void) pthread_cond_wait (&priv->cond,
- &priv->mutex);
- if (priv->down) {
- bye = _gf_true;
- break;
- }
- }
- if (!bye)
- stub = __index_dequeue (&priv->callstubs);
- }
- pthread_mutex_unlock (&priv->mutex);
+index_worker(void *data)
+{
+ index_priv_t *priv = NULL;
+ xlator_t *this = NULL;
+ call_stub_t *stub = NULL;
+ gf_boolean_t bye = _gf_false;
- if (stub) /* guard against spurious wakeups */
- call_resume (stub);
- stub = NULL;
- if (bye)
- break;
+ THIS = data;
+ this = data;
+ priv = this->private;
+
+ for (;;) {
+ pthread_mutex_lock(&priv->mutex);
+ {
+ while (list_empty(&priv->callstubs)) {
+ if (priv->down) {
+ bye = _gf_true; /*Avoid wait*/
+ break;
+ }
+ (void)pthread_cond_wait(&priv->cond, &priv->mutex);
+ if (priv->down) {
+ bye = _gf_true;
+ break;
+ }
+ }
+ if (!bye)
+ stub = __index_dequeue(&priv->callstubs);
}
+ pthread_mutex_unlock(&priv->mutex);
- return NULL;
+ if (stub) /* guard against spurious wakeups */
+ call_resume(stub);
+ stub = NULL;
+ if (bye)
+ break;
+ }
+
+ return NULL;
}
static void
-make_index_dir_path (char *base, const char *subdir,
- char *index_dir, size_t len)
+make_index_dir_path(char *base, const char *subdir, char *index_dir, size_t len)
{
- snprintf (index_dir, len, "%s/%s", base, subdir);
+ snprintf(index_dir, len, "%s/%s", base, subdir);
}
int
-index_dir_create (xlator_t *this, const char *subdir)
-{
- int ret = 0;
- struct stat st = {0};
- char fullpath[PATH_MAX] = {0};
- char path[PATH_MAX] = {0};
- char *dir = NULL;
- index_priv_t *priv = NULL;
- size_t len = 0;
- size_t pathlen = 0;
-
- priv = this->private;
- make_index_dir_path (priv->index_basepath, subdir, fullpath,
- sizeof (fullpath));
- ret = sys_stat (fullpath, &st);
- if (!ret) {
- if (!S_ISDIR (st.st_mode))
- ret = -2;
- goto out;
- }
-
- pathlen = strlen (fullpath);
- if ((pathlen > 1) && fullpath[pathlen - 1] == '/')
- fullpath[pathlen - 1] = '\0';
- dir = strchr (fullpath, '/');
- while (dir) {
- dir = strchr (dir + 1, '/');
- if (dir)
- len = pathlen - strlen (dir);
- else
- len = pathlen;
- strncpy (path, fullpath, len);
- path[len] = '\0';
- ret = sys_mkdir (path, 0600);
- if (ret && (errno != EEXIST))
- goto out;
- }
- ret = 0;
+index_dir_create(xlator_t *this, const char *subdir)
+{
+ int ret = 0;
+ struct stat st = {0};
+ char fullpath[PATH_MAX] = {0};
+ char path[PATH_MAX] = {0};
+ char *dir = NULL;
+ index_priv_t *priv = NULL;
+ size_t len = 0;
+ size_t pathlen = 0;
+
+ priv = this->private;
+ make_index_dir_path(priv->index_basepath, subdir, fullpath,
+ sizeof(fullpath));
+ ret = sys_stat(fullpath, &st);
+ if (!ret) {
+ if (!S_ISDIR(st.st_mode))
+ ret = -2;
+ goto out;
+ }
+
+ pathlen = strlen(fullpath);
+ if ((pathlen > 1) && fullpath[pathlen - 1] == '/')
+ fullpath[pathlen - 1] = '\0';
+ dir = strchr(fullpath, '/');
+ while (dir) {
+ dir = strchr(dir + 1, '/');
+ if (dir)
+ len = pathlen - strlen(dir);
+ else
+ len = pathlen;
+ strncpy(path, fullpath, len);
+ path[len] = '\0';
+ ret = sys_mkdir(path, 0600);
+ if (ret && (errno != EEXIST))
+ goto out;
+ }
+ ret = 0;
out:
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- INDEX_MSG_INDEX_DIR_CREATE_FAILED, "%s/%s: Failed to "
- "create", priv->index_basepath, subdir);
- } else if (ret == -2) {
- gf_msg (this->name, GF_LOG_ERROR, ENOTDIR,
- INDEX_MSG_INDEX_DIR_CREATE_FAILED, "%s/%s: Failed to "
- "create, path exists, not a directory ",
- priv->index_basepath, subdir);
- }
- return ret;
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ INDEX_MSG_INDEX_DIR_CREATE_FAILED,
+ "%s/%s: Failed to "
+ "create",
+ priv->index_basepath, subdir);
+ } else if (ret == -2) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOTDIR,
+ INDEX_MSG_INDEX_DIR_CREATE_FAILED,
+ "%s/%s: Failed to "
+ "create, path exists, not a directory ",
+ priv->index_basepath, subdir);
+ }
+ return ret;
}
void
-index_get_index (index_priv_t *priv, uuid_t index)
+index_get_index(index_priv_t *priv, uuid_t index)
{
- LOCK (&priv->lock);
- {
- gf_uuid_copy (index, priv->index);
- }
- UNLOCK (&priv->lock);
+ LOCK(&priv->lock);
+ {
+ gf_uuid_copy(index, priv->index);
+ }
+ UNLOCK(&priv->lock);
}
void
-index_generate_index (index_priv_t *priv, uuid_t index)
+index_generate_index(index_priv_t *priv, uuid_t index)
{
- LOCK (&priv->lock);
- {
- //To prevent duplicate generates.
- //This method fails if number of contending threads is greater
- //than MAX_LINK count of the fs
- if (!gf_uuid_compare (priv->index, index))
- gf_uuid_generate (priv->index);
- gf_uuid_copy (index, priv->index);
- }
- UNLOCK (&priv->lock);
+ LOCK(&priv->lock);
+ {
+ // To prevent duplicate generates.
+ // This method fails if number of contending threads is greater
+ // than MAX_LINK count of the fs
+ if (!gf_uuid_compare(priv->index, index))
+ gf_uuid_generate(priv->index);
+ gf_uuid_copy(index, priv->index);
+ }
+ UNLOCK(&priv->lock);
}
static void
-make_index_path (char *base, const char *subdir, uuid_t index,
- char *index_path, size_t len)
+make_index_path(char *base, const char *subdir, uuid_t index, char *index_path,
+ size_t len)
{
- make_index_dir_path (base, subdir, index_path, len);
- snprintf (index_path + strlen (index_path), len - strlen (index_path),
- "/%s-%s", subdir, uuid_utoa (index));
+ make_index_dir_path(base, subdir, index_path, len);
+ snprintf(index_path + strlen(index_path), len - strlen(index_path),
+ "/%s-%s", subdir, uuid_utoa(index));
}
static void
-make_gfid_path (char *base, const char *subdir, uuid_t gfid,
- char *gfid_path, size_t len)
+make_gfid_path(char *base, const char *subdir, uuid_t gfid, char *gfid_path,
+ size_t len)
{
- make_index_dir_path (base, subdir, gfid_path, len);
- snprintf (gfid_path + strlen (gfid_path), len - strlen (gfid_path),
- "/%s", uuid_utoa (gfid));
+ make_index_dir_path(base, subdir, gfid_path, len);
+ snprintf(gfid_path + strlen(gfid_path), len - strlen(gfid_path), "/%s",
+ uuid_utoa(gfid));
}
static void
-make_file_path (char *base, const char *subdir, const char *filename,
- char *file_path, size_t len)
+make_file_path(char *base, const char *subdir, const char *filename,
+ char *file_path, size_t len)
{
- make_index_dir_path (base, subdir, file_path, len);
- snprintf (file_path + strlen (file_path), len - strlen (file_path),
- "/%s", filename);
+ make_index_dir_path(base, subdir, file_path, len);
+ snprintf(file_path + strlen(file_path), len - strlen(file_path), "/%s",
+ filename);
}
static int
-is_index_file_current (char *filename, uuid_t priv_index, char *subdir)
+is_index_file_current(char *filename, uuid_t priv_index, char *subdir)
{
- char current_index[GF_UUID_BUF_SIZE + 16] = {0, };
+ char current_index[GF_UUID_BUF_SIZE + 16] = {
+ 0,
+ };
- snprintf (current_index, sizeof current_index,
- "%s-%s", subdir, uuid_utoa(priv_index));
- return (!strcmp(filename, current_index));
+ snprintf(current_index, sizeof current_index, "%s-%s", subdir,
+ uuid_utoa(priv_index));
+ return (!strcmp(filename, current_index));
}
static void
-check_delete_stale_index_file (xlator_t *this, char *filename, char *subdir)
+check_delete_stale_index_file(xlator_t *this, char *filename, char *subdir)
{
- int ret = 0;
- struct stat st = {0};
- char filepath[PATH_MAX] = {0};
- index_priv_t *priv = NULL;
+ int ret = 0;
+ struct stat st = {0};
+ char filepath[PATH_MAX] = {0};
+ index_priv_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- if (is_index_file_current (filename, priv->index, subdir))
- return;
+ if (is_index_file_current(filename, priv->index, subdir))
+ return;
- make_file_path (priv->index_basepath, subdir,
- filename, filepath, sizeof (filepath));
- ret = sys_stat (filepath, &st);
- if (!ret && st.st_nlink == 1)
- sys_unlink (filepath);
+ make_file_path(priv->index_basepath, subdir, filename, filepath,
+ sizeof(filepath));
+ ret = sys_stat(filepath, &st);
+ if (!ret && st.st_nlink == 1)
+ sys_unlink(filepath);
}
static void
-index_set_link_count (index_priv_t *priv, int64_t count,
- index_xattrop_type_t type)
+index_set_link_count(index_priv_t *priv, int64_t count,
+ index_xattrop_type_t type)
{
- switch (type) {
+ switch (type) {
case XATTROP:
- LOCK (&priv->lock);
- {
- priv->pending_count = count;
- }
- UNLOCK (&priv->lock);
- break;
+ LOCK(&priv->lock);
+ {
+ priv->pending_count = count;
+ }
+ UNLOCK(&priv->lock);
+ break;
default:
- break;
- }
+ break;
+ }
}
static void
-index_get_link_count (index_priv_t *priv, int64_t *count,
- index_xattrop_type_t type)
+index_get_link_count(index_priv_t *priv, int64_t *count,
+ index_xattrop_type_t type)
{
- switch (type) {
+ switch (type) {
case XATTROP:
- LOCK (&priv->lock);
- {
- *count = priv->pending_count;
- }
- UNLOCK (&priv->lock);
- break;
+ LOCK(&priv->lock);
+ {
+ *count = priv->pending_count;
+ }
+ UNLOCK(&priv->lock);
+ break;
default:
- break;
- }
+ break;
+ }
}
static void
-index_dec_link_count (index_priv_t *priv, index_xattrop_type_t type)
+index_dec_link_count(index_priv_t *priv, index_xattrop_type_t type)
{
- switch (type) {
+ switch (type) {
case XATTROP:
- LOCK (&priv->lock);
- {
- priv->pending_count--;
- if (priv->pending_count == 0)
- priv->pending_count--;
- }
- UNLOCK (&priv->lock);
- break;
+ LOCK(&priv->lock);
+ {
+ priv->pending_count--;
+ if (priv->pending_count == 0)
+ priv->pending_count--;
+ }
+ UNLOCK(&priv->lock);
+ break;
default:
- break;
- }
+ break;
+ }
}
-char*
-index_get_subdir_from_type (index_xattrop_type_t type)
+char *
+index_get_subdir_from_type(index_xattrop_type_t type)
{
- if (type < XATTROP || type >= XATTROP_TYPE_END)
- return NULL;
- return index_subdirs[type];
+ if (type < XATTROP || type >= XATTROP_TYPE_END)
+ return NULL;
+ return index_subdirs[type];
}
-char*
-index_get_subdir_from_vgfid (index_priv_t *priv, uuid_t vgfid)
+char *
+index_get_subdir_from_vgfid(index_priv_t *priv, uuid_t vgfid)
{
- return index_get_subdir_from_type (index_get_type_from_vgfid (priv,
- vgfid));
+ return index_get_subdir_from_type(index_get_type_from_vgfid(priv, vgfid));
}
static int
-index_fill_readdir (fd_t *fd, index_fd_ctx_t *fctx, DIR *dir, off_t off,
- size_t size, gf_dirent_t *entries)
-{
- off_t in_case = -1;
- off_t last_off = 0;
- size_t filled = 0;
- int count = 0;
- struct dirent *entry = NULL;
- struct dirent scratch[2] = {{0,},};
- int32_t this_size = -1;
- gf_dirent_t *this_entry = NULL;
- xlator_t *this = NULL;
-
- this = THIS;
- if (!off) {
- rewinddir (dir);
- } else {
- seekdir (dir, off);
+index_fill_readdir(fd_t *fd, index_fd_ctx_t *fctx, DIR *dir, off_t off,
+ size_t size, gf_dirent_t *entries)
+{
+ off_t in_case = -1;
+ off_t last_off = 0;
+ size_t filled = 0;
+ int count = 0;
+ struct dirent *entry = NULL;
+ struct dirent scratch[2] = {
+ {
+ 0,
+ },
+ };
+ int32_t this_size = -1;
+ gf_dirent_t *this_entry = NULL;
+ xlator_t *this = NULL;
+
+ this = THIS;
+ if (!off) {
+ rewinddir(dir);
+ } else {
+ seekdir(dir, off);
#ifndef GF_LINUX_HOST_OS
- if ((u_long)telldir(dir) != off && off != fctx->dir_eof) {
- gf_msg (THIS->name, GF_LOG_ERROR, EINVAL,
- INDEX_MSG_INDEX_READDIR_FAILED,
- "seekdir(0x%llx) failed on dir=%p: "
- "Invalid argument (offset reused from "
- "another DIR * structure?)", off, dir);
- errno = EINVAL;
- count = -1;
- goto out;
- }
-#endif /* GF_LINUX_HOST_OS */
+ if ((u_long)telldir(dir) != off && off != fctx->dir_eof) {
+ gf_msg(THIS->name, GF_LOG_ERROR, EINVAL,
+ INDEX_MSG_INDEX_READDIR_FAILED,
+ "seekdir(0x%llx) failed on dir=%p: "
+ "Invalid argument (offset reused from "
+ "another DIR * structure?)",
+ off, dir);
+ errno = EINVAL;
+ count = -1;
+ goto out;
}
+#endif /* GF_LINUX_HOST_OS */
+ }
- while (filled <= size) {
- in_case = (u_long)telldir (dir);
+ while (filled <= size) {
+ in_case = (u_long)telldir(dir);
- if (in_case == -1) {
- gf_msg (THIS->name, GF_LOG_ERROR, errno,
- INDEX_MSG_INDEX_READDIR_FAILED,
- "telldir failed on dir=%p", dir);
- goto out;
- }
+ if (in_case == -1) {
+ gf_msg(THIS->name, GF_LOG_ERROR, errno,
+ INDEX_MSG_INDEX_READDIR_FAILED, "telldir failed on dir=%p",
+ dir);
+ goto out;
+ }
- errno = 0;
- entry = sys_readdir (dir, scratch);
- if (!entry || errno != 0) {
- if (errno == EBADF) {
- gf_msg (THIS->name, GF_LOG_WARNING, errno,
- INDEX_MSG_INDEX_READDIR_FAILED,
- "readdir failed on dir=%p", dir);
- goto out;
- }
- break;
- }
+ errno = 0;
+ entry = sys_readdir(dir, scratch);
+ if (!entry || errno != 0) {
+ if (errno == EBADF) {
+ gf_msg(THIS->name, GF_LOG_WARNING, errno,
+ INDEX_MSG_INDEX_READDIR_FAILED,
+ "readdir failed on dir=%p", dir);
+ goto out;
+ }
+ break;
+ }
- if (!strncmp (entry->d_name, XATTROP_SUBDIR"-",
- strlen (XATTROP_SUBDIR"-"))) {
- check_delete_stale_index_file (this, entry->d_name,
- XATTROP_SUBDIR);
- continue;
- } else if (!strncmp (entry->d_name, DIRTY_SUBDIR"-",
- strlen (DIRTY_SUBDIR"-"))) {
- check_delete_stale_index_file (this, entry->d_name,
- DIRTY_SUBDIR);
- continue;
- }
+ if (!strncmp(entry->d_name, XATTROP_SUBDIR "-",
+ strlen(XATTROP_SUBDIR "-"))) {
+ check_delete_stale_index_file(this, entry->d_name, XATTROP_SUBDIR);
+ continue;
+ } else if (!strncmp(entry->d_name, DIRTY_SUBDIR "-",
+ strlen(DIRTY_SUBDIR "-"))) {
+ check_delete_stale_index_file(this, entry->d_name, DIRTY_SUBDIR);
+ continue;
+ }
- this_size = max (sizeof (gf_dirent_t),
- sizeof (gfs3_dirplist))
- + strlen (entry->d_name) + 1;
+ this_size = max(sizeof(gf_dirent_t), sizeof(gfs3_dirplist)) +
+ strlen(entry->d_name) + 1;
- if (this_size + filled > size) {
- seekdir (dir, in_case);
+ if (this_size + filled > size) {
+ seekdir(dir, in_case);
#ifndef GF_LINUX_HOST_OS
- if ((u_long)telldir(dir) != in_case &&
- in_case != fctx->dir_eof) {
- gf_msg (THIS->name, GF_LOG_ERROR, EINVAL,
- INDEX_MSG_INDEX_READDIR_FAILED,
- "seekdir(0x%llx) failed on dir=%p: "
- "Invalid argument (offset reused from "
- "another DIR * structure?)",
- in_case, dir);
- errno = EINVAL;
- count = -1;
- goto out;
- }
+ if ((u_long)telldir(dir) != in_case && in_case != fctx->dir_eof) {
+ gf_msg(THIS->name, GF_LOG_ERROR, EINVAL,
+ INDEX_MSG_INDEX_READDIR_FAILED,
+ "seekdir(0x%llx) failed on dir=%p: "
+ "Invalid argument (offset reused from "
+ "another DIR * structure?)",
+ in_case, dir);
+ errno = EINVAL;
+ count = -1;
+ goto out;
+ }
#endif /* GF_LINUX_HOST_OS */
- break;
- }
+ break;
+ }
- this_entry = gf_dirent_for_name (entry->d_name);
+ this_entry = gf_dirent_for_name(entry->d_name);
- if (!this_entry) {
- gf_msg (THIS->name, GF_LOG_ERROR, errno,
- INDEX_MSG_INDEX_READDIR_FAILED,
- "could not create gf_dirent for entry %s",
- entry->d_name);
- goto out;
- }
- /*
- * we store the offset of next entry here, which is
- * probably not intended, but code using syncop_readdir()
- * (glfs-heal.c, afr-self-heald.c, pump.c) rely on it
- * for directory read resumption.
- */
- last_off = (u_long)telldir(dir);
- this_entry->d_off = last_off;
- this_entry->d_ino = entry->d_ino;
-
- list_add_tail (&this_entry->list, &entries->list);
-
- filled += this_size;
- count ++;
+ if (!this_entry) {
+ gf_msg(THIS->name, GF_LOG_ERROR, errno,
+ INDEX_MSG_INDEX_READDIR_FAILED,
+ "could not create gf_dirent for entry %s", entry->d_name);
+ goto out;
}
+ /*
+ * we store the offset of next entry here, which is
+ * probably not intended, but code using syncop_readdir()
+ * (glfs-heal.c, afr-self-heald.c, pump.c) rely on it
+ * for directory read resumption.
+ */
+ last_off = (u_long)telldir(dir);
+ this_entry->d_off = last_off;
+ this_entry->d_ino = entry->d_ino;
- errno = 0;
+ list_add_tail(&this_entry->list, &entries->list);
- if ((!sys_readdir (dir, scratch) && (errno == 0))) {
- /* Indicate EOF */
- errno = ENOENT;
- /* Remember EOF offset for later detection */
- fctx->dir_eof = last_off;
- }
+ filled += this_size;
+ count++;
+ }
+
+ errno = 0;
+
+ if ((!sys_readdir(dir, scratch) && (errno == 0))) {
+ /* Indicate EOF */
+ errno = ENOENT;
+ /* Remember EOF offset for later detection */
+ fctx->dir_eof = last_off;
+ }
out:
- return count;
+ return count;
}
int
-index_link_to_base (xlator_t *this, char *fpath, const char *subdir)
-{
- int ret = 0;
- int fd = 0;
- int op_errno = 0;
- uuid_t index = {0};
- index_priv_t *priv = this->private;
- char base[PATH_MAX] = {0};
-
- index_get_index (priv, index);
- make_index_path (priv->index_basepath, subdir,
- index, base, sizeof (base));
-
- ret = sys_link (base, fpath);
- if (!ret || (errno == EEXIST)) {
- ret = 0;
- goto out;
- }
-
- op_errno = errno;
- if (op_errno == ENOENT) {
- ret = index_dir_create (this, subdir);
- if (ret) {
- op_errno = errno;
- goto out;
- }
- } else if (op_errno == EMLINK) {
- index_generate_index (priv, index);
- make_index_path (priv->index_basepath, subdir,
- index, base, sizeof (base));
- } else {
- goto out;
- }
+index_link_to_base(xlator_t *this, char *fpath, const char *subdir)
+{
+ int ret = 0;
+ int fd = 0;
+ int op_errno = 0;
+ uuid_t index = {0};
+ index_priv_t *priv = this->private;
+ char base[PATH_MAX] = {0};
- op_errno = 0;
- fd = sys_creat (base, 0);
- if ((fd < 0) && (errno != EEXIST)) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- INDEX_MSG_INDEX_ADD_FAILED, "%s: Not able to "
- "create index", fpath);
- goto out;
- }
+ index_get_index(priv, index);
+ make_index_path(priv->index_basepath, subdir, index, base, sizeof(base));
- if (fd >= 0)
- sys_close (fd);
+ ret = sys_link(base, fpath);
+ if (!ret || (errno == EEXIST)) {
+ ret = 0;
+ goto out;
+ }
- ret = sys_link (base, fpath);
- if (ret && (errno != EEXIST)) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- INDEX_MSG_INDEX_ADD_FAILED, "%s: Not able to "
- "add to index", fpath);
- goto out;
- }
+ op_errno = errno;
+ if (op_errno == ENOENT) {
+ ret = index_dir_create(this, subdir);
+ if (ret) {
+ op_errno = errno;
+ goto out;
+ }
+ } else if (op_errno == EMLINK) {
+ index_generate_index(priv, index);
+ make_index_path(priv->index_basepath, subdir, index, base,
+ sizeof(base));
+ } else {
+ goto out;
+ }
+
+ op_errno = 0;
+ fd = sys_creat(base, 0);
+ if ((fd < 0) && (errno != EEXIST)) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, INDEX_MSG_INDEX_ADD_FAILED,
+ "%s: Not able to "
+ "create index",
+ fpath);
+ goto out;
+ }
+
+ if (fd >= 0)
+ sys_close(fd);
+
+ ret = sys_link(base, fpath);
+ if (ret && (errno != EEXIST)) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, INDEX_MSG_INDEX_ADD_FAILED,
+ "%s: Not able to "
+ "add to index",
+ fpath);
+ goto out;
+ }
out:
- return -op_errno;
+ return -op_errno;
}
int
-index_add (xlator_t *this, uuid_t gfid, const char *subdir,
- index_xattrop_type_t type)
+index_add(xlator_t *this, uuid_t gfid, const char *subdir,
+ index_xattrop_type_t type)
{
- char gfid_path[PATH_MAX] = {0};
- int ret = -1;
- index_priv_t *priv = NULL;
- struct stat st = {0};
+ char gfid_path[PATH_MAX] = {0};
+ int ret = -1;
+ index_priv_t *priv = NULL;
+ struct stat st = {0};
- priv = this->private;
+ priv = this->private;
- if (gf_uuid_is_null (gfid)) {
- GF_ASSERT (0);
- goto out;
- }
+ if (gf_uuid_is_null(gfid)) {
+ GF_ASSERT(0);
+ goto out;
+ }
- make_gfid_path (priv->index_basepath, subdir, gfid,
- gfid_path, sizeof (gfid_path));
+ make_gfid_path(priv->index_basepath, subdir, gfid, gfid_path,
+ sizeof(gfid_path));
- ret = sys_stat (gfid_path, &st);
- if (!ret)
- goto out;
- ret = index_link_to_base (this, gfid_path, subdir);
+ ret = sys_stat(gfid_path, &st);
+ if (!ret)
+ goto out;
+ ret = index_link_to_base(this, gfid_path, subdir);
out:
- return ret;
+ return ret;
}
int
-index_del (xlator_t *this, uuid_t gfid, const char *subdir, int type)
-{
- int32_t op_errno __attribute__((unused)) = 0;
- index_priv_t *priv = NULL;
- int ret = 0;
- char gfid_path[PATH_MAX] = {0};
- char rename_dst[PATH_MAX] = {0,};
- uuid_t uuid;
-
- priv = this->private;
- GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, !gf_uuid_is_null (gfid),
- out, op_errno, EINVAL);
- make_gfid_path (priv->index_basepath, subdir, gfid,
- gfid_path, sizeof (gfid_path));
-
- if ((strcmp (subdir, ENTRY_CHANGES_SUBDIR)) == 0) {
- ret = sys_rmdir (gfid_path);
- /* rmdir above could fail with ENOTEMPTY if the indices under
- * it were created when granular-entry-heal was enabled, whereas
- * the actual heal that happened was non-granular (or full) in
- * nature, resulting in name indices getting left out. To
- * clean up this directory without it affecting the IO path perf,
- * the directory is renamed to a unique name under
- * indices/entry-changes. Self-heal will pick up this entry
- * during crawl and on lookup into the file system figure that
- * the index is stale and subsequently wipe it out using rmdir().
- */
- if ((ret) && (errno == ENOTEMPTY)) {
- gf_uuid_generate (uuid);
- make_gfid_path (priv->index_basepath, subdir, uuid,
- rename_dst, sizeof (rename_dst));
- ret = sys_rename (gfid_path, rename_dst);
- }
- } else {
- ret = sys_unlink (gfid_path);
- }
-
- if (ret && (errno != ENOENT)) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- INDEX_MSG_INDEX_DEL_FAILED, "%s: failed to delete"
- " from index", gfid_path);
- ret = -errno;
- goto out;
- }
-
- index_dec_link_count (priv, type);
- ret = 0;
+index_del(xlator_t *this, uuid_t gfid, const char *subdir, int type)
+{
+ int32_t op_errno __attribute__((unused)) = 0;
+ index_priv_t *priv = NULL;
+ int ret = 0;
+ char gfid_path[PATH_MAX] = {0};
+ char rename_dst[PATH_MAX] = {
+ 0,
+ };
+ uuid_t uuid;
+
+ priv = this->private;
+ GF_ASSERT_AND_GOTO_WITH_ERROR(this->name, !gf_uuid_is_null(gfid), out,
+ op_errno, EINVAL);
+ make_gfid_path(priv->index_basepath, subdir, gfid, gfid_path,
+ sizeof(gfid_path));
+
+ if ((strcmp(subdir, ENTRY_CHANGES_SUBDIR)) == 0) {
+ ret = sys_rmdir(gfid_path);
+ /* rmdir above could fail with ENOTEMPTY if the indices under
+ * it were created when granular-entry-heal was enabled, whereas
+ * the actual heal that happened was non-granular (or full) in
+ * nature, resulting in name indices getting left out. To
+ * clean up this directory without it affecting the IO path perf,
+ * the directory is renamed to a unique name under
+ * indices/entry-changes. Self-heal will pick up this entry
+ * during crawl and on lookup into the file system figure that
+ * the index is stale and subsequently wipe it out using rmdir().
+ */
+ if ((ret) && (errno == ENOTEMPTY)) {
+ gf_uuid_generate(uuid);
+ make_gfid_path(priv->index_basepath, subdir, uuid, rename_dst,
+ sizeof(rename_dst));
+ ret = sys_rename(gfid_path, rename_dst);
+ }
+ } else {
+ ret = sys_unlink(gfid_path);
+ }
+
+ if (ret && (errno != ENOENT)) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, INDEX_MSG_INDEX_DEL_FAILED,
+ "%s: failed to delete"
+ " from index",
+ gfid_path);
+ ret = -errno;
+ goto out;
+ }
+
+ index_dec_link_count(priv, type);
+ ret = 0;
out:
- return ret;
+ return ret;
}
static gf_boolean_t
-_is_xattr_in_watchlist (dict_t *d, char *k, data_t *v, void *tmp)
+_is_xattr_in_watchlist(dict_t *d, char *k, data_t *v, void *tmp)
{
- if (!strncmp (k, tmp, strlen (k)))
- return _gf_true;
+ if (!strncmp(k, tmp, strlen(k)))
+ return _gf_true;
- return _gf_false;
+ return _gf_false;
}
static gf_boolean_t
-is_xattr_in_watchlist (dict_t *this, char *key, data_t *value, void *matchdata)
+is_xattr_in_watchlist(dict_t *this, char *key, data_t *value, void *matchdata)
{
- int ret = -1;
+ int ret = -1;
- //matchdata is a list of xattrs
- //key is strncmp'ed with each xattr in matchdata.
- //ret will be 0 if key pattern is not present in the matchdata
- //else ret will be count number of xattrs the key pattern-matches with.
- ret = dict_foreach_match (matchdata, _is_xattr_in_watchlist, key,
- dict_null_foreach_fn, NULL);
+ // matchdata is a list of xattrs
+ // key is strncmp'ed with each xattr in matchdata.
+ // ret will be 0 if key pattern is not present in the matchdata
+ // else ret will be count number of xattrs the key pattern-matches with.
+ ret = dict_foreach_match(matchdata, _is_xattr_in_watchlist, key,
+ dict_null_foreach_fn, NULL);
- if (ret > 0)
- return _gf_true;
- return _gf_false;
+ if (ret > 0)
+ return _gf_true;
+ return _gf_false;
}
static int
-index_find_xattr_type (dict_t *d, char *k, data_t *v)
+index_find_xattr_type(dict_t *d, char *k, data_t *v)
{
- int idx = -1;
- index_priv_t *priv = THIS->private;
+ int idx = -1;
+ index_priv_t *priv = THIS->private;
- if (priv->dirty_watchlist && is_xattr_in_watchlist (d, k, v,
- priv->dirty_watchlist))
- idx = DIRTY;
- else if (priv->pending_watchlist && is_xattr_in_watchlist (d, k, v,
- priv->pending_watchlist))
- idx = XATTROP;
+ if (priv->dirty_watchlist &&
+ is_xattr_in_watchlist(d, k, v, priv->dirty_watchlist))
+ idx = DIRTY;
+ else if (priv->pending_watchlist &&
+ is_xattr_in_watchlist(d, k, v, priv->pending_watchlist))
+ idx = XATTROP;
- return idx;
+ return idx;
}
int
-index_fill_zero_array (dict_t *d, char *k, data_t *v, void *adata)
+index_fill_zero_array(dict_t *d, char *k, data_t *v, void *adata)
{
- int idx = -1;
- int *zfilled = adata;
- //zfilled array contains `state` for all types xattrs.
- //state : whether the gfid file of this file exists in
- //corresponding xattr directory or not.
+ int idx = -1;
+ int *zfilled = adata;
+ // zfilled array contains `state` for all types xattrs.
+ // state : whether the gfid file of this file exists in
+ // corresponding xattr directory or not.
- idx = index_find_xattr_type (d, k, v);
- if (idx == -1)
- return 0;
- zfilled[idx] = 0;
+ idx = index_find_xattr_type(d, k, v);
+ if (idx == -1)
return 0;
+ zfilled[idx] = 0;
+ return 0;
}
static int
-_check_key_is_zero_filled (dict_t *d, char *k, data_t *v,
- void *tmp)
+_check_key_is_zero_filled(dict_t *d, char *k, data_t *v, void *tmp)
{
- int *zfilled = tmp;
- int idx = -1;
-
- idx = index_find_xattr_type (d, k, v);
- if (idx == -1)
- return 0;
+ int *zfilled = tmp;
+ int idx = -1;
- /* Along with checking that the value of a key is zero filled
- * the key's corresponding index should be assigned
- * appropriate value.
- * zfilled[idx] will be 0(false) if value not zero.
- * will be 1(true) if value is zero.
- */
- if (mem_0filled ((const char*)v->data, v->len)) {
- zfilled[idx] = 0;
- return 0;
- }
+ idx = index_find_xattr_type(d, k, v);
+ if (idx == -1)
+ return 0;
- /* If zfilled[idx] was previously 0, it means at least
- * one xattr of its "kind" is non-zero. Keep its value
- * the same.
- */
- if (zfilled[idx])
- zfilled[idx] = 1;
+ /* Along with checking that the value of a key is zero filled
+ * the key's corresponding index should be assigned
+ * appropriate value.
+ * zfilled[idx] will be 0(false) if value not zero.
+ * will be 1(true) if value is zero.
+ */
+ if (mem_0filled((const char *)v->data, v->len)) {
+ zfilled[idx] = 0;
return 0;
+ }
+
+ /* If zfilled[idx] was previously 0, it means at least
+ * one xattr of its "kind" is non-zero. Keep its value
+ * the same.
+ */
+ if (zfilled[idx])
+ zfilled[idx] = 1;
+ return 0;
}
int
-index_entry_create (xlator_t *this, inode_t *inode, char *filename)
-{
- int ret = -1;
- int op_errno = 0;
- char pgfid_path[PATH_MAX] = {0};
- char entry_path[PATH_MAX] = {0};
- index_priv_t *priv = NULL;
- index_inode_ctx_t *ctx = NULL;
- int32_t len = 0;
-
- priv = this->private;
-
- GF_ASSERT_AND_GOTO_WITH_ERROR (this->name,
- !gf_uuid_is_null (inode->gfid), out,
- op_errno, EINVAL);
- GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, filename, out, op_errno,
- EINVAL);
-
- ret = index_inode_ctx_get (inode, this, &ctx);
- if (ret) {
- op_errno = EINVAL;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- INDEX_MSG_INODE_CTX_GET_SET_FAILED,
- "Not able to get inode ctx for %s",
- uuid_utoa (inode->gfid));
- goto out;
- }
-
- make_gfid_path (priv->index_basepath, ENTRY_CHANGES_SUBDIR,
- inode->gfid, pgfid_path, sizeof (pgfid_path));
-
- if (ctx->state[ENTRY_CHANGES] != IN) {
- ret = sys_mkdir (pgfid_path, 0600);
- if (ret != 0 && errno != EEXIST) {
- op_errno = errno;
- goto out;
- }
- ctx->state[ENTRY_CHANGES] = IN;
- }
-
- len = snprintf (entry_path, sizeof(entry_path), "%s/%s", pgfid_path,
- filename);
- if ((len < 0) || (len >= sizeof(entry_path))) {
- op_errno = EINVAL;
- goto out;
- }
-
- op_errno = 0;
-
- ret = index_link_to_base (this, entry_path, ENTRY_CHANGES_SUBDIR);
+index_entry_create(xlator_t *this, inode_t *inode, char *filename)
+{
+ int ret = -1;
+ int op_errno = 0;
+ char pgfid_path[PATH_MAX] = {0};
+ char entry_path[PATH_MAX] = {0};
+ index_priv_t *priv = NULL;
+ index_inode_ctx_t *ctx = NULL;
+ int32_t len = 0;
+
+ priv = this->private;
+
+ GF_ASSERT_AND_GOTO_WITH_ERROR(this->name, !gf_uuid_is_null(inode->gfid),
+ out, op_errno, EINVAL);
+ GF_ASSERT_AND_GOTO_WITH_ERROR(this->name, filename, out, op_errno, EINVAL);
+
+ ret = index_inode_ctx_get(inode, this, &ctx);
+ if (ret) {
+ op_errno = EINVAL;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno,
+ INDEX_MSG_INODE_CTX_GET_SET_FAILED,
+ "Not able to get inode ctx for %s", uuid_utoa(inode->gfid));
+ goto out;
+ }
+
+ make_gfid_path(priv->index_basepath, ENTRY_CHANGES_SUBDIR, inode->gfid,
+ pgfid_path, sizeof(pgfid_path));
+
+ if (ctx->state[ENTRY_CHANGES] != IN) {
+ ret = sys_mkdir(pgfid_path, 0600);
+ if (ret != 0 && errno != EEXIST) {
+ op_errno = errno;
+ goto out;
+ }
+ ctx->state[ENTRY_CHANGES] = IN;
+ }
+
+ len = snprintf(entry_path, sizeof(entry_path), "%s/%s", pgfid_path,
+ filename);
+ if ((len < 0) || (len >= sizeof(entry_path))) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ op_errno = 0;
+
+ ret = index_link_to_base(this, entry_path, ENTRY_CHANGES_SUBDIR);
out:
- if (op_errno)
- ret = -op_errno;
- return ret;
+ if (op_errno)
+ ret = -op_errno;
+ return ret;
}
int
-index_entry_delete (xlator_t *this, uuid_t pgfid, char *filename)
-{
- int ret = 0;
- int op_errno = 0;
- char pgfid_path[PATH_MAX] = {0};
- char entry_path[PATH_MAX] = {0};
- index_priv_t *priv = NULL;
- int32_t len = 0;
-
- priv = this->private;
-
- GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, !gf_uuid_is_null (pgfid),
- out, op_errno, EINVAL);
- GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, filename, out, op_errno,
- EINVAL);
-
- make_gfid_path (priv->index_basepath, ENTRY_CHANGES_SUBDIR, pgfid,
- pgfid_path, sizeof (pgfid_path));
- len = snprintf (entry_path, sizeof(entry_path), "%s/%s", pgfid_path,
- filename);
- if ((len < 0) || (len >= sizeof(entry_path))) {
- op_errno = EINVAL;
- goto out;
- }
-
- ret = sys_unlink (entry_path);
- if (ret && (errno != ENOENT)) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- INDEX_MSG_INDEX_DEL_FAILED,
- "%s: failed to delete from index/entry-changes",
- entry_path);
- }
+index_entry_delete(xlator_t *this, uuid_t pgfid, char *filename)
+{
+ int ret = 0;
+ int op_errno = 0;
+ char pgfid_path[PATH_MAX] = {0};
+ char entry_path[PATH_MAX] = {0};
+ index_priv_t *priv = NULL;
+ int32_t len = 0;
+
+ priv = this->private;
+
+ GF_ASSERT_AND_GOTO_WITH_ERROR(this->name, !gf_uuid_is_null(pgfid), out,
+ op_errno, EINVAL);
+ GF_ASSERT_AND_GOTO_WITH_ERROR(this->name, filename, out, op_errno, EINVAL);
+
+ make_gfid_path(priv->index_basepath, ENTRY_CHANGES_SUBDIR, pgfid,
+ pgfid_path, sizeof(pgfid_path));
+ len = snprintf(entry_path, sizeof(entry_path), "%s/%s", pgfid_path,
+ filename);
+ if ((len < 0) || (len >= sizeof(entry_path))) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ ret = sys_unlink(entry_path);
+ if (ret && (errno != ENOENT)) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, INDEX_MSG_INDEX_DEL_FAILED,
+ "%s: failed to delete from index/entry-changes", entry_path);
+ }
out:
- return -op_errno;
+ return -op_errno;
}
int
-index_entry_action (xlator_t *this, inode_t *inode, dict_t *xdata, char *key)
+index_entry_action(xlator_t *this, inode_t *inode, dict_t *xdata, char *key)
{
- int ret = 0;
- char *filename = NULL;
+ int ret = 0;
+ char *filename = NULL;
- ret = dict_get_str (xdata, key, &filename);
- if (ret != 0) {
- ret = 0;
- goto out;
- }
+ ret = dict_get_str(xdata, key, &filename);
+ if (ret != 0) {
+ ret = 0;
+ goto out;
+ }
- if (strcmp (key, GF_XATTROP_ENTRY_IN_KEY) == 0)
- ret = index_entry_create (this, inode, filename);
- else if (strcmp (key, GF_XATTROP_ENTRY_OUT_KEY) == 0)
- ret = index_entry_delete (this, inode->gfid, filename);
+ if (strcmp(key, GF_XATTROP_ENTRY_IN_KEY) == 0)
+ ret = index_entry_create(this, inode, filename);
+ else if (strcmp(key, GF_XATTROP_ENTRY_OUT_KEY) == 0)
+ ret = index_entry_delete(this, inode->gfid, filename);
out:
- return ret;
+ return ret;
}
void
-_index_action (xlator_t *this, inode_t *inode, int *zfilled)
-{
- int ret = 0;
- int i = 0;
- index_inode_ctx_t *ctx = NULL;
- char *subdir = NULL;
-
- ret = index_inode_ctx_get (inode, this, &ctx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- INDEX_MSG_INODE_CTX_GET_SET_FAILED, "Not able to get"
- " inode context for %s.", uuid_utoa (inode->gfid));
- goto out;
- }
-
- for (i = 0; i < XATTROP_TYPE_END; i++) {
- subdir = index_get_subdir_from_type (i);
- if (zfilled[i] == 1) {
- if (ctx->state[i] == NOTIN)
- continue;
- ret = index_del (this, inode->gfid, subdir, i);
- if (!ret)
- ctx->state[i] = NOTIN;
- } else if (zfilled[i] == 0){
- if (ctx->state[i] == IN)
- continue;
- ret = index_add (this, inode->gfid, subdir, i);
- if (!ret)
- ctx->state[i] = IN;
- }
- }
+_index_action(xlator_t *this, inode_t *inode, int *zfilled)
+{
+ int ret = 0;
+ int i = 0;
+ index_inode_ctx_t *ctx = NULL;
+ char *subdir = NULL;
+
+ ret = index_inode_ctx_get(inode, this, &ctx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL,
+ INDEX_MSG_INODE_CTX_GET_SET_FAILED,
+ "Not able to get"
+ " inode context for %s.",
+ uuid_utoa(inode->gfid));
+ goto out;
+ }
+
+ for (i = 0; i < XATTROP_TYPE_END; i++) {
+ subdir = index_get_subdir_from_type(i);
+ if (zfilled[i] == 1) {
+ if (ctx->state[i] == NOTIN)
+ continue;
+ ret = index_del(this, inode->gfid, subdir, i);
+ if (!ret)
+ ctx->state[i] = NOTIN;
+ } else if (zfilled[i] == 0) {
+ if (ctx->state[i] == IN)
+ continue;
+ ret = index_add(this, inode->gfid, subdir, i);
+ if (!ret)
+ ctx->state[i] = IN;
+ }
+ }
out:
- return;
+ return;
}
static void
-index_init_state (xlator_t *this, inode_t *inode, index_inode_ctx_t *ctx,
- char *subdir)
+index_init_state(xlator_t *this, inode_t *inode, index_inode_ctx_t *ctx,
+ char *subdir)
{
- int ret = -1;
- char pgfid_path[PATH_MAX] = {0};
- struct stat st = {0};
- index_priv_t *priv = NULL;
+ int ret = -1;
+ char pgfid_path[PATH_MAX] = {0};
+ struct stat st = {0};
+ index_priv_t *priv = NULL;
- priv = this->private;
+ priv = this->private;
- make_gfid_path (priv->index_basepath, subdir, inode->gfid, pgfid_path,
- sizeof (pgfid_path));
+ make_gfid_path(priv->index_basepath, subdir, inode->gfid, pgfid_path,
+ sizeof(pgfid_path));
- ret = sys_stat (pgfid_path, &st);
- if (ret == 0)
- ctx->state[ENTRY_CHANGES] = IN;
- else if (ret != 0 && errno == ENOENT)
- ctx->state[ENTRY_CHANGES] = NOTIN;
+ ret = sys_stat(pgfid_path, &st);
+ if (ret == 0)
+ ctx->state[ENTRY_CHANGES] = IN;
+ else if (ret != 0 && errno == ENOENT)
+ ctx->state[ENTRY_CHANGES] = NOTIN;
- return;
+ return;
}
void
-xattrop_index_action (xlator_t *this, index_local_t *local, dict_t *xattr,
- dict_match_t match, void *match_data)
-{
- int ret = 0;
- int zfilled[XATTROP_TYPE_END] = {0,};
- int8_t value = 0;
- char *subdir = NULL;
- dict_t *req_xdata = NULL;
- inode_t *inode = NULL;
- index_inode_ctx_t *ctx = NULL;
-
- inode = local->inode;
- req_xdata = local->xdata;
-
- memset (zfilled, -1, sizeof (zfilled));
- ret = dict_foreach_match (xattr, match, match_data,
- _check_key_is_zero_filled, zfilled);
- _index_action (this, inode, zfilled);
-
- if (req_xdata) {
- ret = index_entry_action (this, inode, req_xdata,
- GF_XATTROP_ENTRY_OUT_KEY);
-
- ret = dict_get_int8 (req_xdata, GF_XATTROP_PURGE_INDEX, &value);
- if ((ret) || (value == 0))
- goto out;
- }
-
- if (zfilled[XATTROP] != 1)
- goto out;
-
- if (inode->ia_type != IA_IFDIR)
- goto out;
-
- subdir = index_get_subdir_from_type (ENTRY_CHANGES);
- ret = index_inode_ctx_get (inode, this, &ctx);
- if (ctx->state[ENTRY_CHANGES] == UNKNOWN)
- index_init_state (this, inode, ctx, subdir);
- if (ctx->state[ENTRY_CHANGES] == IN) {
- ret = index_del (this, inode->gfid, subdir,
- ENTRY_CHANGES);
- ctx->state[ENTRY_CHANGES] = NOTIN;
- }
+xattrop_index_action(xlator_t *this, index_local_t *local, dict_t *xattr,
+ dict_match_t match, void *match_data)
+{
+ int ret = 0;
+ int zfilled[XATTROP_TYPE_END] = {
+ 0,
+ };
+ int8_t value = 0;
+ char *subdir = NULL;
+ dict_t *req_xdata = NULL;
+ inode_t *inode = NULL;
+ index_inode_ctx_t *ctx = NULL;
+
+ inode = local->inode;
+ req_xdata = local->xdata;
+
+ memset(zfilled, -1, sizeof(zfilled));
+ ret = dict_foreach_match(xattr, match, match_data,
+ _check_key_is_zero_filled, zfilled);
+ _index_action(this, inode, zfilled);
+
+ if (req_xdata) {
+ ret = index_entry_action(this, inode, req_xdata,
+ GF_XATTROP_ENTRY_OUT_KEY);
+
+ ret = dict_get_int8(req_xdata, GF_XATTROP_PURGE_INDEX, &value);
+ if ((ret) || (value == 0))
+ goto out;
+ }
+
+ if (zfilled[XATTROP] != 1)
+ goto out;
+
+ if (inode->ia_type != IA_IFDIR)
+ goto out;
+
+ subdir = index_get_subdir_from_type(ENTRY_CHANGES);
+ ret = index_inode_ctx_get(inode, this, &ctx);
+ if (ctx->state[ENTRY_CHANGES] == UNKNOWN)
+ index_init_state(this, inode, ctx, subdir);
+ if (ctx->state[ENTRY_CHANGES] == IN) {
+ ret = index_del(this, inode->gfid, subdir, ENTRY_CHANGES);
+ ctx->state[ENTRY_CHANGES] = NOTIN;
+ }
out:
- return;
+ return;
}
static gf_boolean_t
-index_xattrop_track (xlator_t *this, gf_xattrop_flags_t flags, dict_t *dict)
+index_xattrop_track(xlator_t *this, gf_xattrop_flags_t flags, dict_t *dict)
{
- index_priv_t *priv = this->private;
+ index_priv_t *priv = this->private;
- if (flags == GF_XATTROP_ADD_ARRAY)
- return _gf_true;
+ if (flags == GF_XATTROP_ADD_ARRAY)
+ return _gf_true;
- if (flags != GF_XATTROP_ADD_ARRAY64)
- return _gf_false;
+ if (flags != GF_XATTROP_ADD_ARRAY64)
+ return _gf_false;
- if (!priv->pending_watchlist)
- return _gf_false;
+ if (!priv->pending_watchlist)
+ return _gf_false;
- if (dict_foreach_match (dict, is_xattr_in_watchlist,
- priv->pending_watchlist, dict_null_foreach_fn,
- NULL) > 0)
- return _gf_true;
+ if (dict_foreach_match(dict, is_xattr_in_watchlist, priv->pending_watchlist,
+ dict_null_foreach_fn, NULL) > 0)
+ return _gf_true;
- return _gf_false;
+ return _gf_false;
}
int
-index_inode_path (xlator_t *this, inode_t *inode, char *dirpath, size_t len)
-{
- char *subdir = NULL;
- int ret = 0;
- index_priv_t *priv = NULL;
- index_inode_ctx_t *ictx = NULL;
-
- priv = this->private;
- if (!index_is_fop_on_internal_inode (this, inode, NULL)) {
- ret = -EINVAL;
- goto out;
- }
-
- subdir = index_get_subdir_from_vgfid (priv, inode->gfid);
- if (subdir) {
- if (len <= strlen (priv->index_basepath) + 1 /*'/'*/ +
- strlen (subdir)) {
- ret = -EINVAL;
- goto out;
- }
- make_index_dir_path (priv->index_basepath, subdir,
- dirpath, len);
- } else {
- ret = index_inode_ctx_get (inode, this, &ictx);
- if (ret)
- goto out;
- if (gf_uuid_is_null (ictx->virtual_pargfid)) {
- ret = -EINVAL;
- goto out;
- }
- make_index_dir_path (priv->index_basepath, ENTRY_CHANGES_SUBDIR,
- dirpath, len);
- if (len <= strlen (dirpath) + 1 /*'/'*/ + SLEN (UUID0_STR)) {
- ret = -EINVAL;
- goto out;
- }
- strcat (dirpath, "/");
- strcat (dirpath, uuid_utoa (ictx->virtual_pargfid));
- }
+index_inode_path(xlator_t *this, inode_t *inode, char *dirpath, size_t len)
+{
+ char *subdir = NULL;
+ int ret = 0;
+ index_priv_t *priv = NULL;
+ index_inode_ctx_t *ictx = NULL;
+
+ priv = this->private;
+ if (!index_is_fop_on_internal_inode(this, inode, NULL)) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ subdir = index_get_subdir_from_vgfid(priv, inode->gfid);
+ if (subdir) {
+ if (len <= strlen(priv->index_basepath) + 1 /*'/'*/ + strlen(subdir)) {
+ ret = -EINVAL;
+ goto out;
+ }
+ make_index_dir_path(priv->index_basepath, subdir, dirpath, len);
+ } else {
+ ret = index_inode_ctx_get(inode, this, &ictx);
+ if (ret)
+ goto out;
+ if (gf_uuid_is_null(ictx->virtual_pargfid)) {
+ ret = -EINVAL;
+ goto out;
+ }
+ make_index_dir_path(priv->index_basepath, ENTRY_CHANGES_SUBDIR, dirpath,
+ len);
+ if (len <= strlen(dirpath) + 1 /*'/'*/ + SLEN(UUID0_STR)) {
+ ret = -EINVAL;
+ goto out;
+ }
+ strcat(dirpath, "/");
+ strcat(dirpath, uuid_utoa(ictx->virtual_pargfid));
+ }
out:
- return ret;
+ return ret;
}
int
-__index_fd_ctx_get (fd_t *fd, xlator_t *this, index_fd_ctx_t **ctx)
+__index_fd_ctx_get(fd_t *fd, xlator_t *this, index_fd_ctx_t **ctx)
{
- int ret = 0;
- index_fd_ctx_t *fctx = NULL;
- uint64_t tmpctx = 0;
- char dirpath[PATH_MAX] = {0};
-
- ret = __fd_ctx_get (fd, this, &tmpctx);
- if (!ret) {
- fctx = (index_fd_ctx_t*) (long) tmpctx;
- *ctx = fctx;
- goto out;
- }
+ int ret = 0;
+ index_fd_ctx_t *fctx = NULL;
+ uint64_t tmpctx = 0;
+ char dirpath[PATH_MAX] = {0};
- ret = index_inode_path (this, fd->inode, dirpath, sizeof (dirpath));
- if (ret)
- goto out;
-
- fctx = GF_CALLOC (1, sizeof (*fctx), gf_index_fd_ctx_t);
- if (!fctx) {
- ret = -ENOMEM;
- goto out;
- }
-
- fctx->dir = sys_opendir (dirpath);
- if (!fctx->dir) {
- ret = -errno;
- GF_FREE (fctx);
- fctx = NULL;
- goto out;
- }
- fctx->dir_eof = -1;
-
- ret = __fd_ctx_set (fd, this, (uint64_t)(long)fctx);
- if (ret) {
- (void) sys_closedir (fctx->dir);
- GF_FREE (fctx);
- fctx = NULL;
- ret = -EINVAL;
- goto out;
- }
+ ret = __fd_ctx_get(fd, this, &tmpctx);
+ if (!ret) {
+ fctx = (index_fd_ctx_t *)(long)tmpctx;
*ctx = fctx;
+ goto out;
+ }
+
+ ret = index_inode_path(this, fd->inode, dirpath, sizeof(dirpath));
+ if (ret)
+ goto out;
+
+ fctx = GF_CALLOC(1, sizeof(*fctx), gf_index_fd_ctx_t);
+ if (!fctx) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ fctx->dir = sys_opendir(dirpath);
+ if (!fctx->dir) {
+ ret = -errno;
+ GF_FREE(fctx);
+ fctx = NULL;
+ goto out;
+ }
+ fctx->dir_eof = -1;
+
+ ret = __fd_ctx_set(fd, this, (uint64_t)(long)fctx);
+ if (ret) {
+ (void)sys_closedir(fctx->dir);
+ GF_FREE(fctx);
+ fctx = NULL;
+ ret = -EINVAL;
+ goto out;
+ }
+ *ctx = fctx;
out:
- return ret;
+ return ret;
}
int
-index_fd_ctx_get (fd_t *fd, xlator_t *this, index_fd_ctx_t **ctx)
+index_fd_ctx_get(fd_t *fd, xlator_t *this, index_fd_ctx_t **ctx)
{
- int ret = 0;
- LOCK (&fd->lock);
- {
- ret = __index_fd_ctx_get (fd, this, ctx);
- }
- UNLOCK (&fd->lock);
- return ret;
+ int ret = 0;
+ LOCK(&fd->lock);
+ {
+ ret = __index_fd_ctx_get(fd, this, ctx);
+ }
+ UNLOCK(&fd->lock);
+ return ret;
}
-//new - Not NULL means start a fop
-//new - NULL means done processing the fop
+// new - Not NULL means start a fop
+// new - NULL means done processing the fop
void
-index_queue_process (xlator_t *this, inode_t *inode, call_stub_t *new)
+index_queue_process(xlator_t *this, inode_t *inode, call_stub_t *new)
{
- call_stub_t *stub = NULL;
- index_inode_ctx_t *ctx = NULL;
- int ret = 0;
- call_frame_t *frame = NULL;
+ call_stub_t *stub = NULL;
+ index_inode_ctx_t *ctx = NULL;
+ int ret = 0;
+ call_frame_t *frame = NULL;
- LOCK (&inode->lock);
- {
- ret = __index_inode_ctx_get (inode, this, &ctx);
- if (ret)
- goto unlock;
-
- if (new) {
- __index_enqueue (&ctx->callstubs, new);
- new = NULL;
- } else {
- ctx->processing = _gf_false;
- }
+ LOCK(&inode->lock);
+ {
+ ret = __index_inode_ctx_get(inode, this, &ctx);
+ if (ret)
+ goto unlock;
- if (!ctx->processing) {
- stub = __index_dequeue (&ctx->callstubs);
- if (stub)
- ctx->processing = _gf_true;
- else
- ctx->processing = _gf_false;
- }
+ if (new) {
+ __index_enqueue(&ctx->callstubs, new);
+ new = NULL;
+ } else {
+ ctx->processing = _gf_false;
}
+
+ if (!ctx->processing) {
+ stub = __index_dequeue(&ctx->callstubs);
+ if (stub)
+ ctx->processing = _gf_true;
+ else
+ ctx->processing = _gf_false;
+ }
+ }
unlock:
- UNLOCK (&inode->lock);
-
- if (ret && new) {
- frame = new->frame;
- if (new->fop == GF_FOP_XATTROP) {
- INDEX_STACK_UNWIND (xattrop, frame, -1, ENOMEM,
- NULL, NULL);
- } else if (new->fop == GF_FOP_FXATTROP) {
- INDEX_STACK_UNWIND (fxattrop, frame, -1, ENOMEM,
- NULL, NULL);
- }
- call_stub_destroy (new);
- } else if (stub) {
- call_resume (stub);
+ UNLOCK(&inode->lock);
+
+ if (ret && new) {
+ frame = new->frame;
+ if (new->fop == GF_FOP_XATTROP) {
+ INDEX_STACK_UNWIND(xattrop, frame, -1, ENOMEM, NULL, NULL);
+ } else if (new->fop == GF_FOP_FXATTROP) {
+ INDEX_STACK_UNWIND(fxattrop, frame, -1, ENOMEM, NULL, NULL);
}
- return;
+ call_stub_destroy(new);
+ } else if (stub) {
+ call_resume(stub);
+ }
+ return;
}
static int
-xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xattr,
- dict_t *xdata, dict_match_t match, dict_t *matchdata)
+xattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, dict_t *xattr, dict_t *xdata, dict_match_t match,
+ dict_t *matchdata)
{
- inode_t *inode = NULL;
- index_local_t *local = NULL;
+ inode_t *inode = NULL;
+ index_local_t *local = NULL;
- local = frame->local;
- inode = inode_ref (local->inode);
+ local = frame->local;
+ inode = inode_ref(local->inode);
- if (op_ret < 0)
- goto out;
+ if (op_ret < 0)
+ goto out;
- xattrop_index_action (this, local, xattr, match, matchdata);
+ xattrop_index_action(this, local, xattr, match, matchdata);
out:
- INDEX_STACK_UNWIND (xattrop, frame, op_ret, op_errno, xattr, xdata);
- index_queue_process (this, inode, NULL);
- inode_unref (inode);
+ INDEX_STACK_UNWIND(xattrop, frame, op_ret, op_errno, xattr, xdata);
+ index_queue_process(this, inode, NULL);
+ inode_unref(inode);
- return 0;
+ return 0;
}
int32_t
-index_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xattr,
- dict_t *xdata)
+index_xattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xattr,
+ dict_t *xdata)
{
- index_priv_t *priv = this->private;
+ index_priv_t *priv = this->private;
- xattrop_cbk (frame, cookie, this, op_ret, op_errno,
- xattr, xdata, is_xattr_in_watchlist,
- priv->complete_watchlist);
- return 0;
+ xattrop_cbk(frame, cookie, this, op_ret, op_errno, xattr, xdata,
+ is_xattr_in_watchlist, priv->complete_watchlist);
+ return 0;
}
int32_t
-index_xattrop64_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xattr,
- dict_t *xdata)
+index_xattrop64_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xattr,
+ dict_t *xdata)
{
- index_priv_t *priv = this->private;
+ index_priv_t *priv = this->private;
- return xattrop_cbk (frame, cookie, this, op_ret, op_errno, xattr, xdata,
- is_xattr_in_watchlist, priv->pending_watchlist);
+ return xattrop_cbk(frame, cookie, this, op_ret, op_errno, xattr, xdata,
+ is_xattr_in_watchlist, priv->pending_watchlist);
}
void
-index_xattrop_do (call_frame_t *frame, xlator_t *this, loc_t *loc,
- fd_t *fd, gf_xattrop_flags_t optype, dict_t *xattr,
- dict_t *xdata)
-{
- int ret = -1;
- int zfilled[XATTROP_TYPE_END] = {0,};
- index_local_t *local = NULL;
- fop_xattrop_cbk_t x_cbk = NULL;
-
- local = frame->local;
-
- if (optype == GF_XATTROP_ADD_ARRAY)
- x_cbk = index_xattrop_cbk;
- else
- x_cbk = index_xattrop64_cbk;
-
- //In wind phase bring the gfid into index. This way if the brick crashes
- //just after posix performs xattrop before _cbk reaches index xlator
- //we will still have the gfid in index.
- memset (zfilled, -1, sizeof (zfilled));
-
- /* Foreach xattr, set corresponding index of zfilled to 1
- * zfilled[index] = 1 implies the xattr's value is zero filled
- * and should be added in its corresponding subdir.
- *
- * zfilled should be set to 1 only for those index that
- * exist in xattr variable. This is to distinguish
- * between different types of volumes.
- * For e.g., if the check is not made,
- * zfilled[DIRTY] is set to 1 for EC volumes,
- * index file will be tried to create in indices/dirty dir
- * which doesn't exist for an EC volume.
- */
- ret = dict_foreach (xattr, index_fill_zero_array, zfilled);
-
- _index_action (this, local->inode, zfilled);
- if (xdata)
- ret = index_entry_action (this, local->inode, xdata,
- GF_XATTROP_ENTRY_IN_KEY);
- if (ret < 0) {
- x_cbk (frame, NULL, this, -1, -ret, NULL, NULL);
- return;
- }
+index_xattrop_do(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
+ gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata)
+{
+ int ret = -1;
+ int zfilled[XATTROP_TYPE_END] = {
+ 0,
+ };
+ index_local_t *local = NULL;
+ fop_xattrop_cbk_t x_cbk = NULL;
+
+ local = frame->local;
+
+ if (optype == GF_XATTROP_ADD_ARRAY)
+ x_cbk = index_xattrop_cbk;
+ else
+ x_cbk = index_xattrop64_cbk;
+
+ // In wind phase bring the gfid into index. This way if the brick crashes
+ // just after posix performs xattrop before _cbk reaches index xlator
+ // we will still have the gfid in index.
+ memset(zfilled, -1, sizeof(zfilled));
+
+ /* Foreach xattr, set corresponding index of zfilled to 1
+ * zfilled[index] = 1 implies the xattr's value is zero filled
+ * and should be added in its corresponding subdir.
+ *
+ * zfilled should be set to 1 only for those index that
+ * exist in xattr variable. This is to distinguish
+ * between different types of volumes.
+ * For e.g., if the check is not made,
+ * zfilled[DIRTY] is set to 1 for EC volumes,
+ * index file will be tried to create in indices/dirty dir
+ * which doesn't exist for an EC volume.
+ */
+ ret = dict_foreach(xattr, index_fill_zero_array, zfilled);
+
+ _index_action(this, local->inode, zfilled);
+ if (xdata)
+ ret = index_entry_action(this, local->inode, xdata,
+ GF_XATTROP_ENTRY_IN_KEY);
+ if (ret < 0) {
+ x_cbk(frame, NULL, this, -1, -ret, NULL, NULL);
+ return;
+ }
- if (loc)
- STACK_WIND (frame, x_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->xattrop,
- loc, optype, xattr, xdata);
- else
- STACK_WIND (frame, x_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->fxattrop, fd,
- optype, xattr, xdata);
+ if (loc)
+ STACK_WIND(frame, x_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->xattrop, loc, optype, xattr, xdata);
+ else
+ STACK_WIND(frame, x_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fxattrop, fd, optype, xattr, xdata);
}
int
-index_xattrop_wrapper (call_frame_t *frame, xlator_t *this, loc_t *loc,
- gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata)
+index_xattrop_wrapper(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata)
{
- index_xattrop_do (frame, this, loc, NULL, optype, xattr, xdata);
- return 0;
+ index_xattrop_do(frame, this, loc, NULL, optype, xattr, xdata);
+ return 0;
}
int
-index_fxattrop_wrapper (call_frame_t *frame, xlator_t *this, fd_t *fd,
- gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata)
+index_fxattrop_wrapper(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata)
{
- index_xattrop_do (frame, this, NULL, fd, optype, xattr, xdata);
- return 0;
+ index_xattrop_do(frame, this, NULL, fd, optype, xattr, xdata);
+ return 0;
}
int32_t
-index_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc,
- gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata)
+index_xattrop(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata)
{
- call_stub_t *stub = NULL;
- index_local_t *local = NULL;
+ call_stub_t *stub = NULL;
+ index_local_t *local = NULL;
- if (!index_xattrop_track (this, flags, dict))
- goto out;
+ if (!index_xattrop_track(this, flags, dict))
+ goto out;
- local = mem_get0 (this->local_pool);
- if (!local)
- goto err;
+ local = mem_get0(this->local_pool);
+ if (!local)
+ goto err;
- frame->local = local;
- local->inode = inode_ref (loc->inode);
- if (xdata)
- local->xdata = dict_ref (xdata);
- stub = fop_xattrop_stub (frame, index_xattrop_wrapper,
- loc, flags, dict, xdata);
+ frame->local = local;
+ local->inode = inode_ref(loc->inode);
+ if (xdata)
+ local->xdata = dict_ref(xdata);
+ stub = fop_xattrop_stub(frame, index_xattrop_wrapper, loc, flags, dict,
+ xdata);
err:
- if ((!local) || (!stub)) {
- INDEX_STACK_UNWIND (xattrop, frame, -1, ENOMEM, NULL, NULL);
- return 0;
- }
-
- index_queue_process (this, loc->inode, stub);
+ if ((!local) || (!stub)) {
+ INDEX_STACK_UNWIND(xattrop, frame, -1, ENOMEM, NULL, NULL);
return 0;
+ }
+
+ index_queue_process(this, loc->inode, stub);
+ return 0;
out:
- STACK_WIND (frame, default_xattrop_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->xattrop, loc, flags, dict, xdata);
- return 0;
+ STACK_WIND(frame, default_xattrop_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->xattrop, loc, flags, dict, xdata);
+ return 0;
}
int32_t
-index_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd,
- gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata)
+index_fxattrop(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata)
{
- call_stub_t *stub = NULL;
- index_local_t *local = NULL;
+ call_stub_t *stub = NULL;
+ index_local_t *local = NULL;
- if (!index_xattrop_track (this, flags, dict))
- goto out;
+ if (!index_xattrop_track(this, flags, dict))
+ goto out;
- local = mem_get0 (this->local_pool);
- if (!local)
- goto err;
+ local = mem_get0(this->local_pool);
+ if (!local)
+ goto err;
- frame->local = local;
- local->inode = inode_ref (fd->inode);
- if (xdata)
- local->xdata = dict_ref (xdata);
- stub = fop_fxattrop_stub (frame, index_fxattrop_wrapper,
- fd, flags, dict, xdata);
+ frame->local = local;
+ local->inode = inode_ref(fd->inode);
+ if (xdata)
+ local->xdata = dict_ref(xdata);
+ stub = fop_fxattrop_stub(frame, index_fxattrop_wrapper, fd, flags, dict,
+ xdata);
err:
- if ((!local) || (!stub)) {
- INDEX_STACK_UNWIND (fxattrop, frame, -1, ENOMEM, NULL, xdata);
- return 0;
- }
-
- index_queue_process (this, fd->inode, stub);
+ if ((!local) || (!stub)) {
+ INDEX_STACK_UNWIND(fxattrop, frame, -1, ENOMEM, NULL, xdata);
return 0;
+ }
+
+ index_queue_process(this, fd->inode, stub);
+ return 0;
out:
- STACK_WIND (frame, default_fxattrop_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fxattrop, fd, flags, dict, xdata);
- return 0;
+ STACK_WIND(frame, default_fxattrop_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fxattrop, fd, flags, dict, xdata);
+ return 0;
}
uint64_t
-index_entry_count (xlator_t *this, char *subdir)
+index_entry_count(xlator_t *this, char *subdir)
{
- uint64_t count = 0;
- index_priv_t *priv = NULL;
- DIR *dirp = NULL;
- struct dirent *entry = NULL;
- struct dirent scratch[2] = {{0,},};
- char index_dir[PATH_MAX] = {0,};
+ uint64_t count = 0;
+ index_priv_t *priv = NULL;
+ DIR *dirp = NULL;
+ struct dirent *entry = NULL;
+ struct dirent scratch[2] = {
+ {
+ 0,
+ },
+ };
+ char index_dir[PATH_MAX] = {
+ 0,
+ };
- priv = this->private;
+ priv = this->private;
- make_index_dir_path (priv->index_basepath, subdir,
- index_dir, sizeof (index_dir));
+ make_index_dir_path(priv->index_basepath, subdir, index_dir,
+ sizeof(index_dir));
- dirp = sys_opendir (index_dir);
- if (!dirp)
- return 0;
+ dirp = sys_opendir(index_dir);
+ if (!dirp)
+ return 0;
- for (;;) {
- errno = 0;
- entry = sys_readdir (dirp, scratch);
- if (!entry || errno != 0)
- break;
+ for (;;) {
+ errno = 0;
+ entry = sys_readdir(dirp, scratch);
+ if (!entry || errno != 0)
+ break;
- if (strcmp (entry->d_name, ".") == 0 ||
- strcmp (entry->d_name, "..") == 0)
- continue;
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
+ continue;
- if (!strncmp (entry->d_name, subdir, strlen (subdir)))
- continue;
+ if (!strncmp(entry->d_name, subdir, strlen(subdir)))
+ continue;
- count++;
- }
+ count++;
+ }
- (void) sys_closedir (dirp);
+ (void)sys_closedir(dirp);
- return count;
+ return count;
}
int32_t
-index_getxattr_wrapper (call_frame_t *frame, xlator_t *this,
- loc_t *loc, const char *name, dict_t *xdata)
-{
- index_priv_t *priv = NULL;
- dict_t *xattr = NULL;
- int ret = 0;
- int vgfid_type = 0;
- uint64_t count = 0;
+index_getxattr_wrapper(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
+{
+ index_priv_t *priv = NULL;
+ dict_t *xattr = NULL;
+ int ret = 0;
+ int vgfid_type = 0;
+ uint64_t count = 0;
+
+ priv = this->private;
+
+ xattr = dict_new();
+ if (!xattr) {
+ ret = -ENOMEM;
+ goto done;
+ }
+
+ vgfid_type = index_get_type_from_vgfid_xattr(name);
+ if (vgfid_type >= 0) {
+ ret = dict_set_static_bin(xattr, (char *)name,
+ priv->internal_vgfid[vgfid_type],
+ sizeof(priv->internal_vgfid[vgfid_type]));
+ if (ret) {
+ ret = -EINVAL;
+ gf_msg(this->name, GF_LOG_ERROR, -ret, INDEX_MSG_DICT_SET_FAILED,
+ "xattrop index "
+ "gfid set failed");
+ goto done;
+ }
+ }
- priv = this->private;
+ /* TODO: Need to check what kind of link-counts are needed for
+ * ENTRY-CHANGES before refactor of this block with array*/
+ if (strcmp(name, GF_XATTROP_INDEX_COUNT) == 0) {
+ count = index_entry_count(this, XATTROP_SUBDIR);
- xattr = dict_new ();
- if (!xattr) {
- ret = -ENOMEM;
- goto done;
+ ret = dict_set_uint64(xattr, (char *)name, count);
+ if (ret) {
+ ret = -EINVAL;
+ gf_msg(this->name, GF_LOG_ERROR, -ret, INDEX_MSG_DICT_SET_FAILED,
+ "xattrop index "
+ "count set failed");
+ goto done;
}
+ } else if (strcmp(name, GF_XATTROP_DIRTY_COUNT) == 0) {
+ count = index_entry_count(this, DIRTY_SUBDIR);
- vgfid_type = index_get_type_from_vgfid_xattr (name);
- if (vgfid_type >= 0) {
- ret = dict_set_static_bin (xattr, (char *)name,
- priv->internal_vgfid[vgfid_type],
- sizeof (priv->internal_vgfid[vgfid_type]));
- if (ret) {
- ret = -EINVAL;
- gf_msg (this->name, GF_LOG_ERROR, -ret,
- INDEX_MSG_DICT_SET_FAILED, "xattrop index "
- "gfid set failed");
- goto done;
- }
+ ret = dict_set_uint64(xattr, (char *)name, count);
+ if (ret) {
+ ret = -EINVAL;
+ gf_msg(this->name, GF_LOG_ERROR, -ret, INDEX_MSG_DICT_SET_FAILED,
+ "dirty index "
+ "count set failed");
+ goto done;
}
-
- /* TODO: Need to check what kind of link-counts are needed for
- * ENTRY-CHANGES before refactor of this block with array*/
- if (strcmp (name, GF_XATTROP_INDEX_COUNT) == 0) {
- count = index_entry_count (this, XATTROP_SUBDIR);
-
- ret = dict_set_uint64 (xattr, (char *)name, count);
- if (ret) {
- ret = -EINVAL;
- gf_msg (this->name, GF_LOG_ERROR, -ret,
- INDEX_MSG_DICT_SET_FAILED, "xattrop index "
- "count set failed");
- goto done;
- }
- } else if (strcmp (name, GF_XATTROP_DIRTY_COUNT) == 0) {
- count = index_entry_count (this, DIRTY_SUBDIR);
-
- ret = dict_set_uint64 (xattr, (char *)name, count);
- if (ret) {
- ret = -EINVAL;
- gf_msg (this->name, GF_LOG_ERROR, -ret,
- INDEX_MSG_DICT_SET_FAILED, "dirty index "
- "count set failed");
- goto done;
- }
- }
+ }
done:
- if (ret)
- STACK_UNWIND_STRICT (getxattr, frame, -1, -ret, xattr, NULL);
- else
- STACK_UNWIND_STRICT (getxattr, frame, 0, 0, xattr, NULL);
+ if (ret)
+ STACK_UNWIND_STRICT(getxattr, frame, -1, -ret, xattr, NULL);
+ else
+ STACK_UNWIND_STRICT(getxattr, frame, 0, 0, xattr, NULL);
- if (xattr)
- dict_unref (xattr);
+ if (xattr)
+ dict_unref(xattr);
- return 0;
+ return 0;
}
static int
-index_save_pargfid_for_entry_changes (xlator_t *this, loc_t *loc, char *path)
+index_save_pargfid_for_entry_changes(xlator_t *this, loc_t *loc, char *path)
{
- index_priv_t *priv = NULL;
- index_inode_ctx_t *ctx = NULL;
- int ret = 0;
+ index_priv_t *priv = NULL;
+ index_inode_ctx_t *ctx = NULL;
+ int ret = 0;
- priv = this->private;
- if (gf_uuid_compare (loc->pargfid,
- priv->internal_vgfid[ENTRY_CHANGES]))
- return 0;
-
- ret = index_inode_ctx_get (loc->inode, this, &ctx);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- INDEX_MSG_INODE_CTX_GET_SET_FAILED,
- "Unable to get inode context for %s", path);
- return -EINVAL;
- }
- ret = gf_uuid_parse (loc->name, ctx->virtual_pargfid);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- INDEX_MSG_INODE_CTX_GET_SET_FAILED, "Unable to store "
- "virtual gfid in inode context for %s", path);
- return -EINVAL;
- }
+ priv = this->private;
+ if (gf_uuid_compare(loc->pargfid, priv->internal_vgfid[ENTRY_CHANGES]))
return 0;
+
+ ret = index_inode_ctx_get(loc->inode, this, &ctx);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL,
+ INDEX_MSG_INODE_CTX_GET_SET_FAILED,
+ "Unable to get inode context for %s", path);
+ return -EINVAL;
+ }
+ ret = gf_uuid_parse(loc->name, ctx->virtual_pargfid);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL,
+ INDEX_MSG_INODE_CTX_GET_SET_FAILED,
+ "Unable to store "
+ "virtual gfid in inode context for %s",
+ path);
+ return -EINVAL;
+ }
+ return 0;
}
int32_t
-index_lookup_wrapper (call_frame_t *frame, xlator_t *this,
- loc_t *loc, dict_t *xattr_req)
-{
- index_priv_t *priv = NULL;
- struct stat lstatbuf = {0};
- int ret = 0;
- int32_t op_errno = EINVAL;
- int32_t op_ret = -1;
- uint64_t val = IA_INVAL;
- char path[PATH_MAX] = {0};
- struct iatt stbuf = {0, };
- struct iatt postparent = {0,};
- dict_t *xattr = NULL;
- gf_boolean_t is_dir = _gf_false;
- char *subdir = NULL;
- loc_t iloc = {0};
-
- priv = this->private;
- loc_copy (&iloc, loc);
-
- VALIDATE_OR_GOTO (loc, done);
- if (index_is_fop_on_internal_inode (this, loc->parent, loc->pargfid)) {
- subdir = index_get_subdir_from_vgfid (priv, loc->pargfid);
- ret = index_inode_path (this, loc->parent, path, sizeof (path));
- if (ret < 0) {
- op_errno = -ret;
- goto done;
- }
- strcat (path, "/");
- strcat (path, (char *)loc->name);
- } else if (index_is_virtual_gfid (priv, loc->gfid)) {
- subdir = index_get_subdir_from_vgfid (priv, loc->gfid);
- make_index_dir_path (priv->index_basepath, subdir,
- path, sizeof (path));
- is_dir = _gf_true;
-
- if ((xattr_req) &&
- (dict_get (xattr_req, GF_INDEX_IA_TYPE_GET_REQ))) {
- if (0 == strcmp (subdir,
- index_get_subdir_from_type(ENTRY_CHANGES)))
- val = IA_IFDIR;
- else
- val = IA_IFREG;
- }
- } else {
- if (!inode_is_linked (loc->inode)) {
- inode_unref (iloc.inode);
- iloc.inode = inode_find (loc->inode->table, loc->gfid);
- }
- ret = index_inode_path (this, iloc.inode, path,
- sizeof (path));
- if (ret < 0) {
- op_errno = -ret;
- goto done;
- }
+index_lookup_wrapper(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ dict_t *xattr_req)
+{
+ index_priv_t *priv = NULL;
+ struct stat lstatbuf = {0};
+ int ret = 0;
+ int32_t op_errno = EINVAL;
+ int32_t op_ret = -1;
+ uint64_t val = IA_INVAL;
+ char path[PATH_MAX] = {0};
+ struct iatt stbuf = {
+ 0,
+ };
+ struct iatt postparent = {
+ 0,
+ };
+ dict_t *xattr = NULL;
+ gf_boolean_t is_dir = _gf_false;
+ char *subdir = NULL;
+ loc_t iloc = {0};
+
+ priv = this->private;
+ loc_copy(&iloc, loc);
+
+ VALIDATE_OR_GOTO(loc, done);
+ if (index_is_fop_on_internal_inode(this, loc->parent, loc->pargfid)) {
+ subdir = index_get_subdir_from_vgfid(priv, loc->pargfid);
+ ret = index_inode_path(this, loc->parent, path, sizeof(path));
+ if (ret < 0) {
+ op_errno = -ret;
+ goto done;
+ }
+ strcat(path, "/");
+ strcat(path, (char *)loc->name);
+ } else if (index_is_virtual_gfid(priv, loc->gfid)) {
+ subdir = index_get_subdir_from_vgfid(priv, loc->gfid);
+ make_index_dir_path(priv->index_basepath, subdir, path, sizeof(path));
+ is_dir = _gf_true;
+
+ if ((xattr_req) && (dict_get(xattr_req, GF_INDEX_IA_TYPE_GET_REQ))) {
+ if (0 == strcmp(subdir, index_get_subdir_from_type(ENTRY_CHANGES)))
+ val = IA_IFDIR;
+ else
+ val = IA_IFREG;
+ }
+ } else {
+ if (!inode_is_linked(loc->inode)) {
+ inode_unref(iloc.inode);
+ iloc.inode = inode_find(loc->inode->table, loc->gfid);
+ }
+ ret = index_inode_path(this, iloc.inode, path, sizeof(path));
+ if (ret < 0) {
+ op_errno = -ret;
+ goto done;
}
- ret = sys_lstat (path, &lstatbuf);
+ }
+ ret = sys_lstat(path, &lstatbuf);
+ if (ret) {
+ gf_msg_debug(this->name, errno, "Stat failed on %s dir ", path);
+ op_errno = errno;
+ goto done;
+ } else if (!S_ISDIR(lstatbuf.st_mode) && is_dir) {
+ op_errno = ENOTDIR;
+ gf_msg_debug(this->name, op_errno,
+ "Stat failed on %s dir, "
+ "not a directory",
+ path);
+ goto done;
+ }
+ xattr = dict_new();
+ if (!xattr) {
+ op_errno = ENOMEM;
+ goto done;
+ }
+
+ if (val != IA_INVAL) {
+ ret = dict_set_uint64(xattr, GF_INDEX_IA_TYPE_GET_RSP, val);
if (ret) {
- gf_msg_debug (this->name, errno, "Stat failed on %s dir ",
- path);
- op_errno = errno;
- goto done;
- } else if (!S_ISDIR (lstatbuf.st_mode) && is_dir) {
- op_errno = ENOTDIR;
- gf_msg_debug (this->name, op_errno, "Stat failed on %s dir, "
- "not a directory", path);
- goto done;
- }
- xattr = dict_new ();
- if (!xattr) {
- op_errno = ENOMEM;
- goto done;
- }
-
- if (val != IA_INVAL) {
- ret = dict_set_uint64 (xattr, GF_INDEX_IA_TYPE_GET_RSP, val);
- if (ret) {
- op_ret = -1;
- op_errno = -ret;
- goto done;
- }
- }
-
- iatt_from_stat (&stbuf, &lstatbuf);
- if (is_dir || inode_is_linked (iloc.inode))
- loc_gfid (&iloc, stbuf.ia_gfid);
- else
- gf_uuid_generate (stbuf.ia_gfid);
-
- ret = index_save_pargfid_for_entry_changes (this, &iloc, path);
- if (ret) {
- op_ret = -1;
- op_errno = -ret;
- goto done;
- }
-
- stbuf.ia_ino = -1;
- op_ret = 0;
+ op_ret = -1;
+ op_errno = -ret;
+ goto done;
+ }
+ }
+
+ iatt_from_stat(&stbuf, &lstatbuf);
+ if (is_dir || inode_is_linked(iloc.inode))
+ loc_gfid(&iloc, stbuf.ia_gfid);
+ else
+ gf_uuid_generate(stbuf.ia_gfid);
+
+ ret = index_save_pargfid_for_entry_changes(this, &iloc, path);
+ if (ret) {
+ op_ret = -1;
+ op_errno = -ret;
+ goto done;
+ }
+
+ stbuf.ia_ino = -1;
+ op_ret = 0;
done:
- STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno,
- loc->inode, &stbuf, xattr, &postparent);
- if (xattr)
- dict_unref (xattr);
- loc_wipe (&iloc);
- return 0;
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, loc->inode, &stbuf,
+ xattr, &postparent);
+ if (xattr)
+ dict_unref(xattr);
+ loc_wipe(&iloc);
+ return 0;
}
int
-index_get_gfid_type (void *opaque)
-{
- gf_dirent_t *entry = NULL;
- xlator_t *this = THIS;
- struct index_syncop_args *args = opaque;
- loc_t loc = {0};
- struct iatt iatt = {0};
- int ret = 0;
-
- list_for_each_entry (entry, &args->entries->list, list) {
- if (strcmp (entry->d_name, ".") == 0 ||
- strcmp (entry->d_name, "..") == 0)
- continue;
-
- loc_wipe (&loc);
-
- entry->d_type = IA_INVAL;
- if (gf_uuid_parse (entry->d_name, loc.gfid))
- continue;
-
- loc.inode = inode_find (args->parent->table, loc.gfid);
- if (loc.inode) {
- entry->d_type = loc.inode->ia_type;
- continue;
- }
- loc.inode = inode_new (args->parent->table);
- if (!loc.inode)
- continue;
- ret = syncop_lookup (FIRST_CHILD (this), &loc, &iatt, 0, 0, 0);
- if (ret == 0)
- entry->d_type = iatt.ia_type;
- }
- loc_wipe (&loc);
+index_get_gfid_type(void *opaque)
+{
+ gf_dirent_t *entry = NULL;
+ xlator_t *this = THIS;
+ struct index_syncop_args *args = opaque;
+ loc_t loc = {0};
+ struct iatt iatt = {0};
+ int ret = 0;
+
+ list_for_each_entry(entry, &args->entries->list, list)
+ {
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
+ continue;
+
+ loc_wipe(&loc);
+
+ entry->d_type = IA_INVAL;
+ if (gf_uuid_parse(entry->d_name, loc.gfid))
+ continue;
+
+ loc.inode = inode_find(args->parent->table, loc.gfid);
+ if (loc.inode) {
+ entry->d_type = loc.inode->ia_type;
+ continue;
+ }
+ loc.inode = inode_new(args->parent->table);
+ if (!loc.inode)
+ continue;
+ ret = syncop_lookup(FIRST_CHILD(this), &loc, &iatt, 0, 0, 0);
+ if (ret == 0)
+ entry->d_type = iatt.ia_type;
+ }
+ loc_wipe(&loc);
- return 0;
+ return 0;
}
int32_t
-index_readdir_wrapper (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t off, dict_t *xdata)
-{
- index_fd_ctx_t *fctx = NULL;
- index_priv_t *priv = NULL;
- DIR *dir = NULL;
- int ret = -1;
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- int count = 0;
- gf_dirent_t entries;
- struct index_syncop_args args = {0};
-
- priv = this->private;
- INIT_LIST_HEAD (&entries.list);
-
- ret = index_fd_ctx_get (fd, this, &fctx);
- if (ret < 0) {
- op_errno = -ret;
- gf_msg (this->name, GF_LOG_WARNING, op_errno,
- INDEX_MSG_FD_OP_FAILED, "pfd is NULL, fd=%p", fd);
- goto done;
- }
-
- dir = fctx->dir;
- if (!dir) {
- op_errno = EINVAL;
- gf_msg (this->name, GF_LOG_WARNING, op_errno,
- INDEX_MSG_INDEX_READDIR_FAILED,
- "dir is NULL for fd=%p", fd);
- goto done;
- }
-
- count = index_fill_readdir (fd, fctx, dir, off, size, &entries);
-
- /* pick ENOENT to indicate EOF */
- op_errno = errno;
- op_ret = count;
- if (index_is_virtual_gfid (priv, fd->inode->gfid) &&
- xdata && dict_get (xdata, "get-gfid-type")) {
- args.parent = fd->inode;
- args.entries = &entries;
- ret = synctask_new (this->ctx->env, index_get_gfid_type,
- NULL, NULL, &args);
- }
+index_readdir_wrapper(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ size_t size, off_t off, dict_t *xdata)
+{
+ index_fd_ctx_t *fctx = NULL;
+ index_priv_t *priv = NULL;
+ DIR *dir = NULL;
+ int ret = -1;
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ int count = 0;
+ gf_dirent_t entries;
+ struct index_syncop_args args = {0};
+
+ priv = this->private;
+ INIT_LIST_HEAD(&entries.list);
+
+ ret = index_fd_ctx_get(fd, this, &fctx);
+ if (ret < 0) {
+ op_errno = -ret;
+ gf_msg(this->name, GF_LOG_WARNING, op_errno, INDEX_MSG_FD_OP_FAILED,
+ "pfd is NULL, fd=%p", fd);
+ goto done;
+ }
+
+ dir = fctx->dir;
+ if (!dir) {
+ op_errno = EINVAL;
+ gf_msg(this->name, GF_LOG_WARNING, op_errno,
+ INDEX_MSG_INDEX_READDIR_FAILED, "dir is NULL for fd=%p", fd);
+ goto done;
+ }
+
+ count = index_fill_readdir(fd, fctx, dir, off, size, &entries);
+
+ /* pick ENOENT to indicate EOF */
+ op_errno = errno;
+ op_ret = count;
+ if (index_is_virtual_gfid(priv, fd->inode->gfid) && xdata &&
+ dict_get(xdata, "get-gfid-type")) {
+ args.parent = fd->inode;
+ args.entries = &entries;
+ ret = synctask_new(this->ctx->env, index_get_gfid_type, NULL, NULL,
+ &args);
+ }
done:
- STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, &entries, NULL);
- gf_dirent_free (&entries);
- return 0;
+ STACK_UNWIND_STRICT(readdir, frame, op_ret, op_errno, &entries, NULL);
+ gf_dirent_free(&entries);
+ return 0;
}
int
-deletion_handler (const char *fpath, const struct stat *sb, int typeflag,
- struct FTW *ftwbuf)
+deletion_handler(const char *fpath, const struct stat *sb, int typeflag,
+ struct FTW *ftwbuf)
{
- ia_type_t type = IA_INVAL;
+ ia_type_t type = IA_INVAL;
- switch (sb->st_mode & S_IFMT) {
+ switch (sb->st_mode & S_IFMT) {
case S_IFREG:
- sys_unlink (fpath);
- break;
+ sys_unlink(fpath);
+ break;
case S_IFDIR:
- sys_rmdir (fpath);
- break;
+ sys_rmdir(fpath);
+ break;
default:
- type = ia_type_from_st_mode (sb->st_mode);
- gf_msg (THIS->name, GF_LOG_WARNING, EINVAL,
- INDEX_MSG_INVALID_ARGS,
- "%s neither a regular file nor a directory - type:%s",
- fpath, gf_inode_type_to_str (type));
- break;
- }
- return 0;
+ type = ia_type_from_st_mode(sb->st_mode);
+ gf_msg(THIS->name, GF_LOG_WARNING, EINVAL, INDEX_MSG_INVALID_ARGS,
+ "%s neither a regular file nor a directory - type:%s", fpath,
+ gf_inode_type_to_str(type));
+ break;
+ }
+ return 0;
}
static int
-index_wipe_index_subdir (void *opaque)
+index_wipe_index_subdir(void *opaque)
{
- struct index_syncop_args *args = opaque;
+ struct index_syncop_args *args = opaque;
- nftw (args->path, deletion_handler, 1, FTW_DEPTH | FTW_PHYS);
- return 0;
+ nftw(args->path, deletion_handler, 1, FTW_DEPTH | FTW_PHYS);
+ return 0;
}
static void
-index_get_parent_iatt (struct iatt *parent, char *path, loc_t *loc,
- int32_t *op_ret, int32_t *op_errno)
-{
- int ret = -1;
- struct stat lstatbuf = {0,};
-
- ret = sys_lstat (path, &lstatbuf);
- if (ret < 0) {
- *op_ret = -1;
- *op_errno = errno;
- return;
- }
+index_get_parent_iatt(struct iatt *parent, char *path, loc_t *loc,
+ int32_t *op_ret, int32_t *op_errno)
+{
+ int ret = -1;
+ struct stat lstatbuf = {
+ 0,
+ };
+
+ ret = sys_lstat(path, &lstatbuf);
+ if (ret < 0) {
+ *op_ret = -1;
+ *op_errno = errno;
+ return;
+ }
- iatt_from_stat (parent, &lstatbuf);
- gf_uuid_copy (parent->ia_gfid, loc->pargfid);
- parent->ia_ino = -1;
+ iatt_from_stat(parent, &lstatbuf);
+ gf_uuid_copy(parent->ia_gfid, loc->pargfid);
+ parent->ia_ino = -1;
- return;
+ return;
}
int
-index_rmdir_wrapper (call_frame_t *frame, xlator_t *this, loc_t *loc, int flag,
- dict_t *xdata)
-{
- int ret = 0;
- int32_t op_ret = 0;
- int32_t op_errno = 0;
- char *subdir = NULL;
- char index_dir[PATH_MAX] = {0};
- char index_subdir[PATH_MAX] = {0};
- uuid_t gfid = {0};
- struct iatt preparent = {0};
- struct iatt postparent = {0};
- index_priv_t *priv = NULL;
- index_xattrop_type_t type = XATTROP_TYPE_UNSET;
- struct index_syncop_args args = {0,};
-
- priv = this->private;
-
- type = index_get_type_from_vgfid (priv, loc->pargfid);
- subdir = index_get_subdir_from_vgfid (priv, loc->pargfid);
- make_index_dir_path (priv->index_basepath, subdir,
- index_dir, sizeof (index_dir));
-
- index_get_parent_iatt (&preparent, index_dir, loc, &op_ret, &op_errno);
- if (op_ret < 0)
- goto done;
-
- gf_uuid_parse (loc->name, gfid);
- make_gfid_path (priv->index_basepath, subdir, gfid, index_subdir,
- sizeof (index_subdir));
-
- if (flag == 0) {
- ret = index_del (this, gfid, subdir, type);
- if (ret < 0) {
- op_ret = -1;
- op_errno = -ret;
- goto done;
- }
- } else {
- args.path = index_subdir;
- ret = synctask_new (this->ctx->env, index_wipe_index_subdir,
- NULL, NULL, &args);
+index_rmdir_wrapper(call_frame_t *frame, xlator_t *this, loc_t *loc, int flag,
+ dict_t *xdata)
+{
+ int ret = 0;
+ int32_t op_ret = 0;
+ int32_t op_errno = 0;
+ char *subdir = NULL;
+ char index_dir[PATH_MAX] = {0};
+ char index_subdir[PATH_MAX] = {0};
+ uuid_t gfid = {0};
+ struct iatt preparent = {0};
+ struct iatt postparent = {0};
+ index_priv_t *priv = NULL;
+ index_xattrop_type_t type = XATTROP_TYPE_UNSET;
+ struct index_syncop_args args = {
+ 0,
+ };
+
+ priv = this->private;
+
+ type = index_get_type_from_vgfid(priv, loc->pargfid);
+ subdir = index_get_subdir_from_vgfid(priv, loc->pargfid);
+ make_index_dir_path(priv->index_basepath, subdir, index_dir,
+ sizeof(index_dir));
+
+ index_get_parent_iatt(&preparent, index_dir, loc, &op_ret, &op_errno);
+ if (op_ret < 0)
+ goto done;
+
+ gf_uuid_parse(loc->name, gfid);
+ make_gfid_path(priv->index_basepath, subdir, gfid, index_subdir,
+ sizeof(index_subdir));
+
+ if (flag == 0) {
+ ret = index_del(this, gfid, subdir, type);
+ if (ret < 0) {
+ op_ret = -1;
+ op_errno = -ret;
+ goto done;
}
+ } else {
+ args.path = index_subdir;
+ ret = synctask_new(this->ctx->env, index_wipe_index_subdir, NULL, NULL,
+ &args);
+ }
- index_get_parent_iatt (&postparent, index_dir, loc, &op_ret, &op_errno);
- if (op_ret < 0)
- goto done;
+ index_get_parent_iatt(&postparent, index_dir, loc, &op_ret, &op_errno);
+ if (op_ret < 0)
+ goto done;
done:
- INDEX_STACK_UNWIND (rmdir, frame, op_ret, op_errno, &preparent,
- &postparent, xdata);
- return 0;
+ INDEX_STACK_UNWIND(rmdir, frame, op_ret, op_errno, &preparent, &postparent,
+ xdata);
+ return 0;
}
int
-index_unlink_wrapper (call_frame_t *frame, xlator_t *this, loc_t *loc, int flag,
- dict_t *xdata)
-{
- index_priv_t *priv = NULL;
- index_inode_ctx_t *ictx = NULL;
- int32_t op_ret = 0;
- int32_t op_errno = 0;
- int ret = 0;
- index_xattrop_type_t type = XATTROP_TYPE_UNSET;
- struct iatt preparent = {0};
- struct iatt postparent = {0};
- char index_dir[PATH_MAX] = {0};
- char filepath[PATH_MAX] = {0};
- uuid_t gfid = {0};
- char *subdir = NULL;
-
- priv = this->private;
- type = index_get_type_from_vgfid (priv, loc->pargfid);
- ret = index_inode_path (this, loc->parent, index_dir,
- sizeof (index_dir));
- if (ret < 0) {
- op_ret = -1;
- op_errno = -ret;
- goto done;
- }
-
- index_get_parent_iatt (&preparent, index_dir, loc, &op_ret, &op_errno);
- if (op_ret < 0)
- goto done;
-
- if (type <= XATTROP_TYPE_UNSET) {
- ret = index_inode_ctx_get (loc->parent, this, &ictx);
- if ((ret == 0) && gf_uuid_is_null (ictx->virtual_pargfid)) {
- ret = -EINVAL;
- }
- if (ret == 0) {
- ret = index_entry_delete (this, ictx->virtual_pargfid,
- (char *)loc->name);
- }
- } else if (type == ENTRY_CHANGES) {
- make_file_path (priv->index_basepath, ENTRY_CHANGES_SUBDIR,
- (char *)loc->name, filepath, sizeof (filepath));
- ret = sys_unlink (filepath);
- } else {
- subdir = index_get_subdir_from_type (type);
- gf_uuid_parse (loc->name, gfid);
- ret = index_del (this, gfid, subdir, type);
- }
- if (ret < 0) {
- op_ret = -1;
- op_errno = -ret;
- goto done;
- }
-
- index_get_parent_iatt (&postparent, index_dir, loc, &op_ret, &op_errno);
- if (op_ret < 0)
- goto done;
+index_unlink_wrapper(call_frame_t *frame, xlator_t *this, loc_t *loc, int flag,
+ dict_t *xdata)
+{
+ index_priv_t *priv = NULL;
+ index_inode_ctx_t *ictx = NULL;
+ int32_t op_ret = 0;
+ int32_t op_errno = 0;
+ int ret = 0;
+ index_xattrop_type_t type = XATTROP_TYPE_UNSET;
+ struct iatt preparent = {0};
+ struct iatt postparent = {0};
+ char index_dir[PATH_MAX] = {0};
+ char filepath[PATH_MAX] = {0};
+ uuid_t gfid = {0};
+ char *subdir = NULL;
+
+ priv = this->private;
+ type = index_get_type_from_vgfid(priv, loc->pargfid);
+ ret = index_inode_path(this, loc->parent, index_dir, sizeof(index_dir));
+ if (ret < 0) {
+ op_ret = -1;
+ op_errno = -ret;
+ goto done;
+ }
+
+ index_get_parent_iatt(&preparent, index_dir, loc, &op_ret, &op_errno);
+ if (op_ret < 0)
+ goto done;
+
+ if (type <= XATTROP_TYPE_UNSET) {
+ ret = index_inode_ctx_get(loc->parent, this, &ictx);
+ if ((ret == 0) && gf_uuid_is_null(ictx->virtual_pargfid)) {
+ ret = -EINVAL;
+ }
+ if (ret == 0) {
+ ret = index_entry_delete(this, ictx->virtual_pargfid,
+ (char *)loc->name);
+ }
+ } else if (type == ENTRY_CHANGES) {
+ make_file_path(priv->index_basepath, ENTRY_CHANGES_SUBDIR,
+ (char *)loc->name, filepath, sizeof(filepath));
+ ret = sys_unlink(filepath);
+ } else {
+ subdir = index_get_subdir_from_type(type);
+ gf_uuid_parse(loc->name, gfid);
+ ret = index_del(this, gfid, subdir, type);
+ }
+ if (ret < 0) {
+ op_ret = -1;
+ op_errno = -ret;
+ goto done;
+ }
+
+ index_get_parent_iatt(&postparent, index_dir, loc, &op_ret, &op_errno);
+ if (op_ret < 0)
+ goto done;
done:
- INDEX_STACK_UNWIND (unlink, frame, op_ret, op_errno, &preparent,
- &postparent, xdata);
- return 0;
+ INDEX_STACK_UNWIND(unlink, frame, op_ret, op_errno, &preparent, &postparent,
+ xdata);
+ return 0;
}
int32_t
-index_getxattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc, const char *name, dict_t *xdata)
+index_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
{
- call_stub_t *stub = NULL;
+ call_stub_t *stub = NULL;
- if (!name || (!index_is_vgfid_xattr (name) &&
- strcmp (GF_XATTROP_INDEX_COUNT, name) &&
- strcmp (GF_XATTROP_DIRTY_COUNT, name)))
- goto out;
+ if (!name ||
+ (!index_is_vgfid_xattr(name) && strcmp(GF_XATTROP_INDEX_COUNT, name) &&
+ strcmp(GF_XATTROP_DIRTY_COUNT, name)))
+ goto out;
- stub = fop_getxattr_stub (frame, index_getxattr_wrapper, loc, name,
- xdata);
- if (!stub) {
- STACK_UNWIND_STRICT (getxattr, frame, -1, ENOMEM, NULL, NULL);
- return 0;
- }
- worker_enqueue (this, stub);
+ stub = fop_getxattr_stub(frame, index_getxattr_wrapper, loc, name, xdata);
+ if (!stub) {
+ STACK_UNWIND_STRICT(getxattr, frame, -1, ENOMEM, NULL, NULL);
return 0;
+ }
+ worker_enqueue(this, stub);
+ return 0;
out:
- STACK_WIND (frame, default_getxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->getxattr, loc, name, xdata);
- return 0;
+ STACK_WIND(frame, default_getxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->getxattr, loc, name, xdata);
+ return 0;
}
int64_t
-index_fetch_link_count (xlator_t *this, index_xattrop_type_t type)
-{
- index_priv_t *priv = this->private;
- char *subdir = NULL;
- struct stat lstatbuf = {0,};
- int ret = -1;
- int64_t count = -1;
- DIR *dirp = NULL;
- struct dirent *entry = NULL;
- struct dirent scratch[2] = {{0,},};
- char index_dir[PATH_MAX] = {0,};
- char index_path[PATH_MAX] = {0,};
-
- subdir = index_get_subdir_from_type (type);
- make_index_dir_path (priv->index_basepath, subdir,
- index_dir, sizeof (index_dir));
-
- dirp = sys_opendir (index_dir);
- if (!dirp)
- goto out;
+index_fetch_link_count(xlator_t *this, index_xattrop_type_t type)
+{
+ index_priv_t *priv = this->private;
+ char *subdir = NULL;
+ struct stat lstatbuf = {
+ 0,
+ };
+ int ret = -1;
+ int64_t count = -1;
+ DIR *dirp = NULL;
+ struct dirent *entry = NULL;
+ struct dirent scratch[2] = {
+ {
+ 0,
+ },
+ };
+ char index_dir[PATH_MAX] = {
+ 0,
+ };
+ char index_path[PATH_MAX] = {
+ 0,
+ };
+
+ subdir = index_get_subdir_from_type(type);
+ make_index_dir_path(priv->index_basepath, subdir, index_dir,
+ sizeof(index_dir));
+
+ dirp = sys_opendir(index_dir);
+ if (!dirp)
+ goto out;
+
+ for (;;) {
+ errno = 0;
+ entry = sys_readdir(dirp, scratch);
+ if (!entry || errno != 0) {
+ if (count == -1)
+ count = 0;
+ goto out;
+ }
- for (;;) {
- errno = 0;
- entry = sys_readdir (dirp, scratch);
- if (!entry || errno != 0) {
- if (count == -1)
- count = 0;
- goto out;
- }
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
+ continue;
- if (strcmp (entry->d_name, ".") == 0 ||
- strcmp (entry->d_name, "..") == 0)
- continue;
-
- make_file_path (priv->index_basepath, subdir,
- entry->d_name, index_path, sizeof(index_path));
-
- ret = sys_lstat (index_path, &lstatbuf);
- if (ret < 0) {
- count = -2;
- continue;
- } else {
- count = lstatbuf.st_nlink - 1;
- if (count == 0)
- continue;
- else
- break;
- }
+ make_file_path(priv->index_basepath, subdir, entry->d_name, index_path,
+ sizeof(index_path));
+
+ ret = sys_lstat(index_path, &lstatbuf);
+ if (ret < 0) {
+ count = -2;
+ continue;
+ } else {
+ count = lstatbuf.st_nlink - 1;
+ if (count == 0)
+ continue;
+ else
+ break;
}
+ }
out:
- if (dirp)
- (void) sys_closedir (dirp);
- return count;
+ if (dirp)
+ (void)sys_closedir(dirp);
+ return count;
}
-dict_t*
-index_fill_link_count (xlator_t *this, dict_t *xdata)
+dict_t *
+index_fill_link_count(xlator_t *this, dict_t *xdata)
{
- int ret = -1;
- index_priv_t *priv = NULL;
- int64_t count = -1;
+ int ret = -1;
+ index_priv_t *priv = NULL;
+ int64_t count = -1;
- priv = this->private;
- xdata = (xdata) ? dict_ref (xdata) : dict_new ();
- if (!xdata)
- goto out;
+ priv = this->private;
+ xdata = (xdata) ? dict_ref(xdata) : dict_new();
+ if (!xdata)
+ goto out;
- index_get_link_count (priv, &count, XATTROP);
- if (count < 0) {
- count = index_fetch_link_count (this, XATTROP);
- index_set_link_count (priv, count, XATTROP);
- }
+ index_get_link_count(priv, &count, XATTROP);
+ if (count < 0) {
+ count = index_fetch_link_count(this, XATTROP);
+ index_set_link_count(priv, count, XATTROP);
+ }
- if (count == 0) {
- ret = dict_set_int8 (xdata, "link-count", 0);
- if (ret < 0)
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- INDEX_MSG_DICT_SET_FAILED,
- "Unable to set link-count");
- } else {
- ret = dict_set_int8 (xdata, "link-count", 1);
- if (ret < 0)
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- INDEX_MSG_DICT_SET_FAILED,
- "Unable to set link-count");
- }
+ if (count == 0) {
+ ret = dict_set_int8(xdata, "link-count", 0);
+ if (ret < 0)
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, INDEX_MSG_DICT_SET_FAILED,
+ "Unable to set link-count");
+ } else {
+ ret = dict_set_int8(xdata, "link-count", 1);
+ if (ret < 0)
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, INDEX_MSG_DICT_SET_FAILED,
+ "Unable to set link-count");
+ }
out:
- return xdata;
+ return xdata;
}
int32_t
-index_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, dict_t *xdata, struct iatt *postparent)
+index_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, dict_t *xdata, struct iatt *postparent)
{
-
- xdata = index_fill_link_count (this, xdata);
- STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf,
- xdata, postparent);
- if (xdata)
- dict_unref (xdata);
- return 0;
+ xdata = index_fill_link_count(this, xdata);
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, buf, xdata,
+ postparent);
+ if (xdata)
+ dict_unref(xdata);
+ return 0;
}
int32_t
-index_lookup (call_frame_t *frame, xlator_t *this,
- loc_t *loc, dict_t *xattr_req)
-{
- inode_t *inode = NULL;
- call_stub_t *stub = NULL;
- char *flag = NULL;
- int ret = -1;
-
- if (!index_is_fop_on_internal_inode (this, loc->parent, loc->pargfid) &&
- !index_is_fop_on_internal_inode (this, loc->inode, loc->gfid)) {
- if (!inode_is_linked (loc->inode)) {
- inode = inode_find (loc->inode->table, loc->gfid);
- if (!index_is_fop_on_internal_inode (this, inode,
- loc->gfid)) {
- inode_unref (inode);
- goto normal;
- }
- inode_unref (inode);
- } else {
- goto normal;
- }
+index_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req)
+{
+ inode_t *inode = NULL;
+ call_stub_t *stub = NULL;
+ char *flag = NULL;
+ int ret = -1;
+
+ if (!index_is_fop_on_internal_inode(this, loc->parent, loc->pargfid) &&
+ !index_is_fop_on_internal_inode(this, loc->inode, loc->gfid)) {
+ if (!inode_is_linked(loc->inode)) {
+ inode = inode_find(loc->inode->table, loc->gfid);
+ if (!index_is_fop_on_internal_inode(this, inode, loc->gfid)) {
+ inode_unref(inode);
+ goto normal;
+ }
+ inode_unref(inode);
+ } else {
+ goto normal;
}
+ }
- stub = fop_lookup_stub (frame, index_lookup_wrapper, loc, xattr_req);
- if (!stub) {
- STACK_UNWIND_STRICT (lookup, frame, -1, ENOMEM, loc->inode,
- NULL, NULL, NULL);
- return 0;
- }
- worker_enqueue (this, stub);
+ stub = fop_lookup_stub(frame, index_lookup_wrapper, loc, xattr_req);
+ if (!stub) {
+ STACK_UNWIND_STRICT(lookup, frame, -1, ENOMEM, loc->inode, NULL, NULL,
+ NULL);
return 0;
+ }
+ worker_enqueue(this, stub);
+ return 0;
normal:
- ret = dict_get_str (xattr_req, "link-count", &flag);
- if ((ret == 0) && (strcmp (flag, GF_XATTROP_INDEX_COUNT) == 0)) {
- STACK_WIND (frame, index_lookup_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->lookup, loc, xattr_req);
- } else {
- STACK_WIND (frame, default_lookup_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->lookup, loc, xattr_req);
- }
+ ret = dict_get_str(xattr_req, "link-count", &flag);
+ if ((ret == 0) && (strcmp(flag, GF_XATTROP_INDEX_COUNT) == 0)) {
+ STACK_WIND(frame, index_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, loc, xattr_req);
+ } else {
+ STACK_WIND(frame, default_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, loc, xattr_req);
+ }
- return 0;
+ return 0;
}
int32_t
-index_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *buf,
- dict_t *xdata)
-{
- xdata = index_fill_link_count (this, xdata);
- STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf, xdata);
- if (xdata)
- dict_unref (xdata);
- return 0;
+index_fstat_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf,
+ dict_t *xdata)
+{
+ xdata = index_fill_link_count(this, xdata);
+ STACK_UNWIND_STRICT(fstat, frame, op_ret, op_errno, buf, xdata);
+ if (xdata)
+ dict_unref(xdata);
+ return 0;
}
int32_t
-index_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
+index_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
{
- int ret = -1;
- char *flag = NULL;
+ int ret = -1;
+ char *flag = NULL;
- ret = dict_get_str (xdata, "link-count", &flag);
- if ((ret == 0) && (strcmp (flag, GF_XATTROP_INDEX_COUNT) == 0)) {
- STACK_WIND (frame, index_fstat_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fstat, fd, xdata);
- } else {
- STACK_WIND (frame, default_fstat_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fstat, fd, xdata);
- }
+ ret = dict_get_str(xdata, "link-count", &flag);
+ if ((ret == 0) && (strcmp(flag, GF_XATTROP_INDEX_COUNT) == 0)) {
+ STACK_WIND(frame, index_fstat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, fd, xdata);
+ } else {
+ STACK_WIND(frame, default_fstat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, fd, xdata);
+ }
- return 0;
+ return 0;
}
int32_t
-index_opendir (call_frame_t *frame, xlator_t *this,
- loc_t *loc, fd_t *fd, dict_t *xdata)
+index_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
+ dict_t *xdata)
{
- if (!index_is_fop_on_internal_inode (this, fd->inode, NULL))
- goto normal;
+ if (!index_is_fop_on_internal_inode(this, fd->inode, NULL))
+ goto normal;
- frame->local = NULL;
- STACK_UNWIND_STRICT (opendir, frame, 0, 0, fd, NULL);
- return 0;
+ frame->local = NULL;
+ STACK_UNWIND_STRICT(opendir, frame, 0, 0, fd, NULL);
+ return 0;
normal:
- STACK_WIND (frame, default_opendir_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->opendir, loc, fd, xdata);
- return 0;
+ STACK_WIND(frame, default_opendir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->opendir, loc, fd, xdata);
+ return 0;
}
int32_t
-index_readdir (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t off, dict_t *xdata)
+index_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t off, dict_t *xdata)
{
- call_stub_t *stub = NULL;
+ call_stub_t *stub = NULL;
- if (!index_is_fop_on_internal_inode (this, fd->inode, NULL))
- goto out;
+ if (!index_is_fop_on_internal_inode(this, fd->inode, NULL))
+ goto out;
- stub = fop_readdir_stub (frame, index_readdir_wrapper, fd, size, off,
- xdata);
- if (!stub) {
- STACK_UNWIND_STRICT (readdir, frame, -1, ENOMEM, NULL, NULL);
- return 0;
- }
- worker_enqueue (this, stub);
+ stub = fop_readdir_stub(frame, index_readdir_wrapper, fd, size, off, xdata);
+ if (!stub) {
+ STACK_UNWIND_STRICT(readdir, frame, -1, ENOMEM, NULL, NULL);
return 0;
+ }
+ worker_enqueue(this, stub);
+ return 0;
out:
- STACK_WIND (frame, default_readdir_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->readdir, fd, size, off, xdata);
- return 0;
+ STACK_WIND(frame, default_readdir_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readdir, fd, size, off, xdata);
+ return 0;
}
int
-index_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
- dict_t *xdata)
+index_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
+ dict_t *xdata)
{
- call_stub_t *stub = NULL;
+ call_stub_t *stub = NULL;
- if (!index_is_fop_on_internal_inode (this, loc->parent, NULL))
- goto out;
+ if (!index_is_fop_on_internal_inode(this, loc->parent, NULL))
+ goto out;
- stub = fop_unlink_stub (frame, index_unlink_wrapper, loc, xflag, xdata);
- if (!stub) {
- STACK_UNWIND_STRICT (unlink, frame, -1, ENOMEM, NULL, NULL,
- NULL);
- return 0;
- }
- worker_enqueue (this, stub);
+ stub = fop_unlink_stub(frame, index_unlink_wrapper, loc, xflag, xdata);
+ if (!stub) {
+ STACK_UNWIND_STRICT(unlink, frame, -1, ENOMEM, NULL, NULL, NULL);
return 0;
+ }
+ worker_enqueue(this, stub);
+ return 0;
out:
- STACK_WIND (frame, default_unlink_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->unlink, loc, xflag, xdata);
- return 0;
+ STACK_WIND(frame, default_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, loc, xflag, xdata);
+ return 0;
}
int
-index_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
- dict_t *xdata)
+index_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ dict_t *xdata)
{
- call_stub_t *stub = NULL;
+ call_stub_t *stub = NULL;
- if (!index_is_fop_on_internal_inode (this, loc->parent, NULL))
- goto out;
+ if (!index_is_fop_on_internal_inode(this, loc->parent, NULL))
+ goto out;
- stub = fop_rmdir_stub (frame, index_rmdir_wrapper, loc, flags, xdata);
- if (!stub) {
- STACK_UNWIND_STRICT (rmdir, frame, -1, ENOMEM, NULL, NULL,
- NULL);
- return 0;
- }
- worker_enqueue (this, stub);
+ stub = fop_rmdir_stub(frame, index_rmdir_wrapper, loc, flags, xdata);
+ if (!stub) {
+ STACK_UNWIND_STRICT(rmdir, frame, -1, ENOMEM, NULL, NULL, NULL);
return 0;
+ }
+ worker_enqueue(this, stub);
+ return 0;
out:
- STACK_WIND_TAIL (frame, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->rmdir, loc, flags, xdata);
- return 0;
+ STACK_WIND_TAIL(frame, FIRST_CHILD(this), FIRST_CHILD(this)->fops->rmdir,
+ loc, flags, xdata);
+ return 0;
}
int
-index_make_xattrop_watchlist (xlator_t *this, index_priv_t *priv,
- char *watchlist, index_xattrop_type_t type)
-{
- char *delim = NULL;
- char *dup_watchlist = NULL;
- char *key = NULL;
- char *saveptr = NULL;
- dict_t *xattrs = NULL;
- data_t *dummy = NULL;
- int ret = 0;
-
- if (!watchlist)
- return 0;
-
- dup_watchlist = gf_strdup (watchlist);
- if (!dup_watchlist)
- return -1;
-
- xattrs = dict_new ();
- if (!xattrs) {
- ret = -1;
- goto out;
- }
+index_make_xattrop_watchlist(xlator_t *this, index_priv_t *priv,
+ char *watchlist, index_xattrop_type_t type)
+{
+ char *delim = NULL;
+ char *dup_watchlist = NULL;
+ char *key = NULL;
+ char *saveptr = NULL;
+ dict_t *xattrs = NULL;
+ data_t *dummy = NULL;
+ int ret = 0;
+
+ if (!watchlist)
+ return 0;
- dummy = int_to_data (1);
- if (!dummy) {
- ret = -1;
- goto out;
- }
+ dup_watchlist = gf_strdup(watchlist);
+ if (!dup_watchlist)
+ return -1;
- data_ref (dummy);
+ xattrs = dict_new();
+ if (!xattrs) {
+ ret = -1;
+ goto out;
+ }
- delim = ",";
- key = strtok_r (dup_watchlist, delim, &saveptr);
- while (key) {
- if (strlen (key) == 0) {
- ret = -1;
- goto out;
- }
+ dummy = int_to_data(1);
+ if (!dummy) {
+ ret = -1;
+ goto out;
+ }
- ret = dict_set (xattrs, key, dummy);
- if (ret)
- goto out;
+ data_ref(dummy);
- key = strtok_r (NULL, delim, &saveptr);
+ delim = ",";
+ key = strtok_r(dup_watchlist, delim, &saveptr);
+ while (key) {
+ if (strlen(key) == 0) {
+ ret = -1;
+ goto out;
}
- switch (type) {
+ ret = dict_set(xattrs, key, dummy);
+ if (ret)
+ goto out;
+
+ key = strtok_r(NULL, delim, &saveptr);
+ }
+
+ switch (type) {
case DIRTY:
- priv->dirty_watchlist = dict_copy_with_ref (xattrs,
- priv->dirty_watchlist);
- if (!priv->dirty_watchlist) {
- ret = -1;
- goto out;
- }
- break;
+ priv->dirty_watchlist = dict_copy_with_ref(xattrs,
+ priv->dirty_watchlist);
+ if (!priv->dirty_watchlist) {
+ ret = -1;
+ goto out;
+ }
+ break;
case XATTROP:
- priv->pending_watchlist = dict_copy_with_ref (xattrs,
- priv->pending_watchlist);
- if (!priv->pending_watchlist) {
- ret = -1;
- goto out;
- }
- break;
+ priv->pending_watchlist = dict_copy_with_ref(
+ xattrs, priv->pending_watchlist);
+ if (!priv->pending_watchlist) {
+ ret = -1;
+ goto out;
+ }
+ break;
default:
- break;
- }
+ break;
+ }
- ret = 0;
+ ret = 0;
out:
- if (xattrs)
- dict_unref (xattrs);
+ if (xattrs)
+ dict_unref(xattrs);
- GF_FREE (dup_watchlist);
+ GF_FREE(dup_watchlist);
- if (dummy)
- data_unref (dummy);
+ if (dummy)
+ data_unref(dummy);
- return ret;
+ return ret;
}
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int ret = -1;
+ int ret = -1;
- ret = xlator_mem_acct_init (this, gf_index_mt_end + 1);
+ ret = xlator_mem_acct_init(this, gf_index_mt_end + 1);
- return ret;
+ return ret;
}
int
-init (xlator_t *this)
-{
- int i = 0;
- int ret = -1;
- int64_t count = -1;
- index_priv_t *priv = NULL;
- pthread_attr_t w_attr;
- gf_boolean_t mutex_inited = _gf_false;
- gf_boolean_t cond_inited = _gf_false;
- gf_boolean_t attr_inited = _gf_false;
- char *watchlist = NULL;
- char *dirtylist = NULL;
- char *pendinglist = NULL;
- char *index_base_parent = NULL;
- char *tmp = NULL;
-
- if (!this->children || this->children->next) {
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- INDEX_MSG_INVALID_GRAPH,
- "'index' not configured with exactly one child");
- goto out;
- }
-
- if (!this->parents) {
- gf_msg (this->name, GF_LOG_WARNING, EINVAL,
- INDEX_MSG_INVALID_GRAPH,
- "dangling volume. check volfile ");
- }
-
- priv = GF_CALLOC (1, sizeof (*priv), gf_index_mt_priv_t);
- if (!priv)
- goto out;
-
- LOCK_INIT (&priv->lock);
- if ((ret = pthread_cond_init(&priv->cond, NULL)) != 0) {
- gf_msg (this->name, GF_LOG_ERROR, ret,
- INDEX_MSG_INVALID_ARGS,
- "pthread_cond_init failed");
- goto out;
- }
- cond_inited = _gf_true;
-
- if ((ret = pthread_mutex_init(&priv->mutex, NULL)) != 0) {
- gf_msg (this->name, GF_LOG_ERROR, ret,
- INDEX_MSG_INVALID_ARGS,
- "pthread_mutex_init failed");
- goto out;
- }
- mutex_inited = _gf_true;
-
- if ((ret = pthread_attr_init (&w_attr)) != 0) {
- gf_msg (this->name, GF_LOG_ERROR, ret,
- INDEX_MSG_INVALID_ARGS,
- "pthread_attr_init failed");
- goto out;
- }
- attr_inited = _gf_true;
-
- ret = pthread_attr_setstacksize (&w_attr, INDEX_THREAD_STACK_SIZE);
- if (ret == EINVAL) {
- gf_msg (this->name, GF_LOG_WARNING, ret,
- INDEX_MSG_INVALID_ARGS,
- "Using default thread stack size");
- }
-
- GF_OPTION_INIT ("index-base", priv->index_basepath, path, out);
- tmp = gf_strdup(priv->index_basepath);
- index_base_parent = dirname(tmp);
- if (gf_lstat_dir (index_base_parent, NULL) != 0) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- INDEX_MSG_INDEX_DIR_CREATE_FAILED,
- "Failed to find parent dir (%s) of index basepath %s.",
- index_base_parent, priv->index_basepath);
- goto out;
- }
-
- GF_OPTION_INIT ("xattrop64-watchlist", watchlist, str, out);
- ret = index_make_xattrop_watchlist (this, priv, watchlist,
- XATTROP);
- if (ret)
- goto out;
-
- GF_OPTION_INIT ("xattrop-dirty-watchlist", dirtylist, str, out);
- ret = index_make_xattrop_watchlist (this, priv, dirtylist,
- DIRTY);
- if (ret)
- goto out;
-
- GF_OPTION_INIT ("xattrop-pending-watchlist", pendinglist, str, out);
- ret = index_make_xattrop_watchlist (this, priv, pendinglist,
- XATTROP);
- if (ret)
- goto out;
-
- if (priv->dirty_watchlist)
- priv->complete_watchlist = dict_copy_with_ref (priv->dirty_watchlist,
+init(xlator_t *this)
+{
+ int i = 0;
+ int ret = -1;
+ int64_t count = -1;
+ index_priv_t *priv = NULL;
+ pthread_attr_t w_attr;
+ gf_boolean_t mutex_inited = _gf_false;
+ gf_boolean_t cond_inited = _gf_false;
+ gf_boolean_t attr_inited = _gf_false;
+ char *watchlist = NULL;
+ char *dirtylist = NULL;
+ char *pendinglist = NULL;
+ char *index_base_parent = NULL;
+ char *tmp = NULL;
+
+ if (!this->children || this->children->next) {
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, INDEX_MSG_INVALID_GRAPH,
+ "'index' not configured with exactly one child");
+ goto out;
+ }
+
+ if (!this->parents) {
+ gf_msg(this->name, GF_LOG_WARNING, EINVAL, INDEX_MSG_INVALID_GRAPH,
+ "dangling volume. check volfile ");
+ }
+
+ priv = GF_CALLOC(1, sizeof(*priv), gf_index_mt_priv_t);
+ if (!priv)
+ goto out;
+
+ LOCK_INIT(&priv->lock);
+ if ((ret = pthread_cond_init(&priv->cond, NULL)) != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, ret, INDEX_MSG_INVALID_ARGS,
+ "pthread_cond_init failed");
+ goto out;
+ }
+ cond_inited = _gf_true;
+
+ if ((ret = pthread_mutex_init(&priv->mutex, NULL)) != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, ret, INDEX_MSG_INVALID_ARGS,
+ "pthread_mutex_init failed");
+ goto out;
+ }
+ mutex_inited = _gf_true;
+
+ if ((ret = pthread_attr_init(&w_attr)) != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, ret, INDEX_MSG_INVALID_ARGS,
+ "pthread_attr_init failed");
+ goto out;
+ }
+ attr_inited = _gf_true;
+
+ ret = pthread_attr_setstacksize(&w_attr, INDEX_THREAD_STACK_SIZE);
+ if (ret == EINVAL) {
+ gf_msg(this->name, GF_LOG_WARNING, ret, INDEX_MSG_INVALID_ARGS,
+ "Using default thread stack size");
+ }
+
+ GF_OPTION_INIT("index-base", priv->index_basepath, path, out);
+ tmp = gf_strdup(priv->index_basepath);
+ index_base_parent = dirname(tmp);
+ if (gf_lstat_dir(index_base_parent, NULL) != 0) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ INDEX_MSG_INDEX_DIR_CREATE_FAILED,
+ "Failed to find parent dir (%s) of index basepath %s.",
+ index_base_parent, priv->index_basepath);
+ goto out;
+ }
+
+ GF_OPTION_INIT("xattrop64-watchlist", watchlist, str, out);
+ ret = index_make_xattrop_watchlist(this, priv, watchlist, XATTROP);
+ if (ret)
+ goto out;
+
+ GF_OPTION_INIT("xattrop-dirty-watchlist", dirtylist, str, out);
+ ret = index_make_xattrop_watchlist(this, priv, dirtylist, DIRTY);
+ if (ret)
+ goto out;
+
+ GF_OPTION_INIT("xattrop-pending-watchlist", pendinglist, str, out);
+ ret = index_make_xattrop_watchlist(this, priv, pendinglist, XATTROP);
+ if (ret)
+ goto out;
+
+ if (priv->dirty_watchlist)
+ priv->complete_watchlist = dict_copy_with_ref(priv->dirty_watchlist,
priv->complete_watchlist);
- if (priv->pending_watchlist)
- priv->complete_watchlist = dict_copy_with_ref (priv->pending_watchlist,
+ if (priv->pending_watchlist)
+ priv->complete_watchlist = dict_copy_with_ref(priv->pending_watchlist,
priv->complete_watchlist);
- gf_uuid_generate (priv->index);
- for (i = 0; i < XATTROP_TYPE_END; i++)
- gf_uuid_generate (priv->internal_vgfid[i]);
-
- INIT_LIST_HEAD (&priv->callstubs);
+ gf_uuid_generate(priv->index);
+ for (i = 0; i < XATTROP_TYPE_END; i++)
+ gf_uuid_generate(priv->internal_vgfid[i]);
- this->local_pool = mem_pool_new (index_local_t, 64);
- if (!this->local_pool) {
- ret = -1;
- goto out;
- }
+ INIT_LIST_HEAD(&priv->callstubs);
- this->private = priv;
+ this->local_pool = mem_pool_new(index_local_t, 64);
+ if (!this->local_pool) {
+ ret = -1;
+ goto out;
+ }
- ret = index_dir_create (this, XATTROP_SUBDIR);
- if (ret < 0)
- goto out;
+ this->private = priv;
- if (priv->dirty_watchlist) {
- ret = index_dir_create (this, DIRTY_SUBDIR);
- if (ret < 0)
- goto out;
- }
+ ret = index_dir_create(this, XATTROP_SUBDIR);
+ if (ret < 0)
+ goto out;
- ret = index_dir_create (this, ENTRY_CHANGES_SUBDIR);
+ if (priv->dirty_watchlist) {
+ ret = index_dir_create(this, DIRTY_SUBDIR);
if (ret < 0)
- goto out;
-
- /*init indices files counts*/
- count = index_fetch_link_count (this, XATTROP);
- index_set_link_count (priv, count, XATTROP);
- priv->down = _gf_false;
-
- ret = gf_thread_create (&priv->thread, &w_attr, index_worker, this,
- "idxwrker");
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, ret,
- INDEX_MSG_WORKER_THREAD_CREATE_FAILED,
- "Failed to create worker thread, aborting");
- goto out;
- }
-
- ret = 0;
+ goto out;
+ }
+
+ ret = index_dir_create(this, ENTRY_CHANGES_SUBDIR);
+ if (ret < 0)
+ goto out;
+
+ /*init indices files counts*/
+ count = index_fetch_link_count(this, XATTROP);
+ index_set_link_count(priv, count, XATTROP);
+ priv->down = _gf_false;
+
+ ret = gf_thread_create(&priv->thread, &w_attr, index_worker, this,
+ "idxwrker");
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, ret,
+ INDEX_MSG_WORKER_THREAD_CREATE_FAILED,
+ "Failed to create worker thread, aborting");
+ goto out;
+ }
+
+ ret = 0;
out:
- GF_FREE(tmp);
-
- if (ret) {
- if (cond_inited)
- pthread_cond_destroy (&priv->cond);
- if (mutex_inited)
- pthread_mutex_destroy (&priv->mutex);
- if (priv && priv->dirty_watchlist)
- dict_unref (priv->dirty_watchlist);
- if (priv && priv->pending_watchlist)
- dict_unref (priv->pending_watchlist);
- if (priv && priv->complete_watchlist)
- dict_unref (priv->complete_watchlist);
- if (priv)
- GF_FREE (priv);
- this->private = NULL;
- mem_pool_destroy (this->local_pool);
- }
+ GF_FREE(tmp);
+
+ if (ret) {
+ if (cond_inited)
+ pthread_cond_destroy(&priv->cond);
+ if (mutex_inited)
+ pthread_mutex_destroy(&priv->mutex);
+ if (priv && priv->dirty_watchlist)
+ dict_unref(priv->dirty_watchlist);
+ if (priv && priv->pending_watchlist)
+ dict_unref(priv->pending_watchlist);
+ if (priv && priv->complete_watchlist)
+ dict_unref(priv->complete_watchlist);
+ if (priv)
+ GF_FREE(priv);
+ this->private = NULL;
+ mem_pool_destroy(this->local_pool);
+ }
- if (attr_inited)
- pthread_attr_destroy (&w_attr);
- return ret;
+ if (attr_inited)
+ pthread_attr_destroy(&w_attr);
+ return ret;
}
void
-fini (xlator_t *this)
-{
- index_priv_t *priv = NULL;
-
- priv = this->private;
- if (!priv)
- goto out;
-
- priv->down = _gf_true;
- pthread_cond_broadcast (&priv->cond);
- if (priv->thread) {
- gf_thread_cleanup_xint (priv->thread);
- priv->thread = 0;
- }
- this->private = NULL;
- LOCK_DESTROY (&priv->lock);
- pthread_cond_destroy (&priv->cond);
- pthread_mutex_destroy (&priv->mutex);
- if (priv->dirty_watchlist)
- dict_unref (priv->dirty_watchlist);
- if (priv->pending_watchlist)
- dict_unref (priv->pending_watchlist);
- if (priv->complete_watchlist)
- dict_unref (priv->complete_watchlist);
- GF_FREE (priv);
-
- if (this->local_pool) {
- mem_pool_destroy (this->local_pool);
- this->local_pool = NULL;
- }
+fini(xlator_t *this)
+{
+ index_priv_t *priv = NULL;
+
+ priv = this->private;
+ if (!priv)
+ goto out;
+
+ priv->down = _gf_true;
+ pthread_cond_broadcast(&priv->cond);
+ if (priv->thread) {
+ gf_thread_cleanup_xint(priv->thread);
+ priv->thread = 0;
+ }
+ this->private = NULL;
+ LOCK_DESTROY(&priv->lock);
+ pthread_cond_destroy(&priv->cond);
+ pthread_mutex_destroy(&priv->mutex);
+ if (priv->dirty_watchlist)
+ dict_unref(priv->dirty_watchlist);
+ if (priv->pending_watchlist)
+ dict_unref(priv->pending_watchlist);
+ if (priv->complete_watchlist)
+ dict_unref(priv->complete_watchlist);
+ GF_FREE(priv);
+
+ if (this->local_pool) {
+ mem_pool_destroy(this->local_pool);
+ this->local_pool = NULL;
+ }
out:
- return;
+ return;
}
int
-index_forget (xlator_t *this, inode_t *inode)
+index_forget(xlator_t *this, inode_t *inode)
{
- uint64_t tmp_cache = 0;
- if (!inode_ctx_del (inode, this, &tmp_cache))
- GF_FREE ((index_inode_ctx_t*) (long)tmp_cache);
+ uint64_t tmp_cache = 0;
+ if (!inode_ctx_del(inode, this, &tmp_cache))
+ GF_FREE((index_inode_ctx_t *)(long)tmp_cache);
- return 0;
+ return 0;
}
int32_t
-index_releasedir (xlator_t *this, fd_t *fd)
+index_releasedir(xlator_t *this, fd_t *fd)
{
- index_fd_ctx_t *fctx = NULL;
- uint64_t ctx = 0;
- int ret = 0;
+ index_fd_ctx_t *fctx = NULL;
+ uint64_t ctx = 0;
+ int ret = 0;
- ret = fd_ctx_del (fd, this, &ctx);
- if (ret < 0)
- goto out;
+ ret = fd_ctx_del(fd, this, &ctx);
+ if (ret < 0)
+ goto out;
- fctx = (index_fd_ctx_t*) (long) ctx;
- if (fctx->dir) {
- ret = sys_closedir (fctx->dir);
- if (ret)
- gf_msg (this->name, GF_LOG_ERROR, errno,
- INDEX_MSG_FD_OP_FAILED,
- "closedir error");
- }
+ fctx = (index_fd_ctx_t *)(long)ctx;
+ if (fctx->dir) {
+ ret = sys_closedir(fctx->dir);
+ if (ret)
+ gf_msg(this->name, GF_LOG_ERROR, errno, INDEX_MSG_FD_OP_FAILED,
+ "closedir error");
+ }
- GF_FREE (fctx);
+ GF_FREE(fctx);
out:
- return 0;
+ return 0;
}
int32_t
-index_release (xlator_t *this, fd_t *fd)
+index_release(xlator_t *this, fd_t *fd)
{
- index_fd_ctx_t *fctx = NULL;
- uint64_t ctx = 0;
- int ret = 0;
+ index_fd_ctx_t *fctx = NULL;
+ uint64_t ctx = 0;
+ int ret = 0;
- ret = fd_ctx_del (fd, this, &ctx);
- if (ret < 0)
- goto out;
+ ret = fd_ctx_del(fd, this, &ctx);
+ if (ret < 0)
+ goto out;
- fctx = (index_fd_ctx_t*) (long) ctx;
- GF_FREE (fctx);
+ fctx = (index_fd_ctx_t *)(long)ctx;
+ GF_FREE(fctx);
out:
- return 0;
+ return 0;
}
int
-notify (xlator_t *this, int event, void *data, ...)
+notify(xlator_t *this, int event, void *data, ...)
{
- int ret = 0;
- index_priv_t *priv = NULL;
+ int ret = 0;
+ index_priv_t *priv = NULL;
- if (!this)
- return 0;
+ if (!this)
+ return 0;
- priv = this->private;
- if (!priv)
- return 0;
+ priv = this->private;
+ if (!priv)
+ return 0;
- ret = default_notify (this, event, data);
- return ret;
+ ret = default_notify(this, event, data);
+ return ret;
}
struct xlator_fops fops = {
- .xattrop = index_xattrop,
- .fxattrop = index_fxattrop,
-
- //interface functions follow
- .getxattr = index_getxattr,
- .lookup = index_lookup,
- .opendir = index_opendir,
- .readdir = index_readdir,
- .unlink = index_unlink,
- .rmdir = index_rmdir,
- .fstat = index_fstat,
+ .xattrop = index_xattrop,
+ .fxattrop = index_fxattrop,
+
+ // interface functions follow
+ .getxattr = index_getxattr,
+ .lookup = index_lookup,
+ .opendir = index_opendir,
+ .readdir = index_readdir,
+ .unlink = index_unlink,
+ .rmdir = index_rmdir,
+ .fstat = index_fstat,
};
struct xlator_dumpops dumpops;
-struct xlator_cbks cbks = {
- .forget = index_forget,
- .release = index_release,
- .releasedir = index_releasedir
-};
+struct xlator_cbks cbks = {.forget = index_forget,
+ .release = index_release,
+ .releasedir = index_releasedir};
struct volume_options options[] = {
- { .key = {"index-base" },
- .type = GF_OPTION_TYPE_PATH,
- .description = "path where the index files need to be stored",
- .default_value = "{{ brick.path }}/.glusterfs/indices"
- },
- { .key = {"xattrop64-watchlist" },
- .type = GF_OPTION_TYPE_STR,
- .description = "Comma separated list of xattrs that are watched",
- .default_value = "trusted.ec.dirty"
- },
- { .key = {"xattrop-dirty-watchlist" },
- .type = GF_OPTION_TYPE_STR,
- .description = "Comma separated list of xattrs that are watched",
- .default_value = "trusted.afr.dirty"
- },
- { .key = {"xattrop-pending-watchlist" },
- .type = GF_OPTION_TYPE_STR,
- .description = "Comma separated list of xattrs that are watched",
- .default_value = "trusted.afr.{{ volume.name }}"
- },
- { .key = {NULL} },
+ {.key = {"index-base"},
+ .type = GF_OPTION_TYPE_PATH,
+ .description = "path where the index files need to be stored",
+ .default_value = "{{ brick.path }}/.glusterfs/indices"},
+ {.key = {"xattrop64-watchlist"},
+ .type = GF_OPTION_TYPE_STR,
+ .description = "Comma separated list of xattrs that are watched",
+ .default_value = "trusted.ec.dirty"},
+ {.key = {"xattrop-dirty-watchlist"},
+ .type = GF_OPTION_TYPE_STR,
+ .description = "Comma separated list of xattrs that are watched",
+ .default_value = "trusted.afr.dirty"},
+ {.key = {"xattrop-pending-watchlist"},
+ .type = GF_OPTION_TYPE_STR,
+ .description = "Comma separated list of xattrs that are watched",
+ .default_value = "trusted.afr.{{ volume.name }}"},
+ {.key = {NULL}},
};
diff --git a/xlators/features/leases/src/leases-internal.c b/xlators/features/leases/src/leases-internal.c
index fd0996e3943..f87d93d945b 100644
--- a/xlators/features/leases/src/leases-internal.c
+++ b/xlators/features/leases/src/leases-internal.c
@@ -15,7 +15,6 @@
#include "leases.h"
-
/* Mutex locks used in this xlator and their order of acquisition:
* Check lease conflict:
* lease_ctx lock
@@ -53,22 +52,21 @@
* _gf_false - lease lock option disabled
*/
gf_boolean_t
-is_leases_enabled (xlator_t *this)
+is_leases_enabled(xlator_t *this)
{
- leases_private_t *priv = NULL;
- gf_boolean_t is_enabled = _gf_false;
+ leases_private_t *priv = NULL;
+ gf_boolean_t is_enabled = _gf_false;
- GF_VALIDATE_OR_GOTO ("leases", this, out);
+ GF_VALIDATE_OR_GOTO("leases", this, out);
- if (this->private) {
- priv = (leases_private_t *)this->private;
- is_enabled = priv->leases_enabled;
- }
+ if (this->private) {
+ priv = (leases_private_t *)this->private;
+ is_enabled = priv->leases_enabled;
+ }
out:
- return is_enabled;
+ return is_enabled;
}
-
/*
* Get the recall_leaselk_timeout
* Return Value:
@@ -76,1276 +74,1275 @@ out:
* -1 error case
*/
int32_t
-get_recall_lease_timeout (xlator_t *this)
+get_recall_lease_timeout(xlator_t *this)
{
- leases_private_t *priv = NULL;
- int32_t timeout = -1;
+ leases_private_t *priv = NULL;
+ int32_t timeout = -1;
- GF_VALIDATE_OR_GOTO ("leases", this, out);
+ GF_VALIDATE_OR_GOTO("leases", this, out);
- if (this->private) {
- priv = (leases_private_t *)this->private;
- timeout = priv->recall_lease_timeout;
- }
+ if (this->private) {
+ priv = (leases_private_t *)this->private;
+ timeout = priv->recall_lease_timeout;
+ }
out:
- return timeout;
+ return timeout;
}
-
static void
-__dump_leases_info (xlator_t *this, lease_inode_ctx_t *lease_ctx)
+__dump_leases_info(xlator_t *this, lease_inode_ctx_t *lease_ctx)
{
- lease_id_entry_t *lease_entry = NULL;
- lease_id_entry_t *tmp = NULL;
-
- GF_VALIDATE_OR_GOTO ("leases", this, out);
- GF_VALIDATE_OR_GOTO ("leases", lease_ctx, out);
-
- gf_msg_debug (this->name, 0, "Lease held on this inode, lease_type: %d,"
- " lease_cnt:%"PRIu64", RD lease:%d, RW lease:%d, "
- "openfd cnt:%"PRIu64, lease_ctx->lease_type,
- lease_ctx->lease_cnt,
- lease_ctx->lease_type_cnt[GF_RD_LEASE],
- lease_ctx->lease_type_cnt[GF_RW_LEASE],
- lease_ctx->openfd_cnt);
-
- list_for_each_entry_safe (lease_entry, tmp,
- &lease_ctx->lease_id_list,
- lease_id_list) {
- gf_msg_debug (this->name, 0, "Leases held by client: %s, lease "
- "ID:%s, RD lease:%d, RW lease:%d, lease_type: %d, "
- "lease_cnt:%"PRIu64, lease_entry->client_uid,
- lease_entry->lease_id,
- lease_entry->lease_type_cnt[GF_RD_LEASE],
- lease_entry->lease_type_cnt[GF_RW_LEASE],
- lease_entry->lease_type, lease_entry->lease_cnt);
- }
+ lease_id_entry_t *lease_entry = NULL;
+ lease_id_entry_t *tmp = NULL;
+
+ GF_VALIDATE_OR_GOTO("leases", this, out);
+ GF_VALIDATE_OR_GOTO("leases", lease_ctx, out);
+
+ gf_msg_debug(this->name, 0,
+ "Lease held on this inode, lease_type: %d,"
+ " lease_cnt:%" PRIu64
+ ", RD lease:%d, RW lease:%d, "
+ "openfd cnt:%" PRIu64,
+ lease_ctx->lease_type, lease_ctx->lease_cnt,
+ lease_ctx->lease_type_cnt[GF_RD_LEASE],
+ lease_ctx->lease_type_cnt[GF_RW_LEASE], lease_ctx->openfd_cnt);
+
+ list_for_each_entry_safe(lease_entry, tmp, &lease_ctx->lease_id_list,
+ lease_id_list)
+ {
+ gf_msg_debug(this->name, 0,
+ "Leases held by client: %s, lease "
+ "ID:%s, RD lease:%d, RW lease:%d, lease_type: %d, "
+ "lease_cnt:%" PRIu64,
+ lease_entry->client_uid, lease_entry->lease_id,
+ lease_entry->lease_type_cnt[GF_RD_LEASE],
+ lease_entry->lease_type_cnt[GF_RW_LEASE],
+ lease_entry->lease_type, lease_entry->lease_cnt);
+ }
out:
- return;
+ return;
}
-
static int
-__lease_ctx_set (inode_t *inode, xlator_t *this)
+__lease_ctx_set(inode_t *inode, xlator_t *this)
{
- lease_inode_ctx_t *inode_ctx = NULL;
- int ret = -1;
- uint64_t ctx = 0;
-
- GF_VALIDATE_OR_GOTO ("leases", inode, out);
- GF_VALIDATE_OR_GOTO ("leases", this, out);
-
- ret = __inode_ctx_get (inode, this, &ctx);
- if (!ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, LEASE_MSG_INVAL_INODE_CTX,
- "inode_ctx_get failed");
- goto out;
- }
-
- inode_ctx = GF_CALLOC (1, sizeof (*inode_ctx),
- gf_leases_mt_lease_inode_ctx_t);
- GF_CHECK_ALLOC (inode_ctx, ret, out);
-
- pthread_mutex_init (&inode_ctx->lock, NULL);
- INIT_LIST_HEAD (&inode_ctx->lease_id_list);
- INIT_LIST_HEAD (&inode_ctx->blocked_list);
-
- inode_ctx->lease_cnt = 0;
-
- ret = __inode_ctx_set (inode, this, (uint64_t *) inode_ctx);
- if (ret) {
- GF_FREE (inode_ctx);
- gf_msg (this->name, GF_LOG_INFO, 0, LEASE_MSG_INVAL_INODE_CTX,
- "failed to set inode ctx (%p)", inode);
- }
+ lease_inode_ctx_t *inode_ctx = NULL;
+ int ret = -1;
+ uint64_t ctx = 0;
+
+ GF_VALIDATE_OR_GOTO("leases", inode, out);
+ GF_VALIDATE_OR_GOTO("leases", this, out);
+
+ ret = __inode_ctx_get(inode, this, &ctx);
+ if (!ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, LEASE_MSG_INVAL_INODE_CTX,
+ "inode_ctx_get failed");
+ goto out;
+ }
+
+ inode_ctx = GF_CALLOC(1, sizeof(*inode_ctx),
+ gf_leases_mt_lease_inode_ctx_t);
+ GF_CHECK_ALLOC(inode_ctx, ret, out);
+
+ pthread_mutex_init(&inode_ctx->lock, NULL);
+ INIT_LIST_HEAD(&inode_ctx->lease_id_list);
+ INIT_LIST_HEAD(&inode_ctx->blocked_list);
+
+ inode_ctx->lease_cnt = 0;
+
+ ret = __inode_ctx_set(inode, this, (uint64_t *)inode_ctx);
+ if (ret) {
+ GF_FREE(inode_ctx);
+ gf_msg(this->name, GF_LOG_INFO, 0, LEASE_MSG_INVAL_INODE_CTX,
+ "failed to set inode ctx (%p)", inode);
+ }
out:
- return ret;
+ return ret;
}
-
static lease_inode_ctx_t *
-__lease_ctx_get (inode_t *inode, xlator_t *this)
+__lease_ctx_get(inode_t *inode, xlator_t *this)
{
- lease_inode_ctx_t *inode_ctx = NULL;
- uint64_t ctx = 0;
- int ret = 0;
+ lease_inode_ctx_t *inode_ctx = NULL;
+ uint64_t ctx = 0;
+ int ret = 0;
- GF_VALIDATE_OR_GOTO ("leases", inode, out);
- GF_VALIDATE_OR_GOTO ("leases", this, out);
+ GF_VALIDATE_OR_GOTO("leases", inode, out);
+ GF_VALIDATE_OR_GOTO("leases", this, out);
- ret = __inode_ctx_get (inode, this, &ctx);
+ ret = __inode_ctx_get(inode, this, &ctx);
+ if (ret < 0) {
+ ret = __lease_ctx_set(inode, this);
+ if (ret < 0)
+ goto out;
+
+ ret = __inode_ctx_get(inode, this, &ctx);
if (ret < 0) {
- ret = __lease_ctx_set (inode, this);
- if (ret < 0)
- goto out;
-
- ret = __inode_ctx_get (inode, this, &ctx);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0, LEASE_MSG_INVAL_INODE_CTX,
- "failed to get inode ctx (%p)", inode);
- goto out;
- }
+ gf_msg(this->name, GF_LOG_WARNING, 0, LEASE_MSG_INVAL_INODE_CTX,
+ "failed to get inode ctx (%p)", inode);
+ goto out;
}
+ }
- inode_ctx = (lease_inode_ctx_t *)(long) ctx;
+ inode_ctx = (lease_inode_ctx_t *)(long)ctx;
out:
- return inode_ctx;
+ return inode_ctx;
}
-
lease_inode_ctx_t *
-lease_ctx_get (inode_t *inode, xlator_t *this)
+lease_ctx_get(inode_t *inode, xlator_t *this)
{
- lease_inode_ctx_t *inode_ctx = NULL;
+ lease_inode_ctx_t *inode_ctx = NULL;
- GF_VALIDATE_OR_GOTO ("leases", inode, out);
- GF_VALIDATE_OR_GOTO ("leases", this, out);
+ GF_VALIDATE_OR_GOTO("leases", inode, out);
+ GF_VALIDATE_OR_GOTO("leases", this, out);
- LOCK (&inode->lock);
- {
- inode_ctx = __lease_ctx_get (inode, this);
- }
- UNLOCK (&inode->lock);
+ LOCK(&inode->lock);
+ {
+ inode_ctx = __lease_ctx_get(inode, this);
+ }
+ UNLOCK(&inode->lock);
out:
- return inode_ctx;
+ return inode_ctx;
}
-
static lease_id_entry_t *
-new_lease_id_entry (call_frame_t *frame, const char *lease_id)
+new_lease_id_entry(call_frame_t *frame, const char *lease_id)
{
- lease_id_entry_t *lease_entry = NULL;
+ lease_id_entry_t *lease_entry = NULL;
- GF_VALIDATE_OR_GOTO ("leases", frame, out);
- GF_VALIDATE_OR_GOTO ("leases", lease_id, out);
+ GF_VALIDATE_OR_GOTO("leases", frame, out);
+ GF_VALIDATE_OR_GOTO("leases", lease_id, out);
- lease_entry = GF_CALLOC (1, sizeof (*lease_entry),
- gf_leases_mt_lease_id_entry_t);
- if (!lease_entry) {
- gf_msg (frame->this->name, GF_LOG_ERROR, ENOMEM, LEASE_MSG_NO_MEM,
- "Memory allocation for lease_entry failed");
- return NULL;
- }
-
- INIT_LIST_HEAD (&lease_entry->lease_id_list);
- lease_entry->lease_type = NONE;
- lease_entry->lease_cnt = 0;
- lease_entry->recall_time =
- get_recall_lease_timeout (frame->this);
- lease_entry->client_uid = gf_strdup (frame->root->client->client_uid);
- if (!lease_entry->client_uid) {
- gf_msg (frame->this->name, GF_LOG_ERROR, ENOMEM, LEASE_MSG_NO_MEM,
- "Memory allocation for client_uid failed");
- GF_FREE (lease_entry);
- lease_entry = NULL;
- goto out;
- }
-
- memcpy (lease_entry->lease_id, lease_id, LEASE_ID_SIZE);
+ lease_entry = GF_CALLOC(1, sizeof(*lease_entry),
+ gf_leases_mt_lease_id_entry_t);
+ if (!lease_entry) {
+ gf_msg(frame->this->name, GF_LOG_ERROR, ENOMEM, LEASE_MSG_NO_MEM,
+ "Memory allocation for lease_entry failed");
+ return NULL;
+ }
+
+ INIT_LIST_HEAD(&lease_entry->lease_id_list);
+ lease_entry->lease_type = NONE;
+ lease_entry->lease_cnt = 0;
+ lease_entry->recall_time = get_recall_lease_timeout(frame->this);
+ lease_entry->client_uid = gf_strdup(frame->root->client->client_uid);
+ if (!lease_entry->client_uid) {
+ gf_msg(frame->this->name, GF_LOG_ERROR, ENOMEM, LEASE_MSG_NO_MEM,
+ "Memory allocation for client_uid failed");
+ GF_FREE(lease_entry);
+ lease_entry = NULL;
+ goto out;
+ }
+
+ memcpy(lease_entry->lease_id, lease_id, LEASE_ID_SIZE);
out:
- return lease_entry;
+ return lease_entry;
}
-
static void
-__destroy_lease_id_entry (lease_id_entry_t *lease_entry)
+__destroy_lease_id_entry(lease_id_entry_t *lease_entry)
{
- GF_VALIDATE_OR_GOTO ("leases", lease_entry, out);
+ GF_VALIDATE_OR_GOTO("leases", lease_entry, out);
- list_del_init (&lease_entry->lease_id_list);
- GF_FREE (lease_entry->client_uid);
- GF_FREE (lease_entry);
+ list_del_init(&lease_entry->lease_id_list);
+ GF_FREE(lease_entry->client_uid);
+ GF_FREE(lease_entry);
out:
- return;
+ return;
}
-
static inline gf_boolean_t
-__is_same_lease_id (const char *k1, const char *k2)
+__is_same_lease_id(const char *k1, const char *k2)
{
- if (memcmp(k1, k2, strlen(k1)) == 0)
- return _gf_true;
+ if (memcmp(k1, k2, strlen(k1)) == 0)
+ return _gf_true;
- return _gf_false;
+ return _gf_false;
}
-
/* Checks if there are any leases, other than the leases taken
* by the given lease_id
*/
static gf_boolean_t
-__another_lease_found (lease_inode_ctx_t *lease_ctx, const char *lease_id)
+__another_lease_found(lease_inode_ctx_t *lease_ctx, const char *lease_id)
{
- lease_id_entry_t *lease_entry = NULL;
- lease_id_entry_t *tmp = NULL;
- gf_boolean_t found_lease = _gf_false;
-
- GF_VALIDATE_OR_GOTO ("leases", lease_id, out);
- GF_VALIDATE_OR_GOTO ("leases", lease_ctx, out);
-
- list_for_each_entry_safe (lease_entry, tmp,
- &lease_ctx->lease_id_list,
- lease_id_list) {
-
- if (!__is_same_lease_id (lease_id, lease_entry->lease_id)) {
- if (lease_entry->lease_cnt > 0) {
- found_lease = _gf_true;
- break;
- }
- }
+ lease_id_entry_t *lease_entry = NULL;
+ lease_id_entry_t *tmp = NULL;
+ gf_boolean_t found_lease = _gf_false;
+
+ GF_VALIDATE_OR_GOTO("leases", lease_id, out);
+ GF_VALIDATE_OR_GOTO("leases", lease_ctx, out);
+
+ list_for_each_entry_safe(lease_entry, tmp, &lease_ctx->lease_id_list,
+ lease_id_list)
+ {
+ if (!__is_same_lease_id(lease_id, lease_entry->lease_id)) {
+ if (lease_entry->lease_cnt > 0) {
+ found_lease = _gf_true;
+ break;
+ }
}
+ }
out:
- return found_lease;
+ return found_lease;
}
-
/* Returns the lease_id_entry for a given lease_id and a given inode.
* Return values:
* NULL - If no client entry found
* lease_id_entry_t* - a pointer to the client entry if found
*/
static lease_id_entry_t *
-__get_lease_id_entry (lease_inode_ctx_t *lease_ctx, const char *lease_id)
+__get_lease_id_entry(lease_inode_ctx_t *lease_ctx, const char *lease_id)
{
- lease_id_entry_t *lease_entry = NULL;
- lease_id_entry_t *tmp = NULL;
- lease_id_entry_t *found = NULL;
-
- GF_VALIDATE_OR_GOTO ("leases", lease_id, out);
- GF_VALIDATE_OR_GOTO ("leases", lease_ctx, out);
-
- list_for_each_entry_safe (lease_entry, tmp,
- &lease_ctx->lease_id_list,
- lease_id_list) {
-
- if (__is_same_lease_id (lease_id, lease_entry->lease_id)) {
- found = lease_entry;
- gf_msg_debug ("leases", 0, "lease ID entry found "
- "Client UID:%s, lease id:%s",
- lease_entry->client_uid,
- leaseid_utoa (lease_entry->lease_id));
- break;
- }
+ lease_id_entry_t *lease_entry = NULL;
+ lease_id_entry_t *tmp = NULL;
+ lease_id_entry_t *found = NULL;
+
+ GF_VALIDATE_OR_GOTO("leases", lease_id, out);
+ GF_VALIDATE_OR_GOTO("leases", lease_ctx, out);
+
+ list_for_each_entry_safe(lease_entry, tmp, &lease_ctx->lease_id_list,
+ lease_id_list)
+ {
+ if (__is_same_lease_id(lease_id, lease_entry->lease_id)) {
+ found = lease_entry;
+ gf_msg_debug("leases", 0,
+ "lease ID entry found "
+ "Client UID:%s, lease id:%s",
+ lease_entry->client_uid,
+ leaseid_utoa(lease_entry->lease_id));
+ break;
}
+ }
out:
- return found;
+ return found;
}
-
/* Returns the lease_id_entry for a given lease_id and a given inode,
* if none found creates one.
* Return values:
* lease_id_entry_t* - a pointer to the client entry
*/
static lease_id_entry_t *
-__get_or_new_lease_entry (call_frame_t *frame, const char *lease_id,
- lease_inode_ctx_t *lease_ctx)
+__get_or_new_lease_entry(call_frame_t *frame, const char *lease_id,
+ lease_inode_ctx_t *lease_ctx)
{
- lease_id_entry_t *lease_entry = NULL;
-
- GF_VALIDATE_OR_GOTO ("leases", frame, out);
- GF_VALIDATE_OR_GOTO ("leases", lease_id, out);
- GF_VALIDATE_OR_GOTO ("leases", lease_ctx, out);
-
- lease_entry = __get_lease_id_entry (lease_ctx, lease_id);
- if (!lease_entry) { /* create one */
- lease_entry = new_lease_id_entry (frame, lease_id);
- if (!lease_entry)
- goto out;
-
- list_add_tail (&lease_entry->lease_id_list,
- &lease_ctx->lease_id_list);
-
- gf_msg_debug (frame->this->name, 0, "lease ID entry added,"
- " Client UID:%s, lease id:%s",
- lease_entry->client_uid,
- leaseid_utoa (lease_entry->lease_id));
- }
+ lease_id_entry_t *lease_entry = NULL;
+
+ GF_VALIDATE_OR_GOTO("leases", frame, out);
+ GF_VALIDATE_OR_GOTO("leases", lease_id, out);
+ GF_VALIDATE_OR_GOTO("leases", lease_ctx, out);
+
+ lease_entry = __get_lease_id_entry(lease_ctx, lease_id);
+ if (!lease_entry) { /* create one */
+ lease_entry = new_lease_id_entry(frame, lease_id);
+ if (!lease_entry)
+ goto out;
+
+ list_add_tail(&lease_entry->lease_id_list, &lease_ctx->lease_id_list);
+
+ gf_msg_debug(frame->this->name, 0,
+ "lease ID entry added,"
+ " Client UID:%s, lease id:%s",
+ lease_entry->client_uid,
+ leaseid_utoa(lease_entry->lease_id));
+ }
out:
- return lease_entry;
+ return lease_entry;
}
-
static lease_inode_t *
-new_lease_inode (inode_t *inode)
+new_lease_inode(inode_t *inode)
{
- lease_inode_t *l_inode = NULL;
+ lease_inode_t *l_inode = NULL;
- l_inode = GF_CALLOC (1, sizeof (*l_inode), gf_leases_mt_lease_inode_t);
- if (!l_inode)
- goto out;
+ l_inode = GF_CALLOC(1, sizeof(*l_inode), gf_leases_mt_lease_inode_t);
+ if (!l_inode)
+ goto out;
- INIT_LIST_HEAD (&l_inode->list);
- l_inode->inode = inode_ref (inode);
+ INIT_LIST_HEAD(&l_inode->list);
+ l_inode->inode = inode_ref(inode);
out:
- return l_inode;
+ return l_inode;
}
-
static void
-__destroy_lease_inode (lease_inode_t *l_inode)
+__destroy_lease_inode(lease_inode_t *l_inode)
{
- list_del_init (&l_inode->list);
- inode_unref (l_inode->inode);
- GF_FREE (l_inode);
+ list_del_init(&l_inode->list);
+ inode_unref(l_inode->inode);
+ GF_FREE(l_inode);
}
-
static lease_client_t *
-new_lease_client (const char *client_uid)
+new_lease_client(const char *client_uid)
{
- lease_client_t *clnt = NULL;
+ lease_client_t *clnt = NULL;
- clnt = GF_CALLOC (1, sizeof (*clnt), gf_leases_mt_lease_client_t);
- if (!clnt)
- goto out;
+ clnt = GF_CALLOC(1, sizeof(*clnt), gf_leases_mt_lease_client_t);
+ if (!clnt)
+ goto out;
- INIT_LIST_HEAD (&clnt->client_list);
- INIT_LIST_HEAD (&clnt->inode_list);
- clnt->client_uid = gf_strdup (client_uid);
+ INIT_LIST_HEAD(&clnt->client_list);
+ INIT_LIST_HEAD(&clnt->inode_list);
+ clnt->client_uid = gf_strdup(client_uid);
out:
- return clnt;
+ return clnt;
}
-
static void
-__destroy_lease_client (lease_client_t *clnt)
+__destroy_lease_client(lease_client_t *clnt)
{
- list_del_init (&clnt->inode_list);
- list_del_init (&clnt->client_list);
- GF_FREE (clnt);
+ list_del_init(&clnt->inode_list);
+ list_del_init(&clnt->client_list);
+ GF_FREE(clnt);
- return;
+ return;
}
-
static lease_client_t *
-__get_lease_client (xlator_t *this, leases_private_t *priv,
- const char *client_uid)
+__get_lease_client(xlator_t *this, leases_private_t *priv,
+ const char *client_uid)
{
- lease_client_t *clnt = NULL;
- lease_client_t *tmp = NULL;
- lease_client_t *found = NULL;
-
- list_for_each_entry_safe (clnt, tmp, &priv->client_list, client_list) {
- if ((strcmp (clnt->client_uid, client_uid) == 0)) {
- found = clnt;
- gf_msg_debug (this->name, 0, "Client:%s already found "
- "in the cleanup list", client_uid);
- break;
- }
+ lease_client_t *clnt = NULL;
+ lease_client_t *tmp = NULL;
+ lease_client_t *found = NULL;
+
+ list_for_each_entry_safe(clnt, tmp, &priv->client_list, client_list)
+ {
+ if ((strcmp(clnt->client_uid, client_uid) == 0)) {
+ found = clnt;
+ gf_msg_debug(this->name, 0,
+ "Client:%s already found "
+ "in the cleanup list",
+ client_uid);
+ break;
}
- return found;
+ }
+ return found;
}
-
static lease_client_t *
-__get_or_new_lease_client (xlator_t *this, leases_private_t *priv,
- const char *client_uid)
+__get_or_new_lease_client(xlator_t *this, leases_private_t *priv,
+ const char *client_uid)
{
- lease_client_t *found = NULL;
-
- found = __get_lease_client (this, priv, client_uid);
- if (!found) {
- found = new_lease_client (client_uid);
- if (!found)
- goto out;
- list_add_tail (&found->client_list, &priv->client_list);
- gf_msg_debug (this->name, 0, "Adding a new client:%s entry "
- "to the cleanup list", client_uid);
- }
+ lease_client_t *found = NULL;
+
+ found = __get_lease_client(this, priv, client_uid);
+ if (!found) {
+ found = new_lease_client(client_uid);
+ if (!found)
+ goto out;
+ list_add_tail(&found->client_list, &priv->client_list);
+ gf_msg_debug(this->name, 0,
+ "Adding a new client:%s entry "
+ "to the cleanup list",
+ client_uid);
+ }
out:
- return found;
+ return found;
}
-
static int
-add_inode_to_client_list (xlator_t *this, inode_t *inode, const char *client_uid)
+add_inode_to_client_list(xlator_t *this, inode_t *inode, const char *client_uid)
{
- int ret = 0;
- leases_private_t *priv = NULL;
- lease_client_t *clnt = NULL;
- lease_inode_t *lease_inode = NULL;
-
- priv = this->private;
- pthread_mutex_lock (&priv->mutex);
- {
- clnt = __get_or_new_lease_client (this, priv, client_uid);
- GF_CHECK_ALLOC (clnt, ret, out);
-
- lease_inode = new_lease_inode (inode);
- GF_CHECK_ALLOC (lease_inode, ret, out);
-
- list_add_tail (&clnt->inode_list, &lease_inode->list);
- gf_msg_debug (this->name, 0,
- "Added a new inode:%p to the client(%s) "
- "cleanup list, gfid(%s)", inode, client_uid,
- uuid_utoa (inode->gfid));
- }
+ int ret = 0;
+ leases_private_t *priv = NULL;
+ lease_client_t *clnt = NULL;
+ lease_inode_t *lease_inode = NULL;
+
+ priv = this->private;
+ pthread_mutex_lock(&priv->mutex);
+ {
+ clnt = __get_or_new_lease_client(this, priv, client_uid);
+ GF_CHECK_ALLOC(clnt, ret, out);
+
+ lease_inode = new_lease_inode(inode);
+ GF_CHECK_ALLOC(lease_inode, ret, out);
+
+ list_add_tail(&clnt->inode_list, &lease_inode->list);
+ gf_msg_debug(this->name, 0,
+ "Added a new inode:%p to the client(%s) "
+ "cleanup list, gfid(%s)",
+ inode, client_uid, uuid_utoa(inode->gfid));
+ }
out:
- pthread_mutex_unlock (&priv->mutex);
- return ret;
+ pthread_mutex_unlock(&priv->mutex);
+ return ret;
}
-
/* Add lease entry to the corresponding client entry.
* Return values:
* 0 Success
* -1 Failure
*/
static int
-__add_lease (call_frame_t *frame, inode_t *inode, lease_inode_ctx_t *lease_ctx,
- const char *client_uid, struct gf_lease *lease)
+__add_lease(call_frame_t *frame, inode_t *inode, lease_inode_ctx_t *lease_ctx,
+ const char *client_uid, struct gf_lease *lease)
{
- lease_id_entry_t *lease_entry = NULL;
- int ret = -1;
-
- GF_VALIDATE_OR_GOTO ("leases", frame, out);
- GF_VALIDATE_OR_GOTO ("leases", client_uid, out);
- GF_VALIDATE_OR_GOTO ("leases", lease_ctx, out);
- GF_VALIDATE_OR_GOTO ("leases", inode, out);
- GF_VALIDATE_OR_GOTO ("leases", lease, out);
-
- gf_msg_trace (frame->this->name, 0,
- "Granting lease lock to client %s with lease id %s"
- " on gfid(%s)", client_uid, leaseid_utoa (lease->lease_id),
- uuid_utoa (inode->gfid));
-
- lease_entry = __get_or_new_lease_entry (frame, lease->lease_id, lease_ctx);
- if (!lease_entry) {
- errno = ENOMEM;
- goto out;
- }
-
- lease_entry->lease_type_cnt[lease->lease_type]++;
- lease_entry->lease_cnt++;
- lease_entry->lease_type |= lease->lease_type;
- /* If this is the first lease taken by the client on the file, then
- * add this inode/file to the client disconnect cleanup list
- */
- if (lease_entry->lease_cnt == 1) {
- add_inode_to_client_list (frame->this, inode, client_uid);
- }
-
- lease_ctx->lease_cnt++;
- lease_ctx->lease_type_cnt[lease->lease_type]++;
- lease_ctx->lease_type |= lease->lease_type;
-
- /* Take a ref for the first lock taken on this inode. Corresponding
- * unref when all the leases are unlocked or during DISCONNECT
- * Ref is required because the inode on which lease is acquired should
- * not be deleted when lru cleanup kicks in*/
- if (lease_ctx->lease_cnt == 1) {
- lease_ctx->inode = inode_ref (inode);
- }
-
- ret = 0;
+ lease_id_entry_t *lease_entry = NULL;
+ int ret = -1;
+
+ GF_VALIDATE_OR_GOTO("leases", frame, out);
+ GF_VALIDATE_OR_GOTO("leases", client_uid, out);
+ GF_VALIDATE_OR_GOTO("leases", lease_ctx, out);
+ GF_VALIDATE_OR_GOTO("leases", inode, out);
+ GF_VALIDATE_OR_GOTO("leases", lease, out);
+
+ gf_msg_trace(frame->this->name, 0,
+ "Granting lease lock to client %s with lease id %s"
+ " on gfid(%s)",
+ client_uid, leaseid_utoa(lease->lease_id),
+ uuid_utoa(inode->gfid));
+
+ lease_entry = __get_or_new_lease_entry(frame, lease->lease_id, lease_ctx);
+ if (!lease_entry) {
+ errno = ENOMEM;
+ goto out;
+ }
+
+ lease_entry->lease_type_cnt[lease->lease_type]++;
+ lease_entry->lease_cnt++;
+ lease_entry->lease_type |= lease->lease_type;
+ /* If this is the first lease taken by the client on the file, then
+ * add this inode/file to the client disconnect cleanup list
+ */
+ if (lease_entry->lease_cnt == 1) {
+ add_inode_to_client_list(frame->this, inode, client_uid);
+ }
+
+ lease_ctx->lease_cnt++;
+ lease_ctx->lease_type_cnt[lease->lease_type]++;
+ lease_ctx->lease_type |= lease->lease_type;
+
+ /* Take a ref for the first lock taken on this inode. Corresponding
+ * unref when all the leases are unlocked or during DISCONNECT
+ * Ref is required because the inode on which lease is acquired should
+ * not be deleted when lru cleanup kicks in*/
+ if (lease_ctx->lease_cnt == 1) {
+ lease_ctx->inode = inode_ref(inode);
+ }
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
static gf_boolean_t
-__is_clnt_lease_none (const char *client_uid, lease_inode_ctx_t *lease_ctx)
+__is_clnt_lease_none(const char *client_uid, lease_inode_ctx_t *lease_ctx)
{
- gf_boolean_t lease_none = _gf_true;
- lease_id_entry_t *lease_entry = NULL;
- lease_id_entry_t *tmp = NULL;
-
- list_for_each_entry_safe (lease_entry, tmp,
- &lease_ctx->lease_id_list,
- lease_id_list) {
- if ((strcmp (client_uid, lease_entry->client_uid) == 0)
- && (lease_entry->lease_cnt != 0)) {
- lease_none = _gf_false;
- break;
- }
+ gf_boolean_t lease_none = _gf_true;
+ lease_id_entry_t *lease_entry = NULL;
+ lease_id_entry_t *tmp = NULL;
+
+ list_for_each_entry_safe(lease_entry, tmp, &lease_ctx->lease_id_list,
+ lease_id_list)
+ {
+ if ((strcmp(client_uid, lease_entry->client_uid) == 0) &&
+ (lease_entry->lease_cnt != 0)) {
+ lease_none = _gf_false;
+ break;
}
+ }
- return lease_none;
+ return lease_none;
}
static int
-__remove_inode_from_clnt_list (xlator_t *this, lease_client_t *clnt,
- inode_t *inode)
+__remove_inode_from_clnt_list(xlator_t *this, lease_client_t *clnt,
+ inode_t *inode)
{
- int ret = -1;
- lease_inode_t *l_inode = NULL;
- lease_inode_t *tmp1 = NULL;
-
- list_for_each_entry_safe (l_inode, tmp1,
- &clnt->inode_list,
- list) {
- if (l_inode->inode == inode) {
- __destroy_lease_inode (l_inode);
- gf_msg_debug (this->name, 0,
- "Removed the inode from the client cleanup list");
- ret = 0;
- }
+ int ret = -1;
+ lease_inode_t *l_inode = NULL;
+ lease_inode_t *tmp1 = NULL;
+
+ list_for_each_entry_safe(l_inode, tmp1, &clnt->inode_list, list)
+ {
+ if (l_inode->inode == inode) {
+ __destroy_lease_inode(l_inode);
+ gf_msg_debug(this->name, 0,
+ "Removed the inode from the client cleanup list");
+ ret = 0;
}
- /* TODO: Remove the client entry from the cleanup list */
+ }
+ /* TODO: Remove the client entry from the cleanup list */
- return ret;
+ return ret;
}
-
static int
-remove_from_clnt_list (xlator_t *this, const char *client_uid, inode_t *inode)
+remove_from_clnt_list(xlator_t *this, const char *client_uid, inode_t *inode)
{
- leases_private_t *priv = NULL;
- int ret = -1;
- lease_client_t *clnt = NULL;
-
- priv = this->private;
- if (!priv)
- goto out;
-
- pthread_mutex_lock (&priv->mutex);
- {
- clnt = __get_lease_client (this, priv, client_uid);
- if (!clnt) {
- gf_msg (this->name, GF_LOG_ERROR, 0, LEASE_MSG_CLNT_NOTFOUND,
- "There is no client entry found in the cleanup list");
- pthread_mutex_unlock (&priv->mutex);
- goto out;
- }
- ret = __remove_inode_from_clnt_list (this, clnt, inode);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, LEASE_MSG_INODE_NOTFOUND,
- "There is no inode entry found in the cleanup list");
- }
+ leases_private_t *priv = NULL;
+ int ret = -1;
+ lease_client_t *clnt = NULL;
+
+ priv = this->private;
+ if (!priv)
+ goto out;
+
+ pthread_mutex_lock(&priv->mutex);
+ {
+ clnt = __get_lease_client(this, priv, client_uid);
+ if (!clnt) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, LEASE_MSG_CLNT_NOTFOUND,
+ "There is no client entry found in the cleanup list");
+ pthread_mutex_unlock(&priv->mutex);
+ goto out;
}
- pthread_mutex_unlock (&priv->mutex);
+ ret = __remove_inode_from_clnt_list(this, clnt, inode);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, LEASE_MSG_INODE_NOTFOUND,
+ "There is no inode entry found in the cleanup list");
+ }
+ }
+ pthread_mutex_unlock(&priv->mutex);
out:
- return ret;
+ return ret;
}
-
/* Remove lease entry in the corresponding client entry.
*/
static int
-__remove_lease (xlator_t *this, inode_t *inode, lease_inode_ctx_t *lease_ctx,
- const char *client_uid, struct gf_lease *lease)
+__remove_lease(xlator_t *this, inode_t *inode, lease_inode_ctx_t *lease_ctx,
+ const char *client_uid, struct gf_lease *lease)
{
- lease_id_entry_t *lease_entry = NULL;
- int ret = 0;
- int32_t lease_type = 0;
- leases_private_t *priv = NULL;
-
- GF_VALIDATE_OR_GOTO ("leases", lease_ctx, out);
- GF_VALIDATE_OR_GOTO ("leases", lease, out);
-
- priv = this->private;
-
- gf_msg_trace (this->name, 0, "Removing lease entry for client: %s, "
- "lease type:%d, lease id:%s", client_uid, lease->lease_type,
- leaseid_utoa (lease->lease_id));
-
- lease_entry = __get_lease_id_entry (lease_ctx, lease->lease_id);
- if (!lease_entry || !(lease_entry->lease_type & lease->lease_type)) {
- gf_msg (this->name, GF_LOG_INFO, 0, LEASE_MSG_INVAL_UNLK_LEASE,
- "Got unlock lease request from client:%s, but has no "
- "corresponding lock", client_uid);
- ret = -EINVAL;
- errno = EINVAL;
- goto out;
- }
-
- lease_type = lease->lease_type;
- lease_entry->lease_type_cnt[lease_type]--;
- lease_entry->lease_cnt--;
-
- lease_ctx->lease_type_cnt[lease_type]--;
- lease_ctx->lease_cnt--;
-
- if (lease_entry->lease_type_cnt[lease_type] == 0)
- lease_entry->lease_type = lease_entry->lease_type & (~lease_type);
-
- if (lease_ctx->lease_type_cnt[lease_type] == 0)
- lease_ctx->lease_type = lease_ctx->lease_type & (~lease_type);
-
- if (lease_entry->lease_cnt == 0) {
- if (__is_clnt_lease_none (client_uid, lease_ctx)) {
- gf_msg_trace (this->name, 0, "Client(%s) has no leases"
- " on gfid (%s), hence removing the inode"
- " from the client cleanup list",
- client_uid, uuid_utoa (inode->gfid));
- remove_from_clnt_list (this, client_uid, lease_ctx->inode);
- }
- __destroy_lease_id_entry (lease_entry);
+ lease_id_entry_t *lease_entry = NULL;
+ int ret = 0;
+ int32_t lease_type = 0;
+ leases_private_t *priv = NULL;
+
+ GF_VALIDATE_OR_GOTO("leases", lease_ctx, out);
+ GF_VALIDATE_OR_GOTO("leases", lease, out);
+
+ priv = this->private;
+
+ gf_msg_trace(this->name, 0,
+ "Removing lease entry for client: %s, "
+ "lease type:%d, lease id:%s",
+ client_uid, lease->lease_type, leaseid_utoa(lease->lease_id));
+
+ lease_entry = __get_lease_id_entry(lease_ctx, lease->lease_id);
+ if (!lease_entry || !(lease_entry->lease_type & lease->lease_type)) {
+ gf_msg(this->name, GF_LOG_INFO, 0, LEASE_MSG_INVAL_UNLK_LEASE,
+ "Got unlock lease request from client:%s, but has no "
+ "corresponding lock",
+ client_uid);
+ ret = -EINVAL;
+ errno = EINVAL;
+ goto out;
+ }
+
+ lease_type = lease->lease_type;
+ lease_entry->lease_type_cnt[lease_type]--;
+ lease_entry->lease_cnt--;
+
+ lease_ctx->lease_type_cnt[lease_type]--;
+ lease_ctx->lease_cnt--;
+
+ if (lease_entry->lease_type_cnt[lease_type] == 0)
+ lease_entry->lease_type = lease_entry->lease_type & (~lease_type);
+
+ if (lease_ctx->lease_type_cnt[lease_type] == 0)
+ lease_ctx->lease_type = lease_ctx->lease_type & (~lease_type);
+
+ if (lease_entry->lease_cnt == 0) {
+ if (__is_clnt_lease_none(client_uid, lease_ctx)) {
+ gf_msg_trace(this->name, 0,
+ "Client(%s) has no leases"
+ " on gfid (%s), hence removing the inode"
+ " from the client cleanup list",
+ client_uid, uuid_utoa(inode->gfid));
+ remove_from_clnt_list(this, client_uid, lease_ctx->inode);
}
+ __destroy_lease_id_entry(lease_entry);
+ }
- if (lease_ctx->lease_cnt == 0 && lease_ctx->timer) {
- ret = gf_tw_del_timer (priv->timer_wheel, lease_ctx->timer);
- lease_ctx->recall_in_progress = _gf_false;
- }
+ if (lease_ctx->lease_cnt == 0 && lease_ctx->timer) {
+ ret = gf_tw_del_timer(priv->timer_wheel, lease_ctx->timer);
+ lease_ctx->recall_in_progress = _gf_false;
+ }
out:
- return ret;
+ return ret;
}
-
static gf_boolean_t
-__is_lease_grantable (xlator_t *this, lease_inode_ctx_t *lease_ctx,
- struct gf_lease *lease, inode_t *inode)
+__is_lease_grantable(xlator_t *this, lease_inode_ctx_t *lease_ctx,
+ struct gf_lease *lease, inode_t *inode)
{
- uint32_t fd_count = 0;
- int32_t flags = 0;
- fd_t *iter_fd = NULL;
- gf_boolean_t grant = _gf_false;
- int ret = 0;
- lease_fd_ctx_t *fd_ctx = NULL;
- uint64_t ctx = 0;
-
- GF_VALIDATE_OR_GOTO ("leases", lease_ctx, out);
- GF_VALIDATE_OR_GOTO ("leases", lease, out);
- GF_VALIDATE_OR_GOTO ("leases", inode, out);
-
- if (lease_ctx->recall_in_progress) {
- gf_msg_debug (this->name, 0, "Recall in progress, hence "
- "failing the lease request");
+ uint32_t fd_count = 0;
+ int32_t flags = 0;
+ fd_t *iter_fd = NULL;
+ gf_boolean_t grant = _gf_false;
+ int ret = 0;
+ lease_fd_ctx_t *fd_ctx = NULL;
+ uint64_t ctx = 0;
+
+ GF_VALIDATE_OR_GOTO("leases", lease_ctx, out);
+ GF_VALIDATE_OR_GOTO("leases", lease, out);
+ GF_VALIDATE_OR_GOTO("leases", inode, out);
+
+ if (lease_ctx->recall_in_progress) {
+ gf_msg_debug(this->name, 0,
+ "Recall in progress, hence "
+ "failing the lease request");
+ grant = _gf_false;
+ goto out;
+ }
+
+ LOCK(&inode->lock);
+ {
+ list_for_each_entry(iter_fd, &inode->fd_list, inode_list)
+ {
+ ret = fd_ctx_get(iter_fd, this, &ctx);
+ if (ret < 0) {
grant = _gf_false;
+ UNLOCK(&inode->lock);
+ gf_msg(this->name, GF_LOG_ERROR, 0, LEASE_MSG_INVAL_FD_CTX,
+ "Unable to get fd ctx");
goto out;
+ }
+ fd_ctx = (lease_fd_ctx_t *)(long)ctx;
+
+ /* Check for open fd conflict, note that open fds from
+ * the same lease id is not checked for conflict, as it is
+ * lease id based lease.
+ */
+ if (fd_ctx->client_uid != NULL &&
+ !__is_same_lease_id(fd_ctx->lease_id, lease->lease_id)) {
+ fd_count++;
+ flags |= iter_fd->flags;
+ }
}
+ }
+ UNLOCK(&inode->lock);
- LOCK (&inode->lock);
- {
- list_for_each_entry (iter_fd, &inode->fd_list, inode_list) {
- ret = fd_ctx_get (iter_fd, this, &ctx);
- if (ret < 0) {
- grant = _gf_false;
- UNLOCK (&inode->lock);
- gf_msg (this->name, GF_LOG_ERROR, 0,
- LEASE_MSG_INVAL_FD_CTX,
- "Unable to get fd ctx");
- goto out;
- }
- fd_ctx = (lease_fd_ctx_t *)(long) ctx;
-
- /* Check for open fd conflict, note that open fds from
- * the same lease id is not checked for conflict, as it is
- * lease id based lease.
- */
- if (fd_ctx->client_uid != NULL
- && !__is_same_lease_id (fd_ctx->lease_id, lease->lease_id)) {
- fd_count++;
- flags |= iter_fd->flags;
- }
- }
- }
- UNLOCK (&inode->lock);
-
- gf_msg_debug (this->name, 0, "open fd count:%d flags:%d",
- fd_count, flags);
+ gf_msg_debug(this->name, 0, "open fd count:%d flags:%d", fd_count, flags);
- __dump_leases_info (this, lease_ctx);
+ __dump_leases_info(this, lease_ctx);
- switch (lease->lease_type) {
+ switch (lease->lease_type) {
case GF_RD_LEASE:
- /* check open fd conflict */
- if ((fd_count > 0) && ((flags & O_WRONLY) || (flags & O_RDWR))) {
- grant = _gf_false;
- break;
- }
-
- /* check for conflict with existing leases */
- if (lease_ctx->lease_type == NONE ||
- lease_ctx->lease_type == GF_RD_LEASE ||
- !(__another_lease_found (lease_ctx, lease->lease_id)))
- grant = _gf_true;
- else
- grant = _gf_false;
+ /* check open fd conflict */
+ if ((fd_count > 0) && ((flags & O_WRONLY) || (flags & O_RDWR))) {
+ grant = _gf_false;
break;
+ }
+
+ /* check for conflict with existing leases */
+ if (lease_ctx->lease_type == NONE ||
+ lease_ctx->lease_type == GF_RD_LEASE ||
+ !(__another_lease_found(lease_ctx, lease->lease_id)))
+ grant = _gf_true;
+ else
+ grant = _gf_false;
+ break;
case GF_RW_LEASE:
- /* check open fd conflict; conflict if there are any fds open
- * other than the client on which the lease is requested. */
- if (fd_count > 0) {
- grant = _gf_false;
- break;
- }
-
- /* check existing lease conflict */
- if (lease_ctx->lease_type == NONE ||
- !(__another_lease_found (lease_ctx, lease->lease_id)))
- grant = _gf_true;
- else
- grant = _gf_false;
+ /* check open fd conflict; conflict if there are any fds open
+ * other than the client on which the lease is requested. */
+ if (fd_count > 0) {
+ grant = _gf_false;
break;
+ }
+
+ /* check existing lease conflict */
+ if (lease_ctx->lease_type == NONE ||
+ !(__another_lease_found(lease_ctx, lease->lease_id)))
+ grant = _gf_true;
+ else
+ grant = _gf_false;
+ break;
default:
- gf_msg (this->name, GF_LOG_ERROR, EINVAL, LEASE_MSG_INVAL_LEASE_TYPE,
- "Invalid lease type specified");
- break;
- }
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, LEASE_MSG_INVAL_LEASE_TYPE,
+ "Invalid lease type specified");
+ break;
+ }
out:
- return grant;
+ return grant;
}
-
static void
-do_blocked_fops (xlator_t *this, lease_inode_ctx_t *lease_ctx)
+do_blocked_fops(xlator_t *this, lease_inode_ctx_t *lease_ctx)
{
- struct list_head wind_list;
- fop_stub_t *blk_fop = NULL;
- fop_stub_t *tmp = NULL;
-
- INIT_LIST_HEAD (&wind_list);
+ struct list_head wind_list;
+ fop_stub_t *blk_fop = NULL;
+ fop_stub_t *tmp = NULL;
- pthread_mutex_lock (&lease_ctx->lock);
- {
- list_for_each_entry_safe (blk_fop, tmp,
- &lease_ctx->blocked_list, list) {
- list_del_init (&blk_fop->list);
- list_add_tail (&blk_fop->list, &wind_list);
- }
- }
- pthread_mutex_unlock (&lease_ctx->lock);
-
- gf_msg_trace (this->name, 0, "Executing the blocked stubs on gfid(%s)",
- uuid_utoa (lease_ctx->inode->gfid));
- list_for_each_entry_safe (blk_fop, tmp, &wind_list, list) {
- list_del_init (&blk_fop->list);
- gf_msg_trace (this->name, 0, "Executing fop:%d", blk_fop->stub->fop);
- call_resume (blk_fop->stub);
- GF_FREE (blk_fop);
- }
+ INIT_LIST_HEAD(&wind_list);
- pthread_mutex_lock (&lease_ctx->lock);
+ pthread_mutex_lock(&lease_ctx->lock);
+ {
+ list_for_each_entry_safe(blk_fop, tmp, &lease_ctx->blocked_list, list)
{
- lease_ctx->lease_type = NONE;
- inode_unref (lease_ctx->inode);
- lease_ctx->inode = NULL;
+ list_del_init(&blk_fop->list);
+ list_add_tail(&blk_fop->list, &wind_list);
}
- pthread_mutex_unlock (&lease_ctx->lock);
-
- return;
+ }
+ pthread_mutex_unlock(&lease_ctx->lock);
+
+ gf_msg_trace(this->name, 0, "Executing the blocked stubs on gfid(%s)",
+ uuid_utoa(lease_ctx->inode->gfid));
+ list_for_each_entry_safe(blk_fop, tmp, &wind_list, list)
+ {
+ list_del_init(&blk_fop->list);
+ gf_msg_trace(this->name, 0, "Executing fop:%d", blk_fop->stub->fop);
+ call_resume(blk_fop->stub);
+ GF_FREE(blk_fop);
+ }
+
+ pthread_mutex_lock(&lease_ctx->lock);
+ {
+ lease_ctx->lease_type = NONE;
+ inode_unref(lease_ctx->inode);
+ lease_ctx->inode = NULL;
+ }
+ pthread_mutex_unlock(&lease_ctx->lock);
+
+ return;
}
-
void
-recall_lease_timer_handler (struct gf_tw_timer_list *timer,
- void *data, unsigned long calltime)
+recall_lease_timer_handler(struct gf_tw_timer_list *timer, void *data,
+ unsigned long calltime)
{
- inode_t *inode = NULL;
- lease_inode_t *lease_inode = NULL;
- leases_private_t *priv = NULL;
- lease_timer_data_t *timer_data = NULL;
-
- timer_data = data;
-
- priv = timer_data->this->private;
- inode = timer_data->inode;
- pthread_mutex_lock (&priv->mutex);
- {
- lease_inode = new_lease_inode (inode);
- if (!lease_inode) {
- errno = ENOMEM;
- goto out;
- }
- list_add_tail (&lease_inode->list, &priv->recall_list);
- pthread_cond_broadcast (&priv->cond);
+ inode_t *inode = NULL;
+ lease_inode_t *lease_inode = NULL;
+ leases_private_t *priv = NULL;
+ lease_timer_data_t *timer_data = NULL;
+
+ timer_data = data;
+
+ priv = timer_data->this->private;
+ inode = timer_data->inode;
+ pthread_mutex_lock(&priv->mutex);
+ {
+ lease_inode = new_lease_inode(inode);
+ if (!lease_inode) {
+ errno = ENOMEM;
+ goto out;
}
+ list_add_tail(&lease_inode->list, &priv->recall_list);
+ pthread_cond_broadcast(&priv->cond);
+ }
out:
- pthread_mutex_unlock (&priv->mutex);
+ pthread_mutex_unlock(&priv->mutex);
- GF_FREE (timer);
+ GF_FREE(timer);
}
-
static void
-__recall_lease (xlator_t *this, lease_inode_ctx_t *lease_ctx)
+__recall_lease(xlator_t *this, lease_inode_ctx_t *lease_ctx)
{
- lease_id_entry_t *lease_entry = NULL;
- lease_id_entry_t *tmp = NULL;
- struct gf_upcall up_req = {0,};
- struct gf_upcall_recall_lease recall_req = {0,};
- int notify_ret = -1;
- struct gf_tw_timer_list *timer = NULL;
- leases_private_t *priv = NULL;
- lease_timer_data_t *timer_data = NULL;
-
- if (lease_ctx->recall_in_progress) {
- gf_msg_debug (this->name, 0, "Lease recall is already in "
- "progress, hence not sending another recall");
- goto out;
- }
-
- priv = this->private;
- list_for_each_entry_safe (lease_entry, tmp,
- &lease_ctx->lease_id_list,
- lease_id_list) {
- gf_uuid_copy (up_req.gfid, lease_ctx->inode->gfid);
- up_req.client_uid = lease_entry->client_uid;
- up_req.event_type = GF_UPCALL_RECALL_LEASE;
- up_req.data = &recall_req;
-
- notify_ret = this->notify (this, GF_EVENT_UPCALL, &up_req);
- if (notify_ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, LEASE_MSG_RECALL_FAIL,
- "Recall notification to client: %s failed",
- lease_entry->client_uid);
- /* Do not return from here, continue registering the timer,
- this is required mostly o keep replicas in sync*/
- } else {
- gf_msg_debug (this->name, 0, "Recall lease (all)"
- "notification sent to client %s",
- lease_entry->client_uid);
- }
-
- lease_ctx->recall_in_progress = _gf_true;
- lease_entry->recall_time = time (NULL);
- }
- timer = GF_CALLOC (1, sizeof (*timer),
- gf_common_mt_tw_timer_list);
- if (!timer) {
- goto out;
- }
- timer_data = GF_MALLOC (sizeof (lease_timer_data_t),
- gf_leases_mt_timer_data_t);
- if (!timer_data) {
- GF_FREE (timer);
- goto out;
+ lease_id_entry_t *lease_entry = NULL;
+ lease_id_entry_t *tmp = NULL;
+ struct gf_upcall up_req = {
+ 0,
+ };
+ struct gf_upcall_recall_lease recall_req = {
+ 0,
+ };
+ int notify_ret = -1;
+ struct gf_tw_timer_list *timer = NULL;
+ leases_private_t *priv = NULL;
+ lease_timer_data_t *timer_data = NULL;
+
+ if (lease_ctx->recall_in_progress) {
+ gf_msg_debug(this->name, 0,
+ "Lease recall is already in "
+ "progress, hence not sending another recall");
+ goto out;
+ }
+
+ priv = this->private;
+ list_for_each_entry_safe(lease_entry, tmp, &lease_ctx->lease_id_list,
+ lease_id_list)
+ {
+ gf_uuid_copy(up_req.gfid, lease_ctx->inode->gfid);
+ up_req.client_uid = lease_entry->client_uid;
+ up_req.event_type = GF_UPCALL_RECALL_LEASE;
+ up_req.data = &recall_req;
+
+ notify_ret = this->notify(this, GF_EVENT_UPCALL, &up_req);
+ if (notify_ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, LEASE_MSG_RECALL_FAIL,
+ "Recall notification to client: %s failed",
+ lease_entry->client_uid);
+ /* Do not return from here, continue registering the timer,
+ this is required mostly o keep replicas in sync*/
+ } else {
+ gf_msg_debug(this->name, 0,
+ "Recall lease (all)"
+ "notification sent to client %s",
+ lease_entry->client_uid);
}
- timer_data->inode = inode_ref (lease_ctx->inode);
- timer_data->this = this;
- timer->data = timer_data;
-
- INIT_LIST_HEAD (&timer->entry);
- timer->expires = get_recall_lease_timeout (this);
- timer->function = recall_lease_timer_handler;
- lease_ctx->timer = timer;
- gf_tw_add_timer (priv->timer_wheel, timer);
- gf_msg_trace (this->name, 0, "Registering timer " "%p, after "
- "sending recall", timer);
+ lease_ctx->recall_in_progress = _gf_true;
+ lease_entry->recall_time = time(NULL);
+ }
+ timer = GF_CALLOC(1, sizeof(*timer), gf_common_mt_tw_timer_list);
+ if (!timer) {
+ goto out;
+ }
+ timer_data = GF_MALLOC(sizeof(lease_timer_data_t),
+ gf_leases_mt_timer_data_t);
+ if (!timer_data) {
+ GF_FREE(timer);
+ goto out;
+ }
+
+ timer_data->inode = inode_ref(lease_ctx->inode);
+ timer_data->this = this;
+ timer->data = timer_data;
+
+ INIT_LIST_HEAD(&timer->entry);
+ timer->expires = get_recall_lease_timeout(this);
+ timer->function = recall_lease_timer_handler;
+ lease_ctx->timer = timer;
+ gf_tw_add_timer(priv->timer_wheel, timer);
+ gf_msg_trace(this->name, 0,
+ "Registering timer "
+ "%p, after "
+ "sending recall",
+ timer);
out:
- return;
+ return;
}
-
/* ret = 0; STACK_UNWIND Success
* ret = -1; STACK_UNWIND failure
*/
int
-process_lease_req (call_frame_t *frame, xlator_t *this,
- inode_t *inode, struct gf_lease *lease)
+process_lease_req(call_frame_t *frame, xlator_t *this, inode_t *inode,
+ struct gf_lease *lease)
{
- int ret = 0;
- char *client_uid = NULL;
- lease_inode_ctx_t *lease_ctx = NULL;
-
- GF_VALIDATE_OR_GOTO ("leases", frame, out);
- GF_VALIDATE_OR_GOTO ("leases", this, out);
- GF_VALIDATE_OR_GOTO ("leases", inode, out);
- GF_VALIDATE_OR_GOTO ("leases", lease, out);
-
- client_uid = frame->root->client->client_uid;
-
- if (!is_valid_lease_id (lease->lease_id)) {
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- LEASE_MSG_INVAL_LEASE_ID, "Invalid lease id, from"
- "client:%s", client_uid);
- ret = -EINVAL;
- errno = EINVAL;
- goto out;
- }
-
- lease_ctx = lease_ctx_get (inode, this);
- if (!lease_ctx) {
- gf_msg (this->name, GF_LOG_WARNING, ENOMEM,
- LEASE_MSG_NO_MEM, "Unable to create/get inode ctx, "
- "inode:%p", inode);
- ret = -ENOMEM;
- errno = ENOMEM;
- goto out;
- }
-
- gf_msg_debug (this->name, 0, "Lease request from client: %s, "
- "lease type:%d, lease cmd:%d, lease ID:%s, gfid:%s",
- client_uid, lease->lease_type, lease->cmd,
- leaseid_utoa (lease->lease_id), uuid_utoa (inode->gfid));
+ int ret = 0;
+ char *client_uid = NULL;
+ lease_inode_ctx_t *lease_ctx = NULL;
+
+ GF_VALIDATE_OR_GOTO("leases", frame, out);
+ GF_VALIDATE_OR_GOTO("leases", this, out);
+ GF_VALIDATE_OR_GOTO("leases", inode, out);
+ GF_VALIDATE_OR_GOTO("leases", lease, out);
+
+ client_uid = frame->root->client->client_uid;
+
+ if (!is_valid_lease_id(lease->lease_id)) {
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, LEASE_MSG_INVAL_LEASE_ID,
+ "Invalid lease id, from"
+ "client:%s",
+ client_uid);
+ ret = -EINVAL;
+ errno = EINVAL;
+ goto out;
+ }
+
+ lease_ctx = lease_ctx_get(inode, this);
+ if (!lease_ctx) {
+ gf_msg(this->name, GF_LOG_WARNING, ENOMEM, LEASE_MSG_NO_MEM,
+ "Unable to create/get inode ctx, "
+ "inode:%p",
+ inode);
+ ret = -ENOMEM;
+ errno = ENOMEM;
+ goto out;
+ }
+
+ gf_msg_debug(this->name, 0,
+ "Lease request from client: %s, "
+ "lease type:%d, lease cmd:%d, lease ID:%s, gfid:%s",
+ client_uid, lease->lease_type, lease->cmd,
+ leaseid_utoa(lease->lease_id), uuid_utoa(inode->gfid));
+
+ pthread_mutex_lock(&lease_ctx->lock);
+ {
+ switch (lease->cmd) {
+ case GF_GET_LEASE:
+ lease->lease_type = lease_ctx->lease_type;
+ gf_msg_debug(this->name, 0,
+ "Get lease, existing lease"
+ "type: %d",
+ lease_ctx->lease_type);
+ /*TODO:Should it consider lease id or client_uid?*/
+ break;
- pthread_mutex_lock (&lease_ctx->lock);
- {
- switch (lease->cmd) {
- case GF_GET_LEASE:
- lease->lease_type = lease_ctx->lease_type;
- gf_msg_debug (this->name, 0, "Get lease, existing lease"
- "type: %d", lease_ctx->lease_type);
- /*TODO:Should it consider lease id or client_uid?*/
- break;
-
- case GF_SET_LEASE:
- if (__is_lease_grantable (this, lease_ctx, lease, inode)) {
- __add_lease (frame, inode, lease_ctx,
- client_uid, lease);
- ret = 0;
- } else {
- gf_msg_debug (this->name, GF_LOG_DEBUG,
- "Not granting the conflicting lease"
- " request from %s on gfid(%s)",
- client_uid, uuid_utoa (inode->gfid));
- __recall_lease (this, lease_ctx);
- ret = -1;
- }
- break;
- case GF_UNLK_LEASE:
- ret = __remove_lease (this, inode, lease_ctx,
- client_uid, lease);
- if ((ret == 0) && (lease_ctx->lease_cnt == 0)) {
- pthread_mutex_unlock (&lease_ctx->lock);
- goto unblock;
- }
- break;
- default:
- ret = -EINVAL;
- break;
+ case GF_SET_LEASE:
+ if (__is_lease_grantable(this, lease_ctx, lease, inode)) {
+ __add_lease(frame, inode, lease_ctx, client_uid, lease);
+ ret = 0;
+ } else {
+ gf_msg_debug(this->name, GF_LOG_DEBUG,
+ "Not granting the conflicting lease"
+ " request from %s on gfid(%s)",
+ client_uid, uuid_utoa(inode->gfid));
+ __recall_lease(this, lease_ctx);
+ ret = -1;
+ }
+ break;
+ case GF_UNLK_LEASE:
+ ret = __remove_lease(this, inode, lease_ctx, client_uid, lease);
+ if ((ret == 0) && (lease_ctx->lease_cnt == 0)) {
+ pthread_mutex_unlock(&lease_ctx->lock);
+ goto unblock;
}
+ break;
+ default:
+ ret = -EINVAL;
+ break;
}
- pthread_mutex_unlock (&lease_ctx->lock);
+ }
+ pthread_mutex_unlock(&lease_ctx->lock);
- return ret;
+ return ret;
unblock:
- do_blocked_fops (this, lease_ctx);
+ do_blocked_fops(this, lease_ctx);
out:
- return ret;
+ return ret;
}
-
/* ret = 1 conflict
* ret = 0 no conflict
*/
gf_boolean_t
-__check_lease_conflict (call_frame_t *frame, lease_inode_ctx_t *lease_ctx,
- const char *lease_id, gf_boolean_t is_write)
+__check_lease_conflict(call_frame_t *frame, lease_inode_ctx_t *lease_ctx,
+ const char *lease_id, gf_boolean_t is_write)
{
- gf_lease_types_t lease_type = {0,};
- gf_boolean_t conflicts = _gf_false;
- lease_id_entry_t *lease_entry = NULL;
-
- GF_VALIDATE_OR_GOTO ("leases", frame, out);
- GF_VALIDATE_OR_GOTO ("leases", lease_ctx, out);
- GF_VALIDATE_OR_GOTO ("leases", lease_id, out);
-
- lease_type = lease_ctx->lease_type;
-
- /* If the fop is rename or unlink conflict the lease even if its
- * from the same client??
- */
- if ((frame->root->op == GF_FOP_RENAME) ||
- (frame->root->op == GF_FOP_UNLINK)) {
- conflicts = _gf_true;
- goto recall;
- }
-
- /* TODO: If lease_id is not sent, fall back to client uid conflict check?
- * Or set conflicts = true if lease_id is 0 when there is an existing
- * lease */
- switch (lease_type) {
+ gf_lease_types_t lease_type = {
+ 0,
+ };
+ gf_boolean_t conflicts = _gf_false;
+ lease_id_entry_t *lease_entry = NULL;
+
+ GF_VALIDATE_OR_GOTO("leases", frame, out);
+ GF_VALIDATE_OR_GOTO("leases", lease_ctx, out);
+ GF_VALIDATE_OR_GOTO("leases", lease_id, out);
+
+ lease_type = lease_ctx->lease_type;
+
+ /* If the fop is rename or unlink conflict the lease even if its
+ * from the same client??
+ */
+ if ((frame->root->op == GF_FOP_RENAME) ||
+ (frame->root->op == GF_FOP_UNLINK)) {
+ conflicts = _gf_true;
+ goto recall;
+ }
+
+ /* TODO: If lease_id is not sent, fall back to client uid conflict check?
+ * Or set conflicts = true if lease_id is 0 when there is an existing
+ * lease */
+ switch (lease_type) {
case (GF_RW_LEASE | GF_RD_LEASE):
case GF_RW_LEASE:
- lease_entry = __get_lease_id_entry (lease_ctx, lease_id);
- if (lease_entry && (lease_entry->lease_type & GF_RW_LEASE))
- conflicts = _gf_false;
- else
- conflicts = _gf_true;
- break;
+ lease_entry = __get_lease_id_entry(lease_ctx, lease_id);
+ if (lease_entry && (lease_entry->lease_type & GF_RW_LEASE))
+ conflicts = _gf_false;
+ else
+ conflicts = _gf_true;
+ break;
case GF_RD_LEASE:
- if (is_write && __another_lease_found(lease_ctx, lease_id))
- conflicts = _gf_true;
- else
- conflicts = _gf_false;
- break;
+ if (is_write && __another_lease_found(lease_ctx, lease_id))
+ conflicts = _gf_true;
+ else
+ conflicts = _gf_false;
+ break;
default:
- break;
- }
+ break;
+ }
recall:
- /* If there is a conflict found and recall is not already sent to all
- * the clients, then send recall to each of the client holding lease.
- */
- if (conflicts)
- __recall_lease (frame->this, lease_ctx);
+ /* If there is a conflict found and recall is not already sent to all
+ * the clients, then send recall to each of the client holding lease.
+ */
+ if (conflicts)
+ __recall_lease(frame->this, lease_ctx);
out:
- return conflicts;
+ return conflicts;
}
-
/* Return values:
* -1 : error, unwind the fop
* WIND_FOP: No conflict, wind the fop
* BLOCK_FOP: Found a conflicting lease, block the fop
*/
int
-check_lease_conflict (call_frame_t *frame, inode_t *inode,
- const char *lease_id, uint32_t fop_flags)
+check_lease_conflict(call_frame_t *frame, inode_t *inode, const char *lease_id,
+ uint32_t fop_flags)
{
- lease_inode_ctx_t *lease_ctx = NULL;
- gf_boolean_t is_blocking_fop = _gf_false;
- gf_boolean_t is_write_fop = _gf_false;
- gf_boolean_t conflicts = _gf_false;
- int ret = WIND_FOP;
-
- lease_ctx = lease_ctx_get (inode, frame->this);
- if (!lease_ctx) {
- gf_msg (frame->this->name, GF_LOG_WARNING, ENOMEM,
- LEASE_MSG_NO_MEM,
- "Unable to create/get inode ctx");
- ret = -1;
- errno = ENOMEM;
- goto out;
+ lease_inode_ctx_t *lease_ctx = NULL;
+ gf_boolean_t is_blocking_fop = _gf_false;
+ gf_boolean_t is_write_fop = _gf_false;
+ gf_boolean_t conflicts = _gf_false;
+ int ret = WIND_FOP;
+
+ lease_ctx = lease_ctx_get(inode, frame->this);
+ if (!lease_ctx) {
+ gf_msg(frame->this->name, GF_LOG_WARNING, ENOMEM, LEASE_MSG_NO_MEM,
+ "Unable to create/get inode ctx");
+ ret = -1;
+ errno = ENOMEM;
+ goto out;
+ }
+
+ is_blocking_fop = ((fop_flags & BLOCKING_FOP) != 0);
+ is_write_fop = ((fop_flags & DATA_MODIFY_FOP) != 0);
+
+ pthread_mutex_lock(&lease_ctx->lock);
+ {
+ if (lease_ctx->lease_type == NONE) {
+ gf_msg_debug(frame->this->name, 0,
+ "No leases found continuing with the"
+ " fop:%s",
+ gf_fop_list[frame->root->op]);
+ ret = WIND_FOP;
+ goto unlock;
}
-
- is_blocking_fop = ((fop_flags & BLOCKING_FOP) != 0);
- is_write_fop = ((fop_flags & DATA_MODIFY_FOP) != 0);
-
- pthread_mutex_lock (&lease_ctx->lock);
- {
- if (lease_ctx->lease_type == NONE) {
- gf_msg_debug (frame->this->name, 0,
- "No leases found continuing with the"
- " fop:%s", gf_fop_list[frame->root->op]);
- ret = WIND_FOP;
- goto unlock;
- }
- conflicts = __check_lease_conflict (frame, lease_ctx,
- lease_id, is_write_fop);
- if (conflicts) {
- if (is_blocking_fop) {
- gf_msg_debug (frame->this->name, 0, "Fop: %s "
- "conflicting existing "
- "lease: %d, blocking the"
- "fop", gf_fop_list[frame->root->op],
- lease_ctx->lease_type);
- ret = BLOCK_FOP;
- } else {
- gf_msg_debug (frame->this->name, 0, "Fop: %s "
- "conflicting existing "
- "lease: %d, sending "
- "EAGAIN",
- gf_fop_list[frame->root->op],
- lease_ctx->lease_type);
- errno = EAGAIN;
- ret = -1;
- }
- }
+ conflicts = __check_lease_conflict(frame, lease_ctx, lease_id,
+ is_write_fop);
+ if (conflicts) {
+ if (is_blocking_fop) {
+ gf_msg_debug(frame->this->name, 0,
+ "Fop: %s "
+ "conflicting existing "
+ "lease: %d, blocking the"
+ "fop",
+ gf_fop_list[frame->root->op],
+ lease_ctx->lease_type);
+ ret = BLOCK_FOP;
+ } else {
+ gf_msg_debug(frame->this->name, 0,
+ "Fop: %s "
+ "conflicting existing "
+ "lease: %d, sending "
+ "EAGAIN",
+ gf_fop_list[frame->root->op],
+ lease_ctx->lease_type);
+ errno = EAGAIN;
+ ret = -1;
+ }
}
+ }
unlock:
- pthread_mutex_unlock (&lease_ctx->lock);
+ pthread_mutex_unlock(&lease_ctx->lock);
out:
- return ret;
+ return ret;
}
-
static int
-remove_clnt_leases (const char *client_uid, inode_t *inode, xlator_t *this)
+remove_clnt_leases(const char *client_uid, inode_t *inode, xlator_t *this)
{
- lease_inode_ctx_t *lease_ctx = NULL;
- lease_id_entry_t *lease_entry = NULL;
- lease_id_entry_t *tmp = NULL;
- int ret = 0;
- int i = 0;
-
- lease_ctx = lease_ctx_get (inode, this);
- if (!lease_ctx) {
- gf_msg (this->name, GF_LOG_WARNING, ENOMEM,
- LEASE_MSG_INVAL_INODE_CTX,
- "Unable to create/get inode ctx");
- ret = -1;
- errno = ENOMEM;
- goto out;
- }
-
- pthread_mutex_lock (&lease_ctx->lock);
+ lease_inode_ctx_t *lease_ctx = NULL;
+ lease_id_entry_t *lease_entry = NULL;
+ lease_id_entry_t *tmp = NULL;
+ int ret = 0;
+ int i = 0;
+
+ lease_ctx = lease_ctx_get(inode, this);
+ if (!lease_ctx) {
+ gf_msg(this->name, GF_LOG_WARNING, ENOMEM, LEASE_MSG_INVAL_INODE_CTX,
+ "Unable to create/get inode ctx");
+ ret = -1;
+ errno = ENOMEM;
+ goto out;
+ }
+
+ pthread_mutex_lock(&lease_ctx->lock);
+ {
+ list_for_each_entry_safe(lease_entry, tmp, &lease_ctx->lease_id_list,
+ lease_id_list)
{
- list_for_each_entry_safe (lease_entry, tmp,
- &lease_ctx->lease_id_list,
- lease_id_list) {
- if (strcmp (client_uid, lease_entry->client_uid) == 0) {
- for (i = 0; i < GF_LEASE_MAX_TYPE; i++) {
- lease_ctx->lease_type_cnt[i] -= lease_entry->lease_type_cnt[i];
- }
- lease_ctx->lease_cnt -= lease_entry->lease_cnt;
- __destroy_lease_id_entry (lease_entry);
- if (lease_ctx->lease_cnt == 0) {
- pthread_mutex_unlock (&lease_ctx->lock);
- goto unblock;
- }
- }
+ if (strcmp(client_uid, lease_entry->client_uid) == 0) {
+ for (i = 0; i < GF_LEASE_MAX_TYPE; i++) {
+ lease_ctx->lease_type_cnt[i] -= lease_entry
+ ->lease_type_cnt[i];
+ }
+ lease_ctx->lease_cnt -= lease_entry->lease_cnt;
+ __destroy_lease_id_entry(lease_entry);
+ if (lease_ctx->lease_cnt == 0) {
+ pthread_mutex_unlock(&lease_ctx->lock);
+ goto unblock;
}
+ }
}
- pthread_mutex_unlock (&lease_ctx->lock);
+ }
+ pthread_mutex_unlock(&lease_ctx->lock);
out:
- return ret;
+ return ret;
unblock:
- do_blocked_fops (this, lease_ctx);
- return ret;
+ do_blocked_fops(this, lease_ctx);
+ return ret;
}
-
int
-cleanup_client_leases (xlator_t *this, const char *client_uid)
+cleanup_client_leases(xlator_t *this, const char *client_uid)
{
- lease_client_t *clnt = NULL;
- lease_client_t *tmp = NULL;
- struct list_head cleanup_list = {0, };
- lease_inode_t *l_inode = NULL;
- lease_inode_t *tmp1 = NULL;
- leases_private_t *priv = NULL;
- int ret = 0;
-
- priv = this->private;
- if (!priv) {
- ret = -1;
- errno = EINVAL;
- goto out;
- }
-
- INIT_LIST_HEAD (&cleanup_list);
- pthread_mutex_lock (&priv->mutex);
+ lease_client_t *clnt = NULL;
+ lease_client_t *tmp = NULL;
+ struct list_head cleanup_list = {
+ 0,
+ };
+ lease_inode_t *l_inode = NULL;
+ lease_inode_t *tmp1 = NULL;
+ leases_private_t *priv = NULL;
+ int ret = 0;
+
+ priv = this->private;
+ if (!priv) {
+ ret = -1;
+ errno = EINVAL;
+ goto out;
+ }
+
+ INIT_LIST_HEAD(&cleanup_list);
+ pthread_mutex_lock(&priv->mutex);
+ {
+ list_for_each_entry_safe(clnt, tmp, &priv->client_list, client_list)
{
- list_for_each_entry_safe (clnt, tmp, &priv->client_list, client_list) {
- if ((strcmp (clnt->client_uid, client_uid) == 0)) {
- list_for_each_entry_safe (l_inode, tmp1,
- &clnt->inode_list, list) {
- list_del_init (&l_inode->list);
- list_add_tail (&l_inode->list, &cleanup_list);
- }
- break;
- }
- __destroy_lease_client (clnt);
+ if ((strcmp(clnt->client_uid, client_uid) == 0)) {
+ list_for_each_entry_safe(l_inode, tmp1, &clnt->inode_list, list)
+ {
+ list_del_init(&l_inode->list);
+ list_add_tail(&l_inode->list, &cleanup_list);
}
+ break;
+ }
+ __destroy_lease_client(clnt);
}
- pthread_mutex_unlock (&priv->mutex);
-
- l_inode = tmp1 = NULL;
- list_for_each_entry_safe (l_inode, tmp1, &cleanup_list, list) {
- remove_clnt_leases (client_uid, l_inode->inode, this);
- }
+ }
+ pthread_mutex_unlock(&priv->mutex);
+
+ l_inode = tmp1 = NULL;
+ list_for_each_entry_safe(l_inode, tmp1, &cleanup_list, list)
+ {
+ remove_clnt_leases(client_uid, l_inode->inode, this);
+ }
out:
- return ret;
+ return ret;
}
-
static void
-__remove_all_leases (xlator_t *this, lease_inode_ctx_t *lease_ctx)
+__remove_all_leases(xlator_t *this, lease_inode_ctx_t *lease_ctx)
{
- int i = 0;
- lease_id_entry_t *lease_entry = NULL;
- lease_id_entry_t *tmp = NULL;
-
- __dump_leases_info (this, lease_ctx);
-
- list_for_each_entry_safe (lease_entry, tmp,
- &lease_ctx->lease_id_list,
- lease_id_list) {
- lease_entry->lease_cnt = 0;
- remove_from_clnt_list (this, lease_entry->client_uid, lease_ctx->inode);
- __destroy_lease_id_entry (lease_entry);
- }
- INIT_LIST_HEAD (&lease_ctx->lease_id_list);
- for (i = 0; i <= GF_LEASE_MAX_TYPE; i++)
- lease_ctx->lease_type_cnt[i] = 0;
- lease_ctx->lease_type = 0;
- lease_ctx->lease_cnt = 0;
- lease_ctx->recall_in_progress = _gf_false;
- inode_unref (lease_ctx->inode);
- lease_ctx->timer = NULL;
-
- /* TODO:
- * - Mark the corresponding fd bad. Could be done on client side
- * as a result of recall
- * - Free the lease_ctx
- */
- return;
-}
+ int i = 0;
+ lease_id_entry_t *lease_entry = NULL;
+ lease_id_entry_t *tmp = NULL;
+ __dump_leases_info(this, lease_ctx);
+
+ list_for_each_entry_safe(lease_entry, tmp, &lease_ctx->lease_id_list,
+ lease_id_list)
+ {
+ lease_entry->lease_cnt = 0;
+ remove_from_clnt_list(this, lease_entry->client_uid, lease_ctx->inode);
+ __destroy_lease_id_entry(lease_entry);
+ }
+ INIT_LIST_HEAD(&lease_ctx->lease_id_list);
+ for (i = 0; i <= GF_LEASE_MAX_TYPE; i++)
+ lease_ctx->lease_type_cnt[i] = 0;
+ lease_ctx->lease_type = 0;
+ lease_ctx->lease_cnt = 0;
+ lease_ctx->recall_in_progress = _gf_false;
+ inode_unref(lease_ctx->inode);
+ lease_ctx->timer = NULL;
+
+ /* TODO:
+ * - Mark the corresponding fd bad. Could be done on client side
+ * as a result of recall
+ * - Free the lease_ctx
+ */
+ return;
+}
static int
-remove_all_leases (xlator_t *this, inode_t *inode)
+remove_all_leases(xlator_t *this, inode_t *inode)
{
- lease_inode_ctx_t *lease_ctx = NULL;
- int ret = 0;
-
- GF_VALIDATE_OR_GOTO ("leases", inode, out);
-
- lease_ctx = lease_ctx_get (inode, this);
- if (!lease_ctx) {
- gf_msg (this->name, GF_LOG_WARNING, ENOMEM,
- LEASE_MSG_INVAL_INODE_CTX,
- "Unable to create/get inode ctx");
- ret = -1;
- errno = ENOMEM;
- goto out;
- }
-
- pthread_mutex_lock (&lease_ctx->lock);
- {
- __remove_all_leases (this, lease_ctx);
- }
- pthread_mutex_unlock (&lease_ctx->lock);
-
- do_blocked_fops (this, lease_ctx);
+ lease_inode_ctx_t *lease_ctx = NULL;
+ int ret = 0;
+
+ GF_VALIDATE_OR_GOTO("leases", inode, out);
+
+ lease_ctx = lease_ctx_get(inode, this);
+ if (!lease_ctx) {
+ gf_msg(this->name, GF_LOG_WARNING, ENOMEM, LEASE_MSG_INVAL_INODE_CTX,
+ "Unable to create/get inode ctx");
+ ret = -1;
+ errno = ENOMEM;
+ goto out;
+ }
+
+ pthread_mutex_lock(&lease_ctx->lock);
+ {
+ __remove_all_leases(this, lease_ctx);
+ }
+ pthread_mutex_unlock(&lease_ctx->lock);
+
+ do_blocked_fops(this, lease_ctx);
out:
- return ret;
+ return ret;
}
-
void *
-expired_recall_cleanup (void *data)
+expired_recall_cleanup(void *data)
{
- struct timespec sleep_till = {0, };
- struct list_head recall_cleanup_list;
- lease_inode_t *recall_entry = NULL;
- lease_inode_t *tmp = NULL;
- leases_private_t *priv = NULL;
- xlator_t *this = NULL;
+ struct timespec sleep_till = {
+ 0,
+ };
+ struct list_head recall_cleanup_list;
+ lease_inode_t *recall_entry = NULL;
+ lease_inode_t *tmp = NULL;
+ leases_private_t *priv = NULL;
+ xlator_t *this = NULL;
- GF_VALIDATE_OR_GOTO ("leases", data, out);
+ GF_VALIDATE_OR_GOTO("leases", data, out);
- this = data;
- priv = this->private;
+ this = data;
+ priv = this->private;
- gf_msg_debug (this->name, 0, "Started the expired_recall_cleanup thread");
+ gf_msg_debug(this->name, 0, "Started the expired_recall_cleanup thread");
- while (1) {
- pthread_mutex_lock (&priv->mutex);
+ while (1) {
+ pthread_mutex_lock(&priv->mutex);
+ {
+ if (priv->fini) {
+ pthread_mutex_unlock(&priv->mutex);
+ goto out;
+ }
+ INIT_LIST_HEAD(&recall_cleanup_list);
+ if (list_empty(&priv->recall_list)) {
+ sleep_till.tv_sec = time(NULL) + 600;
+ pthread_cond_timedwait(&priv->cond, &priv->mutex, &sleep_till);
+ }
+ if (!list_empty(&priv->recall_list)) {
+ gf_msg_debug(this->name, 0, "Found expired recalls");
+ list_for_each_entry_safe(recall_entry, tmp, &priv->recall_list,
+ list)
{
- if (priv->fini) {
- pthread_mutex_unlock (&priv->mutex);
- goto out;
- }
- INIT_LIST_HEAD (&recall_cleanup_list);
- if (list_empty (&priv->recall_list)) {
- sleep_till.tv_sec = time (NULL) + 600;
- pthread_cond_timedwait (&priv->cond, &priv->mutex,
- &sleep_till);
- }
- if (!list_empty (&priv->recall_list)) {
- gf_msg_debug (this->name, 0, "Found expired recalls");
- list_for_each_entry_safe (recall_entry, tmp,
- &priv->recall_list, list) {
- list_del_init (&recall_entry->list);
- list_add_tail (&recall_entry->list, &recall_cleanup_list);
- }
- }
- }
- pthread_mutex_unlock (&priv->mutex);
-
- recall_entry = tmp = NULL;
- list_for_each_entry_safe (recall_entry, tmp, &recall_cleanup_list, list) {
- gf_msg_debug (this->name, 0, "Recall lease was sent on"
- " inode:%p, recall timer has expired"
- " and clients haven't unlocked the lease"
- " hence cleaning up leases on the inode",
- recall_entry->inode);
- remove_all_leases (this, recall_entry->inode);
- list_del_init (&recall_entry->list);
+ list_del_init(&recall_entry->list);
+ list_add_tail(&recall_entry->list, &recall_cleanup_list);
}
+ }
+ }
+ pthread_mutex_unlock(&priv->mutex);
+
+ recall_entry = tmp = NULL;
+ list_for_each_entry_safe(recall_entry, tmp, &recall_cleanup_list, list)
+ {
+ gf_msg_debug(this->name, 0,
+ "Recall lease was sent on"
+ " inode:%p, recall timer has expired"
+ " and clients haven't unlocked the lease"
+ " hence cleaning up leases on the inode",
+ recall_entry->inode);
+ remove_all_leases(this, recall_entry->inode);
+ list_del_init(&recall_entry->list);
}
+ }
out:
- return NULL;
+ return NULL;
}
diff --git a/xlators/features/leases/src/leases.c b/xlators/features/leases/src/leases.c
index 0e1a089ad59..be0f48fd2a2 100644
--- a/xlators/features/leases/src/leases.c
+++ b/xlators/features/leases/src/leases.c
@@ -16,1176 +16,1122 @@
#include "leases.h"
int32_t
-leases_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)
+leases_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)
{
- STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd, xdata);
+ STACK_UNWIND_STRICT(open, frame, op_ret, op_errno, fd, xdata);
- return 0;
+ return 0;
}
-
int32_t
-leases_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
- fd_t *fd, dict_t *xdata)
+leases_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ fd_t *fd, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- int32_t op_errno = EINVAL;
- int ret = 0;
- lease_fd_ctx_t *fd_ctx = NULL;
- char *lease_id = NULL;
-
- EXIT_IF_LEASES_OFF (this, out);
-
- fd_ctx = GF_CALLOC (1, sizeof (*fd_ctx), gf_leases_mt_fd_ctx_t);
- if (!fd_ctx) {
- op_errno = ENOMEM;
- goto err;
- }
-
- fd_ctx->client_uid = gf_strdup (frame->root->client->client_uid);
- if (!fd_ctx->client_uid) {
- op_errno = ENOMEM;
- goto err;
- }
-
- GET_FLAGS (frame->root->op, flags);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- if (lease_id != NULL)
- memcpy (fd_ctx->lease_id, lease_id, LEASE_ID_SIZE);
- else
- memset (fd_ctx->lease_id, 0, LEASE_ID_SIZE);
-
- ret = fd_ctx_set (fd, this, (uint64_t)fd_ctx);
- if (ret) {
- op_errno = ENOMEM;
- goto err;
- }
-
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ uint32_t fop_flags = 0;
+ int32_t op_errno = EINVAL;
+ int ret = 0;
+ lease_fd_ctx_t *fd_ctx = NULL;
+ char *lease_id = NULL;
+
+ EXIT_IF_LEASES_OFF(this, out);
+
+ fd_ctx = GF_CALLOC(1, sizeof(*fd_ctx), gf_leases_mt_fd_ctx_t);
+ if (!fd_ctx) {
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ fd_ctx->client_uid = gf_strdup(frame->root->client->client_uid);
+ if (!fd_ctx->client_uid) {
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ GET_FLAGS(frame->root->op, flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ if (lease_id != NULL)
+ memcpy(fd_ctx->lease_id, lease_id, LEASE_ID_SIZE);
+ else
+ memset(fd_ctx->lease_id, 0, LEASE_ID_SIZE);
+
+ ret = fd_ctx_set(fd, this, (uint64_t)fd_ctx);
+ if (ret) {
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, open, frame, this,
- loc, flags, fd, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, open, frame, this, loc, flags, fd, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_open_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->open,
- loc, flags, fd, xdata);
- return 0;
+ STACK_WIND(frame, leases_open_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata);
+ return 0;
err:
- if (fd_ctx) {
- GF_FREE (fd_ctx->client_uid);
- GF_FREE (fd_ctx);
- }
+ if (fd_ctx) {
+ GF_FREE(fd_ctx->client_uid);
+ GF_FREE(fd_ctx);
+ }
- STACK_UNWIND_STRICT (open, frame, -1, op_errno, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(open, frame, -1, op_errno, NULL, NULL);
+ return 0;
}
int32_t
-leases_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+leases_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct iatt *prebuf, struct iatt *postbuf,
+ dict_t *xdata)
{
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno,
- prebuf, postbuf, xdata);
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
- return 0;
+ return 0;
}
-
int32_t
-leases_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *vector, int count, off_t off, uint32_t flags,
- struct iobref *iobref, dict_t *xdata)
+leases_writev(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *vector, int count, off_t off, uint32_t flags,
+ struct iobref *iobref, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, fd->flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, fd->flags);
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, writev, frame, this, fd, vector, count,
- off, flags, iobref, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, writev, frame, this, fd, vector, count, off,
+ flags, iobref, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_writev_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->writev,
- fd, vector, count, off, flags, iobref, xdata);
- return 0;
+ STACK_WIND(frame, leases_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, vector, count, off, flags,
+ iobref, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (writev, frame, -1, errno, NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(writev, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
-
int32_t
-leases_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno,
- struct iovec *vector, int count, struct iatt *stbuf,
- struct iobref *iobref, dict_t *xdata)
+leases_readv_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct iovec *vector, int count,
+ struct iatt *stbuf, struct iobref *iobref, dict_t *xdata)
{
- STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector,
- count, stbuf, iobref, xdata);
+ STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, vector, count, stbuf,
+ iobref, xdata);
- return 0;
+ return 0;
}
int32_t
-leases_readv (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t offset,
- uint32_t flags, dict_t *xdata)
+leases_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset, uint32_t flags, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, fd->flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, fd->flags);
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, readv, frame, this,
- fd, size, offset, flags, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, readv, frame, this, fd, size, offset, flags,
+ xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_readv_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->readv,
- fd, size, offset, flags, xdata);
- return 0;
+ STACK_WIND(frame, leases_readv_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readv, fd, size, offset, flags, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (readv, frame, -1, errno, NULL, 0,
- NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(readv, frame, -1, errno, NULL, 0, NULL, NULL, NULL);
+ return 0;
}
int32_t
-leases_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct gf_flock *lock,
- dict_t *xdata)
+leases_lk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
+ int32_t op_errno, struct gf_flock *lock, dict_t *xdata)
{
- STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, lock, xdata);
+ STACK_UNWIND_STRICT(lk, frame, op_ret, op_errno, lock, xdata);
- return 0;
+ return 0;
}
int32_t
-leases_lk (call_frame_t *frame, xlator_t *this,
- fd_t *fd, int32_t cmd, struct gf_flock *flock, dict_t *xdata)
+leases_lk(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd,
+ struct gf_flock *flock, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS_LK (cmd, flock->l_type, fd->flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS_LK(cmd, flock->l_type, fd->flags);
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, lk, frame, this,
- fd, cmd, flock, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, lk, frame, this, fd, cmd, flock, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_lk_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->lk,
- fd, cmd, flock, xdata);
- return 0;
+ STACK_WIND(frame, leases_lk_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lk, fd, cmd, flock, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (lk, frame, -1, errno, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(lk, frame, -1, errno, NULL, NULL);
+ return 0;
}
int32_t
-leases_lease (call_frame_t *frame, xlator_t *this,
- loc_t *loc, struct gf_lease *lease, dict_t *xdata)
+leases_lease(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ struct gf_lease *lease, dict_t *xdata)
{
- int32_t op_errno = 0;
- int ret = 0;
- struct gf_lease nullease = {0, };
- int32_t op_ret = 0;
-
- EXIT_IF_LEASES_OFF (this, out);
-
- ret = process_lease_req (frame, this, loc->inode, lease);
- if (ret < 0) {
- op_errno = -ret;
- op_ret = -1;
- }
- goto unwind;
+ int32_t op_errno = 0;
+ int ret = 0;
+ struct gf_lease nullease = {
+ 0,
+ };
+ int32_t op_ret = 0;
+
+ EXIT_IF_LEASES_OFF(this, out);
+
+ ret = process_lease_req(frame, this, loc->inode, lease);
+ if (ret < 0) {
+ op_errno = -ret;
+ op_ret = -1;
+ }
+ goto unwind;
out:
- gf_msg (this->name, GF_LOG_ERROR, EINVAL, LEASE_MSG_NOT_ENABLED,
- "\"features/leases\" translator is not enabled. "
- "You need to enable it for proper functioning of your "
- "application");
- op_errno = ENOSYS;
- op_ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, LEASE_MSG_NOT_ENABLED,
+ "\"features/leases\" translator is not enabled. "
+ "You need to enable it for proper functioning of your "
+ "application");
+ op_errno = ENOSYS;
+ op_ret = -1;
unwind:
- STACK_UNWIND_STRICT (lease, frame, op_ret, op_errno,
- (op_errno == ENOSYS) ? &nullease : lease, xdata);
- return 0;
+ STACK_UNWIND_STRICT(lease, frame, op_ret, op_errno,
+ (op_errno == ENOSYS) ? &nullease : lease, xdata);
+ return 0;
}
int32_t
-leases_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, struct iatt *prebuf,
- struct iatt *postbuf, dict_t *xdata)
+leases_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno,
- prebuf, postbuf, xdata);
+ STACK_UNWIND_STRICT(truncate, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
- return 0;
+ return 0;
}
int32_t
-leases_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
- dict_t *xdata)
+leases_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
+ dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, 0);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, 0);
- ret = check_lease_conflict (frame, loc->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, loc->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (loc->inode, truncate, frame, this,
- loc, offset, xdata);
- return 0;
+ LEASE_BLOCK_FOP(loc->inode, truncate, frame, this, loc, offset, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_truncate_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->truncate,
- loc, offset, xdata);
- return 0;
+ STACK_WIND(frame, leases_truncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (truncate, frame, -1, errno, NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(truncate, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-leases_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, struct iatt *statpre,
- struct iatt *statpost, dict_t *xdata)
+leases_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, struct iatt *statpre,
+ struct iatt *statpost, dict_t *xdata)
{
- STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno,
- statpre, statpost, xdata);
+ STACK_UNWIND_STRICT(setattr, frame, op_ret, op_errno, statpre, statpost,
+ xdata);
- return 0;
+ return 0;
}
int32_t
-leases_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- struct iatt *stbuf, int32_t valid, dict_t *xdata)
+leases_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, 0);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, 0);
- ret = check_lease_conflict (frame, loc->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, loc->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (loc->inode, setattr, frame, this,
- loc, stbuf, valid, xdata);
- return 0;
+ LEASE_BLOCK_FOP(loc->inode, setattr, frame, this, loc, stbuf, valid, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_setattr_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->setattr,
- loc, stbuf, valid, xdata);
- return 0;
+ STACK_WIND(frame, leases_setattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (setattr, frame, -1, errno, NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(setattr, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-leases_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *stbuf,
- struct iatt *preoldparent, struct iatt *postoldparent,
- struct iatt *prenewparent, struct iatt *postnewparent,
- dict_t *xdata)
+leases_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *stbuf,
+ struct iatt *preoldparent, struct iatt *postoldparent,
+ struct iatt *prenewparent, struct iatt *postnewparent,
+ dict_t *xdata)
{
- STACK_UNWIND_STRICT (rename, frame, op_ret, op_errno,
- stbuf, preoldparent, postoldparent,
- prenewparent, postnewparent, xdata);
+ STACK_UNWIND_STRICT(rename, frame, op_ret, op_errno, stbuf, preoldparent,
+ postoldparent, prenewparent, postnewparent, xdata);
- return 0;
+ return 0;
}
int32_t
-leases_rename (call_frame_t *frame, xlator_t *this,
- loc_t *oldloc, loc_t *newloc, dict_t *xdata)
+leases_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
+ dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- /* should the lease be also checked for newloc */
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, 0);
+ /* should the lease be also checked for newloc */
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, 0);
- ret = check_lease_conflict (frame, oldloc->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, oldloc->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (oldloc->inode, rename, frame, this,
- oldloc, newloc, xdata);
- return 0;
+ LEASE_BLOCK_FOP(oldloc->inode, rename, frame, this, oldloc, newloc, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_rename_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->rename,
- oldloc, newloc, xdata);
- return 0;
+ STACK_WIND(frame, leases_rename_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rename, oldloc, newloc, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (rename, frame, -1, errno, NULL,
- NULL, NULL, NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(rename, frame, -1, errno, NULL, NULL, NULL, NULL, NULL,
+ NULL);
+ return 0;
}
int32_t
-leases_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+leases_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct iatt *preparent, struct iatt *postparent,
+ dict_t *xdata)
{
- STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno,
- preparent, postparent, xdata);
+ STACK_UNWIND_STRICT(unlink, frame, op_ret, op_errno, preparent, postparent,
+ xdata);
- return 0;
+ return 0;
}
int32_t
-leases_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
- dict_t *xdata)
+leases_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
+ dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, 0);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, 0);
- ret = check_lease_conflict (frame, loc->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, loc->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (loc->inode, unlink, frame, this,
- loc, xflag, xdata);
- return 0;
+ LEASE_BLOCK_FOP(loc->inode, unlink, frame, this, loc, xflag, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_unlink_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->unlink,
- loc, xflag, xdata);
- return 0;
+ STACK_WIND(frame, leases_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, loc, xflag, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (unlink, frame, -1, errno, NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(unlink, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-leases_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, inode_t *inode, struct iatt *stbuf,
- struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
+leases_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, inode_t *inode, struct iatt *stbuf,
+ struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- STACK_UNWIND_STRICT (link, frame, op_ret, op_errno,
- inode, stbuf, preparent, postparent, xdata);
+ STACK_UNWIND_STRICT(link, frame, op_ret, op_errno, inode, stbuf, preparent,
+ postparent, xdata);
- return 0;
+ return 0;
}
int32_t
-leases_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
- loc_t *newloc, dict_t *xdata)
+leases_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
+ dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, 0);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, 0);
- ret = check_lease_conflict (frame, oldloc->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, oldloc->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (oldloc->inode, link, frame, this,
- oldloc, newloc, xdata);
- return 0;
+ LEASE_BLOCK_FOP(oldloc->inode, link, frame, this, oldloc, newloc, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_link_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->link,
- oldloc, newloc, xdata);
- return 0;
+ STACK_WIND(frame, leases_link_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (link, frame, -1, errno, NULL,
- NULL, NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(link, frame, -1, errno, NULL, NULL, NULL, NULL, NULL);
+ return 0;
}
int32_t
-leases_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, fd_t *fd, inode_t *inode,
- struct iatt *stbuf, struct iatt *preparent,
- struct iatt *postparent, dict_t *xdata)
+leases_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, fd_t *fd, inode_t *inode, struct iatt *stbuf,
+ struct iatt *preparent, struct iatt *postparent,
+ dict_t *xdata)
{
- STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd,
- inode, stbuf, preparent, postparent, xdata);
+ STACK_UNWIND_STRICT(create, frame, op_ret, op_errno, fd, inode, stbuf,
+ preparent, postparent, xdata);
- return 0;
+ return 0;
}
int32_t
-leases_create (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int32_t flags, mode_t mode,
- mode_t umask, fd_t *fd, dict_t *xdata)
+leases_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, flags);
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, create, frame, this,
- loc, flags, mode, umask, fd, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, create, frame, this, loc, flags, mode, umask, fd,
+ xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_create_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->create,
- loc, flags, mode, umask, fd, xdata);
- return 0;
+ STACK_WIND(frame, leases_create_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->create, loc, flags, mode, umask, fd,
+ xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (create, frame, -1, errno, NULL, NULL, NULL,
- NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(create, frame, -1, errno, NULL, NULL, NULL, NULL, NULL,
+ NULL);
+ return 0;
}
int32_t
-leases_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf,
- dict_t *xdata)
+leases_fsync_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, prebuf, postbuf,
- xdata);
- return 0;
+ STACK_UNWIND_STRICT(fsync, frame, op_ret, op_errno, prebuf, postbuf, xdata);
+ return 0;
}
int32_t
-leases_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd,
- int32_t flags, dict_t *xdata)
+leases_fsync(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags,
+ dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, fd->flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, fd->flags);
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, fsync, frame, this,
- fd, flags, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, fsync, frame, this, fd, flags, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_fsync_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fsync, fd, flags, xdata);
- return 0;
+ STACK_WIND(frame, leases_fsync_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsync, fd, flags, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (fsync, frame, -1, errno, NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(fsync, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-leases_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
- struct iatt *postbuf,
- dict_t *xdata)
+leases_ftruncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
+ struct iatt *postbuf, dict_t *xdata)
{
- STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, prebuf,
- postbuf, xdata);
- return 0;
+ STACK_UNWIND_STRICT(ftruncate, frame, op_ret, op_errno, prebuf, postbuf,
+ xdata);
+ return 0;
}
int32_t
-leases_ftruncate (call_frame_t *frame, xlator_t *this,
- fd_t *fd, off_t offset, dict_t *xdata)
+leases_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, 0); /* TODO:fd->flags?*/
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, 0); /* TODO:fd->flags?*/
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, ftruncate, frame, this,
- fd, offset, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, ftruncate, frame, this, fd, offset, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_ftruncate_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->ftruncate,
- fd, offset, xdata);
- return 0;
+ STACK_WIND(frame, leases_ftruncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (ftruncate, frame, -1, errno, NULL,
- NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(ftruncate, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-leases_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *statpre,
- struct iatt *statpost, dict_t *xdata)
+leases_fsetattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *statpre,
+ struct iatt *statpost, dict_t *xdata)
{
- STACK_UNWIND_STRICT (fsetattr, frame, op_ret, op_errno,
- statpre, statpost, xdata);
- return 0;
+ STACK_UNWIND_STRICT(fsetattr, frame, op_ret, op_errno, statpre, statpost,
+ xdata);
+ return 0;
}
int32_t
-leases_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iatt *stbuf, int32_t valid, dict_t *xdata)
+leases_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, fd->flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, fd->flags);
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, fsetattr, frame, this,
- fd, stbuf, valid, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, fsetattr, frame, this, fd, stbuf, valid, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_fsetattr_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsetattr,
- fd, stbuf, valid, xdata);
- return 0;
+ STACK_WIND(frame, leases_fsetattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetattr, fd, stbuf, valid, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (fsetattr, frame, -1, errno, NULL,
- NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(fsetattr, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-leases_fallocate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *pre,
- struct iatt *post, dict_t *xdata)
+leases_fallocate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *pre,
+ struct iatt *post, dict_t *xdata)
{
- STACK_UNWIND_STRICT (fallocate, frame, op_ret, op_errno, pre,
- post, xdata);
+ STACK_UNWIND_STRICT(fallocate, frame, op_ret, op_errno, pre, post, xdata);
- return 0;
+ return 0;
}
int32_t
-leases_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd,
- int32_t mode, off_t offset, size_t len, dict_t *xdata)
+leases_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t mode,
+ off_t offset, size_t len, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, fd->flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, fd->flags);
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, fallocate, frame, this,
- fd, mode, offset, len, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, fallocate, frame, this, fd, mode, offset, len,
+ xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_fallocate_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->fallocate,
- fd, mode, offset, len, xdata);
- return 0;
+ STACK_WIND(frame, leases_fallocate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fallocate, fd, mode, offset, len,
+ xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (fallocate, frame, -1, errno, NULL,
- NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(fallocate, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-leases_discard_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *pre,
- struct iatt *post, dict_t *xdata)
+leases_discard_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *pre,
+ struct iatt *post, dict_t *xdata)
{
- STACK_UNWIND_STRICT (discard, frame, op_ret, op_errno, pre,
- post, xdata);
+ STACK_UNWIND_STRICT(discard, frame, op_ret, op_errno, pre, post, xdata);
- return 0;
+ return 0;
}
int32_t
-leases_discard (call_frame_t *frame, xlator_t *this, fd_t *fd,
- off_t offset, size_t len, dict_t *xdata)
+leases_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ size_t len, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, fd->flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, fd->flags);
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, discard, frame, this,
- fd, offset, len, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, discard, frame, this, fd, offset, len, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_discard_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->discard,
- fd, offset, len, xdata);
- return 0;
+ STACK_WIND(frame, leases_discard_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->discard, fd, offset, len, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (discard, frame, -1, errno, NULL,
- NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(discard, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-leases_zerofill_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct iatt *pre,
- struct iatt *post, dict_t *xdata)
+leases_zerofill_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *pre,
+ struct iatt *post, dict_t *xdata)
{
- STACK_UNWIND_STRICT (zerofill, frame, op_ret, op_errno, pre,
- post, xdata);
+ STACK_UNWIND_STRICT(zerofill, frame, op_ret, op_errno, pre, post, xdata);
- return 0;
+ return 0;
}
int
-leases_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd,
- off_t offset, off_t len, dict_t *xdata)
+leases_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ off_t len, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, fd->flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, fd->flags);
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, zerofill, frame, this,
- fd, offset, len, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, zerofill, frame, this, fd, offset, len, xdata);
+ return 0;
out:
- STACK_WIND (frame, leases_zerofill_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->zerofill,
- fd, offset, len, xdata);
- return 0;
+ STACK_WIND(frame, leases_zerofill_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->zerofill, fd, offset, len, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (zerofill, frame, -1, errno, NULL,
- NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(zerofill, frame, -1, errno, NULL, NULL, NULL);
+ return 0;
}
int
-leases_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *xdata)
+leases_flush_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
- STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno, xdata);
+ STACK_UNWIND_STRICT(flush, frame, op_ret, op_errno, xdata);
- return 0;
+ return 0;
}
int
-leases_flush (call_frame_t *frame, xlator_t *this,
- fd_t *fd, dict_t *xdata)
+leases_flush(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
- lease_fd_ctx_t *fd_ctx = NULL;
- uint64_t ctx = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
+ lease_fd_ctx_t *fd_ctx = NULL;
+ uint64_t ctx = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- GET_LEASE_ID (xdata, lease_id, frame->root->client->client_uid);
- GET_FLAGS (frame->root->op, fd->flags);
+ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid);
+ GET_FLAGS(frame->root->op, fd->flags);
- ret = check_lease_conflict (frame, fd->inode, lease_id, fop_flags);
- if (ret < 0)
- goto err;
- else if (ret == BLOCK_FOP)
- goto block;
- else if (ret == WIND_FOP)
- goto out;
+ ret = check_lease_conflict(frame, fd->inode, lease_id, fop_flags);
+ if (ret < 0)
+ goto err;
+ else if (ret == BLOCK_FOP)
+ goto block;
+ else if (ret == WIND_FOP)
+ goto out;
block:
- LEASE_BLOCK_FOP (fd->inode, flush, frame, this,
- fd, xdata);
- return 0;
+ LEASE_BLOCK_FOP(fd->inode, flush, frame, this, fd, xdata);
+ return 0;
out:
- /* *
- * currently release is not called after the close fop from the
- * application. Hence lease fd ctx is reset on here.
- * This is actually not the right way, since flush can be called
- * not only from the close op.
- * TODO :
- * - Either identify the flush is called from close call on fd from
- * from the application.
- * OR
- * - Find why release is not called post the last close call
- */
- ret = fd_ctx_get (fd, this, &ctx);
- if (ret == 0) {
- fd_ctx = (lease_fd_ctx_t *)(long)ctx;
- if (fd_ctx->client_uid) {
- GF_FREE (fd_ctx->client_uid);
- fd_ctx->client_uid = NULL;
- }
- memset (fd_ctx->lease_id, 0, LEASE_ID_SIZE);
+ /* *
+ * currently release is not called after the close fop from the
+ * application. Hence lease fd ctx is reset on here.
+ * This is actually not the right way, since flush can be called
+ * not only from the close op.
+ * TODO :
+ * - Either identify the flush is called from close call on fd from
+ * from the application.
+ * OR
+ * - Find why release is not called post the last close call
+ */
+ ret = fd_ctx_get(fd, this, &ctx);
+ if (ret == 0) {
+ fd_ctx = (lease_fd_ctx_t *)(long)ctx;
+ if (fd_ctx->client_uid) {
+ GF_FREE(fd_ctx->client_uid);
+ fd_ctx->client_uid = NULL;
}
- STACK_WIND (frame, leases_flush_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->flush, fd, xdata);
- return 0;
+ memset(fd_ctx->lease_id, 0, LEASE_ID_SIZE);
+ }
+ STACK_WIND(frame, leases_flush_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->flush, fd, xdata);
+ return 0;
err:
- STACK_UNWIND_STRICT (create, frame, -1, errno, NULL,
- NULL, NULL, NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(create, frame, -1, errno, NULL, NULL, NULL, NULL, NULL,
+ NULL);
+ return 0;
}
int32_t
-mem_acct_init (xlator_t *this)
+mem_acct_init(xlator_t *this)
{
- int ret = -1;
+ int ret = -1;
- if (!this)
- return ret;
-
- ret = xlator_mem_acct_init (this, gf_leases_mt_end + 1);
+ if (!this)
+ return ret;
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, ENOMEM, LEASE_MSG_NO_MEM,
- "mem account init failed");
- return ret;
- }
+ ret = xlator_mem_acct_init(this, gf_leases_mt_end + 1);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, ENOMEM, LEASE_MSG_NO_MEM,
+ "mem account init failed");
return ret;
+ }
+
+ return ret;
}
static int
-leases_init_priv (xlator_t *this)
+leases_init_priv(xlator_t *this)
{
- int ret = 0;
- leases_private_t *priv = NULL;
+ int ret = 0;
+ leases_private_t *priv = NULL;
- priv = this->private;
- GF_ASSERT (priv);
+ priv = this->private;
+ GF_ASSERT(priv);
+ if (!priv->timer_wheel) {
+ priv->timer_wheel = glusterfs_ctx_tw_get(this->ctx);
if (!priv->timer_wheel) {
- priv->timer_wheel = glusterfs_ctx_tw_get (this->ctx);
- if (!priv->timer_wheel) {
- ret = -1;
- goto out;
- }
+ ret = -1;
+ goto out;
}
+ }
- if (!priv->inited_recall_thr) {
- ret = gf_thread_create (&priv->recall_thr, NULL,
- expired_recall_cleanup, this,
- "leasercl");
- if (!ret)
- priv->inited_recall_thr = _gf_true;
- }
+ if (!priv->inited_recall_thr) {
+ ret = gf_thread_create(&priv->recall_thr, NULL, expired_recall_cleanup,
+ this, "leasercl");
+ if (!ret)
+ priv->inited_recall_thr = _gf_true;
+ }
out:
- return ret;
+ return ret;
}
int
-reconfigure (xlator_t *this, dict_t *options)
+reconfigure(xlator_t *this, dict_t *options)
{
- leases_private_t *priv = NULL;
- int ret = -1;
+ leases_private_t *priv = NULL;
+ int ret = -1;
- priv = this->private;
- GF_ASSERT (priv);
+ priv = this->private;
+ GF_ASSERT(priv);
- /* TODO: In case of reconfigure, if its enabling the leases
- * its not an issue, but if its disabling the leases, there
- * is more to it, like recall all the existing leases, wait
- * for unlock of all the leases etc., hence not supporting the
- * reconfigure for now.
+ /* TODO: In case of reconfigure, if its enabling the leases
+ * its not an issue, but if its disabling the leases, there
+ * is more to it, like recall all the existing leases, wait
+ * for unlock of all the leases etc., hence not supporting the
+ * reconfigure for now.
- GF_OPTION_RECONF ("leases", priv->leases_enabled,
- options, bool, out);
+ GF_OPTION_RECONF ("leases", priv->leases_enabled,
+ options, bool, out);
- if (priv->leases_enabled) {
- ret = leases_init_priv (this);
- if (ret)
- goto out;
- }
- */
+ if (priv->leases_enabled) {
+ ret = leases_init_priv (this);
+ if (ret)
+ goto out;
+ }
+ */
- GF_OPTION_RECONF ("lease-lock-recall-timeout",
- priv->recall_lease_timeout,
- options, int32, out);
+ GF_OPTION_RECONF("lease-lock-recall-timeout", priv->recall_lease_timeout,
+ options, int32, out);
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
int
-init (xlator_t *this)
+init(xlator_t *this)
{
- int ret = -1;
- leases_private_t *priv = NULL;
-
- priv = GF_CALLOC (1, sizeof (*priv),
- gf_leases_mt_private_t);
- if (!priv) {
- gf_msg (this->name, GF_LOG_WARNING, ENOMEM, LEASE_MSG_NO_MEM,
- "Leases init failed");
- goto out;
- }
+ int ret = -1;
+ leases_private_t *priv = NULL;
- GF_OPTION_INIT ("leases", priv->leases_enabled,
- bool, out);
- GF_OPTION_INIT ("lease-lock-recall-timeout",
- priv->recall_lease_timeout, int32, out);
- pthread_mutex_init (&priv->mutex, NULL);
- INIT_LIST_HEAD (&priv->client_list);
- INIT_LIST_HEAD (&priv->recall_list);
+ priv = GF_CALLOC(1, sizeof(*priv), gf_leases_mt_private_t);
+ if (!priv) {
+ gf_msg(this->name, GF_LOG_WARNING, ENOMEM, LEASE_MSG_NO_MEM,
+ "Leases init failed");
+ goto out;
+ }
- this->private = priv;
+ GF_OPTION_INIT("leases", priv->leases_enabled, bool, out);
+ GF_OPTION_INIT("lease-lock-recall-timeout", priv->recall_lease_timeout,
+ int32, out);
+ pthread_mutex_init(&priv->mutex, NULL);
+ INIT_LIST_HEAD(&priv->client_list);
+ INIT_LIST_HEAD(&priv->recall_list);
- if (priv->leases_enabled) {
- ret = leases_init_priv (this);
- if (ret)
- goto out;
- }
+ this->private = priv;
- ret = 0;
+ if (priv->leases_enabled) {
+ ret = leases_init_priv(this);
+ if (ret)
+ goto out;
+ }
+
+ ret = 0;
out:
- if (ret) {
- GF_FREE (priv);
- this->private = NULL;
- }
+ if (ret) {
+ GF_FREE(priv);
+ this->private = NULL;
+ }
- return ret;
+ return ret;
}
int
-fini (xlator_t *this)
+fini(xlator_t *this)
{
- leases_private_t *priv = NULL;
-
- priv = this->private;
- if (!priv) {
- return 0;
- }
- this->private = NULL;
-
- priv->fini = _gf_true;
- pthread_cond_broadcast (&priv->cond);
- if (priv->recall_thr) {
- gf_thread_cleanup_xint (priv->recall_thr);
- priv->recall_thr = 0;
- priv->inited_recall_thr = _gf_false;
- }
-
- GF_FREE (priv);
- if (this->ctx->tw) {
- glusterfs_ctx_tw_put (this->ctx);
- this->ctx->tw = NULL;
- }
- return 0;
+ leases_private_t *priv = NULL;
+
+ priv = this->private;
+ if (!priv) {
+ return 0;
+ }
+ this->private = NULL;
+
+ priv->fini = _gf_true;
+ pthread_cond_broadcast(&priv->cond);
+ if (priv->recall_thr) {
+ gf_thread_cleanup_xint(priv->recall_thr);
+ priv->recall_thr = 0;
+ priv->inited_recall_thr = _gf_false;
+ }
+
+ GF_FREE(priv);
+ if (this->ctx->tw) {
+ glusterfs_ctx_tw_put(this->ctx);
+ this->ctx->tw = NULL;
+ }
+ return 0;
}
static int
-leases_forget (xlator_t *this, inode_t *inode)
+leases_forget(xlator_t *this, inode_t *inode)
{
- /* TODO:leases_cleanup_inode_ctx (this, inode); */
- return 0;
+ /* TODO:leases_cleanup_inode_ctx (this, inode); */
+ return 0;
}
static int
-leases_release (xlator_t *this, fd_t *fd)
+leases_release(xlator_t *this, fd_t *fd)
{
- int ret = -1;
- uint64_t tmp = 0;
- lease_fd_ctx_t *fd_ctx = NULL;
+ int ret = -1;
+ uint64_t tmp = 0;
+ lease_fd_ctx_t *fd_ctx = NULL;
- if (fd == NULL) {
- goto out;
- }
+ if (fd == NULL) {
+ goto out;
+ }
- gf_log (this->name, GF_LOG_TRACE,
- "Releasing all leases with fd %p", fd);
+ gf_log(this->name, GF_LOG_TRACE, "Releasing all leases with fd %p", fd);
- ret = fd_ctx_del (fd, this, &tmp);
- if (ret) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Could not get fdctx");
- goto out;
- }
+ ret = fd_ctx_del(fd, this, &tmp);
+ if (ret) {
+ gf_log(this->name, GF_LOG_DEBUG, "Could not get fdctx");
+ goto out;
+ }
- fd_ctx = (lease_fd_ctx_t *)(long)tmp;
- if (fd_ctx)
- GF_FREE (fd_ctx);
+ fd_ctx = (lease_fd_ctx_t *)(long)tmp;
+ if (fd_ctx)
+ GF_FREE(fd_ctx);
out:
- return ret;
-
+ return ret;
}
static int
-leases_clnt_disconnect_cbk (xlator_t *this, client_t *client)
+leases_clnt_disconnect_cbk(xlator_t *this, client_t *client)
{
- int ret = 0;
+ int ret = 0;
- EXIT_IF_LEASES_OFF (this, out);
+ EXIT_IF_LEASES_OFF(this, out);
- ret = cleanup_client_leases (this, client->client_uid);
+ ret = cleanup_client_leases(this, client->client_uid);
out:
- return ret;
+ return ret;
}
struct xlator_fops fops = {
- /* Metadata modifying fops */
- .fsetattr = leases_fsetattr,
- .setattr = leases_setattr,
-
- /* File Data reading fops */
- .open = leases_open,
- .readv = leases_readv,
-
- /* File Data modifying fops */
- .truncate = leases_truncate,
- .ftruncate = leases_ftruncate,
- .writev = leases_writev,
- .zerofill = leases_zerofill,
- .fallocate = leases_fallocate,
- .discard = leases_discard,
- .lk = leases_lk,
- .fsync = leases_fsync,
- .flush = leases_flush,
- .lease = leases_lease,
-
- /* Directory Data modifying fops */
- .create = leases_create,
- .rename = leases_rename,
- .unlink = leases_unlink,
- .link = leases_link,
+ /* Metadata modifying fops */
+ .fsetattr = leases_fsetattr,
+ .setattr = leases_setattr,
+
+ /* File Data reading fops */
+ .open = leases_open,
+ .readv = leases_readv,
+
+ /* File Data modifying fops */
+ .truncate = leases_truncate,
+ .ftruncate = leases_ftruncate,
+ .writev = leases_writev,
+ .zerofill = leases_zerofill,
+ .fallocate = leases_fallocate,
+ .discard = leases_discard,
+ .lk = leases_lk,
+ .fsync = leases_fsync,
+ .flush = leases_flush,
+ .lease = leases_lease,
+
+ /* Directory Data modifying fops */
+ .create = leases_create,
+ .rename = leases_rename,
+ .unlink = leases_unlink,
+ .link = leases_link,
#ifdef NOT_SUPPORTED
- /* internal lk fops */
- .inodelk = leases_inodelk,
- .finodelk = leases_finodelk,
- .entrylk = leases_entrylk,
- .fentrylk = leases_fentrylk,
-
- /* Internal special fops*/
- .xattrop = leases_xattrop,
- .fxattrop = leases_fxattrop,
+ /* internal lk fops */
+ .inodelk = leases_inodelk,
+ .finodelk = leases_finodelk,
+ .entrylk = leases_entrylk,
+ .fentrylk = leases_fentrylk,
+
+ /* Internal special fops*/
+ .xattrop = leases_xattrop,
+ .fxattrop = leases_fxattrop,
#endif
};
struct xlator_cbks cbks = {
- .forget = leases_forget,
- .release = leases_release,
- .client_disconnect = leases_clnt_disconnect_cbk,
+ .forget = leases_forget,
+ .release = leases_release,
+ .client_disconnect = leases_clnt_disconnect_cbk,
};
struct volume_options options[] = {
- { .key = {"leases"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .op_version = {GD_OP_VERSION_3_8_0},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
- .description = "When \"on\", enables leases support"
- },
- { .key = {"lease-lock-recall-timeout"},
- .type = GF_OPTION_TYPE_INT,
- .default_value = RECALL_LEASE_LK_TIMEOUT,
- .op_version = {GD_OP_VERSION_3_8_0},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
- .description = "After 'timeout' seconds since the recall_lease"
- " request has been sent to the client, the lease lock"
- " will be forcefully purged by the server."
- },
- { .key = {NULL} },
+ {.key = {"leases"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .op_version = {GD_OP_VERSION_3_8_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
+ .description = "When \"on\", enables leases support"},
+ {.key = {"lease-lock-recall-timeout"},
+ .type = GF_OPTION_TYPE_INT,
+ .default_value = RECALL_LEASE_LK_TIMEOUT,
+ .op_version = {GD_OP_VERSION_3_8_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
+ .description = "After 'timeout' seconds since the recall_lease"
+ " request has been sent to the client, the lease lock"
+ " will be forcefully purged by the server."},
+ {.key = {NULL}},
};
diff --git a/xlators/features/locks/src/clear.c b/xlators/features/locks/src/clear.c
index 1609fc416d2..0966ee753d6 100644
--- a/xlators/features/locks/src/clear.c
+++ b/xlators/features/locks/src/clear.c
@@ -24,428 +24,427 @@
#include "clear.h"
int
-clrlk_get_kind (char *kind)
+clrlk_get_kind(char *kind)
{
- char *clrlk_kinds[CLRLK_KIND_MAX] = {"dummy", "blocked", "granted",
- "all"};
- int ret_kind = CLRLK_KIND_MAX;
- int i = 0;
-
- for (i = CLRLK_BLOCKED; i < CLRLK_KIND_MAX; i++) {
- if (!strcmp (clrlk_kinds[i], kind)) {
- ret_kind = i;
- break;
- }
+ char *clrlk_kinds[CLRLK_KIND_MAX] = {"dummy", "blocked", "granted", "all"};
+ int ret_kind = CLRLK_KIND_MAX;
+ int i = 0;
+
+ for (i = CLRLK_BLOCKED; i < CLRLK_KIND_MAX; i++) {
+ if (!strcmp(clrlk_kinds[i], kind)) {
+ ret_kind = i;
+ break;
}
+ }
- return ret_kind;
+ return ret_kind;
}
int
-clrlk_get_type (char *type)
+clrlk_get_type(char *type)
{
- char *clrlk_types[CLRLK_TYPE_MAX] = {"inode", "entry", "posix"};
- int ret_type = CLRLK_TYPE_MAX;
- int i = 0;
-
- for (i = CLRLK_INODE; i < CLRLK_TYPE_MAX; i++) {
- if (!strcmp (clrlk_types[i], type)) {
- ret_type = i;
- break;
- }
+ char *clrlk_types[CLRLK_TYPE_MAX] = {"inode", "entry", "posix"};
+ int ret_type = CLRLK_TYPE_MAX;
+ int i = 0;
+
+ for (i = CLRLK_INODE; i < CLRLK_TYPE_MAX; i++) {
+ if (!strcmp(clrlk_types[i], type)) {
+ ret_type = i;
+ break;
}
+ }
- return ret_type;
+ return ret_type;
}
int
-clrlk_get_lock_range (char *range_str, struct gf_flock *ulock,
- gf_boolean_t *chk_range)
+clrlk_get_lock_range(char *range_str, struct gf_flock *ulock,
+ gf_boolean_t *chk_range)
{
- int ret = -1;
+ int ret = -1;
- if (!chk_range)
- goto out;
-
- if (!range_str) {
- ret = 0;
- *chk_range = _gf_false;
- goto out;
- }
-
- if (sscanf (range_str, "%hd,%"PRId64"-""%"PRId64, &ulock->l_whence,
- &ulock->l_start, &ulock->l_len) != 3) {
- goto out;
- }
+ if (!chk_range)
+ goto out;
+ if (!range_str) {
ret = 0;
- *chk_range = _gf_true;
+ *chk_range = _gf_false;
+ goto out;
+ }
+
+ if (sscanf(range_str,
+ "%hd,%" PRId64 "-"
+ "%" PRId64,
+ &ulock->l_whence, &ulock->l_start, &ulock->l_len) != 3) {
+ goto out;
+ }
+
+ ret = 0;
+ *chk_range = _gf_true;
out:
- return ret;
+ return ret;
}
int
-clrlk_parse_args (const char* cmd, clrlk_args *args)
+clrlk_parse_args(const char *cmd, clrlk_args *args)
{
- char *opts = NULL;
- char *cur = NULL;
- char *tok = NULL;
- char *sptr = NULL;
- char *free_ptr = NULL;
- char kw[KW_MAX] = {[KW_TYPE] = 't',
- [KW_KIND] = 'k',
- };
- int ret = -1;
- int i = 0;
-
- GF_ASSERT (cmd);
- free_ptr = opts = GF_CALLOC (1, strlen (cmd), gf_common_mt_char);
- if (!opts)
- goto out;
-
- if (sscanf (cmd, GF_XATTR_CLRLK_CMD".%s", opts) < 1) {
- ret = -1;
- goto out;
- }
-
- /*clr_lk_prefix.ttype.kkind.args, args - type specific*/
- cur = opts;
- for (i = 0; i < KW_MAX && (tok = strtok_r (cur, ".", &sptr));
- cur = NULL, i++) {
- if (tok[0] != kw[i]) {
- ret = -1;
- goto out;
- }
- if (i == KW_TYPE)
- args->type = clrlk_get_type (tok+1);
- if (i == KW_KIND)
- args->kind = clrlk_get_kind (tok+1);
+ char *opts = NULL;
+ char *cur = NULL;
+ char *tok = NULL;
+ char *sptr = NULL;
+ char *free_ptr = NULL;
+ char kw[KW_MAX] = {
+ [KW_TYPE] = 't',
+ [KW_KIND] = 'k',
+ };
+ int ret = -1;
+ int i = 0;
+
+ GF_ASSERT(cmd);
+ free_ptr = opts = GF_CALLOC(1, strlen(cmd), gf_common_mt_char);
+ if (!opts)
+ goto out;
+
+ if (sscanf(cmd, GF_XATTR_CLRLK_CMD ".%s", opts) < 1) {
+ ret = -1;
+ goto out;
+ }
+
+ /*clr_lk_prefix.ttype.kkind.args, args - type specific*/
+ cur = opts;
+ for (i = 0; i < KW_MAX && (tok = strtok_r(cur, ".", &sptr));
+ cur = NULL, i++) {
+ if (tok[0] != kw[i]) {
+ ret = -1;
+ goto out;
}
-
- if ((args->type == CLRLK_TYPE_MAX) || (args->kind == CLRLK_KIND_MAX))
- goto out;
-
- /*optional args, neither range nor basename can 'legally' contain
- * "/" in them*/
- tok = strtok_r (NULL, "/", &sptr);
- if (tok)
- args->opts = gf_strdup (tok);
-
- ret = 0;
+ if (i == KW_TYPE)
+ args->type = clrlk_get_type(tok + 1);
+ if (i == KW_KIND)
+ args->kind = clrlk_get_kind(tok + 1);
+ }
+
+ if ((args->type == CLRLK_TYPE_MAX) || (args->kind == CLRLK_KIND_MAX))
+ goto out;
+
+ /*optional args, neither range nor basename can 'legally' contain
+ * "/" in them*/
+ tok = strtok_r(NULL, "/", &sptr);
+ if (tok)
+ args->opts = gf_strdup(tok);
+
+ ret = 0;
out:
- GF_FREE (free_ptr);
- return ret;
+ GF_FREE(free_ptr);
+ return ret;
}
int
-clrlk_clear_posixlk (xlator_t *this, pl_inode_t *pl_inode, clrlk_args *args,
- int *blkd, int *granted, int *op_errno)
+clrlk_clear_posixlk(xlator_t *this, pl_inode_t *pl_inode, clrlk_args *args,
+ int *blkd, int *granted, int *op_errno)
{
- posix_lock_t *plock = NULL;
- posix_lock_t *tmp = NULL;
- struct gf_flock ulock = {0, };
- int ret = -1;
- int bcount = 0;
- int gcount = 0;
- gf_boolean_t chk_range = _gf_false;
-
- if (clrlk_get_lock_range (args->opts, &ulock, &chk_range)) {
- *op_errno = EINVAL;
- goto out;
- }
-
- pthread_mutex_lock (&pl_inode->mutex);
+ posix_lock_t *plock = NULL;
+ posix_lock_t *tmp = NULL;
+ struct gf_flock ulock = {
+ 0,
+ };
+ int ret = -1;
+ int bcount = 0;
+ int gcount = 0;
+ gf_boolean_t chk_range = _gf_false;
+
+ if (clrlk_get_lock_range(args->opts, &ulock, &chk_range)) {
+ *op_errno = EINVAL;
+ goto out;
+ }
+
+ pthread_mutex_lock(&pl_inode->mutex);
+ {
+ list_for_each_entry_safe(plock, tmp, &pl_inode->ext_list, list)
{
- list_for_each_entry_safe (plock, tmp, &pl_inode->ext_list,
- list) {
- if ((plock->blocked &&
- !(args->kind & CLRLK_BLOCKED)) ||
- (!plock->blocked &&
- !(args->kind & CLRLK_GRANTED)))
- continue;
-
- if (chk_range &&
- (plock->user_flock.l_whence != ulock.l_whence
- || plock->user_flock.l_start != ulock.l_start
- || plock->user_flock.l_len != ulock.l_len))
- continue;
-
- list_del_init (&plock->list);
- if (plock->blocked) {
- bcount++;
- pl_trace_out (this, plock->frame, NULL, NULL,
- F_SETLKW, &plock->user_flock,
- -1, EAGAIN, NULL);
-
- STACK_UNWIND_STRICT (lk, plock->frame, -1, EAGAIN,
- &plock->user_flock, NULL);
-
- } else {
- gcount++;
- }
- __destroy_lock(plock);
- }
+ if ((plock->blocked && !(args->kind & CLRLK_BLOCKED)) ||
+ (!plock->blocked && !(args->kind & CLRLK_GRANTED)))
+ continue;
+
+ if (chk_range && (plock->user_flock.l_whence != ulock.l_whence ||
+ plock->user_flock.l_start != ulock.l_start ||
+ plock->user_flock.l_len != ulock.l_len))
+ continue;
+
+ list_del_init(&plock->list);
+ if (plock->blocked) {
+ bcount++;
+ pl_trace_out(this, plock->frame, NULL, NULL, F_SETLKW,
+ &plock->user_flock, -1, EAGAIN, NULL);
+
+ STACK_UNWIND_STRICT(lk, plock->frame, -1, EAGAIN,
+ &plock->user_flock, NULL);
+
+ } else {
+ gcount++;
+ }
+ __destroy_lock(plock);
}
- pthread_mutex_unlock (&pl_inode->mutex);
- grant_blocked_locks (this, pl_inode);
- ret = 0;
+ }
+ pthread_mutex_unlock(&pl_inode->mutex);
+ grant_blocked_locks(this, pl_inode);
+ ret = 0;
out:
- *blkd = bcount;
- *granted = gcount;
- return ret;
+ *blkd = bcount;
+ *granted = gcount;
+ return ret;
}
/* Returns 0 on success and -1 on failure */
int
-clrlk_clear_inodelk (xlator_t *this, pl_inode_t *pl_inode, pl_dom_list_t *dom,
- clrlk_args *args, int *blkd, int *granted, int *op_errno)
+clrlk_clear_inodelk(xlator_t *this, pl_inode_t *pl_inode, pl_dom_list_t *dom,
+ clrlk_args *args, int *blkd, int *granted, int *op_errno)
{
- posix_locks_private_t *priv;
- pl_inode_lock_t *ilock = NULL;
- pl_inode_lock_t *tmp = NULL;
- struct gf_flock ulock = {0, };
- int ret = -1;
- int bcount = 0;
- int gcount = 0;
- gf_boolean_t chk_range = _gf_false;
- struct list_head *pcontend = NULL;
- struct list_head released;
- struct list_head contend;
- struct timespec now = { };
-
- INIT_LIST_HEAD (&released);
-
- priv = this->private;
- if (priv->notify_contention) {
- pcontend = &contend;
- INIT_LIST_HEAD (pcontend);
- timespec_now(&now);
- }
-
- if (clrlk_get_lock_range (args->opts, &ulock, &chk_range)) {
- *op_errno = EINVAL;
- goto out;
- }
-
- if (args->kind & CLRLK_BLOCKED)
- goto blkd;
-
- if (args->kind & CLRLK_GRANTED)
- goto granted;
+ posix_locks_private_t *priv;
+ pl_inode_lock_t *ilock = NULL;
+ pl_inode_lock_t *tmp = NULL;
+ struct gf_flock ulock = {
+ 0,
+ };
+ int ret = -1;
+ int bcount = 0;
+ int gcount = 0;
+ gf_boolean_t chk_range = _gf_false;
+ struct list_head *pcontend = NULL;
+ struct list_head released;
+ struct list_head contend;
+ struct timespec now = {};
+
+ INIT_LIST_HEAD(&released);
+
+ priv = this->private;
+ if (priv->notify_contention) {
+ pcontend = &contend;
+ INIT_LIST_HEAD(pcontend);
+ timespec_now(&now);
+ }
+
+ if (clrlk_get_lock_range(args->opts, &ulock, &chk_range)) {
+ *op_errno = EINVAL;
+ goto out;
+ }
+
+ if (args->kind & CLRLK_BLOCKED)
+ goto blkd;
+
+ if (args->kind & CLRLK_GRANTED)
+ goto granted;
blkd:
- pthread_mutex_lock (&pl_inode->mutex);
+ pthread_mutex_lock(&pl_inode->mutex);
+ {
+ list_for_each_entry_safe(ilock, tmp, &dom->blocked_inodelks,
+ blocked_locks)
{
- list_for_each_entry_safe (ilock, tmp, &dom->blocked_inodelks,
- blocked_locks) {
- if (chk_range &&
- (ilock->user_flock.l_whence != ulock.l_whence
- || ilock->user_flock.l_start != ulock.l_start
- || ilock->user_flock.l_len != ulock.l_len))
- continue;
-
- bcount++;
- list_del_init (&ilock->client_list);
- list_del_init (&ilock->blocked_locks);
- list_add (&ilock->blocked_locks, &released);
- }
- }
- pthread_mutex_unlock (&pl_inode->mutex);
-
- list_for_each_entry_safe (ilock, tmp, &released, blocked_locks) {
- list_del_init (&ilock->blocked_locks);
- pl_trace_out (this, ilock->frame, NULL, NULL, F_SETLKW,
- &ilock->user_flock, -1, EAGAIN,
- ilock->volume);
- STACK_UNWIND_STRICT (inodelk, ilock->frame, -1,
- EAGAIN, NULL);
- //No need to take lock as the locks are only in one list
- __pl_inodelk_unref (ilock);
- }
-
- if (!(args->kind & CLRLK_GRANTED)) {
- ret = 0;
- goto out;
+ if (chk_range && (ilock->user_flock.l_whence != ulock.l_whence ||
+ ilock->user_flock.l_start != ulock.l_start ||
+ ilock->user_flock.l_len != ulock.l_len))
+ continue;
+
+ bcount++;
+ list_del_init(&ilock->client_list);
+ list_del_init(&ilock->blocked_locks);
+ list_add(&ilock->blocked_locks, &released);
}
+ }
+ pthread_mutex_unlock(&pl_inode->mutex);
+
+ list_for_each_entry_safe(ilock, tmp, &released, blocked_locks)
+ {
+ list_del_init(&ilock->blocked_locks);
+ pl_trace_out(this, ilock->frame, NULL, NULL, F_SETLKW,
+ &ilock->user_flock, -1, EAGAIN, ilock->volume);
+ STACK_UNWIND_STRICT(inodelk, ilock->frame, -1, EAGAIN, NULL);
+ // No need to take lock as the locks are only in one list
+ __pl_inodelk_unref(ilock);
+ }
+
+ if (!(args->kind & CLRLK_GRANTED)) {
+ ret = 0;
+ goto out;
+ }
granted:
- pthread_mutex_lock (&pl_inode->mutex);
+ pthread_mutex_lock(&pl_inode->mutex);
+ {
+ list_for_each_entry_safe(ilock, tmp, &dom->inodelk_list, list)
{
- list_for_each_entry_safe (ilock, tmp, &dom->inodelk_list,
- list) {
- if (chk_range &&
- (ilock->user_flock.l_whence != ulock.l_whence
- || ilock->user_flock.l_start != ulock.l_start
- || ilock->user_flock.l_len != ulock.l_len))
- continue;
-
- gcount++;
- list_del_init (&ilock->client_list);
- list_del_init (&ilock->list);
- list_add (&ilock->list, &released);
- }
+ if (chk_range && (ilock->user_flock.l_whence != ulock.l_whence ||
+ ilock->user_flock.l_start != ulock.l_start ||
+ ilock->user_flock.l_len != ulock.l_len))
+ continue;
+
+ gcount++;
+ list_del_init(&ilock->client_list);
+ list_del_init(&ilock->list);
+ list_add(&ilock->list, &released);
}
- pthread_mutex_unlock (&pl_inode->mutex);
+ }
+ pthread_mutex_unlock(&pl_inode->mutex);
- list_for_each_entry_safe (ilock, tmp, &released, list) {
- list_del_init (&ilock->list);
- //No need to take lock as the locks are only in one list
- __pl_inodelk_unref (ilock);
- }
+ list_for_each_entry_safe(ilock, tmp, &released, list)
+ {
+ list_del_init(&ilock->list);
+ // No need to take lock as the locks are only in one list
+ __pl_inodelk_unref(ilock);
+ }
- ret = 0;
+ ret = 0;
out:
- grant_blocked_inode_locks (this, pl_inode, dom, &now, pcontend);
- if (pcontend != NULL) {
- inodelk_contention_notify(this, pcontend);
- }
- *blkd = bcount;
- *granted = gcount;
- return ret;
+ grant_blocked_inode_locks(this, pl_inode, dom, &now, pcontend);
+ if (pcontend != NULL) {
+ inodelk_contention_notify(this, pcontend);
+ }
+ *blkd = bcount;
+ *granted = gcount;
+ return ret;
}
/* Returns 0 on success and -1 on failure */
int
-clrlk_clear_entrylk (xlator_t *this, pl_inode_t *pl_inode, pl_dom_list_t *dom,
- clrlk_args *args, int *blkd, int *granted, int *op_errno)
+clrlk_clear_entrylk(xlator_t *this, pl_inode_t *pl_inode, pl_dom_list_t *dom,
+ clrlk_args *args, int *blkd, int *granted, int *op_errno)
{
- posix_locks_private_t *priv;
- pl_entry_lock_t *elock = NULL;
- pl_entry_lock_t *tmp = NULL;
- int bcount = 0;
- int gcount = 0;
- int ret = -1;
- struct list_head *pcontend = NULL;
- struct list_head removed;
- struct list_head released;
- struct list_head contend;
- struct timespec now;
-
- INIT_LIST_HEAD (&released);
-
- priv = this->private;
- if (priv->notify_contention) {
- pcontend = &contend;
- INIT_LIST_HEAD (pcontend);
- timespec_now(&now);
- }
-
- if (args->kind & CLRLK_BLOCKED)
- goto blkd;
-
- if (args->kind & CLRLK_GRANTED)
- goto granted;
+ posix_locks_private_t *priv;
+ pl_entry_lock_t *elock = NULL;
+ pl_entry_lock_t *tmp = NULL;
+ int bcount = 0;
+ int gcount = 0;
+ int ret = -1;
+ struct list_head *pcontend = NULL;
+ struct list_head removed;
+ struct list_head released;
+ struct list_head contend;
+ struct timespec now;
+
+ INIT_LIST_HEAD(&released);
+
+ priv = this->private;
+ if (priv->notify_contention) {
+ pcontend = &contend;
+ INIT_LIST_HEAD(pcontend);
+ timespec_now(&now);
+ }
+
+ if (args->kind & CLRLK_BLOCKED)
+ goto blkd;
+
+ if (args->kind & CLRLK_GRANTED)
+ goto granted;
blkd:
- pthread_mutex_lock (&pl_inode->mutex);
+ pthread_mutex_lock(&pl_inode->mutex);
+ {
+ list_for_each_entry_safe(elock, tmp, &dom->blocked_entrylks,
+ blocked_locks)
{
- list_for_each_entry_safe (elock, tmp, &dom->blocked_entrylks,
- blocked_locks) {
- if (args->opts) {
- if (!elock->basename ||
- strcmp (elock->basename, args->opts))
- continue;
- }
-
- bcount++;
-
- list_del_init (&elock->client_list);
- list_del_init (&elock->blocked_locks);
- list_add_tail (&elock->blocked_locks, &released);
- }
- }
- pthread_mutex_unlock (&pl_inode->mutex);
+ if (args->opts) {
+ if (!elock->basename || strcmp(elock->basename, args->opts))
+ continue;
+ }
- list_for_each_entry_safe (elock, tmp, &released, blocked_locks) {
- list_del_init (&elock->blocked_locks);
- entrylk_trace_out (this, elock->frame, elock->volume, NULL, NULL,
- elock->basename, ENTRYLK_LOCK, elock->type,
- -1, EAGAIN);
- STACK_UNWIND_STRICT (entrylk, elock->frame, -1, EAGAIN, NULL);
+ bcount++;
- __pl_entrylk_unref (elock);
+ list_del_init(&elock->client_list);
+ list_del_init(&elock->blocked_locks);
+ list_add_tail(&elock->blocked_locks, &released);
}
+ }
+ pthread_mutex_unlock(&pl_inode->mutex);
- if (!(args->kind & CLRLK_GRANTED)) {
- ret = 0;
- goto out;
- }
+ list_for_each_entry_safe(elock, tmp, &released, blocked_locks)
+ {
+ list_del_init(&elock->blocked_locks);
+ entrylk_trace_out(this, elock->frame, elock->volume, NULL, NULL,
+ elock->basename, ENTRYLK_LOCK, elock->type, -1,
+ EAGAIN);
+ STACK_UNWIND_STRICT(entrylk, elock->frame, -1, EAGAIN, NULL);
+
+ __pl_entrylk_unref(elock);
+ }
+
+ if (!(args->kind & CLRLK_GRANTED)) {
+ ret = 0;
+ goto out;
+ }
granted:
- INIT_LIST_HEAD (&removed);
- pthread_mutex_lock (&pl_inode->mutex);
+ INIT_LIST_HEAD(&removed);
+ pthread_mutex_lock(&pl_inode->mutex);
+ {
+ list_for_each_entry_safe(elock, tmp, &dom->entrylk_list, domain_list)
{
- list_for_each_entry_safe (elock, tmp, &dom->entrylk_list,
- domain_list) {
- if (args->opts) {
- if (!elock->basename ||
- strcmp (elock->basename, args->opts))
- continue;
- }
-
- gcount++;
- list_del_init (&elock->client_list);
- list_del_init (&elock->domain_list);
- list_add_tail (&elock->domain_list, &removed);
-
- __pl_entrylk_unref (elock);
- }
- }
- pthread_mutex_unlock (&pl_inode->mutex);
+ if (args->opts) {
+ if (!elock->basename || strcmp(elock->basename, args->opts))
+ continue;
+ }
- grant_blocked_entry_locks (this, pl_inode, dom, &now, pcontend);
- if (pcontend != NULL) {
- entrylk_contention_notify(this, pcontend);
+ gcount++;
+ list_del_init(&elock->client_list);
+ list_del_init(&elock->domain_list);
+ list_add_tail(&elock->domain_list, &removed);
+
+ __pl_entrylk_unref(elock);
}
+ }
+ pthread_mutex_unlock(&pl_inode->mutex);
- ret = 0;
+ grant_blocked_entry_locks(this, pl_inode, dom, &now, pcontend);
+ if (pcontend != NULL) {
+ entrylk_contention_notify(this, pcontend);
+ }
+
+ ret = 0;
out:
- *blkd = bcount;
- *granted = gcount;
- return ret;
+ *blkd = bcount;
+ *granted = gcount;
+ return ret;
}
int
-clrlk_clear_lks_in_all_domains (xlator_t *this, pl_inode_t *pl_inode,
- clrlk_args *args, int *blkd, int *granted,
- int *op_errno)
+clrlk_clear_lks_in_all_domains(xlator_t *this, pl_inode_t *pl_inode,
+ clrlk_args *args, int *blkd, int *granted,
+ int *op_errno)
{
- pl_dom_list_t *dom = NULL;
- int ret = -1;
- int tmp_bcount = 0;
- int tmp_gcount = 0;
-
- if (list_empty (&pl_inode->dom_list)) {
- ret = 0;
- goto out;
- }
+ pl_dom_list_t *dom = NULL;
+ int ret = -1;
+ int tmp_bcount = 0;
+ int tmp_gcount = 0;
- list_for_each_entry (dom, &pl_inode->dom_list, inode_list) {
- tmp_bcount = tmp_gcount = 0;
-
- switch (args->type)
- {
- case CLRLK_INODE:
- ret = clrlk_clear_inodelk (this, pl_inode, dom, args,
- &tmp_bcount, &tmp_gcount,
- op_errno);
- if (ret)
- goto out;
- break;
- case CLRLK_ENTRY:
- ret = clrlk_clear_entrylk (this, pl_inode, dom, args,
- &tmp_bcount, &tmp_gcount,
- op_errno);
- if (ret)
- goto out;
- break;
- }
-
- *blkd += tmp_bcount;
- *granted += tmp_gcount;
+ if (list_empty(&pl_inode->dom_list)) {
+ ret = 0;
+ goto out;
+ }
+
+ list_for_each_entry(dom, &pl_inode->dom_list, inode_list)
+ {
+ tmp_bcount = tmp_gcount = 0;
+
+ switch (args->type) {
+ case CLRLK_INODE:
+ ret = clrlk_clear_inodelk(this, pl_inode, dom, args,
+ &tmp_bcount, &tmp_gcount, op_errno);
+ if (ret)
+ goto out;
+ break;
+ case CLRLK_ENTRY:
+ ret = clrlk_clear_entrylk(this, pl_inode, dom, args,
+ &tmp_bcount, &tmp_gcount, op_errno);
+ if (ret)
+ goto out;
+ break;
}
- ret = 0;
+ *blkd += tmp_bcount;
+ *granted += tmp_gcount;
+ }
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c
index b4d8aa37219..a953e0d1a4a 100644
--- a/xlators/features/locks/src/common.c
+++ b/xlators/features/locks/src/common.c
@@ -21,730 +21,701 @@
#include "locks.h"
#include "common.h"
-
static int
-__is_lock_grantable (pl_inode_t *pl_inode, posix_lock_t *lock);
+__is_lock_grantable(pl_inode_t *pl_inode, posix_lock_t *lock);
static void
-__insert_and_merge (pl_inode_t *pl_inode, posix_lock_t *lock);
+__insert_and_merge(pl_inode_t *pl_inode, posix_lock_t *lock);
static int
-pl_send_prelock_unlock (xlator_t *this, pl_inode_t *pl_inode,
- posix_lock_t *old_lock);
+pl_send_prelock_unlock(xlator_t *this, pl_inode_t *pl_inode,
+ posix_lock_t *old_lock);
static pl_dom_list_t *
-__allocate_domain (const char *volume)
+__allocate_domain(const char *volume)
{
- pl_dom_list_t *dom = NULL;
+ pl_dom_list_t *dom = NULL;
- dom = GF_CALLOC (1, sizeof (*dom),
- gf_locks_mt_pl_dom_list_t);
- if (!dom)
- goto out;
+ dom = GF_CALLOC(1, sizeof(*dom), gf_locks_mt_pl_dom_list_t);
+ if (!dom)
+ goto out;
- dom->domain = gf_strdup(volume);
- if (!dom->domain)
- goto out;
+ dom->domain = gf_strdup(volume);
+ if (!dom->domain)
+ goto out;
- gf_log ("posix-locks", GF_LOG_TRACE,
- "New domain allocated: %s", dom->domain);
+ gf_log("posix-locks", GF_LOG_TRACE, "New domain allocated: %s",
+ dom->domain);
- INIT_LIST_HEAD (&dom->inode_list);
- INIT_LIST_HEAD (&dom->entrylk_list);
- INIT_LIST_HEAD (&dom->blocked_entrylks);
- INIT_LIST_HEAD (&dom->inodelk_list);
- INIT_LIST_HEAD (&dom->blocked_inodelks);
+ INIT_LIST_HEAD(&dom->inode_list);
+ INIT_LIST_HEAD(&dom->entrylk_list);
+ INIT_LIST_HEAD(&dom->blocked_entrylks);
+ INIT_LIST_HEAD(&dom->inodelk_list);
+ INIT_LIST_HEAD(&dom->blocked_inodelks);
out:
- if (dom && (NULL == dom->domain)) {
- GF_FREE (dom);
- dom = NULL;
- }
+ if (dom && (NULL == dom->domain)) {
+ GF_FREE(dom);
+ dom = NULL;
+ }
- return dom;
+ return dom;
}
/* Returns domain for the lock. If domain is not present,
* allocates a domain and returns it
*/
pl_dom_list_t *
-get_domain (pl_inode_t *pl_inode, const char *volume)
+get_domain(pl_inode_t *pl_inode, const char *volume)
{
- pl_dom_list_t *dom = NULL;
+ pl_dom_list_t *dom = NULL;
- GF_VALIDATE_OR_GOTO ("posix-locks", pl_inode, out);
- GF_VALIDATE_OR_GOTO ("posix-locks", volume, out);
+ GF_VALIDATE_OR_GOTO("posix-locks", pl_inode, out);
+ GF_VALIDATE_OR_GOTO("posix-locks", volume, out);
- pthread_mutex_lock (&pl_inode->mutex);
+ pthread_mutex_lock(&pl_inode->mutex);
+ {
+ list_for_each_entry(dom, &pl_inode->dom_list, inode_list)
{
- list_for_each_entry (dom, &pl_inode->dom_list, inode_list) {
- if (strcmp (dom->domain, volume) == 0)
- goto unlock;
- }
-
- dom = __allocate_domain (volume);
- if (dom)
- list_add (&dom->inode_list, &pl_inode->dom_list);
+ if (strcmp(dom->domain, volume) == 0)
+ goto unlock;
}
+
+ dom = __allocate_domain(volume);
+ if (dom)
+ list_add(&dom->inode_list, &pl_inode->dom_list);
+ }
unlock:
- pthread_mutex_unlock (&pl_inode->mutex);
- if (dom) {
- gf_log ("posix-locks", GF_LOG_TRACE, "Domain %s found", volume);
- } else {
- gf_log ("posix-locks", GF_LOG_TRACE, "Domain %s not found", volume);
- }
+ pthread_mutex_unlock(&pl_inode->mutex);
+ if (dom) {
+ gf_log("posix-locks", GF_LOG_TRACE, "Domain %s found", volume);
+ } else {
+ gf_log("posix-locks", GF_LOG_TRACE, "Domain %s not found", volume);
+ }
out:
- return dom;
+ return dom;
}
unsigned long
-fd_to_fdnum (fd_t *fd)
+fd_to_fdnum(fd_t *fd)
{
- return ((unsigned long) fd);
+ return ((unsigned long)fd);
}
fd_t *
-fd_from_fdnum (posix_lock_t *lock)
+fd_from_fdnum(posix_lock_t *lock)
{
- return ((fd_t *) lock->fd_num);
+ return ((fd_t *)lock->fd_num);
}
int
-__pl_inode_is_empty (pl_inode_t *pl_inode)
+__pl_inode_is_empty(pl_inode_t *pl_inode)
{
- return (list_empty (&pl_inode->ext_list));
+ return (list_empty(&pl_inode->ext_list));
}
void
-pl_print_locker (char *str, int size, xlator_t *this, call_frame_t *frame)
+pl_print_locker(char *str, int size, xlator_t *this, call_frame_t *frame)
{
- snprintf (str, size, "Pid=%llu, lk-owner=%s, Client=%p, Frame=%llu",
- (unsigned long long) frame->root->pid,
- lkowner_utoa (&frame->root->lk_owner),
- frame->root->client,
- (unsigned long long) frame->root->unique);
+ snprintf(str, size, "Pid=%llu, lk-owner=%s, Client=%p, Frame=%llu",
+ (unsigned long long)frame->root->pid,
+ lkowner_utoa(&frame->root->lk_owner), frame->root->client,
+ (unsigned long long)frame->root->unique);
}
-
void
-pl_print_lockee (char *str, int size, fd_t *fd, loc_t *loc)
+pl_print_lockee(char *str, int size, fd_t *fd, loc_t *loc)
{
- inode_t *inode = NULL;
- char *ipath = NULL;
- int ret = 0;
+ inode_t *inode = NULL;
+ char *ipath = NULL;
+ int ret = 0;
- if (fd)
- inode = fd->inode;
- if (loc)
- inode = loc->inode;
+ if (fd)
+ inode = fd->inode;
+ if (loc)
+ inode = loc->inode;
- if (!inode) {
- snprintf (str, size, "<nul>");
- return;
- }
+ if (!inode) {
+ snprintf(str, size, "<nul>");
+ return;
+ }
- if (loc && loc->path) {
- ipath = gf_strdup (loc->path);
- } else {
- ret = inode_path (inode, NULL, &ipath);
- if (ret <= 0)
- ipath = NULL;
- }
+ if (loc && loc->path) {
+ ipath = gf_strdup(loc->path);
+ } else {
+ ret = inode_path(inode, NULL, &ipath);
+ if (ret <= 0)
+ ipath = NULL;
+ }
- snprintf (str, size, "gfid=%s, fd=%p, path=%s",
- uuid_utoa (inode->gfid), fd,
- ipath ? ipath : "<nul>");
+ snprintf(str, size, "gfid=%s, fd=%p, path=%s", uuid_utoa(inode->gfid), fd,
+ ipath ? ipath : "<nul>");
- GF_FREE (ipath);
+ GF_FREE(ipath);
}
-
void
-pl_print_lock (char *str, int size, int cmd,
- struct gf_flock *flock, gf_lkowner_t *owner)
+pl_print_lock(char *str, int size, int cmd, struct gf_flock *flock,
+ gf_lkowner_t *owner)
{
- char *cmd_str = NULL;
- char *type_str = NULL;
+ char *cmd_str = NULL;
+ char *type_str = NULL;
- switch (cmd) {
+ switch (cmd) {
#if F_GETLK != F_GETLK64
case F_GETLK64:
#endif
case F_GETLK:
- cmd_str = "GETLK";
- break;
+ cmd_str = "GETLK";
+ break;
#if F_SETLK != F_SETLK64
case F_SETLK64:
#endif
case F_SETLK:
- cmd_str = "SETLK";
- break;
+ cmd_str = "SETLK";
+ break;
#if F_SETLKW != F_SETLKW64
case F_SETLKW64:
#endif
case F_SETLKW:
- cmd_str = "SETLKW";
- break;
+ cmd_str = "SETLKW";
+ break;
default:
- cmd_str = "UNKNOWN";
- break;
- }
+ cmd_str = "UNKNOWN";
+ break;
+ }
- switch (flock->l_type) {
+ switch (flock->l_type) {
case F_RDLCK:
- type_str = "READ";
- break;
+ type_str = "READ";
+ break;
case F_WRLCK:
- type_str = "WRITE";
- break;
+ type_str = "WRITE";
+ break;
case F_UNLCK:
- type_str = "UNLOCK";
- break;
+ type_str = "UNLOCK";
+ break;
default:
- type_str = "UNKNOWN";
- break;
- }
-
- snprintf (str, size, "lock=FCNTL, cmd=%s, type=%s, "
- "start=%llu, len=%llu, pid=%llu, lk-owner=%s",
- cmd_str, type_str, (unsigned long long) flock->l_start,
- (unsigned long long) flock->l_len,
- (unsigned long long) flock->l_pid,
- lkowner_utoa (owner));
+ type_str = "UNKNOWN";
+ break;
+ }
+
+ snprintf(str, size,
+ "lock=FCNTL, cmd=%s, type=%s, "
+ "start=%llu, len=%llu, pid=%llu, lk-owner=%s",
+ cmd_str, type_str, (unsigned long long)flock->l_start,
+ (unsigned long long)flock->l_len, (unsigned long long)flock->l_pid,
+ lkowner_utoa(owner));
}
-
void
-pl_trace_in (xlator_t *this, call_frame_t *frame, fd_t *fd, loc_t *loc,
- int cmd, struct gf_flock *flock, const char *domain)
+pl_trace_in(xlator_t *this, call_frame_t *frame, fd_t *fd, loc_t *loc, int cmd,
+ struct gf_flock *flock, const char *domain)
{
- posix_locks_private_t *priv = NULL;
- char pl_locker[256];
- char pl_lockee[256];
- char pl_lock[256];
+ posix_locks_private_t *priv = NULL;
+ char pl_locker[256];
+ char pl_lockee[256];
+ char pl_lock[256];
- priv = this->private;
+ priv = this->private;
- if (!priv->trace)
- return;
+ if (!priv->trace)
+ return;
- pl_print_locker (pl_locker, 256, this, frame);
- pl_print_lockee (pl_lockee, 256, fd, loc);
- if (domain)
- pl_print_inodelk (pl_lock, 256, cmd, flock, domain);
- else
- pl_print_lock (pl_lock, 256, cmd, flock, &frame->root->lk_owner);
+ pl_print_locker(pl_locker, 256, this, frame);
+ pl_print_lockee(pl_lockee, 256, fd, loc);
+ if (domain)
+ pl_print_inodelk(pl_lock, 256, cmd, flock, domain);
+ else
+ pl_print_lock(pl_lock, 256, cmd, flock, &frame->root->lk_owner);
- gf_log (this->name, GF_LOG_INFO,
- "[REQUEST] Locker = {%s} Lockee = {%s} Lock = {%s}",
- pl_locker, pl_lockee, pl_lock);
+ gf_log(this->name, GF_LOG_INFO,
+ "[REQUEST] Locker = {%s} Lockee = {%s} Lock = {%s}", pl_locker,
+ pl_lockee, pl_lock);
}
-
void
-pl_print_verdict (char *str, int size, int op_ret, int op_errno)
+pl_print_verdict(char *str, int size, int op_ret, int op_errno)
{
- char *verdict = NULL;
-
- if (op_ret == 0) {
- verdict = "GRANTED";
- } else {
- switch (op_errno) {
- case EAGAIN:
- verdict = "TRYAGAIN";
- break;
- default:
- verdict = strerror (op_errno);
- }
+ char *verdict = NULL;
+
+ if (op_ret == 0) {
+ verdict = "GRANTED";
+ } else {
+ switch (op_errno) {
+ case EAGAIN:
+ verdict = "TRYAGAIN";
+ break;
+ default:
+ verdict = strerror(op_errno);
}
+ }
- snprintf (str, size, "%s", verdict);
+ snprintf(str, size, "%s", verdict);
}
-
void
-pl_trace_out (xlator_t *this, call_frame_t *frame, fd_t *fd, loc_t *loc,
- int cmd, struct gf_flock *flock, int op_ret, int op_errno, const char *domain)
+pl_trace_out(xlator_t *this, call_frame_t *frame, fd_t *fd, loc_t *loc, int cmd,
+ struct gf_flock *flock, int op_ret, int op_errno,
+ const char *domain)
{
- posix_locks_private_t *priv = NULL;
- char pl_locker[256];
- char pl_lockee[256];
- char pl_lock[256];
- char verdict[32];
+ posix_locks_private_t *priv = NULL;
+ char pl_locker[256];
+ char pl_lockee[256];
+ char pl_lock[256];
+ char verdict[32];
- priv = this->private;
+ priv = this->private;
- if (!priv->trace)
- return;
+ if (!priv->trace)
+ return;
- pl_print_locker (pl_locker, 256, this, frame);
- pl_print_lockee (pl_lockee, 256, fd, loc);
- if (domain)
- pl_print_inodelk (pl_lock, 256, cmd, flock, domain);
- else
- pl_print_lock (pl_lock, 256, cmd, flock, &frame->root->lk_owner);
+ pl_print_locker(pl_locker, 256, this, frame);
+ pl_print_lockee(pl_lockee, 256, fd, loc);
+ if (domain)
+ pl_print_inodelk(pl_lock, 256, cmd, flock, domain);
+ else
+ pl_print_lock(pl_lock, 256, cmd, flock, &frame->root->lk_owner);
- pl_print_verdict (verdict, 32, op_ret, op_errno);
+ pl_print_verdict(verdict, 32, op_ret, op_errno);
- gf_log (this->name, GF_LOG_INFO,
- "[%s] Locker = {%s} Lockee = {%s} Lock = {%s}",
- verdict, pl_locker, pl_lockee, pl_lock);
+ gf_log(this->name, GF_LOG_INFO,
+ "[%s] Locker = {%s} Lockee = {%s} Lock = {%s}", verdict, pl_locker,
+ pl_lockee, pl_lock);
}
-
void
-pl_trace_block (xlator_t *this, call_frame_t *frame, fd_t *fd, loc_t *loc,
- int cmd, struct gf_flock *flock, const char *domain)
+pl_trace_block(xlator_t *this, call_frame_t *frame, fd_t *fd, loc_t *loc,
+ int cmd, struct gf_flock *flock, const char *domain)
{
- posix_locks_private_t *priv = NULL;
- char pl_locker[256];
- char pl_lockee[256];
- char pl_lock[256];
+ posix_locks_private_t *priv = NULL;
+ char pl_locker[256];
+ char pl_lockee[256];
+ char pl_lock[256];
- priv = this->private;
+ priv = this->private;
- if (!priv->trace)
- return;
+ if (!priv->trace)
+ return;
- pl_print_locker (pl_locker, 256, this, frame);
- pl_print_lockee (pl_lockee, 256, fd, loc);
- if (domain)
- pl_print_inodelk (pl_lock, 256, cmd, flock, domain);
- else
- pl_print_lock (pl_lock, 256, cmd, flock, &frame->root->lk_owner);
+ pl_print_locker(pl_locker, 256, this, frame);
+ pl_print_lockee(pl_lockee, 256, fd, loc);
+ if (domain)
+ pl_print_inodelk(pl_lock, 256, cmd, flock, domain);
+ else
+ pl_print_lock(pl_lock, 256, cmd, flock, &frame->root->lk_owner);
- gf_log (this->name, GF_LOG_INFO,
- "[BLOCKED] Locker = {%s} Lockee = {%s} Lock = {%s}",
- pl_locker, pl_lockee, pl_lock);
+ gf_log(this->name, GF_LOG_INFO,
+ "[BLOCKED] Locker = {%s} Lockee = {%s} Lock = {%s}", pl_locker,
+ pl_lockee, pl_lock);
}
-
void
-pl_trace_flush (xlator_t *this, call_frame_t *frame, fd_t *fd)
+pl_trace_flush(xlator_t *this, call_frame_t *frame, fd_t *fd)
{
- posix_locks_private_t *priv = NULL;
- char pl_locker[256];
- char pl_lockee[256];
- pl_inode_t *pl_inode = NULL;
+ posix_locks_private_t *priv = NULL;
+ char pl_locker[256];
+ char pl_lockee[256];
+ pl_inode_t *pl_inode = NULL;
- priv = this->private;
+ priv = this->private;
- if (!priv->trace)
- return;
+ if (!priv->trace)
+ return;
- pl_inode = pl_inode_get (this, fd->inode);
+ pl_inode = pl_inode_get(this, fd->inode);
- if (pl_inode && __pl_inode_is_empty (pl_inode))
- return;
+ if (pl_inode && __pl_inode_is_empty(pl_inode))
+ return;
- pl_print_locker (pl_locker, 256, this, frame);
- pl_print_lockee (pl_lockee, 256, fd, NULL);
+ pl_print_locker(pl_locker, 256, this, frame);
+ pl_print_lockee(pl_lockee, 256, fd, NULL);
- gf_log (this->name, GF_LOG_INFO,
- "[FLUSH] Locker = {%s} Lockee = {%s}",
- pl_locker, pl_lockee);
+ gf_log(this->name, GF_LOG_INFO, "[FLUSH] Locker = {%s} Lockee = {%s}",
+ pl_locker, pl_lockee);
}
void
-pl_trace_release (xlator_t *this, fd_t *fd)
+pl_trace_release(xlator_t *this, fd_t *fd)
{
- posix_locks_private_t *priv = NULL;
- char pl_lockee[256];
+ posix_locks_private_t *priv = NULL;
+ char pl_lockee[256];
- priv = this->private;
+ priv = this->private;
- if (!priv->trace)
- return;
+ if (!priv->trace)
+ return;
- pl_print_lockee (pl_lockee, 256, fd, NULL);
+ pl_print_lockee(pl_lockee, 256, fd, NULL);
- gf_log (this->name, GF_LOG_INFO,
- "[RELEASE] Lockee = {%s}", pl_lockee);
+ gf_log(this->name, GF_LOG_INFO, "[RELEASE] Lockee = {%s}", pl_lockee);
}
-
void
-pl_update_refkeeper (xlator_t *this, inode_t *inode)
+pl_update_refkeeper(xlator_t *this, inode_t *inode)
{
- pl_inode_t *pl_inode = NULL;
- int is_empty = 0;
- int need_unref = 0;
- int need_ref = 0;
+ pl_inode_t *pl_inode = NULL;
+ int is_empty = 0;
+ int need_unref = 0;
+ int need_ref = 0;
- pl_inode = pl_inode_get (this, inode);
+ pl_inode = pl_inode_get(this, inode);
- pthread_mutex_lock (&pl_inode->mutex);
- {
- is_empty = __pl_inode_is_empty (pl_inode);
+ pthread_mutex_lock(&pl_inode->mutex);
+ {
+ is_empty = __pl_inode_is_empty(pl_inode);
- if (is_empty && pl_inode->refkeeper) {
- need_unref = 1;
- pl_inode->refkeeper = NULL;
- }
+ if (is_empty && pl_inode->refkeeper) {
+ need_unref = 1;
+ pl_inode->refkeeper = NULL;
+ }
- if (!is_empty && !pl_inode->refkeeper) {
- need_ref = 1;
- pl_inode->refkeeper = inode;
- }
+ if (!is_empty && !pl_inode->refkeeper) {
+ need_ref = 1;
+ pl_inode->refkeeper = inode;
}
- pthread_mutex_unlock (&pl_inode->mutex);
+ }
+ pthread_mutex_unlock(&pl_inode->mutex);
- if (need_unref)
- inode_unref (inode);
+ if (need_unref)
+ inode_unref(inode);
- if (need_ref)
- inode_ref (inode);
+ if (need_ref)
+ inode_ref(inode);
}
-
pl_inode_t *
-pl_inode_get (xlator_t *this, inode_t *inode)
+pl_inode_get(xlator_t *this, inode_t *inode)
{
- uint64_t tmp_pl_inode = 0;
- pl_inode_t *pl_inode = NULL;
- int ret = 0;
-
- LOCK (&inode->lock);
- {
- ret = __inode_ctx_get (inode, this, &tmp_pl_inode);
- if (ret == 0) {
- pl_inode = (pl_inode_t *)(long)tmp_pl_inode;
- goto unlock;
- }
- pl_inode = GF_CALLOC (1, sizeof (*pl_inode),
- gf_locks_mt_pl_inode_t);
- if (!pl_inode) {
- goto unlock;
- }
+ uint64_t tmp_pl_inode = 0;
+ pl_inode_t *pl_inode = NULL;
+ int ret = 0;
+
+ LOCK(&inode->lock);
+ {
+ ret = __inode_ctx_get(inode, this, &tmp_pl_inode);
+ if (ret == 0) {
+ pl_inode = (pl_inode_t *)(long)tmp_pl_inode;
+ goto unlock;
+ }
+ pl_inode = GF_CALLOC(1, sizeof(*pl_inode), gf_locks_mt_pl_inode_t);
+ if (!pl_inode) {
+ goto unlock;
+ }
- gf_log (this->name, GF_LOG_TRACE,
- "Allocating new pl inode");
-
- pthread_mutex_init (&pl_inode->mutex, NULL);
-
- INIT_LIST_HEAD (&pl_inode->dom_list);
- INIT_LIST_HEAD (&pl_inode->ext_list);
- INIT_LIST_HEAD (&pl_inode->rw_list);
- INIT_LIST_HEAD (&pl_inode->reservelk_list);
- INIT_LIST_HEAD (&pl_inode->blocked_reservelks);
- INIT_LIST_HEAD (&pl_inode->blocked_calls);
- INIT_LIST_HEAD (&pl_inode->metalk_list);
- INIT_LIST_HEAD (&pl_inode->queued_locks);
- gf_uuid_copy (pl_inode->gfid, inode->gfid);
-
- ret = __inode_ctx_put (inode, this, (uint64_t)(long)(pl_inode));
- if (ret) {
- pthread_mutex_destroy (&pl_inode->mutex);
- GF_FREE (pl_inode);
- pl_inode = NULL;
- goto unlock;
- }
+ gf_log(this->name, GF_LOG_TRACE, "Allocating new pl inode");
+
+ pthread_mutex_init(&pl_inode->mutex, NULL);
+
+ INIT_LIST_HEAD(&pl_inode->dom_list);
+ INIT_LIST_HEAD(&pl_inode->ext_list);
+ INIT_LIST_HEAD(&pl_inode->rw_list);
+ INIT_LIST_HEAD(&pl_inode->reservelk_list);
+ INIT_LIST_HEAD(&pl_inode->blocked_reservelks);
+ INIT_LIST_HEAD(&pl_inode->blocked_calls);
+ INIT_LIST_HEAD(&pl_inode->metalk_list);
+ INIT_LIST_HEAD(&pl_inode->queued_locks);
+ gf_uuid_copy(pl_inode->gfid, inode->gfid);
+
+ ret = __inode_ctx_put(inode, this, (uint64_t)(long)(pl_inode));
+ if (ret) {
+ pthread_mutex_destroy(&pl_inode->mutex);
+ GF_FREE(pl_inode);
+ pl_inode = NULL;
+ goto unlock;
}
+ }
unlock:
- UNLOCK (&inode->lock);
+ UNLOCK(&inode->lock);
- return pl_inode;
+ return pl_inode;
}
-
/* Create a new posix_lock_t */
posix_lock_t *
-new_posix_lock (struct gf_flock *flock, client_t *client, pid_t client_pid,
- gf_lkowner_t *owner, fd_t *fd, uint32_t lk_flags, int blocking)
+new_posix_lock(struct gf_flock *flock, client_t *client, pid_t client_pid,
+ gf_lkowner_t *owner, fd_t *fd, uint32_t lk_flags, int blocking)
{
- posix_lock_t *lock = NULL;
+ posix_lock_t *lock = NULL;
- GF_VALIDATE_OR_GOTO ("posix-locks", flock, out);
- GF_VALIDATE_OR_GOTO ("posix-locks", client, out);
- GF_VALIDATE_OR_GOTO ("posix-locks", fd, out);
+ GF_VALIDATE_OR_GOTO("posix-locks", flock, out);
+ GF_VALIDATE_OR_GOTO("posix-locks", client, out);
+ GF_VALIDATE_OR_GOTO("posix-locks", fd, out);
- lock = GF_CALLOC (1, sizeof (posix_lock_t),
- gf_locks_mt_posix_lock_t);
- if (!lock) {
- goto out;
- }
+ lock = GF_CALLOC(1, sizeof(posix_lock_t), gf_locks_mt_posix_lock_t);
+ if (!lock) {
+ goto out;
+ }
- lock->fl_start = flock->l_start;
- lock->fl_type = flock->l_type;
+ lock->fl_start = flock->l_start;
+ lock->fl_type = flock->l_type;
- if (flock->l_len == 0)
- lock->fl_end = LLONG_MAX;
- else
- lock->fl_end = flock->l_start + flock->l_len - 1;
+ if (flock->l_len == 0)
+ lock->fl_end = LLONG_MAX;
+ else
+ lock->fl_end = flock->l_start + flock->l_len - 1;
- lock->client = client;
+ lock->client = client;
- lock->client_uid = gf_strdup (client->client_uid);
- if (lock->client_uid == NULL) {
- GF_FREE (lock);
- lock = NULL;
- goto out;
- }
+ lock->client_uid = gf_strdup(client->client_uid);
+ if (lock->client_uid == NULL) {
+ GF_FREE(lock);
+ lock = NULL;
+ goto out;
+ }
- lock->fd_num = fd_to_fdnum (fd);
- lock->fd = fd;
- lock->client_pid = client_pid;
- lock->owner = *owner;
- lock->lk_flags = lk_flags;
+ lock->fd_num = fd_to_fdnum(fd);
+ lock->fd = fd;
+ lock->client_pid = client_pid;
+ lock->owner = *owner;
+ lock->lk_flags = lk_flags;
- lock->blocking = blocking;
- memcpy (&lock->user_flock, flock, sizeof (lock->user_flock));
+ lock->blocking = blocking;
+ memcpy(&lock->user_flock, flock, sizeof(lock->user_flock));
- INIT_LIST_HEAD (&lock->list);
+ INIT_LIST_HEAD(&lock->list);
out:
- return lock;
+ return lock;
}
-
/* Delete a lock from the inode's lock list */
void
-__delete_lock (posix_lock_t *lock)
+__delete_lock(posix_lock_t *lock)
{
- list_del_init (&lock->list);
+ list_del_init(&lock->list);
}
-
/* Destroy a posix_lock */
void
-__destroy_lock (posix_lock_t *lock)
+__destroy_lock(posix_lock_t *lock)
{
- GF_FREE (lock->client_uid);
- GF_FREE (lock);
+ GF_FREE(lock->client_uid);
+ GF_FREE(lock);
}
static posix_lock_t *
__copy_lock(posix_lock_t *src)
{
- posix_lock_t *dst;
-
- dst = GF_MALLOC(sizeof(posix_lock_t), gf_locks_mt_posix_lock_t);
- if (dst != NULL) {
- memcpy (dst, src, sizeof(posix_lock_t));
- dst->client_uid = gf_strdup(src->client_uid);
- if (dst->client_uid == NULL) {
- GF_FREE(dst);
- dst = NULL;
- }
-
- if (dst != NULL)
- INIT_LIST_HEAD (&dst->list);
+ posix_lock_t *dst;
+
+ dst = GF_MALLOC(sizeof(posix_lock_t), gf_locks_mt_posix_lock_t);
+ if (dst != NULL) {
+ memcpy(dst, src, sizeof(posix_lock_t));
+ dst->client_uid = gf_strdup(src->client_uid);
+ if (dst->client_uid == NULL) {
+ GF_FREE(dst);
+ dst = NULL;
}
- return dst;
+ if (dst != NULL)
+ INIT_LIST_HEAD(&dst->list);
+ }
+
+ return dst;
}
/* Convert a posix_lock to a struct gf_flock */
void
-posix_lock_to_flock (posix_lock_t *lock, struct gf_flock *flock)
+posix_lock_to_flock(posix_lock_t *lock, struct gf_flock *flock)
{
- flock->l_pid = lock->user_flock.l_pid;
- flock->l_type = lock->fl_type;
- flock->l_start = lock->fl_start;
- flock->l_owner = lock->owner;
-
- if (lock->fl_end == LLONG_MAX)
- flock->l_len = 0;
- else
- flock->l_len = lock->fl_end - lock->fl_start + 1;
+ flock->l_pid = lock->user_flock.l_pid;
+ flock->l_type = lock->fl_type;
+ flock->l_start = lock->fl_start;
+ flock->l_owner = lock->owner;
+
+ if (lock->fl_end == LLONG_MAX)
+ flock->l_len = 0;
+ else
+ flock->l_len = lock->fl_end - lock->fl_start + 1;
}
/* Insert the lock into the inode's lock list */
static void
-__insert_lock (pl_inode_t *pl_inode, posix_lock_t *lock)
+__insert_lock(pl_inode_t *pl_inode, posix_lock_t *lock)
{
- if (lock->blocked)
- gettimeofday (&lock->blkd_time, NULL);
- else
- gettimeofday (&lock->granted_time, NULL);
+ if (lock->blocked)
+ gettimeofday(&lock->blkd_time, NULL);
+ else
+ gettimeofday(&lock->granted_time, NULL);
- list_add_tail (&lock->list, &pl_inode->ext_list);
+ list_add_tail(&lock->list, &pl_inode->ext_list);
- return;
+ return;
}
-
/* Return true if the locks overlap, false otherwise */
int
-locks_overlap (posix_lock_t *l1, posix_lock_t *l2)
+locks_overlap(posix_lock_t *l1, posix_lock_t *l2)
{
- /*
- Note:
- FUSE always gives us absolute offsets, so no need to worry
- about SEEK_CUR or SEEK_END
- */
+ /*
+ Note:
+ FUSE always gives us absolute offsets, so no need to worry
+ about SEEK_CUR or SEEK_END
+ */
- return ((l1->fl_end >= l2->fl_start) &&
- (l2->fl_end >= l1->fl_start));
+ return ((l1->fl_end >= l2->fl_start) && (l2->fl_end >= l1->fl_start));
}
-
/* Return true if the locks have the same owner */
int
-same_owner (posix_lock_t *l1, posix_lock_t *l2)
+same_owner(posix_lock_t *l1, posix_lock_t *l2)
{
-
- return (is_same_lkowner (&l1->owner, &l2->owner) &&
- (l1->client == l2->client));
-
+ return (is_same_lkowner(&l1->owner, &l2->owner) &&
+ (l1->client == l2->client));
}
-
/* Delete all F_UNLCK locks */
void
-__delete_unlck_locks (pl_inode_t *pl_inode)
+__delete_unlck_locks(pl_inode_t *pl_inode)
{
- posix_lock_t *l = NULL;
- posix_lock_t *tmp = NULL;
-
- list_for_each_entry_safe (l, tmp, &pl_inode->ext_list, list) {
- if (l->fl_type == F_UNLCK) {
- __delete_lock (l);
- __destroy_lock (l);
- }
+ posix_lock_t *l = NULL;
+ posix_lock_t *tmp = NULL;
+
+ list_for_each_entry_safe(l, tmp, &pl_inode->ext_list, list)
+ {
+ if (l->fl_type == F_UNLCK) {
+ __delete_lock(l);
+ __destroy_lock(l);
}
+ }
}
-
/* Add two locks */
static posix_lock_t *
-add_locks (posix_lock_t *l1, posix_lock_t *l2, posix_lock_t *dst)
+add_locks(posix_lock_t *l1, posix_lock_t *l2, posix_lock_t *dst)
{
- posix_lock_t *sum = NULL;
+ posix_lock_t *sum = NULL;
- sum = __copy_lock (dst);
- if (!sum)
- return NULL;
+ sum = __copy_lock(dst);
+ if (!sum)
+ return NULL;
- sum->fl_start = min (l1->fl_start, l2->fl_start);
- sum->fl_end = max (l1->fl_end, l2->fl_end);
+ sum->fl_start = min(l1->fl_start, l2->fl_start);
+ sum->fl_end = max(l1->fl_end, l2->fl_end);
- posix_lock_to_flock (sum, &sum->user_flock);
+ posix_lock_to_flock(sum, &sum->user_flock);
- return sum;
+ return sum;
}
/* Subtract two locks */
struct _values {
- posix_lock_t *locks[3];
+ posix_lock_t *locks[3];
};
/* {big} must always be contained inside {small} */
static struct _values
-subtract_locks (posix_lock_t *big, posix_lock_t *small)
+subtract_locks(posix_lock_t *big, posix_lock_t *small)
{
+ struct _values v = {.locks = {0, 0, 0}};
- struct _values v = { .locks = {0, 0, 0} };
-
- if ((big->fl_start == small->fl_start) &&
- (big->fl_end == small->fl_end)) {
- /* both edges coincide with big */
- v.locks[0] = __copy_lock(big);
- if (!v.locks[0]) {
- goto out;
- }
-
- v.locks[0]->fl_type = small->fl_type;
- v.locks[0]->user_flock.l_type = small->fl_type;
- goto done;
+ if ((big->fl_start == small->fl_start) && (big->fl_end == small->fl_end)) {
+ /* both edges coincide with big */
+ v.locks[0] = __copy_lock(big);
+ if (!v.locks[0]) {
+ goto out;
}
- if ((small->fl_start > big->fl_start) &&
- (small->fl_end < big->fl_end)) {
- /* both edges lie inside big */
- v.locks[0] = __copy_lock(big);
- v.locks[1] = __copy_lock(small);
- v.locks[2] = __copy_lock(big);
- if ((v.locks[0] == NULL) || (v.locks[1] == NULL) ||
- (v.locks[2] == NULL)) {
- goto out;
- }
-
- v.locks[0]->fl_end = small->fl_start - 1;
- v.locks[2]->fl_start = small->fl_end + 1;
- posix_lock_to_flock (v.locks[0], &v.locks[0]->user_flock);
- posix_lock_to_flock (v.locks[2], &v.locks[2]->user_flock);
- goto done;
-
+ v.locks[0]->fl_type = small->fl_type;
+ v.locks[0]->user_flock.l_type = small->fl_type;
+ goto done;
+ }
+
+ if ((small->fl_start > big->fl_start) && (small->fl_end < big->fl_end)) {
+ /* both edges lie inside big */
+ v.locks[0] = __copy_lock(big);
+ v.locks[1] = __copy_lock(small);
+ v.locks[2] = __copy_lock(big);
+ if ((v.locks[0] == NULL) || (v.locks[1] == NULL) ||
+ (v.locks[2] == NULL)) {
+ goto out;
}
- /* one edge coincides with big */
- if (small->fl_start == big->fl_start) {
- v.locks[0] = __copy_lock(big);
- v.locks[1] = __copy_lock(small);
- if ((v.locks[0] == NULL) || (v.locks[1] == NULL)) {
- goto out;
- }
-
- v.locks[0]->fl_start = small->fl_end + 1;
- posix_lock_to_flock (v.locks[0], &v.locks[0]->user_flock);
- goto done;
+ v.locks[0]->fl_end = small->fl_start - 1;
+ v.locks[2]->fl_start = small->fl_end + 1;
+ posix_lock_to_flock(v.locks[0], &v.locks[0]->user_flock);
+ posix_lock_to_flock(v.locks[2], &v.locks[2]->user_flock);
+ goto done;
+ }
+
+ /* one edge coincides with big */
+ if (small->fl_start == big->fl_start) {
+ v.locks[0] = __copy_lock(big);
+ v.locks[1] = __copy_lock(small);
+ if ((v.locks[0] == NULL) || (v.locks[1] == NULL)) {
+ goto out;
}
- if (small->fl_end == big->fl_end) {
- v.locks[0] = __copy_lock(big);
- v.locks[1] = __copy_lock(small);
- if ((v.locks[0] == NULL) || (v.locks[1] == NULL)) {
- goto out;
- }
+ v.locks[0]->fl_start = small->fl_end + 1;
+ posix_lock_to_flock(v.locks[0], &v.locks[0]->user_flock);
+ goto done;
+ }
- v.locks[0]->fl_end = small->fl_start - 1;
- posix_lock_to_flock (v.locks[0], &v.locks[0]->user_flock);
- goto done;
+ if (small->fl_end == big->fl_end) {
+ v.locks[0] = __copy_lock(big);
+ v.locks[1] = __copy_lock(small);
+ if ((v.locks[0] == NULL) || (v.locks[1] == NULL)) {
+ goto out;
}
- GF_ASSERT (0);
- gf_log ("posix-locks", GF_LOG_ERROR, "Unexpected case in subtract_locks");
+ v.locks[0]->fl_end = small->fl_start - 1;
+ posix_lock_to_flock(v.locks[0], &v.locks[0]->user_flock);
+ goto done;
+ }
+
+ GF_ASSERT(0);
+ gf_log("posix-locks", GF_LOG_ERROR, "Unexpected case in subtract_locks");
out:
- if (v.locks[0]) {
- __destroy_lock(v.locks[0]);
- v.locks[0] = NULL;
- }
- if (v.locks[1]) {
- __destroy_lock(v.locks[1]);
- v.locks[1] = NULL;
- }
- if (v.locks[2]) {
- __destroy_lock(v.locks[2]);
- v.locks[2] = NULL;
- }
+ if (v.locks[0]) {
+ __destroy_lock(v.locks[0]);
+ v.locks[0] = NULL;
+ }
+ if (v.locks[1]) {
+ __destroy_lock(v.locks[1]);
+ v.locks[1] = NULL;
+ }
+ if (v.locks[2]) {
+ __destroy_lock(v.locks[2]);
+ v.locks[2] = NULL;
+ }
done:
- return v;
+ return v;
}
static posix_lock_t *
-first_conflicting_overlap (pl_inode_t *pl_inode, posix_lock_t *lock)
+first_conflicting_overlap(pl_inode_t *pl_inode, posix_lock_t *lock)
{
- posix_lock_t *l = NULL;
- posix_lock_t *conf = NULL;
+ posix_lock_t *l = NULL;
+ posix_lock_t *conf = NULL;
- pthread_mutex_lock (&pl_inode->mutex);
+ pthread_mutex_lock(&pl_inode->mutex);
+ {
+ list_for_each_entry(l, &pl_inode->ext_list, list)
{
- list_for_each_entry (l, &pl_inode->ext_list, list) {
- if (l->blocked)
- continue;
-
- if (locks_overlap (l, lock)) {
- if (same_owner (l, lock))
- continue;
-
- if ((l->fl_type == F_WRLCK) ||
- (lock->fl_type == F_WRLCK)) {
- conf = l;
- goto unlock;
- }
- }
+ if (l->blocked)
+ continue;
+
+ if (locks_overlap(l, lock)) {
+ if (same_owner(l, lock))
+ continue;
+
+ if ((l->fl_type == F_WRLCK) || (lock->fl_type == F_WRLCK)) {
+ conf = l;
+ goto unlock;
}
+ }
}
+ }
unlock:
- pthread_mutex_unlock (&pl_inode->mutex);
+ pthread_mutex_unlock(&pl_inode->mutex);
- return conf;
+ return conf;
}
/*
@@ -753,364 +724,354 @@ unlock:
If {begin} is NULL, then start from the beginning of the list
*/
static posix_lock_t *
-first_overlap (pl_inode_t *pl_inode, posix_lock_t *lock)
+first_overlap(pl_inode_t *pl_inode, posix_lock_t *lock)
{
- posix_lock_t *l = NULL;
+ posix_lock_t *l = NULL;
- list_for_each_entry (l, &pl_inode->ext_list, list) {
- if (l->blocked)
- continue;
+ list_for_each_entry(l, &pl_inode->ext_list, list)
+ {
+ if (l->blocked)
+ continue;
- if (locks_overlap (l, lock))
- return l;
- }
+ if (locks_overlap(l, lock))
+ return l;
+ }
- return NULL;
+ return NULL;
}
-
-
/* Return true if lock is grantable */
static int
-__is_lock_grantable (pl_inode_t *pl_inode, posix_lock_t *lock)
+__is_lock_grantable(pl_inode_t *pl_inode, posix_lock_t *lock)
{
- posix_lock_t *l = NULL;
- int ret = 1;
-
- list_for_each_entry (l, &pl_inode->ext_list, list) {
- if (!l->blocked && locks_overlap (lock, l)) {
- if (((l->fl_type == F_WRLCK)
- || (lock->fl_type == F_WRLCK))
- && (lock->fl_type != F_UNLCK)
- && !same_owner (l, lock)) {
- ret = 0;
- break;
- }
- }
+ posix_lock_t *l = NULL;
+ int ret = 1;
+
+ list_for_each_entry(l, &pl_inode->ext_list, list)
+ {
+ if (!l->blocked && locks_overlap(lock, l)) {
+ if (((l->fl_type == F_WRLCK) || (lock->fl_type == F_WRLCK)) &&
+ (lock->fl_type != F_UNLCK) && !same_owner(l, lock)) {
+ ret = 0;
+ break;
+ }
}
- return ret;
+ }
+ return ret;
}
-
-extern void do_blocked_rw (pl_inode_t *);
-
+extern void
+do_blocked_rw(pl_inode_t *);
static void
-__insert_and_merge (pl_inode_t *pl_inode, posix_lock_t *lock)
+__insert_and_merge(pl_inode_t *pl_inode, posix_lock_t *lock)
{
- posix_lock_t *conf = NULL;
- posix_lock_t *t = NULL;
- posix_lock_t *sum = NULL;
- int i = 0;
- struct _values v = { .locks = {0, 0, 0} };
-
- list_for_each_entry_safe (conf, t, &pl_inode->ext_list, list) {
- if (conf->blocked)
- continue;
- if (!locks_overlap (conf, lock))
- continue;
+ posix_lock_t *conf = NULL;
+ posix_lock_t *t = NULL;
+ posix_lock_t *sum = NULL;
+ int i = 0;
+ struct _values v = {.locks = {0, 0, 0}};
+
+ list_for_each_entry_safe(conf, t, &pl_inode->ext_list, list)
+ {
+ if (conf->blocked)
+ continue;
+ if (!locks_overlap(conf, lock))
+ continue;
+
+ if (same_owner(conf, lock)) {
+ if (conf->fl_type == lock->fl_type &&
+ conf->lk_flags == lock->lk_flags) {
+ sum = add_locks(lock, conf, lock);
+
+ __delete_lock(conf);
+ __destroy_lock(conf);
- if (same_owner (conf, lock)) {
- if (conf->fl_type == lock->fl_type &&
- conf->lk_flags == lock->lk_flags) {
- sum = add_locks (lock, conf, lock);
-
- __delete_lock (conf);
- __destroy_lock (conf);
-
- __destroy_lock (lock);
- INIT_LIST_HEAD (&sum->list);
- posix_lock_to_flock (sum, &sum->user_flock);
- __insert_and_merge (pl_inode, sum);
-
- return;
- } else {
- sum = add_locks (lock, conf, conf);
+ __destroy_lock(lock);
+ INIT_LIST_HEAD(&sum->list);
+ posix_lock_to_flock(sum, &sum->user_flock);
+ __insert_and_merge(pl_inode, sum);
- v = subtract_locks (sum, lock);
+ return;
+ } else {
+ sum = add_locks(lock, conf, conf);
- __delete_lock (conf);
- __destroy_lock (conf);
+ v = subtract_locks(sum, lock);
- __delete_lock (lock);
- __destroy_lock (lock);
+ __delete_lock(conf);
+ __destroy_lock(conf);
- __destroy_lock (sum);
+ __delete_lock(lock);
+ __destroy_lock(lock);
- for (i = 0; i < 3; i++) {
- if (!v.locks[i])
- continue;
+ __destroy_lock(sum);
- __insert_and_merge (pl_inode,
- v.locks[i]);
- }
+ for (i = 0; i < 3; i++) {
+ if (!v.locks[i])
+ continue;
- __delete_unlck_locks (pl_inode);
- return;
- }
+ __insert_and_merge(pl_inode, v.locks[i]);
}
- if (lock->fl_type == F_UNLCK) {
- continue;
- }
+ __delete_unlck_locks(pl_inode);
+ return;
+ }
+ }
- if ((conf->fl_type == F_RDLCK) && (lock->fl_type == F_RDLCK)) {
- __insert_lock (pl_inode, lock);
- return;
- }
+ if (lock->fl_type == F_UNLCK) {
+ continue;
}
- /* no conflicts, so just insert */
- if (lock->fl_type != F_UNLCK) {
- __insert_lock (pl_inode, lock);
- } else {
- __destroy_lock (lock);
+ if ((conf->fl_type == F_RDLCK) && (lock->fl_type == F_RDLCK)) {
+ __insert_lock(pl_inode, lock);
+ return;
}
+ }
+
+ /* no conflicts, so just insert */
+ if (lock->fl_type != F_UNLCK) {
+ __insert_lock(pl_inode, lock);
+ } else {
+ __destroy_lock(lock);
+ }
}
-
void
-__grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode, struct list_head *granted)
+__grant_blocked_locks(xlator_t *this, pl_inode_t *pl_inode,
+ struct list_head *granted)
{
- struct list_head tmp_list;
- posix_lock_t *l = NULL;
- posix_lock_t *tmp = NULL;
- posix_lock_t *conf = NULL;
-
- INIT_LIST_HEAD (&tmp_list);
-
- list_for_each_entry_safe (l, tmp, &pl_inode->ext_list, list) {
- if (l->blocked) {
- conf = first_overlap (pl_inode, l);
- if (conf)
- continue;
-
- l->blocked = 0;
- list_move_tail (&l->list, &tmp_list);
- }
+ struct list_head tmp_list;
+ posix_lock_t *l = NULL;
+ posix_lock_t *tmp = NULL;
+ posix_lock_t *conf = NULL;
+
+ INIT_LIST_HEAD(&tmp_list);
+
+ list_for_each_entry_safe(l, tmp, &pl_inode->ext_list, list)
+ {
+ if (l->blocked) {
+ conf = first_overlap(pl_inode, l);
+ if (conf)
+ continue;
+
+ l->blocked = 0;
+ list_move_tail(&l->list, &tmp_list);
}
+ }
- list_for_each_entry_safe (l, tmp, &tmp_list, list) {
- list_del_init (&l->list);
+ list_for_each_entry_safe(l, tmp, &tmp_list, list)
+ {
+ list_del_init(&l->list);
- if (__is_lock_grantable (pl_inode, l)) {
- conf = GF_CALLOC (1, sizeof (*conf),
- gf_locks_mt_posix_lock_t);
+ if (__is_lock_grantable(pl_inode, l)) {
+ conf = GF_CALLOC(1, sizeof(*conf), gf_locks_mt_posix_lock_t);
- if (!conf) {
- l->blocked = 1;
- __insert_lock (pl_inode, l);
- continue;
- }
+ if (!conf) {
+ l->blocked = 1;
+ __insert_lock(pl_inode, l);
+ continue;
+ }
- conf->frame = l->frame;
- l->frame = NULL;
+ conf->frame = l->frame;
+ l->frame = NULL;
- posix_lock_to_flock (l, &conf->user_flock);
+ posix_lock_to_flock(l, &conf->user_flock);
- gf_log (this->name, GF_LOG_TRACE,
- "%s (pid=%d) lk-owner:%s %"PRId64" - %"PRId64" => Granted",
- l->fl_type == F_UNLCK ? "Unlock" : "Lock",
- l->client_pid, lkowner_utoa (&l->owner),
- l->user_flock.l_start,
- l->user_flock.l_len);
+ gf_log(this->name, GF_LOG_TRACE,
+ "%s (pid=%d) lk-owner:%s %" PRId64 " - %" PRId64
+ " => Granted",
+ l->fl_type == F_UNLCK ? "Unlock" : "Lock", l->client_pid,
+ lkowner_utoa(&l->owner), l->user_flock.l_start,
+ l->user_flock.l_len);
- __insert_and_merge (pl_inode, l);
+ __insert_and_merge(pl_inode, l);
- list_add (&conf->list, granted);
- } else {
- l->blocked = 1;
- __insert_lock (pl_inode, l);
- }
+ list_add(&conf->list, granted);
+ } else {
+ l->blocked = 1;
+ __insert_lock(pl_inode, l);
}
+ }
}
-
void
-grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode)
+grant_blocked_locks(xlator_t *this, pl_inode_t *pl_inode)
{
- struct list_head granted_list;
- posix_lock_t *tmp = NULL;
- posix_lock_t *lock = NULL;
+ struct list_head granted_list;
+ posix_lock_t *tmp = NULL;