summaryrefslogtreecommitdiffstats
path: root/xlators/storage
diff options
context:
space:
mode:
authorGluster Ant <bugzilla-bot@gluster.org>2018-09-12 17:52:45 +0530
committerNigel Babu <nigelb@redhat.com>2018-09-12 17:52:45 +0530
commite16868dede6455cab644805af6fe1ac312775e13 (patch)
tree15aebdb4fff2d87cf8a72f836816b3aa634da58d /xlators/storage
parent45a71c0548b6fd2c757aa2e7b7671a1411948894 (diff)
Land part 2 of clang-format changes
Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4 Signed-off-by: Nigel Babu <nigelb@redhat.com>
Diffstat (limited to 'xlators/storage')
-rw-r--r--xlators/storage/bd/src/bd-aio.c835
-rw-r--r--xlators/storage/bd/src/bd-helper.c1685
-rw-r--r--xlators/storage/bd/src/bd.c3593
-rw-r--r--xlators/storage/posix/src/posix-aio.c970
-rw-r--r--xlators/storage/posix/src/posix-common.c2208
-rw-r--r--xlators/storage/posix/src/posix-entry-ops.c3943
-rw-r--r--xlators/storage/posix/src/posix-gfid-path.c501
-rw-r--r--xlators/storage/posix/src/posix-handle.c1607
-rw-r--r--xlators/storage/posix/src/posix-helpers.c5180
-rw-r--r--xlators/storage/posix/src/posix-inode-fd-ops.c8575
-rw-r--r--xlators/storage/posix/src/posix-metadata.c1063
-rw-r--r--xlators/storage/posix/src/posix.c118
12 files changed, 15018 insertions, 15260 deletions
diff --git a/xlators/storage/bd/src/bd-aio.c b/xlators/storage/bd/src/bd-aio.c
index 6f5c90f..6bc7d4a 100644
--- a/xlators/storage/bd/src/bd-aio.c
+++ b/xlators/storage/bd/src/bd-aio.c
@@ -27,495 +27,492 @@
#include "bd-mem-types.h"
struct bd_aio_cb {
- struct iocb iocb;
- call_frame_t *frame;
- struct iobuf *iobuf;
- struct iobref *iobref;
- struct iatt prebuf;
- int op;
- off_t offset;
- fd_t *fd;
+ struct iocb iocb;
+ call_frame_t *frame;
+ struct iobuf *iobuf;
+ struct iobref *iobref;
+ struct iatt prebuf;
+ int op;
+ off_t offset;
+ fd_t *fd;
};
void
-__bd_fd_set_odirect (fd_t *fd, bd_fd_t *bd_fd, int opflags,
- off_t offset, size_t size)
+__bd_fd_set_odirect(fd_t *fd, bd_fd_t *bd_fd, int opflags, off_t offset,
+ size_t size)
{
- int odirect = 0;
- int flags = 0;
- int ret = 0;
-
- odirect = bd_fd->odirect;
-
- if ((fd->flags|opflags) & O_DIRECT) {
- /* if instructed, use O_DIRECT always */
- odirect = 1;
- } else {
- /* else use O_DIRECT when feasible */
- if ((offset|size) & 0xfff)
- odirect = 0;
- else
- odirect = 1;
- }
-
- if (!odirect && bd_fd->odirect) {
- flags = fcntl (bd_fd->fd, F_GETFL);
- ret = fcntl (bd_fd->fd, F_SETFL, (flags & (~O_DIRECT)));
- bd_fd->odirect = 0;
- }
-
- if (odirect && !bd_fd->odirect) {
- flags = fcntl (bd_fd->fd, F_GETFL);
- ret = fcntl (bd_fd->fd, F_SETFL, (flags | O_DIRECT));
- bd_fd->odirect = 1;
- }
-
- if (ret) {
- gf_log (THIS->name, GF_LOG_WARNING,
- "fcntl() failed (%s). fd=%d flags=%d pfd->odirect=%d",
- strerror (errno), bd_fd->fd, flags, bd_fd->odirect);
- }
+ int odirect = 0;
+ int flags = 0;
+ int ret = 0;
+
+ odirect = bd_fd->odirect;
+
+ if ((fd->flags | opflags) & O_DIRECT) {
+ /* if instructed, use O_DIRECT always */
+ odirect = 1;
+ } else {
+ /* else use O_DIRECT when feasible */
+ if ((offset | size) & 0xfff)
+ odirect = 0;
+ else
+ odirect = 1;
+ }
+
+ if (!odirect && bd_fd->odirect) {
+ flags = fcntl(bd_fd->fd, F_GETFL);
+ ret = fcntl(bd_fd->fd, F_SETFL, (flags & (~O_DIRECT)));
+ bd_fd->odirect = 0;
+ }
+
+ if (odirect && !bd_fd->odirect) {
+ flags = fcntl(bd_fd->fd, F_GETFL);
+ ret = fcntl(bd_fd->fd, F_SETFL, (flags | O_DIRECT));
+ bd_fd->odirect = 1;
+ }
+
+ if (ret) {
+ gf_log(THIS->name, GF_LOG_WARNING,
+ "fcntl() failed (%s). fd=%d flags=%d pfd->odirect=%d",
+ strerror(errno), bd_fd->fd, flags, bd_fd->odirect);
+ }
}
int
-bd_aio_readv_complete (struct bd_aio_cb *paiocb, int res, int res2)
+bd_aio_readv_complete(struct bd_aio_cb *paiocb, int res, int res2)
{
- call_frame_t *frame = NULL;
- xlator_t *this = NULL;
- struct iobuf *iobuf = NULL;
- struct iatt postbuf = {0,};
- int op_ret = -1;
- int op_errno = 0;
- struct iovec iov;
- struct iobref *iobref = NULL;
- off_t offset = 0;
- bd_attr_t *bdatt = NULL;
-
- frame = paiocb->frame;
- this = frame->this;
- iobuf = paiocb->iobuf;
- offset = paiocb->offset;
-
- if (res < 0) {
- op_ret = -1;
- op_errno = -res;
- gf_log (this->name, GF_LOG_ERROR,
- "readv(async) failed fd=%p,size=%lu,offset=%llu (%d/%s)",
- paiocb->fd, paiocb->iocb.u.c.nbytes,
- (unsigned long long) paiocb->offset,
- res, strerror (op_errno));
- goto out;
- }
-
- bd_inode_ctx_get (paiocb->fd->inode, this, &bdatt);
- memcpy (&postbuf, &bdatt->iatt, sizeof (struct iatt));
-
- op_ret = res;
- op_errno = 0;
-
- iobref = iobref_new ();
- if (!iobref) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto out;
- }
-
- iobref_add (iobref, iobuf);
-
- iov.iov_base = iobuf_ptr (iobuf);
- iov.iov_len = op_ret;
-
- /* Hack to notify higher layers of EOF. */
- if (!postbuf.ia_size || (offset + iov.iov_len) >= postbuf.ia_size)
- op_errno = ENOENT;
+ call_frame_t *frame = NULL;
+ xlator_t *this = NULL;
+ struct iobuf *iobuf = NULL;
+ struct iatt postbuf = {
+ 0,
+ };
+ int op_ret = -1;
+ int op_errno = 0;
+ struct iovec iov;
+ struct iobref *iobref = NULL;
+ off_t offset = 0;
+ bd_attr_t *bdatt = NULL;
+
+ frame = paiocb->frame;
+ this = frame->this;
+ iobuf = paiocb->iobuf;
+ offset = paiocb->offset;
+
+ if (res < 0) {
+ op_ret = -1;
+ op_errno = -res;
+ gf_log(this->name, GF_LOG_ERROR,
+ "readv(async) failed fd=%p,size=%lu,offset=%llu (%d/%s)",
+ paiocb->fd, paiocb->iocb.u.c.nbytes,
+ (unsigned long long)paiocb->offset, res, strerror(op_errno));
+ goto out;
+ }
+
+ bd_inode_ctx_get(paiocb->fd->inode, this, &bdatt);
+ memcpy(&postbuf, &bdatt->iatt, sizeof(struct iatt));
+
+ op_ret = res;
+ op_errno = 0;
+
+ iobref = iobref_new();
+ if (!iobref) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto out;
+ }
+
+ iobref_add(iobref, iobuf);
+
+ iov.iov_base = iobuf_ptr(iobuf);
+ iov.iov_len = op_ret;
+
+ /* Hack to notify higher layers of EOF. */
+ if (!postbuf.ia_size || (offset + iov.iov_len) >= postbuf.ia_size)
+ op_errno = ENOENT;
out:
- STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, &iov, 1,
- &postbuf, iobref, NULL);
- if (iobuf)
- iobuf_unref (iobuf);
- if (iobref)
- iobref_unref (iobref);
+ STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, &iov, 1, &postbuf,
+ iobref, NULL);
+ if (iobuf)
+ iobuf_unref(iobuf);
+ if (iobref)
+ iobref_unref(iobref);
- GF_FREE (paiocb);
+ GF_FREE(paiocb);
- return 0;
+ return 0;
}
int
-bd_aio_readv (call_frame_t *frame, xlator_t *this, fd_t *fd,
- size_t size, off_t offset, uint32_t flags, dict_t *xdata)
+bd_aio_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_errno = EINVAL;
- int _fd = -1;
- struct iobuf *iobuf = NULL;
- bd_fd_t *bd_fd = NULL;
- int ret = -1;
- struct bd_aio_cb *paiocb = NULL;
- bd_priv_t *priv = NULL;
- struct iocb *iocb = NULL;
- bd_attr_t *bdatt = NULL;
-
- VALIDATE_OR_GOTO (frame, err);
- VALIDATE_OR_GOTO (this, err);
- VALIDATE_OR_GOTO (fd, err);
-
- priv = this->private;
-
- ret = bd_fd_ctx_get (this, fd, &bd_fd);
- if (ret < 0 || !bd_fd) {
- STACK_WIND (frame, default_readv_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->readv, fd, size, offset,
- flags, xdata);
- return 0;
- }
- _fd = bd_fd->fd;
- bd_inode_ctx_get (fd->inode, this, &bdatt);
- if (!size) {
- op_errno = EINVAL;
- gf_log (this->name, GF_LOG_WARNING, "size=%"GF_PRI_SIZET, size);
- goto err;
- }
-
- iobuf = iobuf_get2 (this->ctx->iobuf_pool, size);
- if (!iobuf) {
- op_errno = ENOMEM;
- goto err;
- }
-
- paiocb = GF_CALLOC (1, sizeof (*paiocb), gf_bd_aio_cb);
- if (!paiocb) {
- op_errno = ENOMEM;
- goto err;
- }
-
- paiocb->frame = frame;
- paiocb->iobuf = iobuf;
- paiocb->offset = offset;
- paiocb->op = GF_FOP_READ;
- paiocb->fd = fd;
-
- paiocb->iocb.data = paiocb;
- paiocb->iocb.aio_fildes = _fd;
- paiocb->iocb.aio_lio_opcode = IO_CMD_PREAD;
- paiocb->iocb.aio_reqprio = 0;
- paiocb->iocb.u.c.buf = iobuf_ptr (iobuf);
- paiocb->iocb.u.c.nbytes = size;
- paiocb->iocb.u.c.offset = offset;
-
- iocb = &paiocb->iocb;
-
- LOCK (&fd->lock);
- {
- __bd_fd_set_odirect (fd, bd_fd, flags, offset, size);
-
- ret = io_submit (priv->ctxp, 1, &iocb);
- }
- UNLOCK (&fd->lock);
-
- if (ret != 1) {
- gf_log (this->name, GF_LOG_ERROR,
- "io_submit() returned %d", ret);
- op_errno = -ret;
- goto err;
- }
-
+ int32_t op_errno = EINVAL;
+ int _fd = -1;
+ struct iobuf *iobuf = NULL;
+ bd_fd_t *bd_fd = NULL;
+ int ret = -1;
+ struct bd_aio_cb *paiocb = NULL;
+ bd_priv_t *priv = NULL;
+ struct iocb *iocb = NULL;
+ bd_attr_t *bdatt = NULL;
+
+ VALIDATE_OR_GOTO(frame, err);
+ VALIDATE_OR_GOTO(this, err);
+ VALIDATE_OR_GOTO(fd, err);
+
+ priv = this->private;
+
+ ret = bd_fd_ctx_get(this, fd, &bd_fd);
+ if (ret < 0 || !bd_fd) {
+ STACK_WIND(frame, default_readv_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readv, fd, size, offset, flags,
+ xdata);
return 0;
+ }
+ _fd = bd_fd->fd;
+ bd_inode_ctx_get(fd->inode, this, &bdatt);
+ if (!size) {
+ op_errno = EINVAL;
+ gf_log(this->name, GF_LOG_WARNING, "size=%" GF_PRI_SIZET, size);
+ goto err;
+ }
+
+ iobuf = iobuf_get2(this->ctx->iobuf_pool, size);
+ if (!iobuf) {
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ paiocb = GF_CALLOC(1, sizeof(*paiocb), gf_bd_aio_cb);
+ if (!paiocb) {
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ paiocb->frame = frame;
+ paiocb->iobuf = iobuf;
+ paiocb->offset = offset;
+ paiocb->op = GF_FOP_READ;
+ paiocb->fd = fd;
+
+ paiocb->iocb.data = paiocb;
+ paiocb->iocb.aio_fildes = _fd;
+ paiocb->iocb.aio_lio_opcode = IO_CMD_PREAD;
+ paiocb->iocb.aio_reqprio = 0;
+ paiocb->iocb.u.c.buf = iobuf_ptr(iobuf);
+ paiocb->iocb.u.c.nbytes = size;
+ paiocb->iocb.u.c.offset = offset;
+
+ iocb = &paiocb->iocb;
+
+ LOCK(&fd->lock);
+ {
+ __bd_fd_set_odirect(fd, bd_fd, flags, offset, size);
+
+ ret = io_submit(priv->ctxp, 1, &iocb);
+ }
+ UNLOCK(&fd->lock);
+
+ if (ret != 1) {
+ gf_log(this->name, GF_LOG_ERROR, "io_submit() returned %d", ret);
+ op_errno = -ret;
+ goto err;
+ }
+
+ return 0;
err:
- STACK_UNWIND_STRICT (readv, frame, -1, op_errno, 0, 0, 0, 0, 0);
- if (iobuf)
- iobuf_unref (iobuf);
+ STACK_UNWIND_STRICT(readv, frame, -1, op_errno, 0, 0, 0, 0, 0);
+ if (iobuf)
+ iobuf_unref(iobuf);
- if (paiocb)
- GF_FREE (paiocb);
+ if (paiocb)
+ GF_FREE(paiocb);
- return 0;
+ return 0;
}
int
-bd_aio_writev_complete (struct bd_aio_cb *paiocb, int res, int res2)
+bd_aio_writev_complete(struct bd_aio_cb *paiocb, int res, int res2)
{
- call_frame_t *frame = NULL;
- xlator_t *this = NULL;
- struct iatt prebuf = {0,};
- struct iatt postbuf = {0,};
- int op_ret = -1;
- int op_errno = 0;
- bd_attr_t *bdatt = NULL;
-
- frame = paiocb->frame;
- prebuf = paiocb->prebuf;
- this = frame->this;
-
- if (res < 0) {
- op_ret = -1;
- op_errno = -res;
- gf_log (this->name, GF_LOG_ERROR,
- "writev(async) failed fd=%p,offset=%llu (%d/%s)",
- paiocb->fd, (unsigned long long) paiocb->offset, res,
- strerror (op_errno));
-
- goto out;
- }
-
- bd_inode_ctx_get (paiocb->fd->inode, this, &bdatt);
- bd_update_amtime (&bdatt->iatt, GF_SET_ATTR_MTIME);
- memcpy (&postbuf, &bdatt->iatt, sizeof (struct iatt));
-
- op_ret = res;
- op_errno = 0;
+ call_frame_t *frame = NULL;
+ xlator_t *this = NULL;
+ struct iatt prebuf = {
+ 0,
+ };
+ struct iatt postbuf = {
+ 0,
+ };
+ int op_ret = -1;
+ int op_errno = 0;
+ bd_attr_t *bdatt = NULL;
+
+ frame = paiocb->frame;
+ prebuf = paiocb->prebuf;
+ this = frame->this;
+
+ if (res < 0) {
+ op_ret = -1;
+ op_errno = -res;
+ gf_log(this->name, GF_LOG_ERROR,
+ "writev(async) failed fd=%p,offset=%llu (%d/%s)", paiocb->fd,
+ (unsigned long long)paiocb->offset, res, strerror(op_errno));
+
+ goto out;
+ }
+
+ bd_inode_ctx_get(paiocb->fd->inode, this, &bdatt);
+ bd_update_amtime(&bdatt->iatt, GF_SET_ATTR_MTIME);
+ memcpy(&postbuf, &bdatt->iatt, sizeof(struct iatt));
+
+ op_ret = res;
+ op_errno = 0;
out:
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, &prebuf, &postbuf,
- NULL);
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, &prebuf, &postbuf,
+ NULL);
- if (paiocb->iobref)
- iobref_unref (paiocb->iobref);
- GF_FREE (paiocb);
+ if (paiocb->iobref)
+ iobref_unref(paiocb->iobref);
+ GF_FREE(paiocb);
- return 0;
+ return 0;
}
int
-bd_aio_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *iov, int count, off_t offset, uint32_t flags,
- struct iobref *iobref, dict_t *xdata)
+bd_aio_writev(call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *iov,
+ int count, off_t offset, uint32_t flags, struct iobref *iobref,
+ dict_t *xdata)
{
- int32_t op_errno = EINVAL;
- int _fd = -1;
- bd_fd_t *bd_fd = NULL;
- int ret = -1;
- struct bd_aio_cb *paiocb = NULL;
- bd_priv_t *priv = NULL;
- struct iocb *iocb = NULL;
- bd_attr_t *bdatt = NULL;
-
- VALIDATE_OR_GOTO (frame, err);
- VALIDATE_OR_GOTO (this, err);
- VALIDATE_OR_GOTO (fd, err);
-
- priv = this->private;
-
- ret = bd_fd_ctx_get (this, fd, &bd_fd);
- if (ret < 0 || !bd_fd) {
- STACK_WIND (frame, default_writev_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->writev,
- fd, iov, count, offset, flags, iobref, xdata);
- return 0;
- }
-
- bd_inode_ctx_get (fd->inode, this, &bdatt);
-
- _fd = bd_fd->fd;
-
- paiocb = GF_CALLOC (1, sizeof (*paiocb), gf_bd_aio_cb);
- if (!paiocb) {
- op_errno = ENOMEM;
- goto err;
- }
-
-
- paiocb->frame = frame;
- paiocb->offset = offset;
- paiocb->op = GF_FOP_WRITE;
- paiocb->fd = fd;
-
- paiocb->iocb.data = paiocb;
- paiocb->iocb.aio_fildes = _fd;
- paiocb->iobref = iobref_ref (iobref);
- paiocb->iocb.aio_lio_opcode = IO_CMD_PWRITEV;
- paiocb->iocb.aio_reqprio = 0;
- paiocb->iocb.u.v.vec = iov;
- paiocb->iocb.u.v.nr = count;
- paiocb->iocb.u.v.offset = offset;
-
- iocb = &paiocb->iocb;
-
- memcpy (&paiocb->prebuf, &bdatt->iatt, sizeof (struct iatt));
- LOCK (&fd->lock);
- {
- __bd_fd_set_odirect (fd, bd_fd, flags, offset,
- iov_length (iov, count));
-
- ret = io_submit (priv->ctxp, 1, &iocb);
- }
- UNLOCK (&fd->lock);
-
- if (ret != 1) {
- gf_log (this->name, GF_LOG_ERROR,
- "io_submit() returned %d", ret);
- op_errno = -ret;
- goto err;
- }
-
+ int32_t op_errno = EINVAL;
+ int _fd = -1;
+ bd_fd_t *bd_fd = NULL;
+ int ret = -1;
+ struct bd_aio_cb *paiocb = NULL;
+ bd_priv_t *priv = NULL;
+ struct iocb *iocb = NULL;
+ bd_attr_t *bdatt = NULL;
+
+ VALIDATE_OR_GOTO(frame, err);
+ VALIDATE_OR_GOTO(this, err);
+ VALIDATE_OR_GOTO(fd, err);
+
+ priv = this->private;
+
+ ret = bd_fd_ctx_get(this, fd, &bd_fd);
+ if (ret < 0 || !bd_fd) {
+ STACK_WIND(frame, default_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, iov, count, offset,
+ flags, iobref, xdata);
return 0;
+ }
+
+ bd_inode_ctx_get(fd->inode, this, &bdatt);
+
+ _fd = bd_fd->fd;
+
+ paiocb = GF_CALLOC(1, sizeof(*paiocb), gf_bd_aio_cb);
+ if (!paiocb) {
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ paiocb->frame = frame;
+ paiocb->offset = offset;
+ paiocb->op = GF_FOP_WRITE;
+ paiocb->fd = fd;
+
+ paiocb->iocb.data = paiocb;
+ paiocb->iocb.aio_fildes = _fd;
+ paiocb->iobref = iobref_ref(iobref);
+ paiocb->iocb.aio_lio_opcode = IO_CMD_PWRITEV;
+ paiocb->iocb.aio_reqprio = 0;
+ paiocb->iocb.u.v.vec = iov;
+ paiocb->iocb.u.v.nr = count;
+ paiocb->iocb.u.v.offset = offset;
+
+ iocb = &paiocb->iocb;
+
+ memcpy(&paiocb->prebuf, &bdatt->iatt, sizeof(struct iatt));
+ LOCK(&fd->lock);
+ {
+ __bd_fd_set_odirect(fd, bd_fd, flags, offset, iov_length(iov, count));
+
+ ret = io_submit(priv->ctxp, 1, &iocb);
+ }
+ UNLOCK(&fd->lock);
+
+ if (ret != 1) {
+ gf_log(this->name, GF_LOG_ERROR, "io_submit() returned %d", ret);
+ op_errno = -ret;
+ goto err;
+ }
+
+ return 0;
err:
- STACK_UNWIND_STRICT (writev, frame, -1, op_errno, 0, 0, 0);
+ STACK_UNWIND_STRICT(writev, frame, -1, op_errno, 0, 0, 0);
- if (paiocb) {
- if (paiocb->iobref)
- iobref_unref (paiocb->iobref);
- GF_FREE (paiocb);
- }
+ if (paiocb) {
+ if (paiocb->iobref)
+ iobref_unref(paiocb->iobref);
+ GF_FREE(paiocb);
+ }
- return 0;
+ return 0;
}
void *
-bd_aio_thread (void *data)
+bd_aio_thread(void *data)
{
- xlator_t *this = NULL;
- bd_priv_t *priv = NULL;
- int ret = 0;
- int i = 0;
- struct io_event *event = NULL;
- struct bd_aio_cb *paiocb = NULL;
- struct io_event events[BD_AIO_MAX_NR_GETEVENTS];
- struct timespec ts = {0, };
-
- this = data;
- THIS = this;
- priv = this->private;
-
- ts.tv_sec = 5;
- for (;;) {
- memset (&events[0], 0, sizeof (events));
- ret = io_getevents (priv->ctxp, 1, BD_AIO_MAX_NR_GETEVENTS,
- &events[0], &ts);
- if (ret < 0) {
- if (ret == -EINTR)
- continue;
- gf_log (this->name, GF_LOG_ERROR,
- "io_getevents() returned %d, exiting", ret);
- break;
- }
-
- for (i = 0; i < ret; i++) {
- event = &events[i];
-
- paiocb = event->data;
-
- switch (paiocb->op) {
- case GF_FOP_READ:
- bd_aio_readv_complete (paiocb, event->res,
- event->res2);
- break;
- case GF_FOP_WRITE:
- bd_aio_writev_complete (paiocb, event->res,
- event->res2);
- break;
- default:
- gf_log (this->name, GF_LOG_ERROR,
- "unknown op %d found in piocb",
- paiocb->op);
- break;
- }
- }
+ xlator_t *this = NULL;
+ bd_priv_t *priv = NULL;
+ int ret = 0;
+ int i = 0;
+ struct io_event *event = NULL;
+ struct bd_aio_cb *paiocb = NULL;
+ struct io_event events[BD_AIO_MAX_NR_GETEVENTS];
+ struct timespec ts = {
+ 0,
+ };
+
+ this = data;
+ THIS = this;
+ priv = this->private;
+
+ ts.tv_sec = 5;
+ for (;;) {
+ memset(&events[0], 0, sizeof(events));
+ ret = io_getevents(priv->ctxp, 1, BD_AIO_MAX_NR_GETEVENTS, &events[0],
+ &ts);
+ if (ret < 0) {
+ if (ret == -EINTR)
+ continue;
+ gf_log(this->name, GF_LOG_ERROR,
+ "io_getevents() returned %d, exiting", ret);
+ break;
}
- return NULL;
+ for (i = 0; i < ret; i++) {
+ event = &events[i];
+
+ paiocb = event->data;
+
+ switch (paiocb->op) {
+ case GF_FOP_READ:
+ bd_aio_readv_complete(paiocb, event->res, event->res2);
+ break;
+ case GF_FOP_WRITE:
+ bd_aio_writev_complete(paiocb, event->res, event->res2);
+ break;
+ default:
+ gf_log(this->name, GF_LOG_ERROR,
+ "unknown op %d found in piocb", paiocb->op);
+ break;
+ }
+ }
+ }
+
+ return NULL;
}
int
-bd_aio_init (xlator_t *this)
+bd_aio_init(xlator_t *this)
{
- bd_priv_t *priv = NULL;
- int ret = 0;
-
- priv = this->private;
-
- ret = io_setup (BD_AIO_MAX_NR_EVENTS, &priv->ctxp);
- if ((ret == -1 && errno == ENOSYS) || ret == -ENOSYS) {
- gf_log (this->name, GF_LOG_WARNING,
- "Linux AIO not available at run-time."
- " Continuing with synchronous IO");
- ret = 0;
- goto out;
- }
-
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "io_setup() failed. ret=%d, errno=%d",
- ret, errno);
- goto out;
- }
-
- ret = gf_thread_create (&priv->aiothread, NULL,
- bd_aio_thread, this, "bdaio");
- if (ret != 0) {
- io_destroy (priv->ctxp);
- goto out;
- }
-
- this->fops->readv = bd_aio_readv;
- this->fops->writev = bd_aio_writev;
+ bd_priv_t *priv = NULL;
+ int ret = 0;
+
+ priv = this->private;
+
+ ret = io_setup(BD_AIO_MAX_NR_EVENTS, &priv->ctxp);
+ if ((ret == -1 && errno == ENOSYS) || ret == -ENOSYS) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "Linux AIO not available at run-time."
+ " Continuing with synchronous IO");
+ ret = 0;
+ goto out;
+ }
+
+ if (ret < 0) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "io_setup() failed. ret=%d, errno=%d", ret, errno);
+ goto out;
+ }
+
+ ret = gf_thread_create(&priv->aiothread, NULL, bd_aio_thread, this,
+ "bdaio");
+ if (ret != 0) {
+ io_destroy(priv->ctxp);
+ goto out;
+ }
+
+ this->fops->readv = bd_aio_readv;
+ this->fops->writev = bd_aio_writev;
out:
- return ret;
+ return ret;
}
-
int
-bd_aio_on (xlator_t *this)
+bd_aio_on(xlator_t *this)
{
- bd_priv_t *priv = NULL;
- int ret = 0;
-
- priv = this->private;
-
- if (!priv->aio_init_done) {
- ret = bd_aio_init (this);
- if (ret == 0)
- priv->aio_capable = _gf_true;
- else
- priv->aio_capable = _gf_false;
- priv->aio_init_done = _gf_true;
- }
-
- if (priv->aio_capable) {
- this->fops->readv = bd_aio_readv;
- this->fops->writev = bd_aio_writev;
- }
+ bd_priv_t *priv = NULL;
+ int ret = 0;
+
+ priv = this->private;
+
+ if (!priv->aio_init_done) {
+ ret = bd_aio_init(this);
+ if (ret == 0)
+ priv->aio_capable = _gf_true;
+ else
+ priv->aio_capable = _gf_false;
+ priv->aio_init_done = _gf_true;
+ }
+
+ if (priv->aio_capable) {
+ this->fops->readv = bd_aio_readv;
+ this->fops->writev = bd_aio_writev;
+ }
- return ret;
+ return ret;
}
int
-bd_aio_off (xlator_t *this)
+bd_aio_off(xlator_t *this)
{
- this->fops->readv = bd_readv;
- this->fops->writev = bd_writev;
+ this->fops->readv = bd_readv;
+ this->fops->writev = bd_writev;
- return 0;
+ return 0;
}
#else
int
-bd_aio_on (xlator_t *this)
+bd_aio_on(xlator_t *this)
{
- gf_log (this->name, GF_LOG_INFO,
- "Linux AIO not available at build-time."
- " Continuing with synchronous IO");
- return 0;
+ gf_log(this->name, GF_LOG_INFO,
+ "Linux AIO not available at build-time."
+ " Continuing with synchronous IO");
+ return 0;
}
int
-bd_aio_off (xlator_t *this)
+bd_aio_off(xlator_t *this)
{
- gf_log (this->name, GF_LOG_INFO,
- "Linux AIO not available at build-time."
- " Continuing with synchronous IO");
- return 0;
+ gf_log(this->name, GF_LOG_INFO,
+ "Linux AIO not available at build-time."
+ " Continuing with synchronous IO");
+ return 0;
}
void
-__bd_fd_set_odirect (fd_t *fd, struct bd_fd *pfd, int opflags,
- off_t offset, size_t size)
+__bd_fd_set_odirect(fd_t *fd, struct bd_fd *pfd, int opflags, off_t offset,
+ size_t size)
{
- xlator_t *this = THIS;
- gf_log (this->name, GF_LOG_INFO,
- "Linux AIO not available at build-time."
- " Continuing with synchronous IO");
- return;
+ xlator_t *this = THIS;
+ gf_log(this->name, GF_LOG_INFO,
+ "Linux AIO not available at build-time."
+ " Continuing with synchronous IO");
+ return;
}
#endif
diff --git a/xlators/storage/bd/src/bd-helper.c b/xlators/storage/bd/src/bd-helper.c
index b2bcf06..895c650 100644
--- a/xlators/storage/bd/src/bd-helper.c
+++ b/xlators/storage/bd/src/bd-helper.c
@@ -11,65 +11,65 @@
#include "syscall.h"
int
-bd_inode_ctx_set (inode_t *inode, xlator_t *this, bd_attr_t *ctx)
+bd_inode_ctx_set(inode_t *inode, xlator_t *this, bd_attr_t *ctx)
{
- int ret = -1;
- uint64_t ctx_int = 0;
+ int ret = -1;
+ uint64_t ctx_int = 0;
- GF_VALIDATE_OR_GOTO (this->name, inode, out);
- GF_VALIDATE_OR_GOTO (this->name, ctx, out);
+ GF_VALIDATE_OR_GOTO(this->name, inode, out);
+ GF_VALIDATE_OR_GOTO(this->name, ctx, out);
- ctx_int = (long)ctx;
- ret = inode_ctx_set (inode, this, &ctx_int);
+ ctx_int = (long)ctx;
+ ret = inode_ctx_set(inode, this, &ctx_int);
out:
- return ret;
+ return ret;
}
int
-bd_inode_ctx_get (inode_t *inode, xlator_t *this, bd_attr_t **ctx)
+bd_inode_ctx_get(inode_t *inode, xlator_t *this, bd_attr_t **ctx)
{
- int ret = -1;
- uint64_t ctx_int = 0;
-
- GF_VALIDATE_OR_GOTO (this->name, inode, out);
- ret = inode_ctx_get (inode, this, &ctx_int);
- if (ret)
- return ret;
- if (ctx)
- *ctx = (bd_attr_t *) ctx_int;
-out:
+ int ret = -1;
+ uint64_t ctx_int = 0;
+
+ GF_VALIDATE_OR_GOTO(this->name, inode, out);
+ ret = inode_ctx_get(inode, this, &ctx_int);
+ if (ret)
return ret;
+ if (ctx)
+ *ctx = (bd_attr_t *)ctx_int;
+out:
+ return ret;
}
void
-bd_local_free (xlator_t *this, bd_local_t *local)
+bd_local_free(xlator_t *this, bd_local_t *local)
{
- if (!local)
- return;
- if (local->fd)
- fd_unref (local->fd);
- else if (local->loc.path)
- loc_wipe (&local->loc);
- if (local->dict)
- dict_unref (local->dict);
- if (local->inode)
- inode_unref (local->inode);
- if (local->bdatt) {
- GF_FREE (local->bdatt->type);
- GF_FREE (local->bdatt);
- }
- mem_put (local);
- local = NULL;
+ if (!local)
+ return;
+ if (local->fd)
+ fd_unref(local->fd);
+ else if (local->loc.path)
+ loc_wipe(&local->loc);
+ if (local->dict)
+ dict_unref(local->dict);
+ if (local->inode)
+ inode_unref(local->inode);
+ if (local->bdatt) {
+ GF_FREE(local->bdatt->type);
+ GF_FREE(local->bdatt);
+ }
+ mem_put(local);
+ local = NULL;
}
bd_local_t *
-bd_local_init (call_frame_t *frame, xlator_t *this)
+bd_local_init(call_frame_t *frame, xlator_t *this)
{
- frame->local = mem_get0 (this->local_pool);
- if (!frame->local)
- return NULL;
+ frame->local = mem_get0(this->local_pool);
+ if (!frame->local)
+ return NULL;
- return frame->local;
+ return frame->local;
}
/*
@@ -77,218 +77,229 @@ bd_local_init (call_frame_t *frame, xlator_t *this)
* This function validates this tag against volume-uuid. Also goes
* through LV list to find out if a thin-pool is configured or not.
*/
-int bd_scan_vg (xlator_t *this, bd_priv_t *priv)
+int
+bd_scan_vg(xlator_t *this, bd_priv_t *priv)
{
- vg_t brick = NULL;
- data_t *tmp_data = NULL;
- struct dm_list *tags = NULL;
- int op_ret = -1;
- uuid_t dict_uuid = {0, };
- uuid_t vg_uuid = {0, };
- gf_boolean_t uuid = _gf_false;
- lvm_str_list_t *strl = NULL;
- struct dm_list *lv_dm_list = NULL;
- lv_list_t *lv_list = NULL;
- struct dm_list *dm_seglist = NULL;
- lvseg_list_t *seglist = NULL;
- lvm_property_value_t prop = {0, };
- gf_boolean_t thin = _gf_false;
- const char *lv_name = NULL;
-
- brick = lvm_vg_open (priv->handle, priv->vg, "w", 0);
- if (!brick) {
- gf_log (this->name, GF_LOG_CRITICAL, "VG %s is not found",
- priv->vg);
- return ENOENT;
- }
-
- lv_dm_list = lvm_vg_list_lvs (brick);
- if (!lv_dm_list)
- goto check;
-
- dm_list_iterate_items (lv_list, lv_dm_list) {
- dm_seglist = lvm_lv_list_lvsegs (lv_list->lv);
- if (!dm_seglist)
- continue;
- dm_list_iterate_items (seglist, dm_seglist) {
- prop = lvm_lvseg_get_property (seglist->lvseg,
- "segtype");
- if (!prop.is_valid || !prop.value.string)
- continue;
- if (!strcmp (prop.value.string, "thin-pool")) {
- thin = _gf_true;
- lv_name = lvm_lv_get_name (lv_list->lv);
- priv->pool = gf_strdup (lv_name);
- gf_log (THIS->name, GF_LOG_INFO, "Thin Pool "
- "\"%s\" will be used for thin LVs",
- lv_name);
- break;
- }
- }
+ vg_t brick = NULL;
+ data_t *tmp_data = NULL;
+ struct dm_list *tags = NULL;
+ int op_ret = -1;
+ uuid_t dict_uuid = {
+ 0,
+ };
+ uuid_t vg_uuid = {
+ 0,
+ };
+ gf_boolean_t uuid = _gf_false;
+ lvm_str_list_t *strl = NULL;
+ struct dm_list *lv_dm_list = NULL;
+ lv_list_t *lv_list = NULL;
+ struct dm_list *dm_seglist = NULL;
+ lvseg_list_t *seglist = NULL;
+ lvm_property_value_t prop = {
+ 0,
+ };
+ gf_boolean_t thin = _gf_false;
+ const char *lv_name = NULL;
+
+ brick = lvm_vg_open(priv->handle, priv->vg, "w", 0);
+ if (!brick) {
+ gf_log(this->name, GF_LOG_CRITICAL, "VG %s is not found", priv->vg);
+ return ENOENT;
+ }
+
+ lv_dm_list = lvm_vg_list_lvs(brick);
+ if (!lv_dm_list)
+ goto check;
+
+ dm_list_iterate_items(lv_list, lv_dm_list)
+ {
+ dm_seglist = lvm_lv_list_lvsegs(lv_list->lv);
+ if (!dm_seglist)
+ continue;
+ dm_list_iterate_items(seglist, dm_seglist)
+ {
+ prop = lvm_lvseg_get_property(seglist->lvseg, "segtype");
+ if (!prop.is_valid || !prop.value.string)
+ continue;
+ if (!strcmp(prop.value.string, "thin-pool")) {
+ thin = _gf_true;
+ lv_name = lvm_lv_get_name(lv_list->lv);
+ priv->pool = gf_strdup(lv_name);
+ gf_log(THIS->name, GF_LOG_INFO,
+ "Thin Pool "
+ "\"%s\" will be used for thin LVs",
+ lv_name);
+ break;
+ }
}
+ }
check:
- /* If there is no volume-id set in dict, we can't validate */
- tmp_data = dict_get (this->options, "volume-id");
- if (!tmp_data) {
- op_ret = 0;
- goto out;
- }
-
- op_ret = gf_uuid_parse (tmp_data->data, dict_uuid);
- if (op_ret < 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "wrong volume-id (%s) set in volume file",
- tmp_data->data);
- op_ret = -1;
- goto out;
- }
-
- tags = lvm_vg_get_tags (brick);
- if (!tags) { /* no tags in the VG */
- gf_log (this->name, GF_LOG_ERROR,
- "Extended attribute trusted.glusterfs."
- "volume-id is absent");
- op_ret = -1;
- goto out;
- }
- dm_list_iterate_items (strl, tags) {
- if (!strncmp (strl->str, GF_XATTR_VOL_ID_KEY,
- SLEN (GF_XATTR_VOL_ID_KEY))) {
- uuid = _gf_true;
- break;
- }
- }
- /* UUID tag is not set in VG */
- if (!uuid) {
- gf_log (this->name, GF_LOG_ERROR,
- "Extended attribute trusted.glusterfs."
- "volume-id is absent");
- op_ret = -1;
- goto out;
- }
-
- op_ret = gf_uuid_parse (strl->str + SLEN (GF_XATTR_VOL_ID_KEY) + 1,
- vg_uuid);
- if (op_ret < 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "wrong volume-id (%s) set in VG", strl->str);
- op_ret = -1;
- goto out;
- }
- if (gf_uuid_compare (dict_uuid, vg_uuid)) {
- gf_log (this->name, GF_LOG_ERROR,
- "mismatching volume-id (%s) received. "
- "already is a part of volume %s ",
- tmp_data->data, vg_uuid);
- op_ret = -1;
- goto out;
- }
-
+ /* If there is no volume-id set in dict, we can't validate */
+ tmp_data = dict_get(this->options, "volume-id");
+ if (!tmp_data) {
op_ret = 0;
+ goto out;
+ }
+
+ op_ret = gf_uuid_parse(tmp_data->data, dict_uuid);
+ if (op_ret < 0) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "wrong volume-id (%s) set in volume file", tmp_data->data);
+ op_ret = -1;
+ goto out;
+ }
+
+ tags = lvm_vg_get_tags(brick);
+ if (!tags) { /* no tags in the VG */
+ gf_log(this->name, GF_LOG_ERROR,
+ "Extended attribute trusted.glusterfs."
+ "volume-id is absent");
+ op_ret = -1;
+ goto out;
+ }
+ dm_list_iterate_items(strl, tags)
+ {
+ if (!strncmp(strl->str, GF_XATTR_VOL_ID_KEY,
+ SLEN(GF_XATTR_VOL_ID_KEY))) {
+ uuid = _gf_true;
+ break;
+ }
+ }
+ /* UUID tag is not set in VG */
+ if (!uuid) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "Extended attribute trusted.glusterfs."
+ "volume-id is absent");
+ op_ret = -1;
+ goto out;
+ }
+
+ op_ret = gf_uuid_parse(strl->str + SLEN(GF_XATTR_VOL_ID_KEY) + 1, vg_uuid);
+ if (op_ret < 0) {
+ gf_log(this->name, GF_LOG_ERROR, "wrong volume-id (%s) set in VG",
+ strl->str);
+ op_ret = -1;
+ goto out;
+ }
+ if (gf_uuid_compare(dict_uuid, vg_uuid)) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "mismatching volume-id (%s) received. "
+ "already is a part of volume %s ",
+ tmp_data->data, vg_uuid);
+ op_ret = -1;
+ goto out;
+ }
+
+ op_ret = 0;
out:
- lvm_vg_close (brick);
+ lvm_vg_close(brick);
- if (!thin)
- gf_log (THIS->name, GF_LOG_WARNING, "No thin pool found in "
- "VG %s\n", priv->vg);
- else
- priv->caps |= BD_CAPS_THIN;
+ if (!thin)
+ gf_log(THIS->name, GF_LOG_WARNING,
+ "No thin pool found in "
+ "VG %s\n",
+ priv->vg);
+ else
+ priv->caps |= BD_CAPS_THIN;
- return op_ret;
+ return op_ret;
}
/* FIXME: Move this code to common place, so posix and bd xlator can use */
char *
-page_aligned_alloc (size_t size, char **aligned_buf)
+page_aligned_alloc(size_t size, char **aligned_buf)
{
- char *alloc_buf = NULL;
- char *buf = NULL;
+ char *alloc_buf = NULL;
+ char *buf = NULL;
- alloc_buf = GF_CALLOC (1, (size + ALIGN_SIZE), gf_common_mt_char);
- if (!alloc_buf)
- return NULL;
- /* page aligned buffer */
- buf = GF_ALIGN_BUF (alloc_buf, ALIGN_SIZE);
- *aligned_buf = buf;
+ alloc_buf = GF_CALLOC(1, (size + ALIGN_SIZE), gf_common_mt_char);
+ if (!alloc_buf)
+ return NULL;
+ /* page aligned buffer */
+ buf = GF_ALIGN_BUF(alloc_buf, ALIGN_SIZE);
+ *aligned_buf = buf;
- return alloc_buf;
+ return alloc_buf;
}
static int
-__bd_fd_ctx_get (xlator_t *this, fd_t *fd, bd_fd_t **bdfd_p)
+__bd_fd_ctx_get(xlator_t *this, fd_t *fd, bd_fd_t **bdfd_p)
{
- int ret = -1;
- int _fd = -1;
- char *devpath = NULL;
- bd_fd_t *bdfd = NULL;
- uint64_t tmp_bdfd = 0;
- bd_priv_t *priv = this->private;
- bd_gfid_t gfid = {0, };
- bd_attr_t *bdatt = NULL;
-
- /* not bd file */
- if (fd->inode->ia_type != IA_IFREG ||
- bd_inode_ctx_get (fd->inode, this, &bdatt))
- return 0;
-
- ret = __fd_ctx_get (fd, this, &tmp_bdfd);
- if (ret == 0) {
- bdfd = (void *)(long) tmp_bdfd;
- *bdfd_p = bdfd;
- return 0;
- }
-
- uuid_utoa_r (fd->inode->gfid, gfid);
- gf_asprintf (&devpath, "/dev/%s/%s", priv->vg, gfid);
- if (!devpath)
- goto out;
-
- _fd = open (devpath, O_RDWR | O_LARGEFILE, 0);
- if (_fd < 0) {
- ret = errno;
- gf_log (this->name, GF_LOG_ERROR, "open on %s: %s", devpath,
- strerror (ret));
- goto out;
- }
- bdfd = GF_CALLOC (1, sizeof(bd_fd_t), gf_bd_fd);
- BD_VALIDATE_MEM_ALLOC (bdfd, ret, out);
-
- bdfd->fd = _fd;
- bdfd->flag = O_RDWR | O_LARGEFILE;
- if (__fd_ctx_set (fd, this, (uint64_t)(long)bdfd) < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "failed to set the fd context fd=%p", fd);
- goto out;
- }
+ int ret = -1;
+ int _fd = -1;
+ char *devpath = NULL;
+ bd_fd_t *bdfd = NULL;
+ uint64_t tmp_bdfd = 0;
+ bd_priv_t *priv = this->private;
+ bd_gfid_t gfid = {
+ 0,
+ };
+ bd_attr_t *bdatt = NULL;
+
+ /* not bd file */
+ if (fd->inode->ia_type != IA_IFREG ||
+ bd_inode_ctx_get(fd->inode, this, &bdatt))
+ return 0;
+ ret = __fd_ctx_get(fd, this, &tmp_bdfd);
+ if (ret == 0) {
+ bdfd = (void *)(long)tmp_bdfd;
*bdfd_p = bdfd;
-
- ret = 0;
+ return 0;
+ }
+
+ uuid_utoa_r(fd->inode->gfid, gfid);
+ gf_asprintf(&devpath, "/dev/%s/%s", priv->vg, gfid);
+ if (!devpath)
+ goto out;
+
+ _fd = open(devpath, O_RDWR | O_LARGEFILE, 0);
+ if (_fd < 0) {
+ ret = errno;
+ gf_log(this->name, GF_LOG_ERROR, "open on %s: %s", devpath,
+ strerror(ret));
+ goto out;
+ }
+ bdfd = GF_CALLOC(1, sizeof(bd_fd_t), gf_bd_fd);
+ BD_VALIDATE_MEM_ALLOC(bdfd, ret, out);
+
+ bdfd->fd = _fd;
+ bdfd->flag = O_RDWR | O_LARGEFILE;
+ if (__fd_ctx_set(fd, this, (uint64_t)(long)bdfd) < 0) {
+ gf_log(this->name, GF_LOG_WARNING, "failed to set the fd context fd=%p",
+ fd);
+ goto out;
+ }
+
+ *bdfd_p = bdfd;
+
+ ret = 0;
out:
- GF_FREE (devpath);
- if (ret) {
- if (_fd >= 0)
- sys_close (_fd);
- GF_FREE (bdfd);
- }
- return ret;
+ GF_FREE(devpath);
+ if (ret) {
+ if (_fd >= 0)
+ sys_close(_fd);
+ GF_FREE(bdfd);
+ }
+ return ret;
}
int
-bd_fd_ctx_get (xlator_t *this, fd_t *fd, bd_fd_t **bdfd)
+bd_fd_ctx_get(xlator_t *this, fd_t *fd, bd_fd_t **bdfd)
{
- int ret;
+ int ret;
- /* FIXME: Is it ok to fd->lock here ? */
- LOCK (&fd->lock);
- {
- ret = __bd_fd_ctx_get (this, fd, bdfd);
- }
- UNLOCK (&fd->lock);
+ /* FIXME: Is it ok to fd->lock here ? */
+ LOCK(&fd->lock);
+ {
+ ret = __bd_fd_ctx_get(this, fd, bdfd);
+ }
+ UNLOCK(&fd->lock);
- return ret;
+ return ret;
}
/*
@@ -299,579 +310,606 @@ bd_fd_ctx_get (xlator_t *this, fd_t *fd, bd_fd_t **bdfd)
* size
*/
int
-bd_validate_bd_xattr (xlator_t *this, char *bd, char **type,
- uint64_t *lv_size, uuid_t uuid)
+bd_validate_bd_xattr(xlator_t *this, char *bd, char **type, uint64_t *lv_size,
+ uuid_t uuid)
{
- char *path = NULL;
- int ret = -1;
- bd_gfid_t gfid = {0, };
- bd_priv_t *priv = this->private;
- struct stat stbuf = {0, };
- uint64_t size = 0;
- vg_t vg = NULL;
- lv_t lv = NULL;
- char *bytes = NULL;
-
- bytes = strrchr (bd, ':');
- if (bytes) {
- *bytes = '\0';
- bytes++;
- gf_string2bytesize (bytes, &size);
- }
-
- if (strcmp (bd, BD_LV) && strcmp (bd, BD_THIN)) {
- gf_log (this->name, GF_LOG_WARNING,
- "invalid xattr %s", bd);
- return -1;
- }
- *type = gf_strdup (bd);
-
- /*
- * Check if LV really exist, there could be a failure
- * after setxattr and successful LV creation
- */
- uuid_utoa_r (uuid, gfid);
- gf_asprintf (&path, "/dev/%s/%s", priv->vg, gfid);
- if (!path) {
- gf_log (this->name, GF_LOG_WARNING,
- "insufficient memory");
- return 0;
- }
-
- /* Destination file does not exist */
- if (sys_stat (path, &stbuf)) {
- gf_log (this->name, GF_LOG_WARNING,
- "lstat failed for path %s", path);
- GF_FREE (path);
- return -1;
- }
-
- vg = lvm_vg_open (priv->handle, priv->vg, "r", 0);
- if (!vg) {
- gf_log (this->name, GF_LOG_WARNING,
- "VG %s does not exist?", priv->vg);
- ret = -1;
- goto out;
- }
-
- lv = lvm_lv_from_name (vg, gfid);
- if (!lv) {
- gf_log (this->name, GF_LOG_WARNING,
- "LV %s does not exist", gfid);
- ret = -1;
- goto out;
- }
-
- *lv_size = lvm_lv_get_size (lv);
- if (size == *lv_size) {
- ret = 0;
- goto out;
- }
+ char *path = NULL;
+ int ret = -1;
+ bd_gfid_t gfid = {
+ 0,
+ };
+ bd_priv_t *priv = this->private;
+ struct stat stbuf = {
+ 0,
+ };
+ uint64_t size = 0;
+ vg_t vg = NULL;
+ lv_t lv = NULL;
+ char *bytes = NULL;
+
+ bytes = strrchr(bd, ':');
+ if (bytes) {
+ *bytes = '\0';
+ bytes++;
+ gf_string2bytesize(bytes, &size);
+ }
+
+ if (strcmp(bd, BD_LV) && strcmp(bd, BD_THIN)) {
+ gf_log(this->name, GF_LOG_WARNING, "invalid xattr %s", bd);
+ return -1;
+ }
+ *type = gf_strdup(bd);
+
+ /*
+ * Check if LV really exist, there could be a failure
+ * after setxattr and successful LV creation
+ */
+ uuid_utoa_r(uuid, gfid);
+ gf_asprintf(&path, "/dev/%s/%s", priv->vg, gfid);
+ if (!path) {
+ gf_log(this->name, GF_LOG_WARNING, "insufficient memory");
+ return 0;
+ }
+
+ /* Destination file does not exist */
+ if (sys_stat(path, &stbuf)) {
+ gf_log(this->name, GF_LOG_WARNING, "lstat failed for path %s", path);
+ GF_FREE(path);
+ return -1;
+ }
+
+ vg = lvm_vg_open(priv->handle, priv->vg, "r", 0);
+ if (!vg) {
+ gf_log(this->name, GF_LOG_WARNING, "VG %s does not exist?", priv->vg);
+ ret = -1;
+ goto out;
+ }
+
+ lv = lvm_lv_from_name(vg, gfid);
+ if (!lv) {
+ gf_log(this->name, GF_LOG_WARNING, "LV %s does not exist", gfid);
+ ret = -1;
+ goto out;
+ }
+
+ *lv_size = lvm_lv_get_size(lv);
+ if (size == *lv_size) {
+ ret = 0;
+ goto out;
+ }
- ret = 1;
+ ret = 1;
out:
- if (vg)
- lvm_vg_close (vg);
+ if (vg)
+ lvm_vg_close(vg);
- GF_FREE (path);
- return ret;
+ GF_FREE(path);
+ return ret;
}
static int
-create_thin_lv (char *vg, char *pool, char *lv, uint64_t extent)
+create_thin_lv(char *vg, char *pool, char *lv, uint64_t extent)
{
- int ret = -1;
- runner_t runner = {0, };
- char *path = NULL;
- struct stat stat = {0, };
-
- runinit (&runner);
- runner_add_args (&runner, LVM_CREATE, NULL);
- runner_add_args (&runner, "--thin", NULL);
- runner_argprintf (&runner, "%s/%s", vg, pool);
- runner_add_args (&runner, "--name", NULL);
- runner_argprintf (&runner, "%s", lv);
- runner_add_args (&runner, "--virtualsize", NULL);
- runner_argprintf (&runner, "%ldB", extent);
- runner_start (&runner);
- runner_end (&runner);
-
- gf_asprintf (&path, "/dev/%s/%s", vg, lv);
- if (!path) {
- ret = ENOMEM;
- goto out;
- }
- if (sys_lstat (path, &stat) < 0)
- ret = EAGAIN;
- else
- ret = 0;
+ int ret = -1;
+ runner_t runner = {
+ 0,
+ };
+ char *path = NULL;
+ struct stat stat = {
+ 0,
+ };
+
+ runinit(&runner);
+ runner_add_args(&runner, LVM_CREATE, NULL);
+ runner_add_args(&runner, "--thin", NULL);
+ runner_argprintf(&runner, "%s/%s", vg, pool);
+ runner_add_args(&runner, "--name", NULL);
+ runner_argprintf(&runner, "%s", lv);
+ runner_add_args(&runner, "--virtualsize", NULL);
+ runner_argprintf(&runner, "%ldB", extent);
+ runner_start(&runner);
+ runner_end(&runner);
+
+ gf_asprintf(&path, "/dev/%s/%s", vg, lv);
+ if (!path) {
+ ret = ENOMEM;
+ goto out;
+ }
+ if (sys_lstat(path, &stat) < 0)
+ ret = EAGAIN;
+ else
+ ret = 0;
out:
- GF_FREE (path);
- return ret;
+ GF_FREE(path);
+ return ret;
}
int
-bd_create (uuid_t uuid, uint64_t size, char *type, bd_priv_t *priv)
+bd_create(uuid_t uuid, uint64_t size, char *type, bd_priv_t *priv)
{
- int ret = 0;
- vg_t vg = NULL;
- bd_gfid_t gfid = {0, };
+ int ret = 0;
+ vg_t vg = NULL;
+ bd_gfid_t gfid = {
+ 0,
+ };
- uuid_utoa_r (uuid, gfid);
+ uuid_utoa_r(uuid, gfid);
- if (!strcmp (type, BD_THIN))
- return create_thin_lv (priv->vg, priv->pool, gfid,
- size);
+ if (!strcmp(type, BD_THIN))
+ return create_thin_lv(priv->vg, priv->pool, gfid, size);
- vg = lvm_vg_open (priv->handle, priv->vg, "w", 0);
- if (!vg) {
- gf_log (THIS->name, GF_LOG_WARNING, "opening VG %s failed",
- priv->vg);
- return ENOENT;
- }
+ vg = lvm_vg_open(priv->handle, priv->vg, "w", 0);
+ if (!vg) {
+ gf_log(THIS->name, GF_LOG_WARNING, "opening VG %s failed", priv->vg);
+ return ENOENT;
+ }
- if (!lvm_vg_create_lv_linear (vg, gfid, size)) {
- gf_log (THIS->name, GF_LOG_WARNING, "lvm_vg_create_lv_linear "
- "failed");
- ret = errno;
- }
+ if (!lvm_vg_create_lv_linear(vg, gfid, size)) {
+ gf_log(THIS->name, GF_LOG_WARNING,
+ "lvm_vg_create_lv_linear "
+ "failed");
+ ret = errno;
+ }
- lvm_vg_close (vg);
+ lvm_vg_close(vg);
- return ret;
+ return ret;
}
int32_t
-bd_resize (bd_priv_t *priv, uuid_t uuid, size_t size)
+bd_resize(bd_priv_t *priv, uuid_t uuid, size_t size)
{
- uint64_t new_size = 0;
- runner_t runner = {0, };
- bd_gfid_t gfid = {0, };
- int ret = 0;
- vg_t vg = NULL;
- lv_t lv = NULL;
-
- uuid_utoa_r (uuid, gfid);
-
- runinit (&runner);
-
- runner_add_args (&runner, LVM_RESIZE, NULL);
- runner_argprintf (&runner, "%s/%s", priv->vg, gfid);
- runner_argprintf (&runner, "-L%ldb", size);
- runner_add_args (&runner, "-f", NULL);
-
- runner_start (&runner);
- runner_end (&runner);
-
- vg = lvm_vg_open (priv->handle, priv->vg, "w", 0);
- if (!vg) {
- gf_log (THIS->name, GF_LOG_WARNING, "opening VG %s failed",
- priv->vg);
- return EAGAIN;
- }
-
- lv = lvm_lv_from_name (vg, gfid);
- if (!lv) {
- gf_log (THIS->name, GF_LOG_WARNING, "LV %s not found", gfid);
- ret = EIO;
- goto out;
- }
- new_size = lvm_lv_get_size (lv);
-
- if (new_size != size) {
- gf_log (THIS->name, GF_LOG_WARNING,
- "resized LV size %" PRIu64 " does "
- "not match requested size %zd", new_size, size);
- ret = EIO;
- }
+ uint64_t new_size = 0;
+ runner_t runner = {
+ 0,
+ };
+ bd_gfid_t gfid = {
+ 0,
+ };
+ int ret = 0;
+ vg_t vg = NULL;
+ lv_t lv = NULL;
+
+ uuid_utoa_r(uuid, gfid);
+
+ runinit(&runner);
+
+ runner_add_args(&runner, LVM_RESIZE, NULL);
+ runner_argprintf(&runner, "%s/%s", priv->vg, gfid);
+ runner_argprintf(&runner, "-L%ldb", size);
+ runner_add_args(&runner, "-f", NULL);
+
+ runner_start(&runner);
+ runner_end(&runner);
+
+ vg = lvm_vg_open(priv->handle, priv->vg, "w", 0);
+ if (!vg) {
+ gf_log(THIS->name, GF_LOG_WARNING, "opening VG %s failed", priv->vg);
+ return EAGAIN;
+ }
+
+ lv = lvm_lv_from_name(vg, gfid);
+ if (!lv) {
+ gf_log(THIS->name, GF_LOG_WARNING, "LV %s not found", gfid);
+ ret = EIO;
+ goto out;
+ }
+ new_size = lvm_lv_get_size(lv);
+
+ if (new_size != size) {
+ gf_log(THIS->name, GF_LOG_WARNING,
+ "resized LV size %" PRIu64
+ " does "
+ "not match requested size %zd",
+ new_size, size);
+ ret = EIO;
+ }
out:
- lvm_vg_close (vg);
- return ret;
+ lvm_vg_close(vg);
+ return ret;
}
uint64_t
-bd_get_default_extent (bd_priv_t *priv)
+bd_get_default_extent(bd_priv_t *priv)
{
- vg_t vg = NULL;
- uint64_t size = 0;
-
- vg = lvm_vg_open (priv->handle, priv->vg, "w", 0);
- if (!vg) {
- gf_log (THIS->name, GF_LOG_WARNING, "opening VG %s failed",
- priv->vg);
- return 0;
- }
+ vg_t vg = NULL;
+ uint64_t size = 0;
+
+ vg = lvm_vg_open(priv->handle, priv->vg, "w", 0);
+ if (!vg) {
+ gf_log(THIS->name, GF_LOG_WARNING, "opening VG %s failed", priv->vg);
+ return 0;
+ }
- size = lvm_vg_get_extent_size (vg);
+ size = lvm_vg_get_extent_size(vg);
- lvm_vg_close (vg);
+ lvm_vg_close(vg);
- return size;
+ return size;
}
/*
* Adjusts the user specified size to VG specific extent size
*/
uint64_t
-bd_adjust_size (bd_priv_t *priv, size_t size)
+bd_adjust_size(bd_priv_t *priv, size_t size)
{
- uint64_t extent = 0;
- uint64_t nr_ex = 0;
+ uint64_t extent = 0;
+ uint64_t nr_ex = 0;
- extent = bd_get_default_extent (priv);
- if (!extent)
- return 0;
+ extent = bd_get_default_extent(priv);
+ if (!extent)
+ return 0;
- nr_ex = size / extent;
- if (size % extent)
- nr_ex++;
+ nr_ex = size / extent;
+ if (size % extent)
+ nr_ex++;
- size = extent * nr_ex;
+ size = extent * nr_ex;
- return size;
+ return size;
}
int
-bd_delete_lv (bd_priv_t *priv, const char *lv_name, int *op_errno)
+bd_delete_lv(bd_priv_t *priv, const char *lv_name, int *op_errno)
{
- vg_t vg = NULL;
- lv_t lv = NULL;
- int ret = -1;
-
- *op_errno = 0;
- vg = lvm_vg_open (priv->handle, priv->vg, "w", 0);
- if (!vg) {
- gf_log (THIS->name, GF_LOG_WARNING, "opening VG %s failed",
- priv->vg);
- *op_errno = ENOENT;
- return -1;
- }
- lv = lvm_lv_from_name (vg, lv_name);
- if (!lv) {
- gf_log (THIS->name, GF_LOG_WARNING, "No such LV %s", lv_name);
- *op_errno = ENOENT;
- goto out;
- }
- ret = lvm_vg_remove_lv (lv);
- if (ret < 0) {
- gf_log (THIS->name, GF_LOG_WARNING, "removing LV %s failed",
- lv_name);
- *op_errno = errno;
- goto out;
- }
+ vg_t vg = NULL;
+ lv_t lv = NULL;
+ int ret = -1;
+
+ *op_errno = 0;
+ vg = lvm_vg_open(priv->handle, priv->vg, "w", 0);
+ if (!vg) {
+ gf_log(THIS->name, GF_LOG_WARNING, "opening VG %s failed", priv->vg);
+ *op_errno = ENOENT;
+ return -1;
+ }
+ lv = lvm_lv_from_name(vg, lv_name);
+ if (!lv) {
+ gf_log(THIS->name, GF_LOG_WARNING, "No such LV %s", lv_name);
+ *op_errno = ENOENT;
+ goto out;
+ }
+ ret = lvm_vg_remove_lv(lv);
+ if (ret < 0) {
+ gf_log(THIS->name, GF_LOG_WARNING, "removing LV %s failed", lv_name);
+ *op_errno = errno;
+ goto out;
+ }
out:
- lvm_vg_close (vg);
+ lvm_vg_close(vg);
- return ret;
+ return ret;
}
void
bd_update_amtime(struct iatt *iatt, int flag)
{
- struct timespec ts = {0, };
-
- clock_gettime (CLOCK_REALTIME, &ts);
- if (flag & GF_SET_ATTR_ATIME) {
- iatt->ia_atime = ts.tv_sec;
- iatt->ia_atime_nsec = ts.tv_nsec;
- }
- if (flag & GF_SET_ATTR_MTIME) {
- iatt->ia_mtime = ts.tv_sec;
- iatt->ia_mtime_nsec = ts.tv_nsec;
- }
+ struct timespec ts = {
+ 0,
+ };
+
+ clock_gettime(CLOCK_REALTIME, &ts);
+ if (flag & GF_SET_ATTR_ATIME) {
+ iatt->ia_atime = ts.tv_sec;
+ iatt->ia_atime_nsec = ts.tv_nsec;
+ }
+ if (flag & GF_SET_ATTR_MTIME) {
+ iatt->ia_mtime = ts.tv_sec;
+ iatt->ia_mtime_nsec = ts.tv_nsec;
+ }
}
int
-bd_snapshot_create (bd_local_t *local, bd_priv_t *priv)
+bd_snapshot_create(bd_local_t *local, bd_priv_t *priv)
{
- char *path = NULL;
- bd_gfid_t dest = {0, };
- bd_gfid_t origin = {0, };
- int ret = 0;
- runner_t runner = {0, };
- struct stat stat = {0, };
-
- uuid_utoa_r (local->dloc->gfid, dest);
- uuid_utoa_r (local->loc.gfid, origin);
-
- gf_asprintf (&path, "/dev/%s/%s", priv->vg, dest);
- if (!path) {
- gf_log (THIS->name, GF_LOG_WARNING,
- "Insufficient memory");
- return ENOMEM;
- }
-
- runinit (&runner);
- runner_add_args (&runner, LVM_CREATE, NULL);
- runner_add_args (&runner, "--snapshot", NULL);
- runner_argprintf (&runner, "/dev/%s/%s", priv->vg, origin);
- runner_add_args (&runner, "--name", NULL);
- runner_argprintf (&runner, "%s", dest);
- if (strcmp (local->bdatt->type, BD_THIN))
- runner_argprintf (&runner, "-L%ldB", local->size);
- runner_start (&runner);
- runner_end (&runner);
-
- if (sys_lstat (path, &stat) < 0)
- ret = EIO;
-
- GF_FREE (path);
- return ret;
+ char *path = NULL;
+ bd_gfid_t dest = {
+ 0,
+ };
+ bd_gfid_t origin = {
+ 0,
+ };
+ int ret = 0;
+ runner_t runner = {
+ 0,
+ };
+ struct stat stat = {
+ 0,
+ };
+
+ uuid_utoa_r(local->dloc->gfid, dest);
+ uuid_utoa_r(local->loc.gfid, origin);
+
+ gf_asprintf(&path, "/dev/%s/%s", priv->vg, dest);
+ if (!path) {
+ gf_log(THIS->name, GF_LOG_WARNING, "Insufficient memory");
+ return ENOMEM;
+ }
+
+ runinit(&runner);
+ runner_add_args(&runner, LVM_CREATE, NULL);
+ runner_add_args(&runner, "--snapshot", NULL);
+ runner_argprintf(&runner, "/dev/%s/%s", priv->vg, origin);
+ runner_add_args(&runner, "--name", NULL);
+ runner_argprintf(&runner, "%s", dest);
+ if (strcmp(local->bdatt->type, BD_THIN))
+ runner_argprintf(&runner, "-L%ldB", local->size);
+ runner_start(&runner);
+ runner_end(&runner);
+
+ if (sys_lstat(path, &stat) < 0)
+ ret = EIO;
+
+ GF_FREE(path);
+ return ret;
}
int
-bd_clone (bd_local_t *local, bd_priv_t *priv)
+bd_clone(bd_local_t *local, bd_priv_t *priv)
{
- int ret = ENOMEM;
- int fd1 = -1;
- int fd2 = -1;
- int i = 0;
- char *buff = NULL;
- ssize_t bytes = 0;
- char *spath = NULL;
- char *dpath = NULL;
- struct iovec *vec = NULL;
- bd_gfid_t source = {0, };
- bd_gfid_t dest = {0, };
- void *bufp[IOV_NR] = {0, };
-
- vec = GF_CALLOC (IOV_NR, sizeof (struct iovec), gf_common_mt_iovec);
- if (!vec)
- return ENOMEM;
-
- for (i = 0; i < IOV_NR; i++) {
- bufp[i] = page_aligned_alloc (IOV_SIZE, &buff);
- if (!buff)
- goto out;
- vec[i].iov_base = buff;
- vec[i].iov_len = IOV_SIZE;
- }
-
- uuid_utoa_r (local->loc.gfid, source);
- uuid_utoa_r (local->dloc->gfid, dest);
-
- gf_asprintf (&spath, "/dev/%s/%s", priv->vg, source);
- gf_asprintf (&dpath, "/dev/%s/%s", priv->vg, dest);
- if (!spath || !dpath)
- goto out;
-
- ret = bd_create (local->dloc->gfid, local->size,
- local->bdatt->type, priv);
- if (ret)
- goto out;
-
- fd1 = open (spath, O_RDONLY | O_DIRECT);
- if (fd1 < 0) {
- ret = errno;
- goto out;
+ int ret = ENOMEM;
+ int fd1 = -1;
+ int fd2 = -1;
+ int i = 0;
+ char *buff = NULL;
+ ssize_t bytes = 0;
+ char *spath = NULL;
+ char *dpath = NULL;
+ struct iovec *vec = NULL;
+ bd_gfid_t source = {
+ 0,
+ };
+ bd_gfid_t dest = {
+ 0,
+ };
+ void *bufp[IOV_NR] = {
+ 0,
+ };
+
+ vec = GF_CALLOC(IOV_NR, sizeof(struct iovec), gf_common_mt_iovec);
+ if (!vec)
+ return ENOMEM;
+
+ for (i = 0; i < IOV_NR; i++) {
+ bufp[i] = page_aligned_alloc(IOV_SIZE, &buff);
+ if (!buff)
+ goto out;
+ vec[i].iov_base = buff;
+ vec[i].iov_len = IOV_SIZE;
+ }
+
+ uuid_utoa_r(local->loc.gfid, source);
+ uuid_utoa_r(local->dloc->gfid, dest);
+
+ gf_asprintf(&spath, "/dev/%s/%s", priv->vg, source);
+ gf_asprintf(&dpath, "/dev/%s/%s", priv->vg, dest);
+ if (!spath || !dpath)
+ goto out;
+
+ ret = bd_create(local->dloc->gfid, local->size, local->bdatt->type, priv);
+ if (ret)
+ goto out;
+
+ fd1 = open(spath, O_RDONLY | O_DIRECT);
+ if (fd1 < 0) {
+ ret = errno;
+ goto out;
+ }
+ fd2 = open(dpath, O_WRONLY | O_DIRECT);
+ if (fd2 < 0) {
+ ret = errno;
+ goto out;
+ }
+
+ while (1) {
+ bytes = sys_readv(fd1, vec, IOV_NR);
+ if (bytes < 0) {
+ ret = errno;
+ gf_log(THIS->name, GF_LOG_WARNING, "read failed: %s",
+ strerror(ret));
+ goto out;
}
- fd2 = open (dpath, O_WRONLY | O_DIRECT);
- if (fd2 < 0) {
- ret = errno;
- goto out;
+ if (!bytes)
+ break;
+ bytes = sys_writev(fd2, vec, IOV_NR);
+ if (bytes < 0) {
+ ret = errno;
+ gf_log(THIS->name, GF_LOG_WARNING, "write failed: %s",
+ strerror(ret));
+ goto out;
}
-
- while (1) {
- bytes = sys_readv (fd1, vec, IOV_NR);
- if (bytes < 0) {
- ret = errno;
- gf_log (THIS->name, GF_LOG_WARNING, "read failed: %s",
- strerror (ret));
- goto out;
- }
- if (!bytes)
- break;
- bytes = sys_writev (fd2, vec, IOV_NR);
- if (bytes < 0) {
- ret = errno;
- gf_log (THIS->name, GF_LOG_WARNING,
- "write failed: %s", strerror (ret));
- goto out;
- }
- }
- ret = 0;
+ }
+ ret = 0;
out:
- for (i = 0; i < IOV_NR; i++)
- GF_FREE (bufp[i]);
- GF_FREE (vec);
+ for (i = 0; i < IOV_NR; i++)
+ GF_FREE(bufp[i]);
+ GF_FREE(vec);
- if (fd1 != -1)
- sys_close (fd1);
- if (fd2 != -1)
- sys_close (fd2);
+ if (fd1 != -1)
+ sys_close(fd1);
+ if (fd2 != -1)
+ sys_close(fd2);
- GF_FREE (spath);
- GF_FREE (dpath);
+ GF_FREE(spath);
+ GF_FREE(dpath);
- return ret;
+ return ret;
}
/*
* Merges snapshot LV to origin LV and returns status
*/
int
-bd_merge (bd_priv_t *priv, uuid_t gfid)
+bd_merge(bd_priv_t *priv, uuid_t gfid)
{
- bd_gfid_t dest = {0, };
- char *path = NULL;
- struct stat stat = {0, };
- runner_t runner = {0, };
- int ret = 0;
-
- uuid_utoa_r (gfid, dest);
- gf_asprintf (&path, "/dev/%s/%s", priv->vg, dest);
-
- runinit (&runner);
- runner_add_args (&runner, LVM_CONVERT, NULL);
- runner_add_args (&runner, "--merge", NULL);
- runner_argprintf (&runner, "%s", path);
- runner_start (&runner);
- runner_end (&runner);
-
- if (!sys_lstat (path, &stat))
- ret = EIO;
-
- GF_FREE (path);
-
- return ret;
+ bd_gfid_t dest = {
+ 0,
+ };
+ char *path = NULL;
+ struct stat stat = {
+ 0,
+ };
+ runner_t runner = {
+ 0,
+ };
+ int ret = 0;
+
+ uuid_utoa_r(gfid, dest);
+ gf_asprintf(&path, "/dev/%s/%s", priv->vg, dest);
+
+ runinit(&runner);
+ runner_add_args(&runner, LVM_CONVERT, NULL);
+ runner_add_args(&runner, "--merge", NULL);
+ runner_argprintf(&runner, "%s", path);
+ runner_start(&runner);
+ runner_end(&runner);
+
+ if (!sys_lstat(path, &stat))
+ ret = EIO;
+
+ GF_FREE(path);
+
+ return ret;
}
int
-bd_get_origin (bd_priv_t *priv, loc_t *loc, fd_t *fd, dict_t *dict)
+bd_get_origin(bd_priv_t *priv, loc_t *loc, fd_t *fd, dict_t *dict)
{
- vg_t brick = NULL;
- lvm_property_value_t prop = {0, };
- lv_t lv = NULL;
- int ret = -1;
- bd_gfid_t gfid = {0, };
- inode_t *inode = NULL;
- char *origin = NULL;
-
- brick = lvm_vg_open (priv->handle, priv->vg, "w", 0);
- if (!brick) {
- gf_log (THIS->name, GF_LOG_CRITICAL, "VG %s is not found",
- priv->vg);
- return ENOENT;
- }
-
- if (fd)
- inode = fd->inode;
- else
- inode = loc->inode;
-
- uuid_utoa_r (inode->gfid, gfid);
- lv = lvm_lv_from_name (brick, gfid);
- if (!lv) {
- gf_log (THIS->name, GF_LOG_CRITICAL, "LV %s not found", gfid);
- ret = ENOENT;
- goto out;
- }
-
- prop = lvm_lv_get_property (lv, "origin");
- if (!prop.is_valid || !prop.value.string) {
- ret = ENODATA;
- goto out;
- }
-
- origin = gf_strdup (prop.value.string);
- ret = dict_set_dynstr (dict, BD_ORIGIN, origin);
+ vg_t brick = NULL;
+ lvm_property_value_t prop = {
+ 0,
+ };
+ lv_t lv = NULL;
+ int ret = -1;
+ bd_gfid_t gfid = {
+ 0,
+ };
+ inode_t *inode = NULL;
+ char *origin = NULL;
+
+ brick = lvm_vg_open(priv->handle, priv->vg, "w", 0);
+ if (!brick) {
+ gf_log(THIS->name, GF_LOG_CRITICAL, "VG %s is not found", priv->vg);
+ return ENOENT;
+ }
+
+ if (fd)
+ inode = fd->inode;
+ else
+ inode = loc->inode;
+
+ uuid_utoa_r(inode->gfid, gfid);
+ lv = lvm_lv_from_name(brick, gfid);
+ if (!lv) {
+ gf_log(THIS->name, GF_LOG_CRITICAL, "LV %s not found", gfid);
+ ret = ENOENT;
+ goto out;
+ }
+
+ prop = lvm_lv_get_property(lv, "origin");
+ if (!prop.is_valid || !prop.value.string) {
+ ret = ENODATA;
+ goto out;
+ }
+
+ origin = gf_strdup(prop.value.string);
+ ret = dict_set_dynstr(dict, BD_ORIGIN, origin);
out:
- lvm_vg_close (brick);
- return ret;
+ lvm_vg_close(brick);
+ return ret;
}
#ifndef BLKZEROOUT
int
-bd_do_manual_zerofill (int fd, off_t offset, off_t len, int o_direct)
+bd_do_manual_zerofill(int fd, off_t offset, off_t len, int o_direct)
{
- off_t num_vect = 0;
- off_t num_loop = 1;
- int idx = 0;
- int op_ret = -1;
- int vect_size = IOV_SIZE;
- off_t remain = 0;
- off_t extra = 0;
- struct iovec *vector = NULL;
- char *iov_base = NULL;
- char *alloc_buf = NULL;
-
- if (len == 0)
- return 0;
-
- if (len < IOV_SIZE)
- vect_size = len;
-
- num_vect = len / (vect_size);
- remain = len % vect_size ;
-
- if (num_vect > MAX_NO_VECT) {
- extra = num_vect % MAX_NO_VECT;
- num_loop = num_vect / MAX_NO_VECT;
- num_vect = MAX_NO_VECT;
- }
-
- vector = GF_CALLOC (num_vect, sizeof(struct iovec),
- gf_common_mt_iovec);
- if (!vector)
- return -1;
-
- if (o_direct) {
- alloc_buf = page_aligned_alloc (vect_size, &iov_base);
- if (!alloc_buf) {
- gf_log ("bd_do_manual_zerofill", GF_LOG_DEBUG,
- "memory alloc failed, vect_size %d: %s",
- vect_size, strerror (errno));
- GF_FREE (vector);
- return -1;
- }
- } else {
- iov_base = GF_CALLOC (vect_size, sizeof(char),
- gf_common_mt_char);
- if (!iov_base) {
- GF_FREE (vector);
- return -1;
- }
- }
-
- for (idx = 0; idx < num_vect; idx++) {
- vector[idx].iov_base = iov_base;
- vector[idx].iov_len = vect_size;
- }
-
- if (sys_lseek (fd, offset, SEEK_SET) < 0) {
- op_ret = -1;
- goto err;
- }
+ off_t num_vect = 0;
+ off_t num_loop = 1;
+ int idx = 0;
+ int op_ret = -1;
+ int vect_size = IOV_SIZE;
+ off_t remain = 0;
+ off_t extra = 0;
+ struct iovec *vector = NULL;
+ char *iov_base = NULL;
+ char *alloc_buf = NULL;
+
+ if (len == 0)
+ return 0;
- for (idx = 0; idx < num_loop; idx++) {
- op_ret = sys_writev (fd, vector, num_vect);
- if (op_ret < 0)
- goto err;
- }
- if (extra) {
- op_ret = sys_writev (fd, vector, extra);
- if (op_ret < 0)
- goto err;
+ if (len < IOV_SIZE)
+ vect_size = len;
+
+ num_vect = len / (vect_size);
+ remain = len % vect_size;
+
+ if (num_vect > MAX_NO_VECT) {
+ extra = num_vect % MAX_NO_VECT;
+ num_loop = num_vect / MAX_NO_VECT;
+ num_vect = MAX_NO_VECT;
+ }
+
+ vector = GF_CALLOC(num_vect, sizeof(struct iovec), gf_common_mt_iovec);
+ if (!vector)
+ return -1;
+
+ if (o_direct) {
+ alloc_buf = page_aligned_alloc(vect_size, &iov_base);
+ if (!alloc_buf) {
+ gf_log("bd_do_manual_zerofill", GF_LOG_DEBUG,
+ "memory alloc failed, vect_size %d: %s", vect_size,
+ strerror(errno));
+ GF_FREE(vector);
+ return -1;
}
- if (remain) {
- vector[0].iov_len = remain;
- op_ret = sys_writev (fd, vector , 1);
- if (op_ret < 0)
- goto err;
+ } else {
+ iov_base = GF_CALLOC(vect_size, sizeof(char), gf_common_mt_char);
+ if (!iov_base) {
+ GF_FREE(vector);
+ return -1;
}
- op_ret = 0;
+ }
+
+ for (idx = 0; idx < num_vect; idx++) {
+ vector[idx].iov_base = iov_base;
+ vector[idx].iov_len = vect_size;
+ }
+
+ if (sys_lseek(fd, offset, SEEK_SET) < 0) {
+ op_ret = -1;
+ goto err;
+ }
+
+ for (idx = 0; idx < num_loop; idx++) {
+ op_ret = sys_writev(fd, vector, num_vect);
+ if (op_ret < 0)
+ goto err;
+ }
+ if (extra) {
+ op_ret = sys_writev(fd, vector, extra);
+ if (op_ret < 0)
+ goto err;
+ }
+ if (remain) {
+ vector[0].iov_len = remain;
+ op_ret = sys_writev(fd, vector, 1);
+ if (op_ret < 0)
+ goto err;
+ }
+ op_ret = 0;
err:
- if (o_direct)
- GF_FREE (alloc_buf);
- else
- GF_FREE (iov_base);
- GF_FREE (vector);
- return op_ret;
+ if (o_direct)
+ GF_FREE(alloc_buf);
+ else
+ GF_FREE(iov_base);
+ GF_FREE(vector);
+ return op_ret;
}
#else
@@ -886,145 +924,150 @@ err:
* /sys/block/<block-device>/queue/write_same_max_bytes
*/
int
-bd_do_ioctl_zerofill (bd_priv_t *priv, bd_attr_t *bdatt, int fd, char *vg,
- off_t offset, off_t len)
+bd_do_ioctl_zerofill(bd_priv_t *priv, bd_attr_t *bdatt, int fd, char *vg,
+ off_t offset, off_t len)
{
- char *dm = NULL;
- char dmname[4096] = {0, };
- char lvname[4096] = {0, };
- char sysfs[4096] = {0, };
- bd_gfid_t uuid = {0, };
- char *p = NULL;
- off_t max_bytes = 0;
- int sysfd = -1;
- int ret = 0;
- uint64_t param[2] = {0, 0};
- off_t nr_loop = 0;
- char buff[16] = {0, };
-
- uuid_utoa_r (bdatt->iatt.ia_gfid, uuid);
- sprintf (lvname, "/dev/%s/%s", vg, uuid);
-
- ret = sys_readlink(lvname, dmname, 4096);
- if (ret < 0) {
- gf_log("bd", GF_LOG_DEBUG,
- "Failed to read symbolic link '%s': %s",
- lvname, strerror(errno));
- goto skip;
- }
-
- dmname[ret] = '\0';
-
- p = strrchr (dmname, '/');
- if (p)
- dm = p + 1;
- else
- dm = dmname;
-
- sprintf(sysfs, "/sys/block/%s/queue/write_same_max_bytes", dm);
- sysfd = open (sysfs, O_RDONLY);
- if (sysfd < 0) {
- gf_log ("bd_do_ioctl_zerofill", GF_LOG_DEBUG,
- "sysfs file %s does not exist", lvname);
- goto skip;
- }
-
- sys_read (sysfd, buff, sizeof (buff));
- sys_close (sysfd);
-
- max_bytes = atoll (buff);
+ char *dm = NULL;
+ char dmname[4096] = {
+ 0,
+ };
+ char lvname[4096] = {
+ 0,
+ };
+ char sysfs[4096] = {
+ 0,
+ };
+ bd_gfid_t uuid = {
+ 0,
+ };
+ char *p = NULL;
+ off_t max_bytes = 0;
+ int sysfd = -1;
+ int ret = 0;
+ uint64_t param[2] = {0, 0};
+ off_t nr_loop = 0;
+ char buff[16] = {
+ 0,
+ };
+
+ uuid_utoa_r(bdatt->iatt.ia_gfid, uuid);
+ sprintf(lvname, "/dev/%s/%s", vg, uuid);
+
+ ret = sys_readlink(lvname, dmname, 4096);
+ if (ret < 0) {
+ gf_log("bd", GF_LOG_DEBUG, "Failed to read symbolic link '%s': %s",
+ lvname, strerror(errno));
+ goto skip;
+ }
+
+ dmname[ret] = '\0';
+
+ p = strrchr(dmname, '/');
+ if (p)
+ dm = p + 1;
+ else
+ dm = dmname;
+
+ sprintf(sysfs, "/sys/block/%s/queue/write_same_max_bytes", dm);
+ sysfd = open(sysfs, O_RDONLY);
+ if (sysfd < 0) {
+ gf_log("bd_do_ioctl_zerofill", GF_LOG_DEBUG,
+ "sysfs file %s does not exist", lvname);
+ goto skip;
+ }
+
+ sys_read(sysfd, buff, sizeof(buff));
+ sys_close(sysfd);
+
+ max_bytes = atoll(buff);
skip:
- /*
- * If requested len is less than write_same_max_bytes,
- * issue single ioctl to zeroout. Otherwise split the ioctls
- */
- if (!max_bytes || len <= max_bytes) {
- param[0] = offset;
- param[1] = len;
-
- if (ioctl (fd, BLKZEROOUT, param) < 0)
- return errno;
- return 0;
- }
+ /*
+ * If requested len is less than write_same_max_bytes,
+ * issue single ioctl to zeroout. Otherwise split the ioctls
+ */
+ if (!max_bytes || len <= max_bytes) {
+ param[0] = offset;
+ param[1] = len;
- /* Split ioctls to max write_same_max_bytes */
- nr_loop = len / max_bytes;
- for (; nr_loop; nr_loop--) {
- param[0] = offset;
- param[1] = max_bytes;
+ if (ioctl(fd, BLKZEROOUT, param) < 0)
+ return errno;
+ return 0;
+ }
- if (ioctl (fd, BLKZEROOUT, param) < 0)
- return errno;
+ /* Split ioctls to max write_same_max_bytes */
+ nr_loop = len / max_bytes;
+ for (; nr_loop; nr_loop--) {
+ param[0] = offset;
+ param[1] = max_bytes;
- offset += max_bytes;
- }
+ if (ioctl(fd, BLKZEROOUT, param) < 0)
+ return errno;
- if (!(len % max_bytes))
- return 0;
+ offset += max_bytes;
+ }
- param[0] = offset;
- param[1] = len % max_bytes;
+ if (!(len % max_bytes))
+ return 0;
- if (ioctl (fd, BLKZEROOUT, param) < 0)
- return errno;
+ param[0] = offset;
+ param[1] = len % max_bytes;
- return 0;
+ if (ioctl(fd, BLKZEROOUT, param) < 0)
+ return errno;
+
+ return 0;
}
#endif
int
-bd_do_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd,
- off_t offset, size_t len, struct iatt *prebuf,
- struct iatt *postbuf)
+bd_do_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ size_t len, struct iatt *prebuf, struct iatt *postbuf)
{
- int ret = -1;
- bd_fd_t *bd_fd = NULL;
- bd_priv_t *priv = this->private;
- bd_attr_t *bdatt = NULL;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
- VALIDATE_OR_GOTO (priv, out);
-
- ret = bd_fd_ctx_get (this, fd, &bd_fd);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "bd_fd is NULL from fd=%p", fd);
- goto out;
- }
-
- bd_inode_ctx_get (fd->inode, this, &bdatt);
+ int ret = -1;
+ bd_fd_t *bd_fd = NULL;
+ bd_priv_t *priv = this->private;
+ bd_attr_t *bdatt = NULL;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+ VALIDATE_OR_GOTO(priv, out);
+
+ ret = bd_fd_ctx_get(this, fd, &bd_fd);
+ if (ret < 0) {
+ gf_log(this->name, GF_LOG_DEBUG, "bd_fd is NULL from fd=%p", fd);
+ goto out;
+ }
+
+ bd_inode_ctx_get(fd->inode, this, &bdatt);
#ifndef BLKZEROOUT
- ret = bd_do_manual_zerofill(bd_fd->fd, offset, len,
- bd_fd->flag & O_DIRECT);
+ ret = bd_do_manual_zerofill(bd_fd->fd, offset, len, bd_fd->flag & O_DIRECT);
#else
- ret = bd_do_ioctl_zerofill(priv, bdatt, bd_fd->fd, priv->vg, offset,
- len);
+ ret = bd_do_ioctl_zerofill(priv, bdatt, bd_fd->fd, priv->vg, offset, len);
#endif
+ if (ret) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "zerofill failed on fd %d length %zu %s", bd_fd->fd, len,
+ strerror(ret));
+ goto out;
+ }
+
+ if (bd_fd->flag & (O_SYNC | O_DSYNC)) {
+ ret = sys_fsync(bd_fd->fd);
if (ret) {
- gf_log(this->name, GF_LOG_ERROR,
- "zerofill failed on fd %d length %zu %s",
- bd_fd->fd, len, strerror (ret));
- goto out;
- }
-
- if (bd_fd->flag & (O_SYNC|O_DSYNC)) {
- ret = sys_fsync (bd_fd->fd);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "fsync() in writev on fd %d failed: %s",
- bd_fd->fd, strerror (errno));
- return errno;
- }
+ gf_log(this->name, GF_LOG_ERROR,
+ "fsync() in writev on fd %d failed: %s", bd_fd->fd,
+ strerror(errno));
+ return errno;
}
+ }
- memcpy (prebuf, &bdatt->iatt, sizeof (struct iatt));
- bd_update_amtime (&bdatt->iatt, GF_SET_ATTR_MTIME);
- memcpy (postbuf, &bdatt->iatt, sizeof (struct iatt));
+ memcpy(prebuf, &bdatt->iatt, sizeof(struct iatt));
+ bd_update_amtime(&bdatt->iatt, GF_SET_ATTR_MTIME);
+ memcpy(postbuf, &bdatt->iatt, sizeof(struct iatt));
out:
- return ret;
+ return ret;
}
diff --git a/xlators/storage/bd/src/bd.c b/xlators/storage/bd/src/bd.c
index ccb4219..c66ce93 100644
--- a/xlators/storage/bd/src/bd.c
+++ b/xlators/storage/bd/src/bd.c
@@ -42,206 +42,208 @@
* does not do anything. FIXME: How to handle remove/setxattr failure
*/
int
-bd_null_rmsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xdata)
+bd_null_rmsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, dict_t *xdata)
{
- STACK_DESTROY (frame->root);
- return 0;
+ STACK_DESTROY(frame->root);
+ return 0;
}
/*
* returns 0 if a file is mapped to BD or not.
*/
int
-bd_get_bd_info (call_frame_t *frame, xlator_t *this, dict_t *xattr, uuid_t gfid,
- char **type, uint64_t *size)
+bd_get_bd_info(call_frame_t *frame, xlator_t *this, dict_t *xattr, uuid_t gfid,
+ char **type, uint64_t *size)
{
- char *bd_xattr = NULL;
- char *bd = NULL;
- int ret = -1;
- loc_t loc = {0, };
- dict_t *dict = NULL;
- char *p = NULL;
- call_frame_t *bd_frame = NULL;
+ char *bd_xattr = NULL;
+ char *bd = NULL;
+ int ret = -1;
+ loc_t loc = {
+ 0,
+ };
+ dict_t *dict = NULL;
+ char *p = NULL;
+ call_frame_t *bd_frame = NULL;
- if (!xattr)
- return 1;
+ if (!xattr)
+ return 1;
- if (dict_get_str (xattr, BD_XATTR, &p))
- return 1;
+ if (dict_get_str(xattr, BD_XATTR, &p))
+ return 1;
- bd_xattr = gf_strdup (p);
+ bd_xattr = gf_strdup(p);
- memcpy (loc.gfid, gfid, sizeof (uuid_t));
+ memcpy(loc.gfid, gfid, sizeof(uuid_t));
- bd_frame = copy_frame (frame);
- BD_VALIDATE_MEM_ALLOC (bd_frame, ret, out);
+ bd_frame = copy_frame(frame);
+ BD_VALIDATE_MEM_ALLOC(bd_frame, ret, out);
- ret = bd_validate_bd_xattr (this, bd_xattr, type, size, gfid);
- if (ret < 0) {/* LV does not exist */
- STACK_WIND (bd_frame, bd_null_rmsetxattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->removexattr, &loc,
- BD_XATTR, NULL);
+ ret = bd_validate_bd_xattr(this, bd_xattr, type, size, gfid);
+ if (ret < 0) { /* LV does not exist */
+ STACK_WIND(bd_frame, bd_null_rmsetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr, &loc, BD_XATTR, NULL);
- gf_log (this->name, GF_LOG_WARNING,
- "Mapped LV not available for posix file <gfid:%s>, "
- "deleting mapping", uuid_utoa (gfid));
- } else if (ret == 1) {
- /* BD_XATTR size and LV size mismatch. Update BD_XATTR */
- gf_asprintf (&bd, "%s:%ld", *type, *size);
+ gf_log(this->name, GF_LOG_WARNING,
+ "Mapped LV not available for posix file <gfid:%s>, "
+ "deleting mapping",
+ uuid_utoa(gfid));
+ } else if (ret == 1) {
+ /* BD_XATTR size and LV size mismatch. Update BD_XATTR */
+ gf_asprintf(&bd, "%s:%ld", *type, *size);
- dict = dict_new ();
- BD_VALIDATE_MEM_ALLOC (dict, ret, out);
+ dict = dict_new();
+ BD_VALIDATE_MEM_ALLOC(dict, ret, out);
- ret = dict_set_dynstr (dict, BD_XATTR, bd);
- if (ret)
- goto out;
+ ret = dict_set_dynstr(dict, BD_XATTR, bd);
+ if (ret)
+ goto out;
- STACK_WIND (bd_frame, bd_null_rmsetxattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->setxattr, &loc, dict, 0,
- NULL);
- }
+ STACK_WIND(bd_frame, bd_null_rmsetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, &loc, dict, 0, NULL);
+ }
out:
- dict_del (xattr, BD_XATTR);
- GF_FREE (bd_xattr);
- GF_FREE (bd);
- return ret;
+ dict_del(xattr, BD_XATTR);
+ GF_FREE(bd_xattr);
+ GF_FREE(bd);
+ return ret;
}
/*
* bd_lookup_cbk: Call back from posix_lookup.
*/
int32_t
-bd_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
- int op_errno, inode_t *inode, struct iatt *buf, dict_t *xattr,
- struct iatt *postparent)
-{
- int ret = -1;
- bd_attr_t *bdatt = NULL;
- uint64_t size = 0;
- char *type = NULL;
-
- /* only regular files are part of BD object */
- if (op_ret < 0 || buf->ia_type != IA_IFREG)
- goto out;
-
- /* iatt already cached */
- if (!bd_inode_ctx_get (inode, this, &bdatt))
- goto next;
-
- if (bd_get_bd_info (frame, this, xattr, buf->ia_gfid, &type, &size))
- goto out;
-
- /* BD file, update buf */
- bdatt = GF_CALLOC (1, sizeof (bd_attr_t), gf_bd_attr);
- if (!bdatt) {
- op_errno = ENOMEM;
- goto out;
- }
- memcpy (&bdatt->iatt, buf, sizeof (struct iatt));
- bdatt->type = type;
-
- /* Cache LV size in inode_ctx */
- ret = bd_inode_ctx_set (inode, this, bdatt);
- if (ret < 0) {
- GF_FREE (bdatt);
- op_errno = EINVAL;
- goto out;
- }
-
- bdatt->iatt.ia_size = size;
- bdatt->iatt.ia_blocks = size / 512;
+bd_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, inode_t *inode, struct iatt *buf, dict_t *xattr,
+ struct iatt *postparent)
+{
+ int ret = -1;
+ bd_attr_t *bdatt = NULL;
+ uint64_t size = 0;
+ char *type = NULL;
+
+ /* only regular files are part of BD object */
+ if (op_ret < 0 || buf->ia_type != IA_IFREG)
+ goto out;
+
+ /* iatt already cached */
+ if (!bd_inode_ctx_get(inode, this, &bdatt))
+ goto next;
+
+ if (bd_get_bd_info(frame, this, xattr, buf->ia_gfid, &type, &size))
+ goto out;
+
+ /* BD file, update buf */
+ bdatt = GF_CALLOC(1, sizeof(bd_attr_t), gf_bd_attr);
+ if (!bdatt) {
+ op_errno = ENOMEM;
+ goto out;
+ }
+ memcpy(&bdatt->iatt, buf, sizeof(struct iatt));
+ bdatt->type = type;
+
+ /* Cache LV size in inode_ctx */
+ ret = bd_inode_ctx_set(inode, this, bdatt);
+ if (ret < 0) {
+ GF_FREE(bdatt);
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ bdatt->iatt.ia_size = size;
+ bdatt->iatt.ia_blocks = size / 512;
next:
- dict_del (xattr, GF_CONTENT_KEY);
- memcpy (buf, &bdatt->iatt, sizeof (struct iatt));
+ dict_del(xattr, GF_CONTENT_KEY);
+ memcpy(buf, &bdatt->iatt, sizeof(struct iatt));
out:
- BD_STACK_UNWIND (lookup, frame, op_ret, op_errno, inode, buf,
- xattr, postparent);
- return 0;
+ BD_STACK_UNWIND(lookup, frame, op_ret, op_errno, inode, buf, xattr,
+ postparent);
+ return 0;
}
/*
* bd_lookup: Issues posix_lookup to find out if file is mapped to BD
* bd_lookup -> posix_lookup -> bd_lookup_cbk
-*/
+ */
int32_t
-bd_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req)
-{
- dict_t *bd_xattr = NULL;
- bd_attr_t *bdatt = NULL;
- int op_errno = EINVAL;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (loc, out);
- VALIDATE_OR_GOTO (loc->path, out);
- VALIDATE_OR_GOTO (this->private, out);
-
- if (bd_inode_ctx_get (loc->inode, this, &bdatt) < 0) {
- if (!xattr_req) {
- bd_xattr = dict_new ();
- BD_VALIDATE_MEM_ALLOC (bd_xattr, op_errno, out);
- xattr_req = bd_xattr;
- }
- if (dict_set_int8 (xattr_req, BD_XATTR, 1) < 0)
- goto out;
+bd_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req)
+{
+ dict_t *bd_xattr = NULL;
+ bd_attr_t *bdatt = NULL;
+ int op_errno = EINVAL;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(loc, out);
+ VALIDATE_OR_GOTO(loc->path, out);
+ VALIDATE_OR_GOTO(this->private, out);
+
+ if (bd_inode_ctx_get(loc->inode, this, &bdatt) < 0) {
+ if (!xattr_req) {
+ bd_xattr = dict_new();
+ BD_VALIDATE_MEM_ALLOC(bd_xattr, op_errno, out);
+ xattr_req = bd_xattr;
}
+ if (dict_set_int8(xattr_req, BD_XATTR, 1) < 0)
+ goto out;
+ }
- STACK_WIND (frame, bd_lookup_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->lookup, loc, xattr_req);
+ STACK_WIND(frame, bd_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, loc, xattr_req);
- if (bd_xattr)
- dict_unref (bd_xattr);
- return 0;
+ if (bd_xattr)
+ dict_unref(bd_xattr);
+ return 0;
out:
- BD_STACK_UNWIND (lookup, frame, -1, op_errno, NULL, NULL, NULL, NULL);
+ BD_STACK_UNWIND(lookup, frame, -1, op_errno, NULL, NULL, NULL, NULL);
- return 0;
+ return 0;
}
int
-bd_forget (xlator_t *this, inode_t *inode)
+bd_forget(xlator_t *this, inode_t *inode)
{
- int ret = -1;
- uint64_t ctx = 0;
- bd_attr_t *bdatt = NULL;
+ int ret = -1;
+ uint64_t ctx = 0;
+ bd_attr_t *bdatt = NULL;
- ret = bd_inode_ctx_get (inode, this, &bdatt);
- if (!ret) {
- inode_ctx_del (inode, this, &ctx);
- GF_FREE (bdatt);
- }
- return 0;
+ ret = bd_inode_ctx_get(inode, this, &bdatt);
+ if (!ret) {
+ inode_ctx_del(inode, this, &ctx);
+ GF_FREE(bdatt);
+ }
+ return 0;
}
int
-bd_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
- int op_errno, gf_dirent_t *entries, dict_t *xdata)
-{
- gf_dirent_t *entry = NULL;
- uint64_t size = 0;
- char *type = NULL;
-
- if (op_ret < 0)
- goto out;
-
- list_for_each_entry (entry, &entries->list, list) {
- if (entry->d_type != DT_REG)
- continue;
- if (!bd_get_bd_info (frame, this, entry->dict,
- entry->d_stat.ia_gfid, &type, &size)) {
- entry->d_stat.ia_size = size;
- entry->d_stat.ia_blocks = size / 512;
- GF_FREE (type);
- }
+bd_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, gf_dirent_t *entries, dict_t *xdata)
+{
+ gf_dirent_t *entry = NULL;
+ uint64_t size = 0;
+ char *type = NULL;
+
+ if (op_ret < 0)
+ goto out;
+
+ list_for_each_entry(entry, &entries->list, list)
+ {
+ if (entry->d_type != DT_REG)
+ continue;
+ if (!bd_get_bd_info(frame, this, entry->dict, entry->d_stat.ia_gfid,
+ &type, &size)) {
+ entry->d_stat.ia_size = size;
+ entry->d_stat.ia_blocks = size / 512;
+ GF_FREE(type);
}
+ }
out:
- BD_STACK_UNWIND (readdirp, frame, op_ret, op_errno, entries, xdata);
- return 0;
+ BD_STACK_UNWIND(readdirp, frame, op_ret, op_errno, entries, xdata);
+ return 0;
}
/*
@@ -249,198 +251,196 @@ out:
* ia_size is updated with the LV(BD_XATTR_SIZE) size
*/
int32_t
-bd_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
- off_t off, dict_t *dict)
-{
- int op_errno = EINVAL;
- bd_local_t *local = NULL;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
- VALIDATE_OR_GOTO (this->private, out);
-
- if (!dict) {
- local = bd_local_init (frame, this);
- BD_VALIDATE_MEM_ALLOC (local, op_errno, out);
- local->dict = dict_new ();
- BD_VALIDATE_MEM_ALLOC (local->dict, op_errno, out);
- dict = local->dict;
- }
-
- if (dict_set_int8 (dict, BD_XATTR, 0)) {
- gf_log (this->name, GF_LOG_WARNING,
- "failed to set key %s", BD_XATTR);
- goto out;
- }
-
- STACK_WIND (frame, bd_readdirp_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->readdirp, fd, size, off, dict);
-
- return 0;
+bd_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t off, dict_t *dict)
+{
+ int op_errno = EINVAL;
+ bd_local_t *local = NULL;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+ VALIDATE_OR_GOTO(this->private, out);
+
+ if (!dict) {
+ local = bd_local_init(frame, this);
+ BD_VALIDATE_MEM_ALLOC(local, op_errno, out);
+ local->dict = dict_new();
+ BD_VALIDATE_MEM_ALLOC(local->dict, op_errno, out);
+ dict = local->dict;
+ }
+
+ if (dict_set_int8(dict, BD_XATTR, 0)) {
+ gf_log(this->name, GF_LOG_WARNING, "failed to set key %s", BD_XATTR);
+ goto out;
+ }
+
+ STACK_WIND(frame, bd_readdirp_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readdirp, fd, size, off, dict);
+
+ return 0;
out:
- BD_STACK_UNWIND (readdirp, frame, -1, op_errno, NULL, dict);
- return 0;
+ BD_STACK_UNWIND(readdirp, frame, -1, op_errno, NULL, dict);
+ return 0;
}
int
-bd_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
- int op_errno, struct iatt *buf, dict_t *xdata)
+bd_stat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct iatt *buf, dict_t *xdata)
{
- bd_local_t *local = frame->local;
- bd_attr_t *bdatt = NULL;
+ bd_local_t *local = frame->local;
+ bd_attr_t *bdatt = NULL;
- /* only regular files are part of BD object */
- if (op_ret < 0 || buf->ia_type != IA_IFREG)
- goto out;
+ /* only regular files are part of BD object */
+ if (op_ret < 0 || buf->ia_type != IA_IFREG)
+ goto out;
- BD_VALIDATE_LOCAL_OR_GOTO (local, op_errno, out);
+ BD_VALIDATE_LOCAL_OR_GOTO(local, op_errno, out);
- /* update buf with LV size */
- if (!bd_inode_ctx_get (local->inode, this, &bdatt))
- memcpy (buf, bdatt, sizeof (struct iatt));
+ /* update buf with LV size */
+ if (!bd_inode_ctx_get(local->inode, this, &bdatt))
+ memcpy(buf, bdatt, sizeof(struct iatt));
out:
- BD_STACK_UNWIND (stat, frame, op_ret, op_errno, buf, xdata);
- return 0;
+ BD_STACK_UNWIND(stat, frame, op_ret, op_errno, buf, xdata);
+ return 0;
}
int
-bd_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
+bd_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- int op_errno = EINVAL;
- bd_local_t *local = NULL;
- bd_attr_t *bdatt = NULL;
+ int op_errno = EINVAL;
+ bd_local_t *local = NULL;
+ bd_attr_t *bdatt = NULL;
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (loc, out);
- VALIDATE_OR_GOTO (loc->path, out);
- VALIDATE_OR_GOTO (this->private, out);
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(loc, out);
+ VALIDATE_OR_GOTO(loc->path, out);
+ VALIDATE_OR_GOTO(this->private, out);
- if (!bd_inode_ctx_get (loc->inode, this, &bdatt)) {
- BD_STACK_UNWIND (stat, frame, 0, 0, &bdatt->iatt, xdata);
- return 0;
- }
+ if (!bd_inode_ctx_get(loc->inode, this, &bdatt)) {
+ BD_STACK_UNWIND(stat, frame, 0, 0, &bdatt->iatt, xdata);
+ return 0;
+ }
- local = bd_local_init (frame, this);
- BD_VALIDATE_MEM_ALLOC (local, op_errno, out);
- local->inode = inode_ref (loc->inode);
+ local = bd_local_init(frame, this);
+ BD_VALIDATE_MEM_ALLOC(local, op_errno, out);
+ local->inode = inode_ref(loc->inode);
- STACK_WIND(frame, bd_stat_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->stat, loc, xdata);
- return 0;
+ STACK_WIND(frame, bd_stat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->stat, loc, xdata);
+ return 0;
out:
- BD_STACK_UNWIND (stat, frame, -1, op_errno, NULL, xdata);
- return 0;
+ BD_STACK_UNWIND(stat, frame, -1, op_errno, NULL, xdata);
+ return 0;
}
int
-bd_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
- int op_errno, struct statvfs *buff, dict_t *xdata)
-{
- uint64_t size = 0;
- uint64_t fr_size = 0;
- bd_priv_t *priv = NULL;
- vg_t vg = NULL;
-
- if (op_ret < 0)
- goto out;
-
- priv = this->private;
-
- vg = lvm_vg_open (priv->handle, priv->vg, "r", 0);
- if (!vg) {
- gf_log (this->name, GF_LOG_WARNING, "opening VG %s failed",
- priv->vg);
- op_ret = -1;
- op_errno = EAGAIN;
- goto out;
- }
- size = lvm_vg_get_size (vg);
- fr_size = lvm_vg_get_free_size (vg);
- lvm_vg_close (vg);
-
- buff->f_blocks += size / buff->f_frsize;
- buff->f_bfree += fr_size / buff->f_frsize;
- buff->f_bavail += fr_size / buff->f_frsize;
+bd_statfs_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct statvfs *buff, dict_t *xdata)
+{
+ uint64_t size = 0;
+ uint64_t fr_size = 0;
+ bd_priv_t *priv = NULL;
+ vg_t vg = NULL;
+
+ if (op_ret < 0)
+ goto out;
+
+ priv = this->private;
+
+ vg = lvm_vg_open(priv->handle, priv->vg, "r", 0);
+ if (!vg) {
+ gf_log(this->name, GF_LOG_WARNING, "opening VG %s failed", priv->vg);
+ op_ret = -1;
+ op_errno = EAGAIN;
+ goto out;
+ }
+ size = lvm_vg_get_size(vg);
+ fr_size = lvm_vg_get_free_size(vg);
+ lvm_vg_close(vg);
+
+ buff->f_blocks += size / buff->f_frsize;
+ buff->f_bfree += fr_size / buff->f_frsize;
+ buff->f_bavail += fr_size / buff->f_frsize;
out:
- BD_STACK_UNWIND (statfs, frame, op_ret, op_errno, buff, xdata);
- return 0;
+ BD_STACK_UNWIND(statfs, frame, op_ret, op_errno, buff, xdata);
+ return 0;
}
/*
* bd_statfs: Mimics statfs by returning used/free extents in the VG
*/
int
-bd_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
+bd_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (this->private, out);
- VALIDATE_OR_GOTO (loc, out);
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(this->private, out);
+ VALIDATE_OR_GOTO(loc, out);
- STACK_WIND (frame, bd_statfs_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->statfs, loc, xdata);
- return 0;
+ STACK_WIND(frame, bd_statfs_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->statfs, loc, xdata);
+ return 0;
out:
- BD_STACK_UNWIND (statfs, frame, -1, EINVAL, NULL, NULL);
- return 0;
+ BD_STACK_UNWIND(statfs, frame, -1, EINVAL, NULL, NULL);
+ return 0;
}
int
-bd_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
- int op_errno, struct iatt *buf, dict_t *xdata)
+bd_fstat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct iatt *buf, dict_t *xdata)
{
- bd_attr_t *bdatt = NULL;
- bd_local_t *local = frame->local;
+ bd_attr_t *bdatt = NULL;
+ bd_local_t *local = frame->local;
- /* only regular files are part of BD object */
- if (op_ret < 0 || buf->ia_type != IA_IFREG)
- goto out;
+ /* only regular files are part of BD object */
+ if (op_ret < 0 || buf->ia_type != IA_IFREG)
+ goto out;
- BD_VALIDATE_LOCAL_OR_GOTO (local, op_errno, out);
+ BD_VALIDATE_LOCAL_OR_GOTO(local, op_errno, out);
- /* update buf with LV size */
- if (!bd_inode_ctx_get (local->inode, this, &bdatt))
- memcpy (buf, &bdatt->iatt, sizeof (struct iatt));
+ /* update buf with LV size */
+ if (!bd_inode_ctx_get(local->inode, this, &bdatt))
+ memcpy(buf, &bdatt->iatt, sizeof(struct iatt));
out:
- BD_STACK_UNWIND (fstat, frame, op_ret, op_errno, buf, xdata);
- return 0;
+ BD_STACK_UNWIND(fstat, frame, op_ret, op_errno, buf, xdata);
+ return 0;
}
int
-bd_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
+bd_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
{
- int op_errno = EINVAL;
- bd_local_t *local = NULL;
- bd_attr_t *bdatt = NULL;
+ int op_errno = EINVAL;
+ bd_local_t *local = NULL;
+ bd_attr_t *bdatt = NULL;
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
- VALIDATE_OR_GOTO (this->private, out);
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+ VALIDATE_OR_GOTO(this->private, out);
- /* if its already cached return it */
- if (!bd_inode_ctx_get (fd->inode, this, &bdatt)) {
- BD_STACK_UNWIND (fstat, frame, 0, 0, &bdatt->iatt, xdata);
- return 0;
- }
+ /* if its already cached return it */
+ if (!bd_inode_ctx_get(fd->inode, this, &bdatt)) {
+ BD_STACK_UNWIND(fstat, frame, 0, 0, &bdatt->iatt, xdata);
+ return 0;
+ }
- local = bd_local_init (frame, this);
- BD_VALIDATE_MEM_ALLOC (local, op_errno, out);
+ local = bd_local_init(frame, this);
+ BD_VALIDATE_MEM_ALLOC(local, op_errno, out);
- local->inode = inode_ref (fd->inode);
+ local->inode = inode_ref(fd->inode);
- STACK_WIND (frame, bd_fstat_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fstat, fd, xdata);
+ STACK_WIND(frame, bd_fstat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, fd, xdata);
- return 0;
+ return 0;
out:
- BD_STACK_UNWIND (fstat, frame, -1, op_errno, NULL, xdata);
- return 0;
+ BD_STACK_UNWIND(fstat, frame, -1, op_errno, NULL, xdata);
+ return 0;
}
/*
@@ -448,80 +448,81 @@ out:
* file
*/
int
-bd_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
- off_t offset, uint32_t flags, dict_t *xdata)
-{
- int ret = -1;
- int _fd = -1;
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- bd_fd_t *bd_fd = NULL;
- struct iovec vec = {0, };
- struct iobuf *iobuf = NULL;
- struct iobref *iobref = NULL;
- uint64_t bd_size = 0;
- bd_attr_t *bdatt = NULL;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
- VALIDATE_OR_GOTO (this->private, out);
-
- ret = bd_fd_ctx_get (this, fd, &bd_fd);
- if (ret < 0 || !bd_fd) {
- STACK_WIND (frame, default_readv_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->readv,
- fd, size, offset, flags, xdata);
- return 0;
- }
- if (!size) {
- op_errno = EINVAL;
- gf_log (this->name, GF_LOG_WARNING, "size=%"GF_PRI_SIZET, size);
- goto out;
- }
- iobuf = iobuf_get2 (this->ctx->iobuf_pool, size);
- if (!iobuf) {
- op_errno = ENOMEM;
- goto out;
- }
- _fd = bd_fd->fd;
- op_ret = sys_pread (_fd, iobuf->ptr, size, offset);
- if (op_ret == -1) {
- op_errno = errno;
- gf_log (this->name, GF_LOG_ERROR,
- "read failed on fd=%p: %s", fd,
- strerror (op_errno));
- goto out;
- }
-
- vec.iov_base = iobuf->ptr;
- vec.iov_len = op_ret;
-
- iobref = iobref_new ();
- iobref_add (iobref, iobuf);
-
- if (bd_inode_ctx_get (fd->inode, this, &bdatt)) {
- op_errno = EINVAL;
- op_ret = -1;
- goto out;
- }
- bd_size = bdatt->iatt.ia_size;
- if (!bd_size || (offset + vec.iov_len) >= bd_size)
- op_errno = ENOENT;
-
- op_ret = vec.iov_len;
- bd_update_amtime (&bdatt->iatt, GF_SET_ATTR_ATIME);
+bd_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset, uint32_t flags, dict_t *xdata)
+{
+ int ret = -1;
+ int _fd = -1;
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ bd_fd_t *bd_fd = NULL;
+ struct iovec vec = {
+ 0,
+ };
+ struct iobuf *iobuf = NULL;
+ struct iobref *iobref = NULL;
+ uint64_t bd_size = 0;
+ bd_attr_t *bdatt = NULL;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+ VALIDATE_OR_GOTO(this->private, out);
+
+ ret = bd_fd_ctx_get(this, fd, &bd_fd);
+ if (ret < 0 || !bd_fd) {
+ STACK_WIND(frame, default_readv_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readv, fd, size, offset, flags,
+ xdata);
+ return 0;
+ }
+ if (!size) {
+ op_errno = EINVAL;
+ gf_log(this->name, GF_LOG_WARNING, "size=%" GF_PRI_SIZET, size);
+ goto out;
+ }
+ iobuf = iobuf_get2(this->ctx->iobuf_pool, size);
+ if (!iobuf) {
+ op_errno = ENOMEM;
+ goto out;
+ }
+ _fd = bd_fd->fd;
+ op_ret = sys_pread(_fd, iobuf->ptr, size, offset);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_log(this->name, GF_LOG_ERROR, "read failed on fd=%p: %s", fd,
+ strerror(op_errno));
+ goto out;
+ }
+
+ vec.iov_base = iobuf->ptr;
+ vec.iov_len = op_ret;
+
+ iobref = iobref_new();
+ iobref_add(iobref, iobuf);
+
+ if (bd_inode_ctx_get(fd->inode, this, &bdatt)) {
+ op_errno = EINVAL;
+ op_ret = -1;
+ goto out;
+ }
+ bd_size = bdatt->iatt.ia_size;
+ if (!bd_size || (offset + vec.iov_len) >= bd_size)
+ op_errno = ENOENT;
+
+ op_ret = vec.iov_len;
+ bd_update_amtime(&bdatt->iatt, GF_SET_ATTR_ATIME);
out:
- BD_STACK_UNWIND (readv, frame, op_ret, op_errno,
- &vec, 1, &bdatt->iatt, iobref, NULL);
+ BD_STACK_UNWIND(readv, frame, op_ret, op_errno, &vec, 1, &bdatt->iatt,
+ iobref, NULL);
- if (iobref)
- iobref_unref (iobref);
- if (iobuf)
- iobuf_unref (iobuf);
+ if (iobref)
+ iobref_unref(iobref);
+ if (iobuf)
+ iobuf_unref(iobuf);
- return 0;
+ return 0;
}
#ifdef BLKDISCARD
@@ -529,64 +530,67 @@ out:
* bd_discard: Sends BLKDISCARD ioctl to the block device
*/
int
-bd_discard (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
- size_t len, dict_t *xdata)
-{
- int ret = -1;
- int op_errno = EINVAL;
- bd_fd_t *bd_fd = NULL;
- uint64_t param[2] = {0, };
- bd_attr_t *bdatt = NULL;
- struct iatt prebuf = {0, };
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (this->private, out);
- VALIDATE_OR_GOTO (fd, out);
-
- /* posix */
- if (bd_inode_ctx_get (fd->inode, this, &bdatt)) {
- STACK_WIND (frame, default_discard_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->discard,
- fd, offset, len, xdata);
- return 0;
- }
-
- ret = bd_fd_ctx_get (this, fd, &bd_fd);
- if (ret < 0 || !bd_fd) {
- op_errno = EINVAL;
- goto out;
- }
-
- param[0] = offset;
- param[1] = len;
- ret = ioctl (bd_fd->fd, BLKDISCARD, param);
- if (ret < 0) {
- if (errno == ENOTTY)
- op_errno = ENOSYS;
- else
- op_errno = errno;
- goto out;
- }
- memcpy (&prebuf, &bdatt->iatt, sizeof (prebuf));
- bd_update_amtime (&bdatt->iatt, GF_SET_ATTR_MTIME);
+bd_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ size_t len, dict_t *xdata)
+{
+ int ret = -1;
+ int op_errno = EINVAL;
+ bd_fd_t *bd_fd = NULL;
+ uint64_t param[2] = {
+ 0,
+ };
+ bd_attr_t *bdatt = NULL;
+ struct iatt prebuf = {
+ 0,
+ };
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(this->private, out);
+ VALIDATE_OR_GOTO(fd, out);
+
+ /* posix */
+ if (bd_inode_ctx_get(fd->inode, this, &bdatt)) {
+ STACK_WIND(frame, default_discard_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->discard, fd, offset, len, xdata);
+ return 0;
+ }
+
+ ret = bd_fd_ctx_get(this, fd, &bd_fd);
+ if (ret < 0 || !bd_fd) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ param[0] = offset;
+ param[1] = len;
+ ret = ioctl(bd_fd->fd, BLKDISCARD, param);
+ if (ret < 0) {
+ if (errno == ENOTTY)
+ op_errno = ENOSYS;
+ else
+ op_errno = errno;
+ goto out;
+ }
+ memcpy(&prebuf, &bdatt->iatt, sizeof(prebuf));
+ bd_update_amtime(&bdatt->iatt, GF_SET_ATTR_MTIME);
- BD_STACK_UNWIND (discard, frame, ret, op_errno, &prebuf,
- &bdatt->iatt, xdata);
- return 0;
+ BD_STACK_UNWIND(discard, frame, ret, op_errno, &prebuf, &bdatt->iatt,
+ xdata);
+ return 0;
out:
- BD_STACK_UNWIND (discard, frame, -1, op_errno, NULL, NULL, NULL);
- return 0;
+ BD_STACK_UNWIND(discard, frame, -1, op_errno, NULL, NULL, NULL);
+ return 0;
}
#else
int
-bd_discard (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
- size_t len, dict_t *xdata)
+bd_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ size_t len, dict_t *xdata)
{
- BD_STACK_UNWIND (discard, frame, -1, ENOSYS, NULL, NULL, NULL);
- return 0;
+ BD_STACK_UNWIND(discard, frame, -1, ENOSYS, NULL, NULL, NULL);
+ return 0;
}
#endif
@@ -595,32 +599,31 @@ bd_discard (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
* If it failed, close BD fd
*/
int
-bd_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, fd_t *fd, dict_t *xdata)
+bd_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, fd_t *fd, dict_t *xdata)
{
- bd_fd_t *bd_fd = NULL;
- bd_attr_t *bdatt = NULL;
+ bd_fd_t *bd_fd = NULL;
+ bd_attr_t *bdatt = NULL;
- if (!op_ret)
- goto out;
+ if (!op_ret)
+ goto out;
- bd_inode_ctx_get (fd->inode, this, &bdatt);
- if (!bdatt) /* posix file */
- goto out;
+ bd_inode_ctx_get(fd->inode, this, &bdatt);
+ if (!bdatt) /* posix file */
+ goto out;
- /* posix open failed */
- if (bd_fd_ctx_get (this, fd, &bd_fd) < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "bd_fd is NULL from fd=%p", fd);
- goto out;
- }
- sys_close (bd_fd->fd);
- GF_FREE (bd_fd);
+ /* posix open failed */
+ if (bd_fd_ctx_get(this, fd, &bd_fd) < 0) {
+ gf_log(this->name, GF_LOG_WARNING, "bd_fd is NULL from fd=%p", fd);
+ goto out;
+ }
+ sys_close(bd_fd->fd);
+ GF_FREE(bd_fd);
out:
- BD_STACK_UNWIND (open, frame, op_ret, op_errno, fd, NULL);
+ BD_STACK_UNWIND(open, frame, op_ret, op_errno, fd, NULL);
- return 0;
+ return 0;
}
/*
@@ -629,270 +632,270 @@ out:
* fd contains both posix and BD fd
*/
int32_t
-bd_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
- fd_t *fd, dict_t *xdata)
-{
- int32_t ret = EINVAL;
- bd_fd_t *bd_fd = NULL;
- bd_attr_t *bdatt = NULL;
- bd_gfid_t gfid = {0, };
- char *devpath = NULL;
- bd_priv_t *priv = this->private;
- int _fd = -1;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (this->private, out);
- VALIDATE_OR_GOTO (loc, out);
- VALIDATE_OR_GOTO (fd, out);
-
- /* not bd file */
- if (fd->inode->ia_type != IA_IFREG ||
- bd_inode_ctx_get (fd->inode, this, &bdatt))
- goto posix;
-
- uuid_utoa_r (fd->inode->gfid, gfid);
- gf_asprintf (&devpath, "/dev/%s/%s", priv->vg, gfid);
- BD_VALIDATE_MEM_ALLOC (devpath, ret, out);
-
- _fd = open (devpath, flags | O_LARGEFILE, 0);
- if (_fd < 0) {
- ret = errno;
- gf_log (this->name, GF_LOG_ERROR, "open on %s: %s", devpath,
- strerror (ret));
- goto out;
- }
- bd_fd = GF_CALLOC (1, sizeof(bd_fd_t), gf_bd_fd);
- BD_VALIDATE_MEM_ALLOC (bd_fd, ret, out);
-
- bd_fd->fd = _fd;
- bd_fd->flag = flags | O_LARGEFILE;
-
- if (fd_ctx_set (fd, this, (uint64_t)(long)bd_fd) < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "failed to set the fd context fd=%p", fd);
- goto out;
- }
-
- ret = 0;
+bd_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
+ fd_t *fd, dict_t *xdata)
+{
+ int32_t ret = EINVAL;
+ bd_fd_t *bd_fd = NULL;
+ bd_attr_t *bdatt = NULL;
+ bd_gfid_t gfid = {
+ 0,
+ };
+ char *devpath = NULL;
+ bd_priv_t *priv = this->private;
+ int _fd = -1;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(this->private, out);
+ VALIDATE_OR_GOTO(loc, out);
+ VALIDATE_OR_GOTO(fd, out);
+
+ /* not bd file */
+ if (fd->inode->ia_type != IA_IFREG ||
+ bd_inode_ctx_get(fd->inode, this, &bdatt))
+ goto posix;
+
+ uuid_utoa_r(fd->inode->gfid, gfid);
+ gf_asprintf(&devpath, "/dev/%s/%s", priv->vg, gfid);
+ BD_VALIDATE_MEM_ALLOC(devpath, ret, out);
+
+ _fd = open(devpath, flags | O_LARGEFILE, 0);
+ if (_fd < 0) {
+ ret = errno;
+ gf_log(this->name, GF_LOG_ERROR, "open on %s: %s", devpath,
+ strerror(ret));
+ goto out;
+ }
+ bd_fd = GF_CALLOC(1, sizeof(bd_fd_t), gf_bd_fd);
+ BD_VALIDATE_MEM_ALLOC(bd_fd, ret, out);
+
+ bd_fd->fd = _fd;
+ bd_fd->flag = flags | O_LARGEFILE;
+
+ if (fd_ctx_set(fd, this, (uint64_t)(long)bd_fd) < 0) {
+ gf_log(this->name, GF_LOG_WARNING, "failed to set the fd context fd=%p",
+ fd);
+ goto out;
+ }
+
+ ret = 0;
posix:
- /* open posix equivalent of this file, fd needed for fd related
- operations like fsetxattr, ftruncate etc */
- STACK_WIND (frame, bd_open_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata);
+ /* open posix equivalent of this file, fd needed for fd related
+ operations like fsetxattr, ftruncate etc */
+ STACK_WIND(frame, bd_open_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata);
- GF_FREE (devpath);
- return 0;
+ GF_FREE(devpath);
+ return 0;
out:
- BD_STACK_UNWIND (open, frame, -1, ret, fd, NULL);
+ BD_STACK_UNWIND(open, frame, -1, ret, fd, NULL);
- GF_FREE (devpath);
- if (ret) {
- if (_fd >= 0)
- sys_close (_fd);
- GF_FREE (bd_fd);
- }
+ GF_FREE(devpath);
+ if (ret) {
+ if (_fd >= 0)
+ sys_close(_fd);
+ GF_FREE(bd_fd);
+ }
- return 0;
+ return 0;
}
/*
* call back from posix_setattr after updating iatt to posix file.
*/
int
-bd_fsync_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, struct iatt *pre,
- struct iatt *post, dict_t *xdata)
+bd_fsync_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, struct iatt *pre,
+ struct iatt *post, dict_t *xdata)
{
- bd_local_t *local = frame->local;
- bd_attr_t *bdatt = local->bdatt;
+ bd_local_t *local = frame->local;
+ bd_attr_t *bdatt = local->bdatt;
- BD_STACK_UNWIND (fsync, frame, op_ret, op_errno, &bdatt->iatt,
- &bdatt->iatt, NULL);
- return 0;
+ BD_STACK_UNWIND(fsync, frame, op_ret, op_errno, &bdatt->iatt, &bdatt->iatt,
+ NULL);
+ return 0;
}
int
-bd_do_fsync (int fd, int datasync)
+bd_do_fsync(int fd, int datasync)
{
- int op_errno = 0;
+ int op_errno = 0;
- if (datasync) {
- if (sys_fdatasync (fd)) {
- op_errno = errno;
- gf_log (THIS->name, GF_LOG_ERROR,
- "fdatasync on fd=%d failed: %s",
- fd, strerror (errno));
- }
+ if (datasync) {
+ if (sys_fdatasync(fd)) {
+ op_errno = errno;
+ gf_log(THIS->name, GF_LOG_ERROR, "fdatasync on fd=%d failed: %s",
+ fd, strerror(errno));
+ }
- } else
+ } else
- {
- if (sys_fsync (fd)) {
- op_errno = errno;
- gf_log (THIS->name, GF_LOG_ERROR,
- "fsync on fd=%d failed: %s",
- fd, strerror (op_errno));
- }
+ {
+ if (sys_fsync(fd)) {
+ op_errno = errno;
+ gf_log(THIS->name, GF_LOG_ERROR, "fsync on fd=%d failed: %s", fd,
+ strerror(op_errno));
}
+ }
- return op_errno;
+ return op_errno;
}
/*
* bd_fsync: Syncs if BD fd, forwards the request to posix
* fsync -> posix_setattr -> posix_fsync
-*/
+ */
int32_t
-bd_fsync (call_frame_t *frame, xlator_t *this,
- fd_t *fd, int32_t datasync, dict_t *xdata)
-{
- int ret = -1;
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- bd_fd_t *bd_fd = NULL;
- bd_attr_t *bdatt = NULL;
- bd_local_t *local = NULL;
- int valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME;
- struct iatt prebuf = {0, };
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
- VALIDATE_OR_GOTO (this->private, out);
-
- ret = bd_inode_ctx_get (fd->inode, this, &bdatt);
- ret = bd_fd_ctx_get (this, fd, &bd_fd);
- if (ret < 0 || !bd_fd || !bdatt) {
- STACK_WIND (frame, default_fsync_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->fsync, fd, datasync,
- xdata);
- return 0;
- }
-
- memcpy (&prebuf, &bdatt->iatt, sizeof (struct iatt));
-
- op_errno = bd_do_fsync (bd_fd->fd, datasync);
- if (op_errno)
- goto out;
-
- /* For BD, Update the a|mtime during full fsync only */
- if (!datasync) {
- local = bd_local_init (frame, this);
- /* In case of mem failure, should posix flush called ? */
- BD_VALIDATE_MEM_ALLOC (local, op_errno, out);
-
- local->bdatt = GF_CALLOC (1, sizeof (bd_attr_t), gf_bd_attr);
- BD_VALIDATE_MEM_ALLOC (local->bdatt, op_errno, out);
-
- local->bdatt->type = gf_strdup (bdatt->type);
- memcpy (&local->bdatt->iatt, &bdatt->iatt, sizeof (struct iatt));
- bd_update_amtime (&local->bdatt->iatt, valid);
- gf_uuid_copy (local->loc.gfid, fd->inode->gfid);
- STACK_WIND (frame, bd_fsync_setattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->setattr, &local->loc,
- &local->bdatt->iatt,
- valid, NULL);
- return 0;
- }
+bd_fsync(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t datasync,
+ dict_t *xdata)
+{
+ int ret = -1;
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ bd_fd_t *bd_fd = NULL;
+ bd_attr_t *bdatt = NULL;
+ bd_local_t *local = NULL;
+ int valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME;
+ struct iatt prebuf = {
+ 0,
+ };
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+ VALIDATE_OR_GOTO(this->private, out);
+
+ ret = bd_inode_ctx_get(fd->inode, this, &bdatt);
+ ret = bd_fd_ctx_get(this, fd, &bd_fd);
+ if (ret < 0 || !bd_fd || !bdatt) {
+ STACK_WIND(frame, default_fsync_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsync, fd, datasync, xdata);
+ return 0;
+ }
+
+ memcpy(&prebuf, &bdatt->iatt, sizeof(struct iatt));
+
+ op_errno = bd_do_fsync(bd_fd->fd, datasync);
+ if (op_errno)
+ goto out;
+
+ /* For BD, Update the a|mtime during full fsync only */
+ if (!datasync) {
+ local = bd_local_init(frame, this);
+ /* In case of mem failure, should posix flush called ? */
+ BD_VALIDATE_MEM_ALLOC(local, op_errno, out);
+
+ local->bdatt = GF_CALLOC(1, sizeof(bd_attr_t), gf_bd_attr);
+ BD_VALIDATE_MEM_ALLOC(local->bdatt, op_errno, out);
+
+ local->bdatt->type = gf_strdup(bdatt->type);
+ memcpy(&local->bdatt->iatt, &bdatt->iatt, sizeof(struct iatt));
+ bd_update_amtime(&local->bdatt->iatt, valid);
+ gf_uuid_copy(local->loc.gfid, fd->inode->gfid);
+ STACK_WIND(frame, bd_fsync_setattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setattr, &local->loc,
+ &local->bdatt->iatt, valid, NULL);
+ return 0;
+ }
out:
- BD_STACK_UNWIND (fsync, frame, op_ret, op_errno, &prebuf,
- &bdatt->iatt, NULL);
- return 0;
+ BD_STACK_UNWIND(fsync, frame, op_ret, op_errno, &prebuf, &bdatt->iatt,
+ NULL);
+ return 0;
}
int
-bd_flush_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, struct iatt *pre,
- struct iatt *post, dict_t *xdata)
+bd_flush_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, struct iatt *pre,
+ struct iatt *post, dict_t *xdata)
{
- BD_STACK_UNWIND (flush, frame, op_ret, op_errno, xdata);
- return 0;
+ BD_STACK_UNWIND(flush, frame, op_ret, op_errno, xdata);
+ return 0;
}
int
-bd_flush (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
-{
- int ret = -1;
- bd_fd_t *bd_fd = NULL;
- bd_attr_t *bdatt = NULL;
- int valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME;
- bd_local_t *local = NULL;
- loc_t loc = {0, };
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
- VALIDATE_OR_GOTO (this->private, out);
-
- ret = bd_inode_ctx_get (fd->inode, this, &bdatt);
- if (!bdatt)
- goto out;
-
- ret = bd_fd_ctx_get (this, fd, &bd_fd);
- if (ret < 0 || !bd_fd || !bdatt) {
- gf_log (this->name, GF_LOG_WARNING,
- "bdfd/bdatt is NULL from fd=%p", fd);
- goto out;
- }
-
- local = bd_local_init (frame, this);
- if (!local) {
- gf_log (this->name, GF_LOG_ERROR, "out of memory");
- goto out;
- }
-
- local->fd = fd_ref (fd);
- gf_uuid_copy (loc.gfid, bdatt->iatt.ia_gfid);
-
- /* Update the a|mtime during flush */
- STACK_WIND (frame, bd_flush_setattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->setattr, &loc, &bdatt->iatt,
- valid, NULL);
-
- return 0;
+bd_flush(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
+{
+ int ret = -1;
+ bd_fd_t *bd_fd = NULL;
+ bd_attr_t *bdatt = NULL;
+ int valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME;
+ bd_local_t *local = NULL;
+ loc_t loc = {
+ 0,
+ };
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+ VALIDATE_OR_GOTO(this->private, out);
+
+ ret = bd_inode_ctx_get(fd->inode, this, &bdatt);
+ if (!bdatt)
+ goto out;
+
+ ret = bd_fd_ctx_get(this, fd, &bd_fd);
+ if (ret < 0 || !bd_fd || !bdatt) {
+ gf_log(this->name, GF_LOG_WARNING, "bdfd/bdatt is NULL from fd=%p", fd);
+ goto out;
+ }
+
+ local = bd_local_init(frame, this);
+ if (!local) {
+ gf_log(this->name, GF_LOG_ERROR, "out of memory");
+ goto out;
+ }
+
+ local->fd = fd_ref(fd);
+ gf_uuid_copy(loc.gfid, bdatt->iatt.ia_gfid);
+
+ /* Update the a|mtime during flush */
+ STACK_WIND(frame, bd_flush_setattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setattr, &loc, &bdatt->iatt, valid,
+ NULL);
+
+ return 0;
out:
- STACK_WIND (frame, default_flush_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->flush, fd, xdata);
+ STACK_WIND(frame, default_flush_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->flush, fd, xdata);
- return 0;
+ return 0;
}
int32_t
-bd_release (xlator_t *this, fd_t *fd)
+bd_release(xlator_t *this, fd_t *fd)
{
- int ret = -1;
- bd_fd_t *bd_fd = NULL;
- uint64_t tmp_bfd = 0;
- bd_attr_t *bdatt = NULL;
- bd_priv_t *priv = this->private;
+ int ret = -1;
+ bd_fd_t *bd_fd = NULL;
+ uint64_t tmp_bfd = 0;
+ bd_attr_t *bdatt = NULL;
+ bd_priv_t *priv = this->private;
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
- VALIDATE_OR_GOTO (priv, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+ VALIDATE_OR_GOTO(priv, out);
- ret = bd_inode_ctx_get (fd->inode, this, &bdatt);
- if (ret || !bdatt) /* posix file */
- goto out;
+ ret = bd_inode_ctx_get(fd->inode, this, &bdatt);
+ if (ret || !bdatt) /* posix file */
+ goto out;
- /* FIXME: Update amtime during release */
+ /* FIXME: Update amtime during release */
- ret = fd_ctx_del (fd, this, &tmp_bfd);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "bfd is NULL from fd=%p", fd);
- goto out;
- }
- bd_fd = (bd_fd_t *)(long)tmp_bfd;
+ ret = fd_ctx_del(fd, this, &tmp_bfd);
+ if (ret < 0) {
+ gf_log(this->name, GF_LOG_WARNING, "bfd is NULL from fd=%p", fd);
+ goto out;
+ }
+ bd_fd = (bd_fd_t *)(long)tmp_bfd;
- sys_close (bd_fd->fd);
- GF_FREE (bd_fd);
+ sys_close(bd_fd->fd);
+ GF_FREE(bd_fd);
out:
- return 0;
+ return 0;
}
/*
@@ -900,17 +903,16 @@ out:
* bd create failure
*/
int
-bd_setx_rm_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xdata)
+bd_setx_rm_xattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, dict_t *xdata)
{
- bd_local_t *local = frame->local;
-
- if (local->fd)
- BD_STACK_UNWIND (setxattr, frame, -1, EIO, xdata);
- else
- BD_STACK_UNWIND (setxattr, frame, -1, EIO, xdata);
- return 0;
+ bd_local_t *local = frame->local;
+ if (local->fd)
+ BD_STACK_UNWIND(setxattr, frame, -1, EIO, xdata);
+ else
+ BD_STACK_UNWIND(setxattr, frame, -1, EIO, xdata);
+ return 0;
}
/*
@@ -918,426 +920,423 @@ bd_setx_rm_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
* invokes posix_removexattr to remove created BD_XATTR
*/
int
-bd_setx_setx_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xdata)
-{
- bd_local_t *local = frame->local;
- bd_attr_t *bdatt = NULL;
-
- if (op_ret < 0)
- goto next;
-
- /* Create LV */
- op_errno = bd_create (local->inode->gfid, local->bdatt->iatt.ia_size,
- local->bdatt->type, this->private);
- if (!op_errno)
- goto out;
-
- /* LV creation failed, remove BD_XATTR */
- if (local->fd)
- STACK_WIND (frame, bd_setx_rm_xattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fremovexattr,
- local->fd, BD_XATTR, NULL);
- else
- STACK_WIND (frame, bd_setx_rm_xattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->removexattr,
- &local->loc, BD_XATTR, NULL);
-
- return 0;
+bd_setx_setx_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, dict_t *xdata)
+{
+ bd_local_t *local = frame->local;
+ bd_attr_t *bdatt = NULL;
+
+ if (op_ret < 0)
+ goto next;
+
+ /* Create LV */
+ op_errno = bd_create(local->inode->gfid, local->bdatt->iatt.ia_size,
+ local->bdatt->type, this->private);
+ if (!op_errno)
+ goto out;
+
+ /* LV creation failed, remove BD_XATTR */
+ if (local->fd)
+ STACK_WIND(frame, bd_setx_rm_xattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fremovexattr, local->fd, BD_XATTR,
+ NULL);
+ else
+ STACK_WIND(frame, bd_setx_rm_xattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr, &local->loc, BD_XATTR,
+ NULL);
+
+ return 0;
out:
- bdatt = GF_CALLOC (1, sizeof (bd_attr_t), gf_bd_attr);
- if (!bdatt) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto next;
- }
+ bdatt = GF_CALLOC(1, sizeof(bd_attr_t), gf_bd_attr);
+ if (!bdatt) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto next;
+ }
- memcpy (&bdatt->iatt, &local->bdatt->iatt, sizeof (struct iatt));
- bdatt->type = gf_strdup (local->bdatt->type);
+ memcpy(&bdatt->iatt, &local->bdatt->iatt, sizeof(struct iatt));
+ bdatt->type = gf_strdup(local->bdatt->type);
- bd_inode_ctx_set (local->inode, THIS, bdatt);
+ bd_inode_ctx_set(local->inode, THIS, bdatt);
next:
- if (local->fd)
- BD_STACK_UNWIND (setxattr, frame, op_ret, op_errno, xdata);
- else
- BD_STACK_UNWIND (setxattr, frame, op_ret, op_errno, xdata);
- return 0;
-
+ if (local->fd)
+ BD_STACK_UNWIND(setxattr, frame, op_ret, op_errno, xdata);
+ else
+ BD_STACK_UNWIND(setxattr, frame, op_ret, op_errno, xdata);
+ return 0;
}
/*
* Call back from posix_stat
*/
int
-bd_setx_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, struct iatt *iatt,
- dict_t *xdata)
-{
- char *param = NULL;
- char *type = NULL;
- char *s_size = NULL;
- char *p = NULL;
- char *copy = NULL;
- bd_local_t *local = frame->local;
- bd_priv_t *priv = this->private;
- char *bd = NULL;
- uint64_t size = 0;
-
- if (op_ret < 0)
- goto out;
-
- if (!IA_ISREG (iatt->ia_type)) {
- op_errno = EOPNOTSUPP;
- goto out;
- }
-
- param = copy = GF_MALLOC (local->data->len + 1, gf_common_mt_char);
- BD_VALIDATE_MEM_ALLOC (param, op_errno, out);
-
- strncpy (param, local->data->data, local->data->len);
- param[local->data->len] = '\0';
-
- type = strtok_r (param, ":", &p);
- if (!type) {
- op_errno = EINVAL;
- goto out;
- }
-
- if (strcmp (type, BD_LV) && strcmp (type, BD_THIN)) {
- gf_log (this->name, GF_LOG_WARNING, "Invalid bd type %s given",
- type);
- op_errno = EINVAL;
- goto out;
- }
-
- if (!strcmp (type, BD_THIN) && !(priv->caps & BD_CAPS_THIN)) {
- gf_log (this->name, GF_LOG_WARNING, "THIN lv not supported by "
- "this volume");
- op_errno = EOPNOTSUPP;
- goto out;
- }
-
- s_size = strtok_r (NULL, ":", &p);
-
- /* If size not specified get default size */
- if (!s_size)
- size = bd_get_default_extent (priv);
- else
- gf_string2bytesize (s_size, &size);
-
- gf_asprintf (&bd, "%s:%ld", type, size);
- BD_VALIDATE_MEM_ALLOC (bd, op_errno, out);
-
- local->dict = dict_new ();
- BD_VALIDATE_MEM_ALLOC (local->dict, op_errno, out);
-
- local->bdatt = GF_CALLOC (1, sizeof (bd_attr_t), gf_bd_attr);
- BD_VALIDATE_MEM_ALLOC (local->bdatt, op_errno, out);
-
- if (dict_set_dynstr (local->dict, BD_XATTR, bd) < 0) {
- op_errno = EINVAL;
- goto out;
- }
-
- local->bdatt->type = gf_strdup (type);
- memcpy (&local->bdatt->iatt, iatt, sizeof (struct iatt));
- local->bdatt->iatt.ia_size = size;
-
- if (local->fd)
- STACK_WIND (frame, bd_setx_setx_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fsetxattr,
- local->fd, local->dict, 0, NULL);
- else
- STACK_WIND (frame, bd_setx_setx_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setxattr,
- &local->loc, local->dict, 0, NULL);
-
- return 0;
+bd_setx_stat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct iatt *iatt, dict_t *xdata)
+{
+ char *param = NULL;
+ char *type = NULL;
+ char *s_size = NULL;
+ char *p = NULL;
+ char *copy = NULL;
+ bd_local_t *local = frame->local;
+ bd_priv_t *priv = this->private;
+ char *bd = NULL;
+ uint64_t size = 0;
+
+ if (op_ret < 0)
+ goto out;
+
+ if (!IA_ISREG(iatt->ia_type)) {
+ op_errno = EOPNOTSUPP;
+ goto out;
+ }
+
+ param = copy = GF_MALLOC(local->data->len + 1, gf_common_mt_char);
+ BD_VALIDATE_MEM_ALLOC(param, op_errno, out);
+
+ strncpy(param, local->data->data, local->data->len);
+ param[local->data->len] = '\0';
+
+ type = strtok_r(param, ":", &p);
+ if (!type) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ if (strcmp(type, BD_LV) && strcmp(type, BD_THIN)) {
+ gf_log(this->name, GF_LOG_WARNING, "Invalid bd type %s given", type);
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ if (!strcmp(type, BD_THIN) && !(priv->caps & BD_CAPS_THIN)) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "THIN lv not supported by "
+ "this volume");
+ op_errno = EOPNOTSUPP;
+ goto out;
+ }
+
+ s_size = strtok_r(NULL, ":", &p);
+
+ /* If size not specified get default size */
+ if (!s_size)
+ size = bd_get_default_extent(priv);
+ else
+ gf_string2bytesize(s_size, &size);
+
+ gf_asprintf(&bd, "%s:%ld", type, size);
+ BD_VALIDATE_MEM_ALLOC(bd, op_errno, out);
+
+ local->dict = dict_new();
+ BD_VALIDATE_MEM_ALLOC(local->dict, op_errno, out);
+
+ local->bdatt = GF_CALLOC(1, sizeof(bd_attr_t), gf_bd_attr);
+ BD_VALIDATE_MEM_ALLOC(local->bdatt, op_errno, out);
+
+ if (dict_set_dynstr(local->dict, BD_XATTR, bd) < 0) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ local->bdatt->type = gf_strdup(type);
+ memcpy(&local->bdatt->iatt, iatt, sizeof(struct iatt));
+ local->bdatt->iatt.ia_size = size;
+
+ if (local->fd)
+ STACK_WIND(frame, bd_setx_setx_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, local->fd, local->dict,
+ 0, NULL);
+ else
+ STACK_WIND(frame, bd_setx_setx_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, &local->loc, local->dict,
+ 0, NULL);
+
+ return 0;
out:
- if (local->fd)
- BD_STACK_UNWIND (fsetxattr, frame, -1, op_errno, xdata);
- else
- BD_STACK_UNWIND (setxattr, frame, -1, op_errno, xdata);
+ if (local->fd)
+ BD_STACK_UNWIND(fsetxattr, frame, -1, op_errno, xdata);
+ else
+ BD_STACK_UNWIND(setxattr, frame, -1, op_errno, xdata);
- GF_FREE (bd);
- GF_FREE (copy);
- return 0;
+ GF_FREE(bd);
+ GF_FREE(copy);
+ return 0;
}
int
-bd_offload_rm_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xdata)
+bd_offload_rm_xattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, dict_t *xdata)
{
- bd_local_t *local = frame->local;
+ bd_local_t *local = frame->local;
- if (local->fd)
- BD_STACK_UNWIND (fsetxattr, frame, -1, EIO, NULL);
- else
- BD_STACK_UNWIND (setxattr, frame, -1, EIO, NULL);
+ if (local->fd)
+ BD_STACK_UNWIND(fsetxattr, frame, -1, EIO, NULL);
+ else
+ BD_STACK_UNWIND(setxattr, frame, -1, EIO, NULL);
- return 0;
+ return 0;
}
int
-bd_offload_setx_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xdata)
+bd_offload_setx_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, dict_t *xdata)
{
- bd_local_t *local = frame->local;
+ bd_local_t *local = frame->local;
- if (op_ret < 0)
- goto out;
+ if (op_ret < 0)
+ goto out;
- if (local->offload == BD_OF_SNAPSHOT)
- op_ret = bd_snapshot_create (frame->local, this->private);
- else
- op_ret = bd_clone (frame->local, this->private);
+ if (local->offload == BD_OF_SNAPSHOT)
+ op_ret = bd_snapshot_create(frame->local, this->private);
+ else
+ op_ret = bd_clone(frame->local, this->private);
- if (op_ret) {
- STACK_WIND (frame, bd_offload_rm_xattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->removexattr,
- local->dloc, BD_XATTR, NULL);
- return 0;
- }
+ if (op_ret) {
+ STACK_WIND(frame, bd_offload_rm_xattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr, local->dloc, BD_XATTR,
+ NULL);
+ return 0;
+ }
out:
- if (local->fd)
- BD_STACK_UNWIND (fsetxattr, frame, op_ret, op_errno, NULL);
- else
- BD_STACK_UNWIND (setxattr, frame, op_ret, op_errno, NULL);
+ if (local->fd)
+ BD_STACK_UNWIND(fsetxattr, frame, op_ret, op_errno, NULL);
+ else
+ BD_STACK_UNWIND(setxattr, frame, op_ret, op_errno, NULL);
- return 0;
+ return 0;
}
int
-bd_offload_getx_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xattr, dict_t *xdata)
-{
- char *bd = NULL;
- bd_local_t *local = frame->local;
- char *type = NULL;
- char *p = NULL;
-
- if (op_ret < 0)
- goto out;
-
- if (dict_get_str (xattr, BD_XATTR, &p)) {
- op_errno = EINVAL;
- goto out;
- }
-
- type = gf_strdup (p);
- BD_VALIDATE_MEM_ALLOC (type, op_errno, out);
-
- p = strrchr (type, ':');
- if (!p) {
- op_errno = EINVAL;
- gf_log (this->name, GF_LOG_WARNING,
- "source file xattr %s corrupted?", type);
- goto out;
- }
-
- *p='\0';
-
- /* For clone size is taken from source LV */
- if (!local->size) {
- p++;
- gf_string2bytesize (p, &local->size);
- }
- gf_asprintf (&bd, "%s:%ld", type, local->size);
- local->bdatt->type = gf_strdup (type);
- dict_del (local->dict, LINKTO);
- if (dict_set_dynstr (local->dict, BD_XATTR, bd)) {
- op_errno = EINVAL;
- goto out;
- }
-
- STACK_WIND (frame, bd_offload_setx_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setxattr,
- local->dloc, local->dict, 0, NULL);
-
- return 0;
+bd_offload_getx_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, dict_t *xattr, dict_t *xdata)
+{
+ char *bd = NULL;
+ bd_local_t *local = frame->local;
+ char *type = NULL;
+ char *p = NULL;
+
+ if (op_ret < 0)
+ goto out;
+
+ if (dict_get_str(xattr, BD_XATTR, &p)) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ type = gf_strdup(p);
+ BD_VALIDATE_MEM_ALLOC(type, op_errno, out);
+
+ p = strrchr(type, ':');
+ if (!p) {
+ op_errno = EINVAL;
+ gf_log(this->name, GF_LOG_WARNING, "source file xattr %s corrupted?",
+ type);
+ goto out;
+ }
+
+ *p = '\0';
+
+ /* For clone size is taken from source LV */
+ if (!local->size) {
+ p++;
+ gf_string2bytesize(p, &local->size);
+ }
+ gf_asprintf(&bd, "%s:%ld", type, local->size);
+ local->bdatt->type = gf_strdup(type);
+ dict_del(local->dict, LINKTO);
+ if (dict_set_dynstr(local->dict, BD_XATTR, bd)) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ STACK_WIND(frame, bd_offload_setx_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, local->dloc, local->dict, 0,
+ NULL);
+
+ return 0;
out:
- if (local->fd)
- BD_STACK_UNWIND (fsetxattr, frame, -1, op_errno, NULL);
- else
- BD_STACK_UNWIND (setxattr, frame, -1, op_errno, NULL);
+ if (local->fd)
+ BD_STACK_UNWIND(fsetxattr, frame, -1, op_errno, NULL);
+ else
+ BD_STACK_UNWIND(setxattr, frame, -1, op_errno, NULL);
- GF_FREE (type);
- GF_FREE (bd);
+ GF_FREE(type);
+ GF_FREE(bd);
- return 0;
+ return 0;
}
int
-bd_offload_dest_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno,
- inode_t *inode, struct iatt *iatt,
- dict_t *xattr, struct iatt *postparent)
-{
- bd_local_t *local = frame->local;
- char *bd = NULL;
- char *linkto = NULL;
- int ret = -1;
-
- if (op_ret < 0 && op_errno != ENODATA) {
- op_errno = EINVAL;
- goto out;
- }
-
- if (!IA_ISREG (iatt->ia_type)) {
- op_errno = EINVAL;
- gf_log (this->name, GF_LOG_WARNING, "destination gfid is not a "
- "regular file");
- goto out;
- }
-
- ret = dict_get_str (xattr, LINKTO, &linkto);
- if (linkto) {
- op_errno = EINVAL;
- gf_log (this->name, GF_LOG_WARNING, "destination file not "
- "present in same brick");
- goto out;
- }
-
- ret = dict_get_str (xattr, BD_XATTR, &bd);
- if (bd) {
- op_errno = EEXIST;
- goto out;
- }
-
- local->bdatt = GF_CALLOC (1, sizeof (bd_attr_t), gf_bd_attr);
- BD_VALIDATE_MEM_ALLOC (local->bdatt, op_errno, out);
-
- STACK_WIND (frame, bd_offload_getx_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->getxattr,
- &local->loc, BD_XATTR, NULL);
-
- return 0;
+bd_offload_dest_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, inode_t *inode,
+ struct iatt *iatt, dict_t *xattr,
+ struct iatt *postparent)
+{
+ bd_local_t *local = frame->local;
+ char *bd = NULL;
+ char *linkto = NULL;
+ int ret = -1;
+
+ if (op_ret < 0 && op_errno != ENODATA) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ if (!IA_ISREG(iatt->ia_type)) {
+ op_errno = EINVAL;
+ gf_log(this->name, GF_LOG_WARNING,
+ "destination gfid is not a "
+ "regular file");
+ goto out;
+ }
+
+ ret = dict_get_str(xattr, LINKTO, &linkto);
+ if (linkto) {
+ op_errno = EINVAL;
+ gf_log(this->name, GF_LOG_WARNING,
+ "destination file not "
+ "present in same brick");
+ goto out;
+ }
+
+ ret = dict_get_str(xattr, BD_XATTR, &bd);
+ if (bd) {
+ op_errno = EEXIST;
+ goto out;
+ }
+
+ local->bdatt = GF_CALLOC(1, sizeof(bd_attr_t), gf_bd_attr);
+ BD_VALIDATE_MEM_ALLOC(local->bdatt, op_errno, out);
+
+ STACK_WIND(frame, bd_offload_getx_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->getxattr, &local->loc, BD_XATTR, NULL);
+
+ return 0;
out:
- if (local->fd)
- BD_STACK_UNWIND (fsetxattr, frame, -1, op_errno, NULL);
- else
- BD_STACK_UNWIND (setxattr, frame, -1, op_errno, NULL);
+ if (local->fd)
+ BD_STACK_UNWIND(fsetxattr, frame, -1, op_errno, NULL);
+ else
+ BD_STACK_UNWIND(setxattr, frame, -1, op_errno, NULL);
- return (ret == 0) ? 0 : ret;
+ return (ret == 0) ? 0 : ret;
}
int
-bd_merge_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)
+bd_merge_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)
{
- /* FIXME: if delete failed, remove xattr */
+ /* FIXME: if delete failed, remove xattr */
- BD_STACK_UNWIND (setxattr, frame, op_ret, op_errno, NULL);
- return 0;
+ BD_STACK_UNWIND(setxattr, frame, op_ret, op_errno, NULL);
+ return 0;
}
int
bd_do_merge(call_frame_t *frame, xlator_t *this)
{
- bd_local_t *local = frame->local;
- inode_t *parent = NULL;
- char *p = NULL;
- int op_errno = 0;
-
- op_errno = bd_merge (this->private, local->inode->gfid);
- if (op_errno)
- goto out;
-
+ bd_local_t *local = frame->local;
+ inode_t *parent = NULL;
+ char *p = NULL;
+ int op_errno = 0;
+
+ op_errno = bd_merge(this->private, local->inode->gfid);
+ if (op_errno)
+ goto out;
+
+ /*
+ * posix_unlink needs loc->pargfid to be valid, but setxattr FOP does
+ * not have loc->pargfid set. Get parent's gfid by getting parents inode
+ */
+ parent = inode_parent(local->inode, NULL, NULL);
+ if (!parent) {
/*
- * posix_unlink needs loc->pargfid to be valid, but setxattr FOP does
- * not have loc->pargfid set. Get parent's gfid by getting parents inode
+ * FIXME: Snapshot LV already deleted.
+ * remove xattr, instead of returning failure
*/
- parent = inode_parent (local->inode, NULL, NULL);
- if (!parent) {
- /*
- * FIXME: Snapshot LV already deleted.
- * remove xattr, instead of returning failure
- */
- op_errno = EINVAL;
- goto out;
- }
- gf_uuid_copy (local->loc.pargfid, parent->gfid);
+ op_errno = EINVAL;
+ goto out;
+ }
+ gf_uuid_copy(local->loc.pargfid, parent->gfid);
- p = strrchr (local->loc.path, '/');
- if (p)
- p++;
- local->loc.name = p;
+ p = strrchr(local->loc.path, '/');
+ if (p)
+ p++;
+ local->loc.name = p;
- STACK_WIND (frame, bd_merge_unlink_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->unlink,
- &local->loc, 0, NULL);
+ STACK_WIND(frame, bd_merge_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, &local->loc, 0, NULL);
- return 0;
+ return 0;
out:
- BD_STACK_UNWIND (fsetxattr, frame, -1, op_errno, NULL);
+ BD_STACK_UNWIND(fsetxattr, frame, -1, op_errno, NULL);
- return op_errno;
+ return op_errno;
}
int
-bd_offload (call_frame_t *frame, xlator_t *this, loc_t *loc,
- fd_t *fd, bd_offload_t offload)
-{
- char *param = NULL;
- char *param_copy = NULL;
- char *p = NULL;
- char *size = NULL;
- char *gfid = NULL;
- int op_errno = 0;
- bd_local_t *local = frame->local;
-
- param = GF_MALLOC (local->data->len + 1, gf_common_mt_char);
- BD_VALIDATE_MEM_ALLOC (param, op_errno, out);
- param_copy = param;
-
- local->dict = dict_new ();
- BD_VALIDATE_MEM_ALLOC (local->dict, op_errno, out);
-
- local->dloc = GF_CALLOC (1, sizeof (loc_t), gf_bd_loc_t);
- BD_VALIDATE_MEM_ALLOC (local->dloc, op_errno, out);
-
- strncpy (param, local->data->data, local->data->len);
- param[local->data->len] = '\0';
-
- gfid = strtok_r (param, ":", &p);
- size = strtok_r (NULL, ":", &p);
- if (size)
- gf_string2bytesize (size, &local->size);
- else if (offload != BD_OF_CLONE)
- local->size = bd_get_default_extent (this->private);
-
- if (dict_set_int8 (local->dict, BD_XATTR, 1) < 0) {
- op_errno = EINVAL;
- goto out;
- }
- if (dict_set_int8 (local->dict, LINKTO, 1) < 0) {
- op_errno = EINVAL;
- goto out;
- }
-
- gf_uuid_parse (gfid, local->dloc->gfid);
- local->offload = offload;
-
- STACK_WIND (frame, bd_offload_dest_lookup_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->lookup, local->dloc,
- local->dict);
-
- return 0;
+bd_offload(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
+ bd_offload_t offload)
+{
+ char *param = NULL;
+ char *param_copy = NULL;
+ char *p = NULL;
+ char *size = NULL;
+ char *gfid = NULL;
+ int op_errno = 0;
+ bd_local_t *local = frame->local;
+
+ param = GF_MALLOC(local->data->len + 1, gf_common_mt_char);
+ BD_VALIDATE_MEM_ALLOC(param, op_errno, out);
+ param_copy = param;
+
+ local->dict = dict_new();
+ BD_VALIDATE_MEM_ALLOC(local->dict, op_errno, out);
+
+ local->dloc = GF_CALLOC(1, sizeof(loc_t), gf_bd_loc_t);
+ BD_VALIDATE_MEM_ALLOC(local->dloc, op_errno, out);
+
+ strncpy(param, local->data->data, local->data->len);
+ param[local->data->len] = '\0';
+
+ gfid = strtok_r(param, ":", &p);
+ size = strtok_r(NULL, ":", &p);
+ if (size)
+ gf_string2bytesize(size, &local->size);
+ else if (offload != BD_OF_CLONE)
+ local->size = bd_get_default_extent(this->private);
+
+ if (dict_set_int8(local->dict, BD_XATTR, 1) < 0) {
+ op_errno = EINVAL;
+ goto out;
+ }
+ if (dict_set_int8(local->dict, LINKTO, 1) < 0) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ gf_uuid_parse(gfid, local->dloc->gfid);
+ local->offload = offload;
+
+ STACK_WIND(frame, bd_offload_dest_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, local->dloc, local->dict);
+
+ return 0;
out:
- if (fd)
- BD_STACK_UNWIND (fsetxattr, frame, -1, op_errno, NULL);
- else
- BD_STACK_UNWIND (setxattr, frame, -1, op_errno, NULL);
+ if (fd)
+ BD_STACK_UNWIND(fsetxattr, frame, -1, op_errno, NULL);
+ else
+ BD_STACK_UNWIND(setxattr, frame, -1, op_errno, NULL);
- GF_FREE (param_copy);
- return 0;
+ GF_FREE(param_copy);
+ return 0;
}
/*
@@ -1348,71 +1347,70 @@ out:
* if create_lv failed, posix_removexattr -> bd_setx_rm_xattr_cbk
*/
int
-bd_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
- int flags, dict_t *xdata)
-{
- int op_errno = 0;
- data_t *data = NULL;
- bd_local_t *local = NULL;
- bd_attr_t *bdatt = NULL;
- bd_offload_t cl_type = BD_OF_NONE;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
-
- if ((data = dict_get (dict, BD_XATTR)))
- cl_type = BD_OF_NONE;
- else if ((data = dict_get (dict, BD_CLONE)))
- cl_type = BD_OF_CLONE;
- else if ((data = dict_get (dict, BD_SNAPSHOT)))
- cl_type = BD_OF_SNAPSHOT;
- else if ((data = dict_get (dict, BD_MERGE)))
- cl_type = BD_OF_MERGE;
-
- bd_inode_ctx_get (loc->inode, this, &bdatt);
- if (!cl_type && !data) {
- STACK_WIND (frame, default_setxattr_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->setxattr, loc, dict,
- flags, xdata);
- return 0;
+bd_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
+ int flags, dict_t *xdata)
+{
+ int op_errno = 0;
+ data_t *data = NULL;
+ bd_local_t *local = NULL;
+ bd_attr_t *bdatt = NULL;
+ bd_offload_t cl_type = BD_OF_NONE;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+
+ if ((data = dict_get(dict, BD_XATTR)))
+ cl_type = BD_OF_NONE;
+ else if ((data = dict_get(dict, BD_CLONE)))
+ cl_type = BD_OF_CLONE;
+ else if ((data = dict_get(dict, BD_SNAPSHOT)))
+ cl_type = BD_OF_SNAPSHOT;
+ else if ((data = dict_get(dict, BD_MERGE)))
+ cl_type = BD_OF_MERGE;
+
+ bd_inode_ctx_get(loc->inode, this, &bdatt);
+ if (!cl_type && !data) {
+ STACK_WIND(frame, default_setxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, loc, dict, flags, xdata);
+ return 0;
+ }
+
+ local = bd_local_init(frame, this);
+ BD_VALIDATE_MEM_ALLOC(local, op_errno, out);
+
+ local->data = data;
+ loc_copy(&local->loc, loc);
+ local->inode = inode_ref(loc->inode);
+
+ if (cl_type) {
+ /* For cloning/snapshot, source file must be mapped to LV */
+ if (!bdatt) {
+ gf_log(this->name, GF_LOG_WARNING, "%s not mapped to BD",
+ loc->path);
+ op_errno = EINVAL;
+ goto out;
}
-
- local = bd_local_init (frame, this);
- BD_VALIDATE_MEM_ALLOC (local, op_errno, out);
-
- local->data = data;
- loc_copy (&local->loc, loc);
- local->inode = inode_ref (loc->inode);
-
- if (cl_type) {
- /* For cloning/snapshot, source file must be mapped to LV */
- if (!bdatt) {
- gf_log (this->name, GF_LOG_WARNING,
- "%s not mapped to BD", loc->path);
- op_errno = EINVAL;
- goto out;
- }
- if (cl_type == BD_OF_MERGE)
- bd_do_merge (frame, this);
- else
- bd_offload (frame, this, loc, NULL, cl_type);
- } else if (data) {
- if (bdatt) {
- gf_log (this->name, GF_LOG_WARNING,
- "%s already mapped to BD", loc->path);
- op_errno = EEXIST;
- goto out;
- }
- STACK_WIND (frame, bd_setx_stat_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->stat, loc, xdata);
+ if (cl_type == BD_OF_MERGE)
+ bd_do_merge(frame, this);
+ else
+ bd_offload(frame, this, loc, NULL, cl_type);
+ } else if (data) {
+ if (bdatt) {
+ gf_log(this->name, GF_LOG_WARNING, "%s already mapped to BD",
+ loc->path);
+ op_errno = EEXIST;
+ goto out;
}
+ STACK_WIND(frame, bd_setx_stat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->stat, loc, xdata);
+ }
- return 0;
+ return 0;
out:
- if (op_errno)
- STACK_UNWIND_STRICT (setxattr, frame, -1, op_errno, xdata);
+ if (op_errno)
+ STACK_UNWIND_STRICT(setxattr, frame, -1, op_errno, xdata);
- return 0;
+ return 0;
}
/*
@@ -1424,194 +1422,189 @@ out:
* -> bd_fsetxattr_cbk
*/
int32_t
-bd_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
- int flags, dict_t *xdata)
-{
- int op_errno = 0;
- data_t *data = NULL;
- bd_attr_t *bdatt = NULL;
- bd_local_t *local = NULL;
- bd_offload_t cl_type = BD_OF_NONE;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (this->private, out);
- VALIDATE_OR_GOTO (fd, out);
-
- bd_inode_ctx_get (fd->inode, this, &bdatt);
-
- if ((data = dict_get (dict, BD_XATTR)))
- cl_type = BD_OF_NONE;
- else if ((data = dict_get (dict, BD_CLONE)))
- cl_type = BD_OF_CLONE;
- else if ((data = dict_get (dict, BD_SNAPSHOT)))
- cl_type = BD_OF_SNAPSHOT;
- else if ((data = dict_get (dict, BD_MERGE))) {
- /*
- * bd_merge is not supported for fsetxattr, because snapshot LV
- * is opened and it causes problem in snapshot merge
- */
- op_errno = EOPNOTSUPP;
- goto out;
- }
-
- bd_inode_ctx_get (fd->inode, this, &bdatt);
+bd_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
+ int flags, dict_t *xdata)
+{
+ int op_errno = 0;
+ data_t *data = NULL;
+ bd_attr_t *bdatt = NULL;
+ bd_local_t *local = NULL;
+ bd_offload_t cl_type = BD_OF_NONE;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(this->private, out);
+ VALIDATE_OR_GOTO(fd, out);
+
+ bd_inode_ctx_get(fd->inode, this, &bdatt);
+
+ if ((data = dict_get(dict, BD_XATTR)))
+ cl_type = BD_OF_NONE;
+ else if ((data = dict_get(dict, BD_CLONE)))
+ cl_type = BD_OF_CLONE;
+ else if ((data = dict_get(dict, BD_SNAPSHOT)))
+ cl_type = BD_OF_SNAPSHOT;
+ else if ((data = dict_get(dict, BD_MERGE))) {
+ /*
+ * bd_merge is not supported for fsetxattr, because snapshot LV
+ * is opened and it causes problem in snapshot merge
+ */
+ op_errno = EOPNOTSUPP;
+ goto out;
+ }
- if (!cl_type && !data) {
- /* non bd file object */
- STACK_WIND (frame, default_fsetxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fsetxattr,
- fd, dict, flags, xdata);
- return 0;
- }
+ bd_inode_ctx_get(fd->inode, this, &bdatt);
- local = bd_local_init (frame, this);
- BD_VALIDATE_MEM_ALLOC (local, op_errno, out);
+ if (!cl_type && !data) {
+ /* non bd file object */
+ STACK_WIND(frame, default_fsetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata);
+ return 0;
+ }
- local->inode = inode_ref (fd->inode);
- local->fd = fd_ref (fd);
- local->data = data;
+ local = bd_local_init(frame, this);
+ BD_VALIDATE_MEM_ALLOC(local, op_errno, out);
- if (cl_type) {
- /* For cloning/snapshot, source file must be mapped to LV */
- if (!bdatt) {
- gf_log (this->name, GF_LOG_WARNING,
- "fd %p not mapped to BD", fd);
- op_errno = EINVAL;
- goto out;
+ local->inode = inode_ref(fd->inode);
+ local->fd = fd_ref(fd);
+ local->data = data;
- }
- bd_offload (frame, this, NULL, fd, cl_type);
- } else if (data) {
- if (bdatt) {
- gf_log (this->name, GF_LOG_WARNING,
- "fd %p already mapped to BD", fd);
- op_errno = EEXIST;
- goto out;
- }
- STACK_WIND(frame, bd_setx_stat_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fstat, fd, xdata);
+ if (cl_type) {
+ /* For cloning/snapshot, source file must be mapped to LV */
+ if (!bdatt) {
+ gf_log(this->name, GF_LOG_WARNING, "fd %p not mapped to BD", fd);
+ op_errno = EINVAL;
+ goto out;
}
+ bd_offload(frame, this, NULL, fd, cl_type);
+ } else if (data) {
+ if (bdatt) {
+ gf_log(this->name, GF_LOG_WARNING, "fd %p already mapped to BD",
+ fd);
+ op_errno = EEXIST;
+ goto out;
+ }
+ STACK_WIND(frame, bd_setx_stat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, fd, xdata);
+ }
- return 0;
+ return 0;
out:
- BD_STACK_UNWIND (setxattr, frame, -1, op_errno, NULL);
+ BD_STACK_UNWIND(setxattr, frame, -1, op_errno, NULL);
- return 0;
+ return 0;
}
int32_t
-bd_removexattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc, const char *name, dict_t *xdata)
+bd_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name, dict_t *xdata)
{
- if (!strcmp (name, BD_XATTR))
- goto out;
+ if (!strcmp(name, BD_XATTR))
+ goto out;
- STACK_WIND (frame, default_removexattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->removexattr, loc, name, xdata);
- return 0;
+ STACK_WIND(frame, default_removexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr, loc, name, xdata);
+ return 0;
out:
- BD_STACK_UNWIND (removexattr, frame, -1, ENODATA, NULL);
- return 0;
+ BD_STACK_UNWIND(removexattr, frame, -1, ENODATA, NULL);
+ return 0;
}
int32_t
-bd_fremovexattr (call_frame_t *frame, xlator_t *this,
- fd_t *fd, const char *name, dict_t *xdata)
+bd_fremovexattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name,
+ dict_t *xdata)
{
- if (!strcmp (name, BD_XATTR))
- goto out;
+ if (!strcmp(name, BD_XATTR))
+ goto out;
- STACK_WIND (frame, default_removexattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fremovexattr, fd, name, xdata);
+ STACK_WIND(frame, default_removexattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fremovexattr, fd, name, xdata);
- return 0;
+ return 0;
out:
- BD_STACK_UNWIND (fremovexattr, frame, -1, ENODATA, NULL);
- return 0;
+ BD_STACK_UNWIND(fremovexattr, frame, -1, ENODATA, NULL);
+ return 0;
}
int
-bd_trunc_setxattr_setx_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xdata)
+bd_trunc_setxattr_setx_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, dict_t *xdata)
{
- bd_local_t *local = frame->local;
+ bd_local_t *local = frame->local;
- if (local->fd)
- BD_STACK_UNWIND (ftruncate, frame, -1, EIO, NULL, NULL, NULL);
- else
- BD_STACK_UNWIND (truncate, frame, -1, EIO, NULL, NULL, NULL);
+ if (local->fd)
+ BD_STACK_UNWIND(ftruncate, frame, -1, EIO, NULL, NULL, NULL);
+ else
+ BD_STACK_UNWIND(truncate, frame, -1, EIO, NULL, NULL, NULL);
- return 0;
+ return 0;
}
/*
* Call back for setxattr after setting BD_XATTR_SIZE.
*/
int
-bd_trunc_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, dict_t *xdata)
+bd_trunc_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, dict_t *xdata)
{
- bd_local_t *local = frame->local;
- bd_attr_t *bdatt = NULL;
- struct iatt prebuf = {0, };
- char *bd = NULL;
+ bd_local_t *local = frame->local;
+ bd_attr_t *bdatt = NULL;
+ struct iatt prebuf = {
+ 0,
+ };
+ char *bd = NULL;
- if (op_ret < 0)
- goto out;
+ if (op_ret < 0)
+ goto out;
- bd_inode_ctx_get (local->inode, this, &bdatt);
- if (!bdatt)
- goto revert_xattr;
+ bd_inode_ctx_get(local->inode, this, &bdatt);
+ if (!bdatt)
+ goto revert_xattr;
- op_errno = bd_resize (this->private, local->inode->gfid,
- local->bdatt->iatt.ia_size);
- if (op_errno)
- goto revert_xattr;
+ op_errno = bd_resize(this->private, local->inode->gfid,
+ local->bdatt->iatt.ia_size);
+ if (op_errno)
+ goto revert_xattr;
- memcpy (&prebuf, &bdatt->iatt, sizeof (struct iatt));
- /* LV resized, update new size in the cache */
- bdatt->iatt.ia_size = local->bdatt->iatt.ia_size;
+ memcpy(&prebuf, &bdatt->iatt, sizeof(struct iatt));
+ /* LV resized, update new size in the cache */
+ bdatt->iatt.ia_size = local->bdatt->iatt.ia_size;
- if (local->fd)
- BD_STACK_UNWIND (ftruncate, frame, 0, 0, &prebuf, &bdatt->iatt,
- NULL);
- else
- BD_STACK_UNWIND (truncate, frame, 0, 0, &prebuf, &bdatt->iatt,
- NULL);
+ if (local->fd)
+ BD_STACK_UNWIND(ftruncate, frame, 0, 0, &prebuf, &bdatt->iatt, NULL);
+ else
+ BD_STACK_UNWIND(truncate, frame, 0, 0, &prebuf, &bdatt->iatt, NULL);
- return 0;
+ return 0;
revert_xattr:
- /* revert setxattr */
- op_ret = dict_get_str (local->dict, BD_XATTR, &bd);
- GF_FREE (bd);
- bd = NULL;
- if (bdatt)
- gf_asprintf (&bd, "%s:%ld", bdatt->type, bdatt->iatt.ia_size);
-
- if (local->fd)
- STACK_WIND (frame, bd_trunc_setxattr_setx_cbk,
- FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fsetxattr,
- local->fd, local->dict, 0, NULL);
- else
- STACK_WIND (frame, bd_trunc_setxattr_setx_cbk,
- FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setxattr,
- &local->loc, local->dict, 0, NULL);
-
- if (bd)
- GF_FREE (bd);
- return 0;
+ /* revert setxattr */
+ op_ret = dict_get_str(local->dict, BD_XATTR, &bd);
+ GF_FREE(bd);
+ bd = NULL;
+ if (bdatt)
+ gf_asprintf(&bd, "%s:%ld", bdatt->type, bdatt->iatt.ia_size);
+
+ if (local->fd)
+ STACK_WIND(frame, bd_trunc_setxattr_setx_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, local->fd, local->dict,
+ 0, NULL);
+ else
+ STACK_WIND(frame, bd_trunc_setxattr_setx_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, &local->loc, local->dict,
+ 0, NULL);
+
+ if (bd)
+ GF_FREE(bd);
+ return 0;
out:
- if (local->fd)
- BD_STACK_UNWIND (ftruncate, frame, -1, EIO, NULL, NULL, NULL);
- else
- BD_STACK_UNWIND (truncate, frame, -1, EIO, NULL, NULL, NULL);
+ if (local->fd)
+ BD_STACK_UNWIND(ftruncate, frame, -1, EIO, NULL, NULL, NULL);
+ else
+ BD_STACK_UNWIND(truncate, frame, -1, EIO, NULL, NULL, NULL);
- return 0;
+ return 0;
}
/*
@@ -1621,182 +1614,175 @@ out:
* the posix file so that truncate fop behaves properly
*/
int
-bd_trunc_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, struct iatt *buf, dict_t *xdata)
-{
- char *bd = NULL;
- bd_local_t *local = frame->local;
- bd_attr_t *bdatt = NULL;
-
- if (op_ret < 0)
- goto out;
-
- local->dict = dict_new ();
- BD_VALIDATE_MEM_ALLOC (local->dict, op_errno, out);
-
- bd_inode_ctx_get (local->inode, this, &bdatt);
- if (!bdatt) {
- op_errno = EINVAL;
- goto out;
- }
-
- gf_asprintf (&bd, "%s:%ld", bdatt->type, local->bdatt->iatt.ia_size);
- if (dict_set_dynstr (local->dict, BD_XATTR, bd)) {
- op_errno = EINVAL;
- goto out;
- }
-
- if (local->fd)
- STACK_WIND (frame, bd_trunc_setxattr_cbk,
- FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fsetxattr,
- local->fd, local->dict, 0, NULL);
- else
- STACK_WIND (frame, bd_trunc_setxattr_cbk,
- FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setxattr,
- &local->loc, local->dict, 0, NULL);
-
- return 0;
+bd_trunc_stat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, struct iatt *buf, dict_t *xdata)
+{
+ char *bd = NULL;
+ bd_local_t *local = frame->local;
+ bd_attr_t *bdatt = NULL;
+
+ if (op_ret < 0)
+ goto out;
+
+ local->dict = dict_new();
+ BD_VALIDATE_MEM_ALLOC(local->dict, op_errno, out);
+
+ bd_inode_ctx_get(local->inode, this, &bdatt);
+ if (!bdatt) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ gf_asprintf(&bd, "%s:%ld", bdatt->type, local->bdatt->iatt.ia_size);
+ if (dict_set_dynstr(local->dict, BD_XATTR, bd)) {
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ if (local->fd)
+ STACK_WIND(frame, bd_trunc_setxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetxattr, local->fd, local->dict,
+ 0, NULL);
+ else
+ STACK_WIND(frame, bd_trunc_setxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr, &local->loc, local->dict,
+ 0, NULL);
+
+ return 0;
out:
- if (local->fd)
- BD_STACK_UNWIND (ftruncate, frame, -1, op_errno, NULL, NULL,
- NULL);
- else
- BD_STACK_UNWIND (truncate, frame, -1, op_errno, NULL, NULL,
- NULL);
- GF_FREE (bd);
- return 0;
+ if (local->fd)
+ BD_STACK_UNWIND(ftruncate, frame, -1, op_errno, NULL, NULL, NULL);
+ else
+ BD_STACK_UNWIND(truncate, frame, -1, op_errno, NULL, NULL, NULL);
+ GF_FREE(bd);
+ return 0;
}
void
-bd_do_trunc (call_frame_t *frame, xlator_t *this, fd_t *fd, loc_t *loc,
- off_t offset, bd_attr_t *bdatt)
-{
- bd_local_t *local = NULL;
- struct iatt prebuf = {0, };
- int op_errno = 0;
- int op_ret = -1;
-
- /* If requested size is less than LV size, return success */
- if (offset <= bdatt->iatt.ia_size) {
- memcpy (&prebuf, &bdatt->iatt, sizeof (struct iatt));
- bd_update_amtime (&bdatt->iatt, GF_SET_ATTR_MTIME);
- op_ret = 0;
- goto out;
- }
+bd_do_trunc(call_frame_t *frame, xlator_t *this, fd_t *fd, loc_t *loc,
+ off_t offset, bd_attr_t *bdatt)
+{
+ bd_local_t *local = NULL;
+ struct iatt prebuf = {
+ 0,
+ };
+ int op_errno = 0;
+ int op_ret = -1;
+
+ /* If requested size is less than LV size, return success */
+ if (offset <= bdatt->iatt.ia_size) {
+ memcpy(&prebuf, &bdatt->iatt, sizeof(struct iatt));
+ bd_update_amtime(&bdatt->iatt, GF_SET_ATTR_MTIME);
+ op_ret = 0;
+ goto out;
+ }
- local = bd_local_init (frame, this);
- BD_VALIDATE_MEM_ALLOC (local, op_errno, out);
+ local = bd_local_init(frame, this);
+ BD_VALIDATE_MEM_ALLOC(local, op_errno, out);
- local->bdatt = GF_CALLOC (1, sizeof (bd_attr_t), gf_bd_attr);
- BD_VALIDATE_MEM_ALLOC (local->bdatt, op_errno, out);
+ local->bdatt = GF_CALLOC(1, sizeof(bd_attr_t), gf_bd_attr);
+ BD_VALIDATE_MEM_ALLOC(local->bdatt, op_errno, out);
- if (fd) {
- local->inode = inode_ref (fd->inode);
- local->fd = fd_ref (fd);
- } else {
- local->inode = inode_ref (loc->inode);
- loc_copy (&local->loc, loc);
- }
+ if (fd) {
+ local->inode = inode_ref(fd->inode);
+ local->fd = fd_ref(fd);
+ } else {
+ local->inode = inode_ref(loc->inode);
+ loc_copy(&local->loc, loc);
+ }
- local->bdatt->iatt.ia_size =
- bd_adjust_size (this->private, offset);
+ local->bdatt->iatt.ia_size = bd_adjust_size(this->private, offset);
- STACK_WIND (frame, bd_trunc_stat_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fstat, fd, NULL);
+ STACK_WIND(frame, bd_trunc_stat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, fd, NULL);
- return;
+ return;
out:
- if (fd)
- BD_STACK_UNWIND (ftruncate, frame, op_ret, op_errno,
- &prebuf, &bdatt->iatt, NULL);
- else
- BD_STACK_UNWIND (truncate, frame, op_ret, op_errno,
- &prebuf, &bdatt->iatt, NULL);
- return;
+ if (fd)
+ BD_STACK_UNWIND(ftruncate, frame, op_ret, op_errno, &prebuf,
+ &bdatt->iatt, NULL);
+ else
+ BD_STACK_UNWIND(truncate, frame, op_ret, op_errno, &prebuf,
+ &bdatt->iatt, NULL);
+ return;
}
/*
* bd_ftruncate: Resizes a LV if fd belongs to BD.
*/
int32_t
-bd_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
- dict_t *xdata)
-{
- int op_errno = 0;
- bd_attr_t *bdatt = NULL;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
-
- if (bd_inode_ctx_get (fd->inode, this, &bdatt)) {
- STACK_WIND (frame, default_ftruncate_cbk,
- FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->ftruncate, fd,
- offset, xdata);
- return 0;
- }
+bd_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ dict_t *xdata)
+{
+ int op_errno = 0;
+ bd_attr_t *bdatt = NULL;
- bd_do_trunc (frame, this, fd, NULL, offset, bdatt);
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+
+ if (bd_inode_ctx_get(fd->inode, this, &bdatt)) {
+ STACK_WIND(frame, default_ftruncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
return 0;
+ }
+
+ bd_do_trunc(frame, this, fd, NULL, offset, bdatt);
+ return 0;
out:
- BD_STACK_UNWIND (ftruncate, frame, -1, op_errno, NULL, NULL, NULL);
- return 0;
+ BD_STACK_UNWIND(ftruncate, frame, -1, op_errno, NULL, NULL, NULL);
+ return 0;
}
/*
* bd_truncate: Resizes a LV if file maps to LV.
*/
int32_t
-bd_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
- dict_t *xdata)
+bd_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
+ dict_t *xdata)
{
- int op_errno = 0;
- bd_attr_t *bdatt = NULL;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (loc, out);
+ int op_errno = 0;
+ bd_attr_t *bdatt = NULL;
- if (bd_inode_ctx_get (loc->inode, this, &bdatt)) {
- STACK_WIND (frame, default_truncate_cbk,
- FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->truncate, loc,
- offset, xdata);
- return 0;
- }
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(loc, out);
- bd_do_trunc (frame, this, NULL, loc, offset, bdatt);
+ if (bd_inode_ctx_get(loc->inode, this, &bdatt)) {
+ STACK_WIND(frame, default_truncate_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
return 0;
+ }
+
+ bd_do_trunc(frame, this, NULL, loc, offset, bdatt);
+ return 0;
out:
- BD_STACK_UNWIND (truncate, frame, -1, op_errno, NULL, NULL, NULL);
- return 0;
+ BD_STACK_UNWIND(truncate, frame, -1, op_errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-__bd_pwritev (int fd, struct iovec *vector, int count, off_t offset,
- uint64_t bd_size)
-{
- int index = 0;
- int retval = 0;
-
- if (!vector)
- return -EFAULT;
-
- retval = sys_pwritev (fd, vector, count, offset);
- if (retval == -1) {
- int64_t off = offset;
- gf_log (THIS->name, GF_LOG_WARNING,
- "base %p, length %zd, offset %" PRId64 ", message %s",
- vector[index].iov_base, vector[index].iov_len,
- off, strerror (errno));
- retval = -errno;
- goto err;
- }
+__bd_pwritev(int fd, struct iovec *vector, int count, off_t offset,
+ uint64_t bd_size)
+{
+ int index = 0;
+ int retval = 0;
+
+ if (!vector)
+ return -EFAULT;
+
+ retval = sys_pwritev(fd, vector, count, offset);
+ if (retval == -1) {
+ int64_t off = offset;
+ gf_log(THIS->name, GF_LOG_WARNING,
+ "base %p, length %zd, offset %" PRId64 ", message %s",
+ vector[index].iov_base, vector[index].iov_len, off,
+ strerror(errno));
+ retval = -errno;
+ goto err;
+ }
/*
@@ -1827,7 +1813,7 @@ __bd_pwritev (int fd, struct iovec *vector, int count, off_t offset,
}
*/
err:
- return retval;
+ return retval;
}
/*
@@ -1835,615 +1821,600 @@ err:
* bd_writev -> posix_writev -> bd_writev_cbk
*/
int
-bd_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 *xdict)
-{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- int _fd = -1;
- bd_fd_t *bd_fd = NULL;
- int ret = -1;
- uint64_t size = 0;
- struct iatt prebuf = {0, };
- bd_attr_t *bdatt = NULL;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
- VALIDATE_OR_GOTO (vector, out);
-
- ret = bd_fd_ctx_get (this, fd, &bd_fd);
- if (ret < 0 || !bd_fd) { /* posix fd */
- STACK_WIND (frame, default_writev_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->writev, fd, vector, count,
- offset, flags, iobref, xdict);
- return 0;
- }
-
- _fd = bd_fd->fd;
-
- if (bd_inode_ctx_get (fd->inode, this, &bdatt)) {
- op_ret = -1;
- op_errno = EINVAL;
- goto out;
- }
- size = bdatt->iatt.ia_size;
-
- op_ret = __bd_pwritev (_fd, vector, count, offset, size);
- if (op_ret < 0) {
- op_errno = -op_ret;
- op_ret = -1;
- gf_log (this->name, GF_LOG_ERROR, "write failed: offset %"PRIu64
- ", %s", offset, strerror (op_errno));
- goto out;
- }
-
- memcpy (&prebuf, &bdatt->iatt, sizeof (struct iatt));
- bd_update_amtime (&bdatt->iatt, GF_SET_ATTR_MTIME);
+bd_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 *xdict)
+{
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ int _fd = -1;
+ bd_fd_t *bd_fd = NULL;
+ int ret = -1;
+ uint64_t size = 0;
+ struct iatt prebuf = {
+ 0,
+ };
+ bd_attr_t *bdatt = NULL;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+ VALIDATE_OR_GOTO(vector, out);
+
+ ret = bd_fd_ctx_get(this, fd, &bd_fd);
+ if (ret < 0 || !bd_fd) { /* posix fd */
+ STACK_WIND(frame, default_writev_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev, fd, vector, count, offset,
+ flags, iobref, xdict);
+ return 0;
+ }
+
+ _fd = bd_fd->fd;
+
+ if (bd_inode_ctx_get(fd->inode, this, &bdatt)) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto out;
+ }
+ size = bdatt->iatt.ia_size;
+
+ op_ret = __bd_pwritev(_fd, vector, count, offset, size);
+ if (op_ret < 0) {
+ op_errno = -op_ret;
+ op_ret = -1;
+ gf_log(this->name, GF_LOG_ERROR, "write failed: offset %" PRIu64 ", %s",
+ offset, strerror(op_errno));
+ goto out;
+ }
+
+ memcpy(&prebuf, &bdatt->iatt, sizeof(struct iatt));
+ bd_update_amtime(&bdatt->iatt, GF_SET_ATTR_MTIME);
out:
- BD_STACK_UNWIND (writev, frame, op_ret, op_errno, &prebuf,
- &bdatt->iatt, NULL);
- return 0;
+ BD_STACK_UNWIND(writev, frame, op_ret, op_errno, &prebuf, &bdatt->iatt,
+ NULL);
+ return 0;
}
int
-bd_setattr_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)
-{
- bd_attr_t *bdatt = NULL;
- int *valid = cookie;
- bd_local_t *local = frame->local;
-
- if (op_ret < 0 || !valid || !local)
- goto out;
-
- if (bd_inode_ctx_get (local->inode, this, &bdatt))
- goto out;
-
- if (*valid & GF_SET_ATTR_UID)
- bdatt->iatt.ia_uid = postbuf->ia_uid;
- else if (*valid & GF_SET_ATTR_GID)
- bdatt->iatt.ia_gid = postbuf->ia_gid;
- else if (*valid & GF_SET_ATTR_MODE) {
- bdatt->iatt.ia_type = postbuf->ia_type;
- bdatt->iatt.ia_prot = postbuf->ia_prot;
- } else if (*valid & GF_SET_ATTR_ATIME) {
- bdatt->iatt.ia_atime = postbuf->ia_atime;
- bdatt->iatt.ia_atime_nsec = postbuf->ia_atime_nsec;
- } else if (*valid & GF_SET_ATTR_MTIME) {
- bdatt->iatt.ia_mtime = postbuf->ia_mtime;
- bdatt->iatt.ia_mtime_nsec = postbuf->ia_mtime_nsec;
- }
-
- bdatt->iatt.ia_ctime = postbuf->ia_ctime;
- bdatt->iatt.ia_ctime_nsec = postbuf->ia_ctime_nsec;
-
- memcpy (postbuf, &bdatt->iatt, sizeof (struct iatt));
+bd_setattr_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)
+{
+ bd_attr_t *bdatt = NULL;
+ int *valid = cookie;
+ bd_local_t *local = frame->local;
+
+ if (op_ret < 0 || !valid || !local)
+ goto out;
+
+ if (bd_inode_ctx_get(local->inode, this, &bdatt))
+ goto out;
+
+ if (*valid & GF_SET_ATTR_UID)
+ bdatt->iatt.ia_uid = postbuf->ia_uid;
+ else if (*valid & GF_SET_ATTR_GID)
+ bdatt->iatt.ia_gid = postbuf->ia_gid;
+ else if (*valid & GF_SET_ATTR_MODE) {
+ bdatt->iatt.ia_type = postbuf->ia_type;
+ bdatt->iatt.ia_prot = postbuf->ia_prot;
+ } else if (*valid & GF_SET_ATTR_ATIME) {
+ bdatt->iatt.ia_atime = postbuf->ia_atime;
+ bdatt->iatt.ia_atime_nsec = postbuf->ia_atime_nsec;
+ } else if (*valid & GF_SET_ATTR_MTIME) {
+ bdatt->iatt.ia_mtime = postbuf->ia_mtime;
+ bdatt->iatt.ia_mtime_nsec = postbuf->ia_mtime_nsec;
+ }
+
+ bdatt->iatt.ia_ctime = postbuf->ia_ctime;
+ bdatt->iatt.ia_ctime_nsec = postbuf->ia_ctime_nsec;
+
+ memcpy(postbuf, &bdatt->iatt, sizeof(struct iatt));
out:
- GF_FREE (valid);
- BD_STACK_UNWIND (setattr, frame, op_ret, op_errno, prebuf,
- postbuf, xdata);
- return 0;
+ GF_FREE(valid);
+ BD_STACK_UNWIND(setattr, frame, op_ret, op_errno, prebuf, postbuf, xdata);
+ return 0;
}
int
-bd_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, struct iatt *stbuf,
- int32_t valid, dict_t *xdata)
-{
- bd_local_t *local = NULL;
- bd_attr_t *bdatt = NULL;
- int *ck_valid = NULL;
-
- if (bd_inode_ctx_get (loc->inode, this, &bdatt)) {
- STACK_WIND(frame, default_setattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setattr,
- loc, stbuf, valid, xdata);
- return 0;
- }
-
- local = bd_local_init (frame, this);
- if (!local) {
- gf_log (this->name, GF_LOG_ERROR, "out of memory");
- goto out;
- }
-
- ck_valid = GF_CALLOC (1, sizeof (valid), gf_bd_int32_t);
- if (!ck_valid) {
- gf_log (this->name, GF_LOG_ERROR, "out of memory");
- goto out;
- }
-
- local->inode = inode_ref (loc->inode);
- *ck_valid = valid;
-
- STACK_WIND_COOKIE (frame, bd_setattr_cbk, ck_valid, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->setattr,
- loc, stbuf, valid, xdata);
- GF_FREE (ck_valid);
- return 0;
+bd_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc, struct iatt *stbuf,
+ int32_t valid, dict_t *xdata)
+{
+ bd_local_t *local = NULL;
+ bd_attr_t *bdatt = NULL;
+ int *ck_valid = NULL;
+
+ if (bd_inode_ctx_get(loc->inode, this, &bdatt)) {
+ STACK_WIND(frame, default_setattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid, xdata);
+ return 0;
+ }
+
+ local = bd_local_init(frame, this);
+ if (!local) {
+ gf_log(this->name, GF_LOG_ERROR, "out of memory");
+ goto out;
+ }
+
+ ck_valid = GF_CALLOC(1, sizeof(valid), gf_bd_int32_t);
+ if (!ck_valid) {
+ gf_log(this->name, GF_LOG_ERROR, "out of memory");
+ goto out;
+ }
+
+ local->inode = inode_ref(loc->inode);
+ *ck_valid = valid;
+
+ STACK_WIND_COOKIE(frame, bd_setattr_cbk, ck_valid, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid,
+ xdata);
+ GF_FREE(ck_valid);
+ return 0;
out:
- BD_STACK_UNWIND (setattr, frame, -1, ENOMEM, NULL, NULL, xdata);
- return 0;
+ BD_STACK_UNWIND(setattr, frame, -1, ENOMEM, NULL, NULL, xdata);
+ return 0;
}
int
-bd_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, inode_t *inode, struct iatt *buf,
- struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
+bd_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
+ int op_errno, inode_t *inode, struct iatt *buf,
+ struct iatt *preparent, struct iatt *postparent, dict_t *xdata)
{
- bd_attr_t *bdatt = NULL;
+ bd_attr_t *bdatt = NULL;
- if (op_ret < 0)
- goto out;
+ if (op_ret < 0)
+ goto out;
- if (bd_inode_ctx_get (inode, this, &bdatt))
- goto out;
+ if (bd_inode_ctx_get(inode, this, &bdatt))
+ goto out;
- bdatt->iatt.ia_ctime = buf->ia_ctime;
- bdatt->iatt.ia_ctime_nsec = buf->ia_ctime_nsec;
- bdatt->iatt.ia_nlink = buf->ia_nlink;
- memcpy (buf, &bdatt->iatt, sizeof (struct iatt));
+ bdatt->iatt.ia_ctime = buf->ia_ctime;
+ bdatt->iatt.ia_ctime_nsec = buf->ia_ctime_nsec;
+ bdatt->iatt.ia_nlink = buf->ia_nlink;
+ memcpy(buf, &bdatt->iatt, sizeof(struct iatt));
out:
- BD_STACK_UNWIND (link, frame, op_ret, op_errno, inode, buf,
- preparent, postparent, NULL);
- return 0;
+ BD_STACK_UNWIND(link, frame, op_ret, op_errno, inode, buf, preparent,
+ postparent, NULL);
+ return 0;
}
int
-bd_link (call_frame_t *frame, xlator_t *this,
- loc_t *oldloc, loc_t *newloc, dict_t *xdata)
+bd_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
+ dict_t *xdata)
{
- STACK_WIND (frame, bd_link_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata);
- return 0;
+ STACK_WIND(frame, bd_link_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->link, oldloc, newloc, xdata);
+ return 0;
}
int
-bd_handle_special_xattrs (call_frame_t *frame, xlator_t *this, loc_t *loc,
- fd_t *fd, const char *name, dict_t *xdata)
-{
- dict_t *xattr = NULL;
- int op_ret = -1;
- int op_errno = ENOMEM;;
- bd_priv_t *priv = this->private;
-
- xattr = dict_new ();
- if (!xattr)
- goto out;
-
- if (!strcmp (name, VOL_TYPE))
- op_ret = dict_set_int64 (xattr, (char *)name, 1);
- else if (!strcmp (name, VOL_CAPS))
- op_ret = dict_set_int64 (xattr, (char *)name, priv->caps);
- else
- op_ret = bd_get_origin (this->private, loc, fd, xattr);
+bd_handle_special_xattrs(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ fd_t *fd, const char *name, dict_t *xdata)
+{
+ dict_t *xattr = NULL;
+ int op_ret = -1;
+ int op_errno = ENOMEM;
+ ;
+ bd_priv_t *priv = this->private;
+
+ xattr = dict_new();
+ if (!xattr)
+ goto out;
+
+ if (!strcmp(name, VOL_TYPE))
+ op_ret = dict_set_int64(xattr, (char *)name, 1);
+ else if (!strcmp(name, VOL_CAPS))
+ op_ret = dict_set_int64(xattr, (char *)name, priv->caps);
+ else
+ op_ret = bd_get_origin(this->private, loc, fd, xattr);
out:
- if (loc)
- BD_STACK_UNWIND (getxattr, frame, op_ret, op_errno, xattr,
- xdata);
- else
- BD_STACK_UNWIND (fgetxattr, frame, op_ret, op_errno, xattr,
- xdata);
+ if (loc)
+ BD_STACK_UNWIND(getxattr, frame, op_ret, op_errno, xattr, xdata);
+ else
+ BD_STACK_UNWIND(fgetxattr, frame, op_ret, op_errno, xattr, xdata);
- op_ret = dict_reset (xattr);
- dict_unref (xattr);
+ op_ret = dict_reset(xattr);
+ dict_unref(xattr);
- return 0;
+ return 0;
}
int
-bd_fgetxattr (call_frame_t *frame, xlator_t *this,
- fd_t *fd, const char *name, dict_t *xdata)
+bd_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name,
+ dict_t *xdata)
{
- if (name && (!strcmp (name, VOL_TYPE) || !strcmp (name, VOL_CAPS)
- || !strcmp (name, BD_ORIGIN)))
- bd_handle_special_xattrs (frame, this, NULL, fd, name, xdata);
- else
- STACK_WIND (frame, default_fgetxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fgetxattr,
- fd, name, xdata);
- return 0;
+ if (name && (!strcmp(name, VOL_TYPE) || !strcmp(name, VOL_CAPS) ||
+ !strcmp(name, BD_ORIGIN)))
+ bd_handle_special_xattrs(frame, this, NULL, fd, name, xdata);
+ else
+ STACK_WIND(frame, default_fgetxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fgetxattr, fd, name, xdata);
+ return 0;
}
int
-bd_getxattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc, const char *name, dict_t *xdata)
+bd_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name,
+ dict_t *xdata)
{
- if (name && (!strcmp (name, VOL_TYPE) || !strcmp (name, VOL_CAPS)
- || !strcmp (name, BD_ORIGIN)))
- bd_handle_special_xattrs (frame, this, loc, NULL, name, xdata);
- else
- STACK_WIND (frame, default_getxattr_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->getxattr,
- loc, name, xdata);
+ if (name && (!strcmp(name, VOL_TYPE) || !strcmp(name, VOL_CAPS) ||
+ !strcmp(name, BD_ORIGIN)))
+ bd_handle_special_xattrs(frame, this, loc, NULL, name, xdata);
+ else
+ STACK_WIND(frame, default_getxattr_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->getxattr, loc, name, xdata);
- return 0;
+ return 0;
}
int
-bd_unlink_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int op_ret, int op_errno, inode_t *inode,
- struct iatt *buf, dict_t *xattr,
- struct iatt *postparent)
+bd_unlink_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int op_ret, int op_errno, inode_t *inode, struct iatt *buf,
+ dict_t *xattr, struct iatt *postparent)
{
- bd_gfid_t gfid = {0, };
- bd_local_t *local = frame->local;
+ bd_gfid_t gfid = {
+ 0,
+ };
+ bd_local_t *local = frame->local;
- if (buf->ia_nlink > 1)
- goto posix;
+ if (buf->ia_nlink > 1)
+ goto posix;
- BD_VALIDATE_LOCAL_OR_GOTO (local, op_errno, out);
+ BD_VALIDATE_LOCAL_OR_GOTO(local, op_errno, out);
- uuid_utoa_r (inode->gfid, gfid);
- if (bd_delete_lv (this->private, gfid, &op_errno) < 0) {
- if (op_errno != ENOENT)
- goto out;
- }
+ uuid_utoa_r(inode->gfid, gfid);
+ if (bd_delete_lv(this->private, gfid, &op_errno) < 0) {
+ if (op_errno != ENOENT)
+ goto out;
+ }
posix:
- /* remove posix */
- STACK_WIND (frame, default_unlink_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->unlink,
- &local->loc, 0, NULL);
+ /* remove posix */
+ STACK_WIND(frame, default_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, &local->loc, 0, NULL);
- return 0;
+ return 0;
out:
- BD_STACK_UNWIND (unlink, frame, -1, op_errno, NULL, NULL, NULL);
- return 0;
+ BD_STACK_UNWIND(unlink, frame, -1, op_errno, NULL, NULL, NULL);
+ return 0;
}
int
-bd_unlink (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int xflag, dict_t *xdata)
-{
- int op_errno = 0;
- bd_attr_t *bdatt = NULL;
- bd_local_t *local = NULL;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (loc, out);
-
- if (bd_inode_ctx_get (loc->inode, this, &bdatt)) {
- STACK_WIND (frame, default_unlink_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->unlink,
- loc, xflag, xdata);
- return 0;
- }
-
- local = bd_local_init (frame, this);
- BD_VALIDATE_MEM_ALLOC (local, op_errno, out);
+bd_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
+ dict_t *xdata)
+{
+ int op_errno = 0;
+ bd_attr_t *bdatt = NULL;
+ bd_local_t *local = NULL;
- loc_copy (&local->loc, loc);
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(loc, out);
- STACK_WIND (frame, bd_unlink_lookup_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->lookup, loc, NULL);
+ if (bd_inode_ctx_get(loc->inode, this, &bdatt)) {
+ STACK_WIND(frame, default_unlink_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink, loc, xflag, xdata);
return 0;
+ }
+
+ local = bd_local_init(frame, this);
+ BD_VALIDATE_MEM_ALLOC(local, op_errno, out);
+
+ loc_copy(&local->loc, loc);
+
+ STACK_WIND(frame, bd_unlink_lookup_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup, loc, NULL);
+ return 0;
out:
- BD_STACK_UNWIND (unlink, frame, -1, op_errno, NULL, NULL, NULL);
- return 0;
+ BD_STACK_UNWIND(unlink, frame, -1, op_errno, NULL, NULL, NULL);
+ return 0;
}
int32_t
-bd_priv (xlator_t *this)
+bd_priv(xlator_t *this)
{
- return 0;
+ return 0;
}
int32_t
-bd_inode (xlator_t *this)
+bd_inode(xlator_t *this)
{
- return 0;
+ return 0;
}
int32_t
-bd_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
- int32_t len, dict_t *xdata)
-{
- int op_ret = -1;
- int op_errno = 0;
- int ret = 0;
- int _fd = -1;
- char *alloc_buf = NULL;
- char *buf = NULL;
- int32_t weak_checksum = 0;
- bd_fd_t *bd_fd = NULL;
- unsigned char strong_checksum[SHA256_DIGEST_LENGTH] = {0};
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
-
- ret = bd_fd_ctx_get (this, fd, &bd_fd);
- if (ret < 0 || !bd_fd) {
- STACK_WIND (frame, default_rchecksum_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->rchecksum, fd, offset,
- len, xdata);
- return 0;
- }
-
- alloc_buf = page_aligned_alloc (len, &buf);
- if (!alloc_buf) {
- op_errno = ENOMEM;
- goto out;
- }
-
- _fd = bd_fd->fd;
-
- LOCK (&fd->lock);
- {
- ret = sys_pread (_fd, buf, len, offset);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "pread of %d bytes returned %d (%s)",
- len, ret, strerror (errno));
- op_errno = errno;
- }
+bd_rchecksum(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ int32_t len, dict_t *xdata)
+{
+ int op_ret = -1;
+ int op_errno = 0;
+ int ret = 0;
+ int _fd = -1;
+ char *alloc_buf = NULL;
+ char *buf = NULL;
+ int32_t weak_checksum = 0;
+ bd_fd_t *bd_fd = NULL;
+ unsigned char strong_checksum[SHA256_DIGEST_LENGTH] = {0};
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+
+ ret = bd_fd_ctx_get(this, fd, &bd_fd);
+ if (ret < 0 || !bd_fd) {
+ STACK_WIND(frame, default_rchecksum_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rchecksum, fd, offset, len, xdata);
+ return 0;
+ }
+
+ alloc_buf = page_aligned_alloc(len, &buf);
+ if (!alloc_buf) {
+ op_errno = ENOMEM;
+ goto out;
+ }
+
+ _fd = bd_fd->fd;
+
+ LOCK(&fd->lock);
+ {
+ ret = sys_pread(_fd, buf, len, offset);
+ if (ret < 0) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "pread of %d bytes returned %d (%s)", len, ret,
+ strerror(errno));
+ op_errno = errno;
}
- UNLOCK (&fd->lock);
+ }
+ UNLOCK(&fd->lock);
- if (ret < 0)
- goto out;
+ if (ret < 0)
+ goto out;
- weak_checksum = gf_rsync_weak_checksum ((unsigned char *) buf,
- (size_t) len);
- gf_rsync_strong_checksum ((unsigned char *) buf, (size_t) len,
- (unsigned char *) strong_checksum);
+ weak_checksum = gf_rsync_weak_checksum((unsigned char *)buf, (size_t)len);
+ gf_rsync_strong_checksum((unsigned char *)buf, (size_t)len,
+ (unsigned char *)strong_checksum);
- op_ret = 0;
+ op_ret = 0;
out:
- BD_STACK_UNWIND (rchecksum, frame, op_ret, op_errno,
- weak_checksum, strong_checksum, NULL);
+ BD_STACK_UNWIND(rchecksum, frame, op_ret, op_errno, weak_checksum,
+ strong_checksum, NULL);
- GF_FREE (alloc_buf);
+ GF_FREE(alloc_buf);
- return 0;
+ return 0;
}
static int
bd_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
off_t len, dict_t *xdata)
{
- int32_t ret = 0;
- struct iatt statpre = {0,};
- struct iatt statpost = {0,};
- bd_attr_t *bdatt = NULL;
-
- /* iatt already cached */
- if (bd_inode_ctx_get (fd->inode, this, &bdatt) < 0) {
- STACK_WIND (frame, default_zerofill_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->zerofill,
- fd, offset, len, xdata);
- return 0;
- }
-
- ret = bd_do_zerofill(frame, this, fd, offset, len,
- &statpre, &statpost);
- if (ret)
- goto err;
+ int32_t ret = 0;
+ struct iatt statpre = {
+ 0,
+ };
+ struct iatt statpost = {
+ 0,
+ };
+ bd_attr_t *bdatt = NULL;
- STACK_UNWIND_STRICT(zerofill, frame, 0, 0, &statpre, &statpost, NULL);
+ /* iatt already cached */
+ if (bd_inode_ctx_get(fd->inode, this, &bdatt) < 0) {
+ STACK_WIND(frame, default_zerofill_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->zerofill, fd, offset, len, xdata);
return 0;
+ }
+
+ ret = bd_do_zerofill(frame, this, fd, offset, len, &statpre, &statpost);
+ if (ret)
+ goto err;
+
+ STACK_UNWIND_STRICT(zerofill, frame, 0, 0, &statpre, &statpost, NULL);
+ return 0;
err:
- STACK_UNWIND_STRICT(zerofill, frame, -1, (ret == -1 ? 0 : ret),
- NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(zerofill, frame, -1, (ret == -1 ? 0 : ret), NULL, NULL,
+ NULL);
+ return 0;
}
/**
* notify - when parent sends PARENT_UP, send CHILD_UP event from here
*/
int32_t
-notify (xlator_t *this,
- int32_t event,
- void *data,
- ...)
-{
- switch (event)
- {
- case GF_EVENT_PARENT_UP:
- {
- /* Tell the parent that bd xlator is up */
- default_notify (this, GF_EVENT_CHILD_UP, data);
- }
- break;
+notify(xlator_t *this, int32_t event, void *data, ...)
+{
+ switch (event) {
+ case GF_EVENT_PARENT_UP: {
+ /* Tell the parent that bd xlator is up */
+ default_notify(this, GF_EVENT_CHILD_UP, data);
+ } break;
default:
- break;
- }
- return 0;
+ break;
+ }
+ 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;
+ if (!this)
+ return ret;
- ret = xlator_mem_acct_init (this, gf_bd_mt_end + 1);
+ ret = xlator_mem_acct_init(this, gf_bd_mt_end + 1);
- if (ret != 0)
- gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
- "failed");
+ if (ret != 0)
+ gf_log(this->name, GF_LOG_ERROR,
+ "Memory accounting init"
+ "failed");
- return ret;
+ return ret;
}
int
-reconfigure (xlator_t *this, dict_t *options)
+reconfigure(xlator_t *this, dict_t *options)
{
- int ret = -1;
- bd_priv_t *priv = this->private;
+ int ret = -1;
+ bd_priv_t *priv = this->private;
- GF_OPTION_RECONF ("bd-aio", priv->aio_configured, options,
- bool, out);
+ GF_OPTION_RECONF("bd-aio", priv->aio_configured, options, bool, out);
- if (priv->aio_configured)
- bd_aio_on (this);
- else
- bd_aio_off (this);
+ if (priv->aio_configured)
+ bd_aio_on(this);
+ else
+ bd_aio_off(this);
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
/**
* bd xlator init - Validate configured VG
*/
int
-init (xlator_t *this)
+init(xlator_t *this)
{
- char *vg_data = NULL;
- char *device = NULL;
- bd_priv_t *_private = NULL;
+ char *vg_data = NULL;
+ char *device = NULL;
+ bd_priv_t *_private = NULL;
- if (!this->children) {
- gf_log (this->name, GF_LOG_CRITICAL,
- "FATAL: storage/bd needs posix as subvolume");
- return -1;
- }
+ if (!this->children) {
+ gf_log(this->name, GF_LOG_CRITICAL,
+ "FATAL: storage/bd needs posix as subvolume");
+ return -1;
+ }
- if (!this->parents) {
- gf_log (this->name, GF_LOG_WARNING,
- "Volume is dangling. Please check the volume file.");
- }
+ if (!this->parents) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "Volume is dangling. Please check the volume file.");
+ }
- GF_OPTION_INIT ("export", vg_data, str, error);
- GF_OPTION_INIT ("device", device, str, error);
+ GF_OPTION_INIT("export", vg_data, str, error);
+ GF_OPTION_INIT("device", device, str, error);
- /* Now we support only LV device */
- if (strcasecmp (device, BACKEND_VG)) {
- gf_log (this->name, GF_LOG_CRITICAL,
- "FATAL: unknown %s backend %s", BD_XLATOR, device);
- return -1;
- }
+ /* Now we support only LV device */
+ if (strcasecmp(device, BACKEND_VG)) {
+ gf_log(this->name, GF_LOG_CRITICAL, "FATAL: unknown %s backend %s",
+ BD_XLATOR, device);
+ return -1;
+ }
- this->local_pool = mem_pool_new (bd_local_t, 64);
- if (!this->local_pool) {
- gf_log (this->name, GF_LOG_CRITICAL,
- "FATAL: Failed to create bd memory pool");
- return -1;
- }
+ this->local_pool = mem_pool_new(bd_local_t, 64);
+ if (!this->local_pool) {
+ gf_log(this->name, GF_LOG_CRITICAL,
+ "FATAL: Failed to create bd memory pool");
+ return -1;
+ }
- _private = GF_CALLOC (1, sizeof (*_private), gf_bd_private);
- if (!_private)
- goto error;
+ _private = GF_CALLOC(1, sizeof(*_private), gf_bd_private);
+ if (!_private)
+ goto error;
- this->private = _private;
- _private->vg = gf_strdup (vg_data);
- if (!_private->vg)
- goto error;
+ this->private = _private;
+ _private->vg = gf_strdup(vg_data);
+ if (!_private->vg)
+ goto error;
- _private->handle = lvm_init (NULL);
- if (!_private->handle) {
- gf_log (this->name, GF_LOG_CRITICAL, "lvm_init failed");
- goto error;
- }
- _private->caps = BD_CAPS_BD;
- if (bd_scan_vg (this, _private))
- goto error;
-
- _private->aio_init_done = _gf_false;
- _private->aio_capable = _gf_false;
-
- GF_OPTION_INIT ("bd-aio", _private->aio_configured, bool, error);
- if (_private->aio_configured) {
- if (bd_aio_on (this)) {
- gf_log (this->name, GF_LOG_ERROR,
- "BD AIO init failed");
- goto error;
- }
+ _private->handle = lvm_init(NULL);
+ if (!_private->handle) {
+ gf_log(this->name, GF_LOG_CRITICAL, "lvm_init failed");
+ goto error;
+ }
+ _private->caps = BD_CAPS_BD;
+ if (bd_scan_vg(this, _private))
+ goto error;
+
+ _private->aio_init_done = _gf_false;
+ _private->aio_capable = _gf_false;
+
+ GF_OPTION_INIT("bd-aio", _private->aio_configured, bool, error);
+ if (_private->aio_configured) {
+ if (bd_aio_on(this)) {
+ gf_log(this->name, GF_LOG_ERROR, "BD AIO init failed");
+ goto error;
}
+ }
- _private->caps |= BD_CAPS_OFFLOAD_COPY | BD_CAPS_OFFLOAD_SNAPSHOT |
- BD_CAPS_OFFLOAD_ZERO;
+ _private->caps |= BD_CAPS_OFFLOAD_COPY | BD_CAPS_OFFLOAD_SNAPSHOT |
+ BD_CAPS_OFFLOAD_ZERO;
- return 0;
+ return 0;
error:
- if (_private) {
- GF_FREE (_private->vg);
- if (_private->handle)
- lvm_quit (_private->handle);
- GF_FREE (_private);
- }
+ if (_private) {
+ GF_FREE(_private->vg);
+ if (_private->handle)
+ lvm_quit(_private->handle);
+ GF_FREE(_private);
+ }
- mem_pool_destroy (this->local_pool);
+ mem_pool_destroy(this->local_pool);
- return -1;
+ return -1;
}
void
-fini (xlator_t *this)
-{
- bd_priv_t *priv = this->private;
- mem_pool_destroy (this->local_pool);
- this->local_pool = NULL;
- if (!priv)
- return;
- lvm_quit (priv->handle);
- GF_FREE (priv->vg);
- this->private = NULL;
- GF_FREE (priv);
+fini(xlator_t *this)
+{
+ bd_priv_t *priv = this->private;
+ mem_pool_destroy(this->local_pool);
+ this->local_pool = NULL;
+ if (!priv)
return;
+ lvm_quit(priv->handle);
+ GF_FREE(priv->vg);
+ this->private = NULL;
+ GF_FREE(priv);
+ return;
}
struct xlator_dumpops dumpops = {
- .priv = bd_priv,
- .inode = bd_inode,
+ .priv = bd_priv,
+ .inode = bd_inode,
};
struct xlator_fops fops = {
- .readdirp = bd_readdirp,
- .lookup = bd_lookup,
- .stat = bd_stat,
- .statfs = bd_statfs,
- .open = bd_open,
- .fstat = bd_fstat,
- .rchecksum = bd_rchecksum,
- .readv = bd_readv,
- .fsync = bd_fsync,
- .setxattr = bd_setxattr,
- .fsetxattr = bd_fsetxattr,
- .removexattr = bd_removexattr,
- .fremovexattr=bd_fremovexattr,
- .truncate = bd_truncate,
- .ftruncate = bd_ftruncate,
- .writev = bd_writev,
- .getxattr = bd_getxattr,
- .fgetxattr = bd_fgetxattr,
- .unlink = bd_unlink,
- .link = bd_link,
- .flush = bd_flush,
- .setattr = bd_setattr,
- .discard = bd_discard,
- .zerofill = bd_zerofill,
+ .readdirp = bd_readdirp,
+ .lookup = bd_lookup,
+ .stat = bd_stat,
+ .statfs = bd_statfs,
+ .open = bd_open,
+ .fstat = bd_fstat,
+ .rchecksum = bd_rchecksum,
+ .readv = bd_readv,
+ .fsync = bd_fsync,
+ .setxattr = bd_setxattr,
+ .fsetxattr = bd_fsetxattr,
+ .removexattr = bd_removexattr,
+ .fremovexattr = bd_fremovexattr,
+ .truncate = bd_truncate,
+ .ftruncate = bd_ftruncate,
+ .writev = bd_writev,
+ .getxattr = bd_getxattr,
+ .fgetxattr = bd_fgetxattr,
+ .unlink = bd_unlink,
+ .link = bd_link,
+ .flush = bd_flush,
+ .setattr = bd_setattr,
+ .discard = bd_discard,
+ .zerofill = bd_zerofill,
};
struct xlator_cbks cbks = {
- .release = bd_release,
- .forget = bd_forget,
+ .release = bd_release,
+ .forget = bd_forget,
};
struct volume_options options[] = {
- { .key = {"export"},
- .type = GF_OPTION_TYPE_STR},
- { .key = {"device"},
- .type = GF_OPTION_TYPE_STR,
- .default_value = BACKEND_VG},
- {
- .key = {"bd-aio"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .description = "Support for native Linux AIO"
- },
-
- { .key = {NULL} }
-};
+ {.key = {"export"}, .type = GF_OPTION_TYPE_STR},
+ {.key = {"device"},
+ .type = GF_OPTION_TYPE_STR,
+ .default_value = BACKEND_VG},
+ {.key = {"bd-aio"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .description = "Support for native Linux AIO"},
+
+ {.key = {NULL}}};
diff --git a/xlators/storage/posix/src/posix-aio.c b/xlators/storage/posix/src/posix-aio.c
index f8d568b..cf570d5 100644
--- a/xlators/storage/posix/src/posix-aio.c
+++ b/xlators/storage/posix/src/posix-aio.c
@@ -16,571 +16,545 @@
#ifdef HAVE_LIBAIO
#include <libaio.h>
-
void
-__posix_fd_set_odirect (fd_t *fd, struct posix_fd *pfd, int opflags,
- off_t offset, size_t size)
+__posix_fd_set_odirect(fd_t *fd, struct posix_fd *pfd, int opflags,
+ off_t offset, size_t size)
{
- int odirect = 0;
- int flags = 0;
- int ret = 0;
-
- odirect = pfd->odirect;
-
- if ((fd->flags|opflags) & O_DIRECT) {
- /* if instructed, use O_DIRECT always */
- odirect = 1;
- } else {
- /* else use O_DIRECT when feasible */
- if ((offset|size) & 0xfff)
- odirect = 0;
- else
- odirect = 1;
- }
-
- if (!odirect && pfd->odirect) {
- flags = fcntl (pfd->fd, F_GETFL);
- ret = fcntl (pfd->fd, F_SETFL, (flags & (~O_DIRECT)));
- pfd->odirect = 0;
- }
-
- if (odirect && !pfd->odirect) {
- flags = fcntl (pfd->fd, F_GETFL);
- ret = fcntl (pfd->fd, F_SETFL, (flags | O_DIRECT));
- pfd->odirect = 1;
- }
-
- if (ret) {
- gf_msg (THIS->name, GF_LOG_WARNING, errno, P_MSG_FCNTL_FAILED,
- "fcntl() failed. fd=%d flags=%d pfd->odirect=%d",
- pfd->fd, flags, pfd->odirect);
- }
+ int odirect = 0;
+ int flags = 0;
+ int ret = 0;
+
+ odirect = pfd->odirect;
+
+ if ((fd->flags | opflags) & O_DIRECT) {
+ /* if instructed, use O_DIRECT always */
+ odirect = 1;
+ } else {
+ /* else use O_DIRECT when feasible */
+ if ((offset | size) & 0xfff)
+ odirect = 0;
+ else
+ odirect = 1;
+ }
+
+ if (!odirect && pfd->odirect) {
+ flags = fcntl(pfd->fd, F_GETFL);
+ ret = fcntl(pfd->fd, F_SETFL, (flags & (~O_DIRECT)));
+ pfd->odirect = 0;
+ }
+
+ if (odirect && !pfd->odirect) {
+ flags = fcntl(pfd->fd, F_GETFL);
+ ret = fcntl(pfd->fd, F_SETFL, (flags | O_DIRECT));
+ pfd->odirect = 1;
+ }
+
+ if (ret) {
+ gf_msg(THIS->name, GF_LOG_WARNING, errno, P_MSG_FCNTL_FAILED,
+ "fcntl() failed. fd=%d flags=%d pfd->odirect=%d", pfd->fd, flags,
+ pfd->odirect);
+ }
}
-
struct posix_aio_cb {
- struct iocb iocb;
- call_frame_t *frame;
- struct iobuf *iobuf;
- struct iobref *iobref;
- struct iatt prebuf;
- int _fd;
- fd_t *fd;
- int op;
- off_t offset;
+ struct iocb iocb;
+ call_frame_t *frame;
+ struct iobuf *iobuf;
+ struct iobref *iobref;
+ struct iatt prebuf;
+ int _fd;
+ fd_t *fd;
+ int op;
+ off_t offset;
};
-
int
-posix_aio_readv_complete (struct posix_aio_cb *paiocb, int res, int res2)
+posix_aio_readv_complete(struct posix_aio_cb *paiocb, int res, int res2)
{
- call_frame_t *frame = NULL;
- xlator_t *this = NULL;
- struct iobuf *iobuf = NULL;
- struct iatt postbuf = {0,};
- int _fd = -1;
- int op_ret = -1;
- int op_errno = 0;
- struct iovec iov;
- struct iobref *iobref = NULL;
- int ret = 0;
- off_t offset = 0;
- struct posix_private * priv = NULL;
- fd_t *fd = NULL;
-
-
- frame = paiocb->frame;
- this = frame->this;
- priv = this->private;
- iobuf = paiocb->iobuf;
- fd = paiocb->fd;
- _fd = paiocb->_fd;
- offset = paiocb->offset;
-
- if (res < 0) {
- op_ret = -1;
- op_errno = -res;
- gf_msg (this->name, GF_LOG_ERROR, op_errno, P_MSG_READV_FAILED,
- "readv(async) failed fd=%d,size=%lu,offset=%llu (%d)",
- _fd, paiocb->iocb.u.c.nbytes,
- (unsigned long long) paiocb->offset,
- res);
- goto out;
- }
-
- ret = posix_fdstat (this, fd->inode, _fd, &postbuf);
- if (ret != 0) {
- op_ret = -1;
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, op_errno, P_MSG_FSTAT_FAILED,
- "fstat failed on fd=%d", _fd);
- goto out;
- }
-
- op_ret = res;
- op_errno = 0;
-
- iobref = iobref_new ();
- if (!iobref) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto out;
- }
-
- iobref_add (iobref, iobuf);
-
- iov.iov_base = iobuf_ptr (iobuf);
- iov.iov_len = op_ret;
-
-
- /* Hack to notify higher layers of EOF. */
- if (!postbuf.ia_size || (offset + iov.iov_len) >= postbuf.ia_size)
- op_errno = ENOENT;
-
- LOCK (&priv->lock);
- {
- priv->read_value += op_ret;
- }
- UNLOCK (&priv->lock);
+ call_frame_t *frame = NULL;
+ xlator_t *this = NULL;
+ struct iobuf *iobuf = NULL;
+ struct iatt postbuf = {
+ 0,
+ };
+ int _fd = -1;
+ int op_ret = -1;
+ int op_errno = 0;
+ struct iovec iov;
+ struct iobref *iobref = NULL;
+ int ret = 0;
+ off_t offset = 0;
+ struct posix_private *priv = NULL;
+ fd_t *fd = NULL;
+
+ frame = paiocb->frame;
+ this = frame->this;
+ priv = this->private;
+ iobuf = paiocb->iobuf;
+ fd = paiocb->fd;
+ _fd = paiocb->_fd;
+ offset = paiocb->offset;
+
+ if (res < 0) {
+ op_ret = -1;
+ op_errno = -res;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_READV_FAILED,
+ "readv(async) failed fd=%d,size=%lu,offset=%llu (%d)", _fd,
+ paiocb->iocb.u.c.nbytes, (unsigned long long)paiocb->offset,
+ res);
+ goto out;
+ }
+
+ ret = posix_fdstat(this, fd->inode, _fd, &postbuf);
+ if (ret != 0) {
+ op_ret = -1;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_FSTAT_FAILED,
+ "fstat failed on fd=%d", _fd);
+ goto out;
+ }
+
+ op_ret = res;
+ op_errno = 0;
+
+ iobref = iobref_new();
+ if (!iobref) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto out;
+ }
+
+ iobref_add(iobref, iobuf);
+
+ iov.iov_base = iobuf_ptr(iobuf);
+ iov.iov_len = op_ret;
+
+ /* Hack to notify higher layers of EOF. */
+ if (!postbuf.ia_size || (offset + iov.iov_len) >= postbuf.ia_size)
+ op_errno = ENOENT;
+
+ LOCK(&priv->lock);
+ {
+ priv->read_value += op_ret;
+ }
+ UNLOCK(&priv->lock);
out:
- STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, &iov, 1,
- &postbuf, iobref, NULL);
- if (iobuf)
- iobuf_unref (iobuf);
- if (iobref)
- iobref_unref (iobref);
+ STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, &iov, 1, &postbuf,
+ iobref, NULL);
+ if (iobuf)
+ iobuf_unref(iobuf);
+ if (iobref)
+ iobref_unref(iobref);
- if (paiocb->fd)
- fd_unref (paiocb->fd);
+ if (paiocb->fd)
+ fd_unref(paiocb->fd);
- GF_FREE (paiocb);
+ GF_FREE(paiocb);
- return 0;
+ return 0;
}
-
int
-posix_aio_readv (call_frame_t *frame, xlator_t *this, fd_t *fd,
- size_t size, off_t offset, uint32_t flags, dict_t *xdata)
+posix_aio_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_errno = EINVAL;
- int _fd = -1;
- struct iobuf *iobuf = NULL;
- struct posix_fd * pfd = NULL;
- int ret = -1;
- struct posix_aio_cb *paiocb = NULL;
- struct posix_private *priv = NULL;
- struct iocb *iocb = NULL;
-
-
- VALIDATE_OR_GOTO (frame, err);
- VALIDATE_OR_GOTO (this, err);
- VALIDATE_OR_GOTO (fd, err);
-
- priv = this->private;
-
- ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
- "pfd is NULL from fd=%p", fd);
- goto err;
- }
- _fd = pfd->fd;
-
- if (!size) {
- op_errno = EINVAL;
- gf_msg (this->name, GF_LOG_WARNING, op_errno,
- P_MSG_INVALID_ARGUMENT, "size=%"GF_PRI_SIZET, size);
- goto err;
- }
-
- iobuf = iobuf_get2 (this->ctx->iobuf_pool, size);
- if (!iobuf) {
- op_errno = ENOMEM;
- goto err;
- }
-
- paiocb = GF_CALLOC (1, sizeof (*paiocb), gf_posix_mt_paiocb);
- if (!paiocb) {
- op_errno = ENOMEM;
- goto err;
- }
-
-
- paiocb->frame = frame;
- paiocb->iobuf = iobuf;
- paiocb->offset = offset;
- paiocb->fd = fd_ref(fd);
- paiocb->_fd = _fd;
- paiocb->op = GF_FOP_READ;
-
- paiocb->iocb.data = paiocb;
- paiocb->iocb.aio_fildes = _fd;
- paiocb->iocb.aio_lio_opcode = IO_CMD_PREAD;
- paiocb->iocb.aio_reqprio = 0;
- paiocb->iocb.u.c.buf = iobuf_ptr (iobuf);
- paiocb->iocb.u.c.nbytes = size;
- paiocb->iocb.u.c.offset = offset;
-
- iocb = &paiocb->iocb;
-
- LOCK (&fd->lock);
- {
- __posix_fd_set_odirect (fd, pfd, flags, offset, size);
-
- ret = io_submit (priv->ctxp, 1, &iocb);
- }
- UNLOCK (&fd->lock);
-
- if (ret != 1) {
- op_errno = -ret;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- P_MSG_IO_SUBMIT_FAILED,
- "io_submit() returned %d", ret);
- goto err;
- }
-
- return 0;
+ int32_t op_errno = EINVAL;
+ int _fd = -1;
+ struct iobuf *iobuf = NULL;
+ struct posix_fd *pfd = NULL;
+ int ret = -1;
+ struct posix_aio_cb *paiocb = NULL;
+ struct posix_private *priv = NULL;
+ struct iocb *iocb = NULL;
+
+ VALIDATE_OR_GOTO(frame, err);
+ VALIDATE_OR_GOTO(this, err);
+ VALIDATE_OR_GOTO(fd, err);
+
+ priv = this->private;
+
+ ret = posix_fd_ctx_get(fd, this, &pfd, &op_errno);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
+ "pfd is NULL from fd=%p", fd);
+ goto err;
+ }
+ _fd = pfd->fd;
+
+ if (!size) {
+ op_errno = EINVAL;
+ gf_msg(this->name, GF_LOG_WARNING, op_errno, P_MSG_INVALID_ARGUMENT,
+ "size=%" GF_PRI_SIZET, size);
+ goto err;
+ }
+
+ iobuf = iobuf_get2(this->ctx->iobuf_pool, size);
+ if (!iobuf) {
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ paiocb = GF_CALLOC(1, sizeof(*paiocb), gf_posix_mt_paiocb);
+ if (!paiocb) {
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ paiocb->frame = frame;
+ paiocb->iobuf = iobuf;
+ paiocb->offset = offset;
+ paiocb->fd = fd_ref(fd);
+ paiocb->_fd = _fd;
+ paiocb->op = GF_FOP_READ;
+
+ paiocb->iocb.data = paiocb;
+ paiocb->iocb.aio_fildes = _fd;
+ paiocb->iocb.aio_lio_opcode = IO_CMD_PREAD;
+ paiocb->iocb.aio_reqprio = 0;
+ paiocb->iocb.u.c.buf = iobuf_ptr(iobuf);
+ paiocb->iocb.u.c.nbytes = size;
+ paiocb->iocb.u.c.offset = offset;
+
+ iocb = &paiocb->iocb;
+
+ LOCK(&fd->lock);
+ {
+ __posix_fd_set_odirect(fd, pfd, flags, offset, size);
+
+ ret = io_submit(priv->ctxp, 1, &iocb);
+ }
+ UNLOCK(&fd->lock);
+
+ if (ret != 1) {
+ op_errno = -ret;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_IO_SUBMIT_FAILED,
+ "io_submit() returned %d", ret);
+ goto err;
+ }
+
+ return 0;
err:
- STACK_UNWIND_STRICT (readv, frame, -1, op_errno, 0, 0, 0, 0, 0);
- if (iobuf)
- iobuf_unref (iobuf);
-
- if (paiocb) {
- if (paiocb->fd)
- fd_unref(paiocb->fd);
- GF_FREE (paiocb);
- }
+ STACK_UNWIND_STRICT(readv, frame, -1, op_errno, 0, 0, 0, 0, 0);
+ if (iobuf)
+ iobuf_unref(iobuf);
- return 0;
-}
+ if (paiocb) {
+ if (paiocb->fd)
+ fd_unref(paiocb->fd);
+ GF_FREE(paiocb);
+ }
+ return 0;
+}
int
-posix_aio_writev_complete (struct posix_aio_cb *paiocb, int res, int res2)
+posix_aio_writev_complete(struct posix_aio_cb *paiocb, int res, int res2)
{
- call_frame_t *frame = NULL;
- xlator_t *this = NULL;
- struct iatt prebuf = {0,};
- struct iatt postbuf = {0,};
- int _fd = -1;
- int op_ret = -1;
- int op_errno = 0;
- int ret = 0;
- struct posix_private * priv = NULL;
- fd_t *fd = NULL;
-
-
- frame = paiocb->frame;
- this = frame->this;
- priv = this->private;
- prebuf = paiocb->prebuf;
- fd = paiocb->fd;
- _fd = paiocb->_fd;
-
- if (res < 0) {
- op_ret = -1;
- op_errno = -res;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- P_MSG_WRITEV_FAILED,
- "writev(async) failed fd=%d,offset=%llu (%d)",
- _fd, (unsigned long long) paiocb->offset, res);
-
- goto out;
- }
-
- ret = posix_fdstat (this, fd->inode, _fd, &postbuf);
- if (ret != 0) {
- op_ret = -1;
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, op_errno, P_MSG_FSTAT_FAILED,
- "fstat failed on fd=%d", _fd);
- goto out;
- }
-
-
- op_ret = res;
- op_errno = 0;
-
- LOCK (&priv->lock);
- {
- priv->write_value += op_ret;
- }
- UNLOCK (&priv->lock);
+ call_frame_t *frame = NULL;
+ xlator_t *this = NULL;
+ struct iatt prebuf = {
+ 0,
+ };
+ struct iatt postbuf = {
+ 0,
+ };
+ int _fd = -1;
+ int op_ret = -1;
+ int op_errno = 0;
+ int ret = 0;
+ struct posix_private *priv = NULL;
+ fd_t *fd = NULL;
+
+ frame = paiocb->frame;
+ this = frame->this;
+ priv = this->private;
+ prebuf = paiocb->prebuf;
+ fd = paiocb->fd;
+ _fd = paiocb->_fd;
+
+ if (res < 0) {
+ op_ret = -1;
+ op_errno = -res;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_WRITEV_FAILED,
+ "writev(async) failed fd=%d,offset=%llu (%d)", _fd,
+ (unsigned long long)paiocb->offset, res);
+
+ goto out;
+ }
+
+ ret = posix_fdstat(this, fd->inode, _fd, &postbuf);
+ if (ret != 0) {
+ op_ret = -1;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_FSTAT_FAILED,
+ "fstat failed on fd=%d", _fd);
+ goto out;
+ }
+
+ op_ret = res;
+ op_errno = 0;
+
+ LOCK(&priv->lock);
+ {
+ priv->write_value += op_ret;
+ }
+ UNLOCK(&priv->lock);
out:
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, &prebuf, &postbuf,
- NULL);
-
- if (paiocb) {
- if (paiocb->iobref)
- iobref_unref (paiocb->iobref);
- if (paiocb->fd)
- fd_unref(paiocb->fd);
- GF_FREE (paiocb);
- }
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, &prebuf, &postbuf,
+ NULL);
- return 0;
-}
+ if (paiocb) {
+ if (paiocb->iobref)
+ iobref_unref(paiocb->iobref);
+ if (paiocb->fd)
+ fd_unref(paiocb->fd);
+ GF_FREE(paiocb);
+ }
+ return 0;
+}
int
-posix_aio_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *iov, int count, off_t offset, uint32_t flags,
- struct iobref *iobref, dict_t *xdata)
+posix_aio_writev(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *iov, int count, off_t offset, uint32_t flags,
+ struct iobref *iobref, dict_t *xdata)
{
- int32_t op_errno = EINVAL;
- int _fd = -1;
- struct posix_fd *pfd = NULL;
- int ret = -1;
- struct posix_aio_cb *paiocb = NULL;
- struct posix_private *priv = NULL;
- struct iocb *iocb = NULL;
-
-
- VALIDATE_OR_GOTO (frame, err);
- VALIDATE_OR_GOTO (this, err);
- VALIDATE_OR_GOTO (fd, err);
-
- priv = this->private;
- DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_errno, op_errno, err);
-
- ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
- "pfd is NULL from fd=%p", fd);
- goto err;
- }
- _fd = pfd->fd;
-
- paiocb = GF_CALLOC (1, sizeof (*paiocb), gf_posix_mt_paiocb);
- if (!paiocb) {
- op_errno = ENOMEM;
- goto err;
- }
-
-
- paiocb->frame = frame;
- paiocb->offset = offset;
- paiocb->fd = fd_ref(fd);
- paiocb->_fd = _fd;
- paiocb->op = GF_FOP_WRITE;
-
- paiocb->iocb.data = paiocb;
- paiocb->iocb.aio_fildes = _fd;
- paiocb->iobref = iobref_ref (iobref);
- paiocb->iocb.aio_lio_opcode = IO_CMD_PWRITEV;
- paiocb->iocb.aio_reqprio = 0;
- paiocb->iocb.u.v.vec = iov;
- paiocb->iocb.u.v.nr = count;
- paiocb->iocb.u.v.offset = offset;
-
- iocb = &paiocb->iocb;
-
- ret = posix_fdstat (this, fd->inode, _fd, &paiocb->prebuf);
- if (ret != 0) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, op_errno, P_MSG_FSTAT_FAILED,
- "fstat failed on fd=%p", fd);
- goto err;
- }
-
-
- LOCK (&fd->lock);
- {
- __posix_fd_set_odirect (fd, pfd, flags, offset,
- iov_length (iov, count));
-
- ret = io_submit (priv->ctxp, 1, &iocb);
- }
- UNLOCK (&fd->lock);
-
- if (ret != 1) {
- op_errno = -ret;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- P_MSG_IO_SUBMIT_FAILED,
- "io_submit() returned %d,gfid=%s", ret,
- uuid_utoa(fd->inode->gfid));
- goto err;
- }
-
- return 0;
+ int32_t op_errno = EINVAL;
+ int _fd = -1;
+ struct posix_fd *pfd = NULL;
+ int ret = -1;
+ struct posix_aio_cb *paiocb = NULL;
+ struct posix_private *priv = NULL;
+ struct iocb *iocb = NULL;
+
+ VALIDATE_OR_GOTO(frame, err);
+ VALIDATE_OR_GOTO(this, err);
+ VALIDATE_OR_GOTO(fd, err);
+
+ priv = this->private;
+ DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, op_errno, op_errno, err);
+
+ ret = posix_fd_ctx_get(fd, this, &pfd, &op_errno);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_WARNING, op_errno, P_MSG_PFD_NULL,
+ "pfd is NULL from fd=%p", fd);
+ goto err;
+ }
+ _fd = pfd->fd;
+
+ paiocb = GF_CALLOC(1, sizeof(*paiocb), gf_posix_mt_paiocb);
+ if (!paiocb) {
+ op_errno = ENOMEM;
+ goto err;
+ }
+
+ paiocb->frame = frame;
+ paiocb->offset = offset;
+ paiocb->fd = fd_ref(fd);
+ paiocb->_fd = _fd;
+ paiocb->op = GF_FOP_WRITE;
+
+ paiocb->iocb.data = paiocb;
+ paiocb->iocb.aio_fildes = _fd;
+ paiocb->iobref = iobref_ref(iobref);
+ paiocb->iocb.aio_lio_opcode = IO_CMD_PWRITEV;
+ paiocb->iocb.aio_reqprio = 0;
+ paiocb->iocb.u.v.vec = iov;
+ paiocb->iocb.u.v.nr = count;
+ paiocb->iocb.u.v.offset = offset;
+
+ iocb = &paiocb->iocb;
+
+ ret = posix_fdstat(this, fd->inode, _fd, &paiocb->prebuf);
+ if (ret != 0) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_FSTAT_FAILED,
+ "fstat failed on fd=%p", fd);
+ goto err;
+ }
+
+ LOCK(&fd->lock);
+ {
+ __posix_fd_set_odirect(fd, pfd, flags, offset, iov_length(iov, count));
+
+ ret = io_submit(priv->ctxp, 1, &iocb);
+ }
+ UNLOCK(&fd->lock);
+
+ if (ret != 1) {
+ op_errno = -ret;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_IO_SUBMIT_FAILED,
+ "io_submit() returned %d,gfid=%s", ret,
+ uuid_utoa(fd->inode->gfid));
+ goto err;
+ }
+
+ return 0;
err:
- STACK_UNWIND_STRICT (writev, frame, -1, op_errno, 0, 0, 0);
-
- if (paiocb) {
- if (paiocb->iobref)
- iobref_unref (paiocb->iobref);
- if (paiocb->fd)
- fd_unref(paiocb->fd);
- GF_FREE (paiocb);
- }
+ STACK_UNWIND_STRICT(writev, frame, -1, op_errno, 0, 0, 0);
- return 0;
-}
+ if (paiocb) {
+ if (paiocb->iobref)
+ iobref_unref(paiocb->iobref);
+ if (paiocb->fd)
+ fd_unref(paiocb->fd);
+ GF_FREE(paiocb);
+ }
+ return 0;
+}
void *
-posix_aio_thread (void *data)
+posix_aio_thread(void *data)
{
- xlator_t *this = NULL;
- struct posix_private *priv = NULL;
- int ret = 0;
- int i = 0;
- struct io_event events[POSIX_AIO_MAX_NR_GETEVENTS];
- struct io_event *event = NULL;
- struct posix_aio_cb *paiocb = NULL;
-
- this = data;
- THIS = this;
- priv = this->private;
-
- for (;;) {
- memset (&events[0], 0, sizeof (events));
- ret = io_getevents (priv->ctxp, 1, POSIX_AIO_MAX_NR_GETEVENTS,
- &events[0], NULL);
- if (ret <= 0) {
- gf_msg (this->name, GF_LOG_ERROR, -ret,
- P_MSG_IO_GETEVENTS_FAILED,
- "io_getevents() returned %d", ret);
- if (ret == -EINTR)
- continue;
- break;
- }
-
- for (i = 0; i < ret; i++) {
- event = &events[i];
-
- paiocb = event->data;
-
- switch (paiocb->op) {
- case GF_FOP_READ:
- posix_aio_readv_complete (paiocb, event->res,
- event->res2);
- break;
- case GF_FOP_WRITE:
- posix_aio_writev_complete (paiocb, event->res,
- event->res2);
- break;
- default:
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_UNKNOWN_OP,
- "unknown op %d found in piocb",
- paiocb->op);
- break;
- }
- }
+ xlator_t *this = NULL;
+ struct posix_private *priv = NULL;
+ int ret = 0;
+ int i = 0;
+ struct io_event events[POSIX_AIO_MAX_NR_GETEVENTS];
+ struct io_event *event = NULL;
+ struct posix_aio_cb *paiocb = NULL;
+
+ this = data;
+ THIS = this;
+ priv = this->private;
+
+ for (;;) {
+ memset(&events[0], 0, sizeof(events));
+ ret = io_getevents(priv->ctxp, 1, POSIX_AIO_MAX_NR_GETEVENTS,
+ &events[0], NULL);
+ if (ret <= 0) {
+ gf_msg(this->name, GF_LOG_ERROR, -ret, P_MSG_IO_GETEVENTS_FAILED,
+ "io_getevents() returned %d", ret);
+ if (ret == -EINTR)
+ continue;
+ break;
}
- return NULL;
-}
+ for (i = 0; i < ret; i++) {
+ event = &events[i];
+
+ paiocb = event->data;
+
+ switch (paiocb->op) {
+ case GF_FOP_READ:
+ posix_aio_readv_complete(paiocb, event->res, event->res2);
+ break;
+ case GF_FOP_WRITE:
+ posix_aio_writev_complete(paiocb, event->res, event->res2);
+ break;
+ default:
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_UNKNOWN_OP,
+ "unknown op %d found in piocb", paiocb->op);
+ break;
+ }
+ }
+ }
+ return NULL;
+}
int
-posix_aio_init (xlator_t *this)
+posix_aio_init(xlator_t *this)
{
- struct posix_private *priv = NULL;
- int ret = 0;
-
- priv = this->private;
-
- ret = io_setup (POSIX_AIO_MAX_NR_EVENTS, &priv->ctxp);
- if ((ret == -1 && errno == ENOSYS) || ret == -ENOSYS) {
- gf_msg (this->name, GF_LOG_WARNING, 0, P_MSG_AIO_UNAVAILABLE,
- "Linux AIO not available at run-time."
- " Continuing with synchronous IO");
- ret = 0;
- goto out;
- }
-
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, -ret,
- P_MSG_IO_SETUP_FAILED,
- "io_setup() failed. ret=%d",
- ret);
- goto out;
- }
-
- ret = gf_thread_create (&priv->aiothread, NULL,
- posix_aio_thread, this, "posixaio");
- if (ret != 0) {
- io_destroy (priv->ctxp);
- goto out;
- }
-
- this->fops->readv = posix_aio_readv;
- this->fops->writev = posix_aio_writev;
+ struct posix_private *priv = NULL;
+ int ret = 0;
+
+ priv = this->private;
+
+ ret = io_setup(POSIX_AIO_MAX_NR_EVENTS, &priv->ctxp);
+ if ((ret == -1 && errno == ENOSYS) || ret == -ENOSYS) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_AIO_UNAVAILABLE,
+ "Linux AIO not available at run-time."
+ " Continuing with synchronous IO");
+ ret = 0;
+ goto out;
+ }
+
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_WARNING, -ret, P_MSG_IO_SETUP_FAILED,
+ "io_setup() failed. ret=%d", ret);
+ goto out;
+ }
+
+ ret = gf_thread_create(&priv->aiothread, NULL, posix_aio_thread, this,
+ "posixaio");
+ if (ret != 0) {
+ io_destroy(priv->ctxp);
+ goto out;
+ }
+
+ this->fops->readv = posix_aio_readv;
+ this->fops->writev = posix_aio_writev;
out:
- return ret;
+ return ret;
}
-
int
-posix_aio_on (xlator_t *this)
+posix_aio_on(xlator_t *this)
{
- struct posix_private *priv = NULL;
- int ret = 0;
-
- priv = this->private;
-
- if (!priv->aio_init_done) {
- ret = posix_aio_init (this);
- if (ret == 0)
- priv->aio_capable = _gf_true;
- else
- priv->aio_capable = _gf_false;
- priv->aio_init_done = _gf_true;
- }
-
- if (priv->aio_capable) {
- this->fops->readv = posix_aio_readv;
- this->fops->writev = posix_aio_writev;
- }
-
- return ret;
+ struct posix_private *priv = NULL;
+ int ret = 0;
+
+ priv = this->private;
+
+ if (!priv->aio_init_done) {
+ ret = posix_aio_init(this);
+ if (ret == 0)
+ priv->aio_capable = _gf_true;
+ else
+ priv->aio_capable = _gf_false;
+ priv->aio_init_done = _gf_true;
+ }
+
+ if (priv->aio_capable) {
+ this->fops->readv = posix_aio_readv;
+ this->fops->writev = posix_aio_writev;
+ }
+
+ return ret;
}
int
-posix_aio_off (xlator_t *this)
+posix_aio_off(xlator_t *this)
{
- this->fops->readv = posix_readv;
- this->fops->writev = posix_writev;
+ this->fops->readv = posix_readv;
+ this->fops->writev = posix_writev;
- return 0;
+ return 0;
}
-
#else
-
int
-posix_aio_on (xlator_t *this)
+posix_aio_on(xlator_t *this)
{
- gf_msg (this->name, GF_LOG_INFO, 0, P_MSG_AIO_UNAVAILABLE,
- "Linux AIO not available at build-time."
- " Continuing with synchronous IO");
- return 0;
+ gf_msg(this->name, GF_LOG_INFO, 0, P_MSG_AIO_UNAVAILABLE,
+ "Linux AIO not available at build-time."
+ " Continuing with synchronous IO");
+ return 0;
}
int
-posix_aio_off (xlator_t *this)
+posix_aio_off(xlator_t *this)
{
- gf_msg (this->name, GF_LOG_INFO, 0, P_MSG_AIO_UNAVAILABLE,
- "Linux AIO not available at build-time."
- " Continuing with synchronous IO");
- return 0;
+ gf_msg(this->name, GF_LOG_INFO, 0, P_MSG_AIO_UNAVAILABLE,
+ "Linux AIO not available at build-time."
+ " Continuing with synchronous IO");
+ return 0;
}
void
-__posix_fd_set_odirect (fd_t *fd, struct posix_fd *pfd, int opflags,
- off_t offset, size_t size)
+__posix_fd_set_odirect(fd_t *fd, struct posix_fd *pfd, int opflags,
+ off_t offset, size_t size)
{
- xlator_t *this = THIS;
- gf_msg (this->name, GF_LOG_INFO, 0, P_MSG_AIO_UNAVAILABLE,
- "Linux AIO not available at build-time."
- " Continuing with synchronous IO");
- return;
+ xlator_t *this = THIS;
+ gf_msg(this->name, GF_LOG_INFO, 0, P_MSG_AIO_UNAVAILABLE,
+ "Linux AIO not available at build-time."
+ " Continuing with synchronous IO");
+ return;
}
#endif
diff --git a/xlators/storage/posix/src/posix-common.c b/xlators/storage/posix/src/posix-common.c
index 24e990c..2bbf657 100644
--- a/xlators/storage/posix/src/posix-common.c
+++ b/xlators/storage/posix/src/posix-common.c
@@ -67,17 +67,21 @@ extern char *marker_xattrs[];
#undef HAVE_SET_FSID
#ifdef HAVE_SET_FSID
-#define DECLARE_OLD_FS_ID_VAR uid_t old_fsuid; gid_t old_fsgid;
-
-#define SET_FS_ID(uid, gid) do { \
- old_fsuid = setfsuid (uid); \
- old_fsgid = setfsgid (gid); \
- } while (0)
-
-#define SET_TO_OLD_FS_ID() do { \
- setfsuid (old_fsuid); \
- setfsgid (old_fsgid); \
- } while (0)
+#define DECLARE_OLD_FS_ID_VAR \
+ uid_t old_fsuid; \
+ gid_t old_fsgid;
+
+#define SET_FS_ID(uid, gid) \
+ do { \
+ old_fsuid = setfsuid(uid); \
+ old_fsgid = setfsgid(gid); \
+ } while (0)
+
+#define SET_TO_OLD_FS_ID() \
+ do { \
+ setfsuid(old_fsuid); \
+ setfsgid(old_fsgid); \
+ } while (0)
#else
@@ -94,1314 +98,1230 @@ extern char *marker_xattrs[];
struct timeval
otherwise. */
#if HAVE_UTIMENSAT
-#define SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv, nanosecs) \
- tv.tv_nsec = nanosecs
+#define SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv, nanosecs) tv.tv_nsec = nanosecs
#else
-#define SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv, nanosecs) \
- tv.tv_usec = nanosecs / 1000
+#define SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv, nanosecs) \
+ tv.tv_usec = nanosecs / 1000
#endif
-
int32_t
-posix_priv (xlator_t *this)
+posix_priv(xlator_t *this)
{
- struct posix_private *priv = NULL;
- char key_prefix[GF_DUMP_MAX_BUF_LEN];
+ struct posix_private *priv = NULL;
+ char key_prefix[GF_DUMP_MAX_BUF_LEN];
- (void) snprintf(key_prefix, GF_DUMP_MAX_BUF_LEN, "%s.%s",
- this->type, this->name);
- gf_proc_dump_add_section(key_prefix);
+ (void)snprintf(key_prefix, GF_DUMP_MAX_BUF_LEN, "%s.%s", this->type,
+ this->name);
+ gf_proc_dump_add_section(key_prefix);
- if (!this)
- return 0;
+ if (!this)
+ return 0;
- priv = this->private;
+ priv = this->private;
- if (!priv)
- return 0;
+ if (!priv)
+ return 0;
- gf_proc_dump_write("base_path", "%s", priv->base_path);
- gf_proc_dump_write("base_path_length", "%d", priv->base_path_length);
- gf_proc_dump_write("max_read", "%d", priv->read_value);
- gf_proc_dump_write("max_write", "%d", priv->write_value);
- gf_proc_dump_write("nr_files", "%ld", priv->nr_files);
+ gf_proc_dump_write("base_path", "%s", priv->base_path);
+ gf_proc_dump_write("base_path_length", "%d", priv->base_path_length);
+ gf_proc_dump_write("max_read", "%d", priv->read_value);
+ gf_proc_dump_write("max_write", "%d", priv->write_value);
+ gf_proc_dump_write("nr_files", "%ld", priv->nr_files);
- return 0;
+ return 0;
}
int32_t
-posix_inode (xlator_t *this)
+posix_inode(xlator_t *this)
{
- return 0;
+ return 0;
}
/**
* notify - when parent sends PARENT_UP, send CHILD_UP event from here
*/
int32_t
-posix_notify (xlator_t *this,
- int32_t event,
- void *data,
- ...)
+posix_notify(xlator_t *this, int32_t event, void *data, ...)
{
- switch (event)
- {
- case GF_EVENT_PARENT_UP:
- {
- /* Tell the parent that posix xlator is up */
- default_notify (this, GF_EVENT_CHILD_UP, data);
- }
- break;
+ switch (event) {
+ case GF_EVENT_PARENT_UP: {
+ /* Tell the parent that posix xlator is up */
+ default_notify(this, GF_EVENT_CHILD_UP, data);
+ } break;
default:
- /* */
- break;
- }
- return 0;
+ /* */
+ break;
+ }
+ 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_posix_mt_end + 1);
+ if (!this)
+ return ret;
- if (ret != 0) {
- return ret;
- }
+ ret = xlator_mem_acct_init(this, gf_posix_mt_end + 1);
+ if (ret != 0) {
return ret;
+ }
+
+ return ret;
}
static int
-posix_set_owner (xlator_t *this, uid_t uid, gid_t gid)
+posix_set_owner(xlator_t *this, uid_t uid, gid_t gid)
{
- struct posix_private *priv = NULL;
- int ret = -1;
- struct stat st = {0,};
-
- priv = this->private;
-
- ret = sys_lstat (priv->base_path, &st);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_DIR_OPERATION_FAILED, "Failed to stat "
- "brick path %s",
- priv->base_path);
- return ret;
- }
+ struct posix_private *priv = NULL;
+ int ret = -1;
+ struct stat st = {
+ 0,
+ };
+
+ priv = this->private;
+
+ ret = sys_lstat(priv->base_path, &st);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_DIR_OPERATION_FAILED,
+ "Failed to stat "
+ "brick path %s",
+ priv->base_path);
+ return ret;
+ }
- if ((uid == -1 || st.st_uid == uid) &&
- (gid == -1 || st.st_gid == gid))
- return 0;
+ if ((uid == -1 || st.st_uid == uid) && (gid == -1 || st.st_gid == gid))
+ return 0;
- ret = sys_chown (priv->base_path, uid, gid);
- if (ret)
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_DIR_OPERATION_FAILED, "Failed to set uid/gid for"
- " brick path %s", priv->base_path);
+ ret = sys_chown(priv->base_path, uid, gid);
+ if (ret)
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_DIR_OPERATION_FAILED,
+ "Failed to set uid/gid for"
+ " brick path %s",
+ priv->base_path);
- return ret;
+ return ret;
}
static int
-set_gfid2path_separator (struct posix_private *priv, const char *str)
+set_gfid2path_separator(struct posix_private *priv, const char *str)
{
- int str_len = 0;
+ int str_len = 0;
- str_len = strlen(str);
- if (str_len > 0 && str_len < 8) {
- strcpy (priv->gfid2path_sep, str);
- return 0;
- }
+ str_len = strlen(str);
+ if (str_len > 0 && str_len < 8) {
+ strcpy(priv->gfid2path_sep, str);
+ return 0;
+ }
- return -1;
+ return -1;
}
static int
-set_batch_fsync_mode (struct posix_private *priv, const char *str)
+set_batch_fsync_mode(struct posix_private *priv, const char *str)
{
- if (strcmp (str, "none") == 0)
- priv->batch_fsync_mode = BATCH_NONE;
- else if (strcmp (str, "syncfs") == 0)
- priv->batch_fsync_mode = BATCH_SYNCFS;
- else if (strcmp (str, "syncfs-single-fsync") == 0)
- priv->batch_fsync_mode = BATCH_SYNCFS_SINGLE_FSYNC;
- else if (strcmp (str, "syncfs-reverse-fsync") == 0)
- priv->batch_fsync_mode = BATCH_SYNCFS_REVERSE_FSYNC;
- else if (strcmp (str, "reverse-fsync") == 0)
- priv->batch_fsync_mode = BATCH_REVERSE_FSYNC;
- else
- return -1;
+ if (strcmp(str, "none") == 0)
+ priv->batch_fsync_mode = BATCH_NONE;
+ else if (strcmp(str, "syncfs") == 0)
+ priv->batch_fsync_mode = BATCH_SYNCFS;
+ else if (strcmp(str, "syncfs-single-fsync") == 0)
+ priv->batch_fsync_mode = BATCH_SYNCFS_SINGLE_FSYNC;
+ else if (strcmp(str, "syncfs-reverse-fsync") == 0)
+ priv->batch_fsync_mode = BATCH_SYNCFS_REVERSE_FSYNC;
+ else if (strcmp(str, "reverse-fsync") == 0)
+ priv->batch_fsync_mode = BATCH_REVERSE_FSYNC;
+ else
+ return -1;
- return 0;
+ return 0;
}
#ifdef GF_DARWIN_HOST_OS
static int
-set_xattr_user_namespace_mode (struct posix_private *priv, const char *str)
+set_xattr_user_namespace_mode(struct posix_private *priv, const char *str)
{
- if (strcmp (str, "none") == 0)
- priv->xattr_user_namespace = XATTR_NONE;
- else if (strcmp (str, "strip") == 0)
- priv->xattr_user_namespace = XATTR_STRIP;
- else if (strcmp (str, "append") == 0)
- priv->xattr_user_namespace = XATTR_APPEND;
- else if (strcmp (str, "both") == 0)
- priv->xattr_user_namespace = XATTR_BOTH;
- else
- return -1;
- return 0;
+ if (strcmp(str, "none") == 0)
+ priv->xattr_user_namespace = XATTR_NONE;
+ else if (strcmp(str, "strip") == 0)
+ priv->xattr_user_namespace = XATTR_STRIP;
+ else if (strcmp(str, "append") == 0)
+ priv->xattr_user_namespace = XATTR_APPEND;
+ else if (strcmp(str, "both") == 0)
+ priv->xattr_user_namespace = XATTR_BOTH;
+ else
+ return -1;
+ return 0;
}
#endif
int
-posix_reconfigure (xlator_t *this, dict_t *options)
+posix_reconfigure(xlator_t *this, dict_t *options)
{
- int ret = -1;
- struct posix_private *priv = NULL;
- int32_t uid = -1;
- int32_t gid = -1;
- char *batch_fsync_mode_str = NULL;
- char *gfid2path_sep = NULL;
- int32_t force_create_mode = -1;
- int32_t force_directory_mode = -1;
- int32_t create_mask = -1;
- int32_t create_directory_mask = -1;
-
- priv = this->private;
-
- GF_OPTION_RECONF ("brick-uid", uid, options, int32, out);
- GF_OPTION_RECONF ("brick-gid", gid, options, int32, out);
- if (uid != -1 || gid != -1)
- posix_set_owner (this, uid, gid);
-
- GF_OPTION_RECONF ("batch-fsync-delay-usec", priv->batch_fsync_delay_usec,
- options, uint32, out);
-
- GF_OPTION_RECONF ("batch-fsync-mode", batch_fsync_mode_str,
- options, str, out);
-
- if (set_batch_fsync_mode (priv, batch_fsync_mode_str) != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_ARGUMENT,
- "Unknown mode string: %s", batch_fsync_mode_str);
- goto out;
- }
-
- GF_OPTION_RECONF ("gfid2path-separator", gfid2path_sep, options,
- str, out);
- if (set_gfid2path_separator (priv, gfid2path_sep) != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_ARGUMENT,
- "Length of separator exceeds 7: %s", gfid2path_sep);
- goto out;
- }
+ int ret = -1;
+ struct posix_private *priv = NULL;
+ int32_t uid = -1;
+ int32_t gid = -1;
+ char *batch_fsync_mode_str = NULL;
+ char *gfid2path_sep = NULL;
+ int32_t force_create_mode = -1;
+ int32_t force_directory_mode = -1;
+ int32_t create_mask = -1;
+ int32_t create_directory_mask = -1;
+
+ priv = this->private;
+
+ GF_OPTION_RECONF("brick-uid", uid, options, int32, out);
+ GF_OPTION_RECONF("brick-gid", gid, options, int32, out);
+ if (uid != -1 || gid != -1)
+ posix_set_owner(this, uid, gid);
+
+ GF_OPTION_RECONF("batch-fsync-delay-usec", priv->batch_fsync_delay_usec,
+ options, uint32, out);
+
+ GF_OPTION_RECONF("batch-fsync-mode", batch_fsync_mode_str, options, str,
+ out);
+
+ if (set_batch_fsync_mode(priv, batch_fsync_mode_str) != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_ARGUMENT,
+ "Unknown mode string: %s", batch_fsync_mode_str);
+ goto out;
+ }
+
+ GF_OPTION_RECONF("gfid2path-separator", gfid2path_sep, options, str, out);
+ if (set_gfid2path_separator(priv, gfid2path_sep) != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_ARGUMENT,
+ "Length of separator exceeds 7: %s", gfid2path_sep);
+ goto out;
+ }
#ifdef GF_DARWIN_HOST_OS
- char *xattr_user_namespace_mode_str = NULL;
+ char *xattr_user_namespace_mode_str = NULL;
- GF_OPTION_RECONF ("xattr-user-namespace-mode", xattr_user_namespace_mode_str,
- options, str, out);
+ GF_OPTION_RECONF("xattr-user-namespace-mode", xattr_user_namespace_mode_str,
+ options, str, out);
- if (set_xattr_user_namespace_mode (priv, xattr_user_namespace_mode_str) != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_UNKNOWN_ARGUMENT,
- "Unknown xattr user namespace mode string: %s",
- xattr_user_namespace_mode_str);
- goto out;
- }
+ if (set_xattr_user_namespace_mode(priv, xattr_user_namespace_mode_str) !=
+ 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_UNKNOWN_ARGUMENT,
+ "Unknown xattr user namespace mode string: %s",
+ xattr_user_namespace_mode_str);
+ goto out;
+ }
#endif
- GF_OPTION_RECONF ("linux-aio", priv->aio_configured,
- options, bool, out);
+ GF_OPTION_RECONF("linux-aio", priv->aio_configured, options, bool, out);
- if (priv->aio_configured)
- posix_aio_on (this);
- else
- posix_aio_off (this);
+ if (priv->aio_configured)
+ posix_aio_on(this);
+ else
+ posix_aio_off(this);
- GF_OPTION_RECONF ("update-link-count-parent", priv->update_pgfid_nlinks,
- options, bool, out);
+ GF_OPTION_RECONF("update-link-count-parent", priv->update_pgfid_nlinks,
+ options, bool, out);
- GF_OPTION_RECONF ("gfid2path", priv->gfid2path,
- options, bool, out);
+ GF_OPTION_RECONF("gfid2path", priv->gfid2path, options, bool, out);
- GF_OPTION_RECONF ("node-uuid-pathinfo", priv->node_uuid_pathinfo,
- options, bool, out);
+ GF_OPTION_RECONF("node-uuid-pathinfo", priv->node_uuid_pathinfo, options,
+ bool, out);
- if (priv->node_uuid_pathinfo &&
- (gf_uuid_is_null (priv->glusterd_uuid))) {
- gf_msg (this->name, GF_LOG_INFO, 0, P_MSG_UUID_NULL,
- "glusterd uuid is NULL, pathinfo xattr would"
- " fallback to <hostname>:<export>");
- }
+ if (priv->node_uuid_pathinfo && (gf_uuid_is_null(priv->glusterd_uuid))) {
+ gf_msg(this->name, GF_LOG_INFO, 0, P_MSG_UUID_NULL,
+ "glusterd uuid is NULL, pathinfo xattr would"
+ " fallback to <hostname>:<export>");
+ }
- GF_OPTION_RECONF ("reserve", priv->disk_reserve,
- options, uint32, out);
- if (priv->disk_reserve)
- posix_spawn_disk_space_check_thread (this);
-
- GF_OPTION_RECONF ("health-check-interval", priv->health_check_interval,
- options, uint32, out);
- GF_OPTION_RECONF ("health-check-timeout", priv->health_check_timeout,
- options, uint32, out);
- posix_spawn_health_check_thread (this);
-
- GF_OPTION_RECONF ("shared-brick-count", priv->shared_brick_count,
- options, int32, out);
-
- GF_OPTION_RECONF ("disable-landfill-purge",
- priv->disable_landfill_purge,
- options, bool, out);
- if (priv->disable_landfill_purge) {
- gf_log (this->name, GF_LOG_WARNING,
- "Janitor WILL NOT purge the landfill directory. "
- "Your landfill directory"
- " may fill up this brick.");
- } else {
- gf_msg_debug (this->name, 0, "Janitor will purge the landfill "
- "directory, which is default behavior");
- }
+ GF_OPTION_RECONF("reserve", priv->disk_reserve, options, uint32, out);
+ if (priv->disk_reserve)
+ posix_spawn_disk_space_check_thread(this);
+
+ GF_OPTION_RECONF("health-check-interval", priv->health_check_interval,
+ options, uint32, out);
+ GF_OPTION_RECONF("health-check-timeout", priv->health_check_timeout,
+ options, uint32, out);
+ posix_spawn_health_check_thread(this);
+
+ GF_OPTION_RECONF("shared-brick-count", priv->shared_brick_count, options,
+ int32, out);
+
+ GF_OPTION_RECONF("disable-landfill-purge", priv->disable_landfill_purge,
+ options, bool, out);
+ if (priv->disable_landfill_purge) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "Janitor WILL NOT purge the landfill directory. "
+ "Your landfill directory"
+ " may fill up this brick.");
+ } else {
+ gf_msg_debug(this->name, 0,
+ "Janitor will purge the landfill "
+ "directory, which is default behavior");
+ }
- GF_OPTION_RECONF ("force-create-mode", force_create_mode,
- options, int32, out);
- priv->force_create_mode = force_create_mode;
+ GF_OPTION_RECONF("force-create-mode", force_create_mode, options, int32,
+ out);
+ priv->force_create_mode = force_create_mode;
- GF_OPTION_RECONF ("force-directory-mode", force_directory_mode,
- options, int32, out);
- priv->force_directory_mode = force_directory_mode;
+ GF_OPTION_RECONF("force-directory-mode", force_directory_mode, options,
+ int32, out);
+ priv->force_directory_mode = force_directory_mode;
- GF_OPTION_RECONF ("create-mask", create_mask,
- options, int32, out);
- priv->create_mask = create_mask;
+ GF_OPTION_RECONF("create-mask", create_mask, options, int32, out);
+ priv->create_mask = create_mask;
- GF_OPTION_RECONF ("create-directory-mask", create_directory_mask,
- options, int32, out);
- priv->create_directory_mask = create_directory_mask;
+ GF_OPTION_RECONF("create-directory-mask", create_directory_mask, options,
+ int32, out);
+ priv->create_directory_mask = create_directory_mask;
- GF_OPTION_RECONF ("max-hardlinks", priv->max_hardlinks,
- options, uint32, out);
+ GF_OPTION_RECONF("max-hardlinks", priv->max_hardlinks, options, uint32,
+ out);
- GF_OPTION_RECONF ("fips-mode-rchecksum", priv->fips_mode_rchecksum,
- options, bool, out);
+ GF_OPTION_RECONF("fips-mode-rchecksum", priv->fips_mode_rchecksum, options,
+ bool, out);
- GF_OPTION_RECONF ("ctime", priv->ctime, options, bool, out);
+ GF_OPTION_RECONF("ctime", priv->ctime, options, bool, out);
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
int32_t
-posix_delete_unlink_entry (const char *fpath, const struct stat *sb,
- int typeflag, struct FTW *ftwbuf) {
-
- int ret = 0;
+posix_delete_unlink_entry(const char *fpath, const struct stat *sb,
+ int typeflag, struct FTW *ftwbuf)
+{
+ int ret = 0;
- if (!fpath)
- goto out;
+ if (!fpath)
+ goto out;
- switch (typeflag) {
+ switch (typeflag) {
case FTW_SL:
case FTW_NS:
case FTW_F:
case FTW_SLN:
- ret = sys_unlink(fpath);
- break;
+ ret = sys_unlink(fpath);
+ break;
case FTW_D:
case FTW_DP:
case FTW_DNR:
- if (ftwbuf->level != 0) {
- ret = sys_rmdir(fpath);
- }
- break;
+ if (ftwbuf->level != 0) {
+ ret = sys_rmdir(fpath);
+ }
+ break;
default:
- break;
- }
- if (ret) {
- gf_msg ("posix_delete_unlink_entry", GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE,
- "Deletion of entries %s failed"
- "Please delete it manually",
- fpath);
- }
+ break;
+ }
+ if (ret) {
+ gf_msg("posix_delete_unlink_entry", GF_LOG_WARNING, errno,
+ P_MSG_HANDLE_CREATE,
+ "Deletion of entries %s failed"
+ "Please delete it manually",
+ fpath);
+ }
out:
- return 0;
+ return 0;
}
int32_t
-posix_delete_unlink (const char *unlink_path) {
-
- int ret = -1;
- int flags = 0;
+posix_delete_unlink(const char *unlink_path)
+{
+ int ret = -1;
+ int flags = 0;
- flags |= (FTW_DEPTH | FTW_PHYS);
+ flags |= (FTW_DEPTH | FTW_PHYS);
- ret = nftw(unlink_path, posix_delete_unlink_entry, 2, flags);
- if (ret) {
- gf_msg ("posix_delete_unlink", GF_LOG_ERROR, 0,
- P_MSG_HANDLE_CREATE,
- "Deleting files from %s failed",
- unlink_path);
- }
- return ret;
+ ret = nftw(unlink_path, posix_delete_unlink_entry, 2, flags);
+ if (ret) {
+ gf_msg("posix_delete_unlink", GF_LOG_ERROR, 0, P_MSG_HANDLE_CREATE,
+ "Deleting files from %s failed", unlink_path);
+ }
+ return ret;
}
int32_t
-posix_create_unlink_dir (xlator_t *this) {
-
- struct posix_private *priv = NULL;
- struct stat stbuf;
- int ret = -1;
- uuid_t gfid = {0};
- char gfid_str[64] = {0};
- char unlink_path[PATH_MAX] = {0,};
- char landfill_path[PATH_MAX] = {0,};
-
- priv = this->private;
-
- (void) snprintf (unlink_path, sizeof(unlink_path), "%s/%s",
- priv->base_path, GF_UNLINK_PATH);
-
- gf_uuid_generate (gfid);
- uuid_utoa_r (gfid, gfid_str);
-
- (void) snprintf (landfill_path, sizeof(landfill_path), "%s/%s/%s",
- priv->base_path, GF_LANDFILL_PATH, gfid_str);
-
- ret = sys_stat (unlink_path, &stbuf);
- switch (ret) {
+posix_create_unlink_dir(xlator_t *this)
+{
+ struct posix_private *priv = NULL;
+ struct stat stbuf;
+ int ret = -1;
+ uuid_t gfid = {0};
+ char gfid_str[64] = {0};
+ char unlink_path[PATH_MAX] = {
+ 0,
+ };
+ char landfill_path[PATH_MAX] = {
+ 0,
+ };
+
+ priv = this->private;
+
+ (void)snprintf(unlink_path, sizeof(unlink_path), "%s/%s", priv->base_path,
+ GF_UNLINK_PATH);
+
+ gf_uuid_generate(gfid);
+ uuid_utoa_r(gfid, gfid_str);
+
+ (void)snprintf(landfill_path, sizeof(landfill_path), "%s/%s/%s",
+ priv->base_path, GF_LANDFILL_PATH, gfid_str);
+
+ ret = sys_stat(unlink_path, &stbuf);
+ switch (ret) {
case -1:
- if (errno != ENOENT) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_CREATE,
- "Checking for %s failed",
- unlink_path);
- return -1;
- }
- break;
+ if (errno != ENOENT) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_CREATE,
+ "Checking for %s failed", unlink_path);
+ return -1;
+ }
+ break;
case 0:
- if (!S_ISDIR (stbuf.st_mode)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_HANDLE_CREATE,
- "Not a directory: %s",
- unlink_path);
- return -1;
- }
- ret = posix_delete_unlink (unlink_path);
- return 0;
- default:
- break;
- }
- ret = sys_mkdir (unlink_path, 0600);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_CREATE,
- "Creating directory %s failed",
- unlink_path);
+ if (!S_ISDIR(stbuf.st_mode)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_HANDLE_CREATE,
+ "Not a directory: %s", unlink_path);
return -1;
- }
+ }
+ ret = posix_delete_unlink(unlink_path);
+ return 0;
+ default:
+ break;
+ }
+ ret = sys_mkdir(unlink_path, 0600);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_CREATE,
+ "Creating directory %s failed", unlink_path);
+ return -1;
+ }
- return 0;
+ return 0;
}
/**
* init -
*/
int
-posix_init (xlator_t *this)
+posix_init(xlator_t *this)
{
- struct posix_private *_private = NULL;
- data_t *dir_data = NULL;
- data_t *tmp_data = NULL;
- struct stat buf = {0,};
- gf_boolean_t tmp_bool = 0;
- int ret = 0;
- int op_ret = -1;
- int op_errno = 0;
- ssize_t size = -1;
- uuid_t old_uuid = {0,};
- uuid_t dict_uuid = {0,};
- uuid_t gfid = {0,};
- uuid_t rootgfid = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
- char *guuid = NULL;
- int32_t uid = -1;
- int32_t gid = -1;
- char *batch_fsync_mode_str;
- char *gfid2path_sep = NULL;
- int force_create = -1;
- int force_directory = -1;
- int create_mask = -1;
- int create_directory_mask = -1;
-
- dir_data = dict_get (this->options, "directory");
-
- if (this->children) {
- gf_msg (this->name, GF_LOG_CRITICAL, 0, P_MSG_SUBVOLUME_ERROR,
- "FATAL: storage/posix cannot have subvolumes");
- ret = -1;
- goto out;
+ struct posix_private *_private = NULL;
+ data_t *dir_data = NULL;
+ data_t *tmp_data = NULL;
+ struct stat buf = {
+ 0,
+ };
+ gf_boolean_t tmp_bool = 0;
+ int ret = 0;
+ int op_ret = -1;
+ int op_errno = 0;
+ ssize_t size = -1;
+ uuid_t old_uuid = {
+ 0,
+ };
+ uuid_t dict_uuid = {
+ 0,
+ };
+ uuid_t gfid = {
+ 0,
+ };
+ uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
+ char *guuid = NULL;
+ int32_t uid = -1;
+ int32_t gid = -1;
+ char *batch_fsync_mode_str;
+ char *gfid2path_sep = NULL;
+ int force_create = -1;
+ int force_directory = -1;
+ int create_mask = -1;
+ int create_directory_mask = -1;
+
+ dir_data = dict_get(this->options, "directory");
+
+ if (this->children) {
+ gf_msg(this->name, GF_LOG_CRITICAL, 0, P_MSG_SUBVOLUME_ERROR,
+ "FATAL: storage/posix cannot have subvolumes");
+ ret = -1;
+ goto out;
+ }
+
+ if (!this->parents) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_VOLUME_DANGLING,
+ "Volume is dangling. Please check the volume file.");
+ }
+
+ if (!dir_data) {
+ gf_msg(this->name, GF_LOG_CRITICAL, 0, P_MSG_EXPORT_DIR_MISSING,
+ "Export directory not specified in volume file.");
+ ret = -1;
+ goto out;
+ }
+
+ umask(000); // umask `masking' is done at the client side
+
+ /* Check whether the specified directory exists, if not log it. */
+ op_ret = sys_stat(dir_data->data, &buf);
+ if ((op_ret != 0) || !S_ISDIR(buf.st_mode)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_DIR_OPERATION_FAILED,
+ "Directory '%s' doesn't exist, exiting.", dir_data->data);
+ ret = -1;
+ goto out;
+ }
+
+ _private = GF_CALLOC(1, sizeof(*_private), gf_posix_mt_posix_private);
+ if (!_private) {
+ ret = -1;
+ goto out;
+ }
+
+ _private->base_path = gf_strdup(dir_data->data);
+ _private->base_path_length = strlen(_private->base_path);
+
+ ret = dict_get_str(this->options, "hostname", &_private->hostname);
+ if (ret) {
+ _private->hostname = GF_CALLOC(256, sizeof(char), gf_common_mt_char);
+ if (!_private->hostname) {
+ goto out;
}
-
- if (!this->parents) {
- gf_msg (this->name, GF_LOG_WARNING, 0, P_MSG_VOLUME_DANGLING,
- "Volume is dangling. Please check the volume file.");
+ ret = gethostname(_private->hostname, 256);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HOSTNAME_MISSING,
+ "could not find hostname ");
}
+ }
- if (!dir_data) {
- gf_msg (this->name, GF_LOG_CRITICAL, 0,
- P_MSG_EXPORT_DIR_MISSING,
- "Export directory not specified in volume file.");
- ret = -1;
- goto out;
+ /* Check for Extended attribute support, if not present, log it */
+ op_ret = sys_lsetxattr(dir_data->data, "trusted.glusterfs.test", "working",
+ 8, 0);
+ if (op_ret != -1) {
+ ret = sys_lremovexattr(dir_data->data, "trusted.glusterfs.test");
+ if (ret) {
+ gf_msg(this->name, GF_LOG_DEBUG, errno, P_MSG_INVALID_OPTION,
+ "failed to remove xattr: "
+ "trusted.glusterfs.test");
}
-
- umask (000); // umask `masking' is done at the client side
-
- /* Check whether the specified directory exists, if not log it. */
- op_ret = sys_stat (dir_data->data, &buf);
- if ((op_ret != 0) || !S_ISDIR (buf.st_mode)) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_DIR_OPERATION_FAILED,
- "Directory '%s' doesn't exist, exiting.",
- dir_data->data);
+ } else {
+ tmp_data = dict_get(this->options, "mandate-attribute");
+ if (tmp_data) {
+ if (gf_string2boolean(tmp_data->data, &tmp_bool) == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_OPTION,
+ "wrong option provided for key "
+ "\"mandate-attribute\"");
ret = -1;
goto out;
- }
-
- _private = GF_CALLOC (1, sizeof (*_private),
- gf_posix_mt_posix_private);
- if (!_private) {
+ }
+ if (!tmp_bool) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_XATTR_NOTSUP,
+ "Extended attribute not supported, "
+ "starting as per option");
+ } else {
+ gf_msg(this->name, GF_LOG_CRITICAL, 0, P_MSG_XATTR_NOTSUP,
+ "Extended attribute not supported, "
+ "exiting.");
ret = -1;
goto out;
- }
-
- _private->base_path = gf_strdup (dir_data->data);
- _private->base_path_length = strlen (_private->base_path);
-
- ret = dict_get_str (this->options, "hostname", &_private->hostname);
- if (ret) {
- _private->hostname = GF_CALLOC (256, sizeof (char),
- gf_common_mt_char);
- if (!_private->hostname) {
- goto out;
- }
- ret = gethostname (_private->hostname, 256);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HOSTNAME_MISSING,
- "could not find hostname ");
- }
- }
-
- /* Check for Extended attribute support, if not present, log it */
- op_ret = sys_lsetxattr (dir_data->data,
- "trusted.glusterfs.test", "working", 8, 0);
- if (op_ret != -1) {
- ret = sys_lremovexattr (dir_data->data,
- "trusted.glusterfs.test");
- if (ret) {
- gf_msg (this->name, GF_LOG_DEBUG, errno,
- P_MSG_INVALID_OPTION,
- "failed to remove xattr: "
- "trusted.glusterfs.test");
- }
+ }
} else {
- tmp_data = dict_get (this->options,
- "mandate-attribute");
- if (tmp_data) {
- if (gf_string2boolean (tmp_data->data,
- &tmp_bool) == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_INVALID_OPTION,
- "wrong option provided for key "
- "\"mandate-attribute\"");
- ret = -1;
- goto out;
- }
- if (!tmp_bool) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_XATTR_NOTSUP,
- "Extended attribute not supported, "
- "starting as per option");
- } else {
- gf_msg (this->name, GF_LOG_CRITICAL, 0,
- P_MSG_XATTR_NOTSUP,
- "Extended attribute not supported, "
- "exiting.");
- ret = -1;
- goto out;
- }
- } else {
- gf_msg (this->name, GF_LOG_CRITICAL, 0,
- P_MSG_XATTR_NOTSUP,
- "Extended attribute not supported, exiting.");
- ret = -1;
- goto out;
- }
+ gf_msg(this->name, GF_LOG_CRITICAL, 0, P_MSG_XATTR_NOTSUP,
+ "Extended attribute not supported, exiting.");
+ ret = -1;
+ goto out;
}
+ }
- tmp_data = dict_get (this->options, "volume-id");
- if (tmp_data) {
- op_ret = gf_uuid_parse (tmp_data->data, dict_uuid);
- if (op_ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_INVALID_VOLUME_ID,
- "wrong volume-id (%s) set"
- " in volume file", tmp_data->data);
- ret = -1;
- goto out;
- }
- size = sys_lgetxattr (dir_data->data,
- "trusted.glusterfs.volume-id", old_uuid, 16);
- if (size == 16) {
- if (gf_uuid_compare (old_uuid, dict_uuid)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_INVALID_VOLUME_ID,
- "mismatching volume-id (%s) received. "
- "already is a part of volume %s ",
- tmp_data->data, uuid_utoa (old_uuid));
- gf_event (EVENT_POSIX_ALREADY_PART_OF_VOLUME,
- "volume-id=%s;brick=%s:%s",
- uuid_utoa (old_uuid),
- _private->hostname, _private->base_path);
- ret = -1;
- goto out;
- }
- } else if ((size == -1) &&
- (errno == ENODATA || errno == ENOATTR)) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_VOLUME_ID_ABSENT,
- "Extended attribute trusted.glusterfs."
- "volume-id is absent");
- gf_event (EVENT_POSIX_BRICK_NOT_IN_VOLUME,
- "brick=%s:%s",
- _private->hostname, _private->base_path);
- ret = -1;
- goto out;
-
- } else if ((size == -1) && (errno != ENODATA) &&
- (errno != ENOATTR)) {
- /* Wrong 'volume-id' is set, it should be error */
- gf_event (EVENT_POSIX_BRICK_VERIFICATION_FAILED,
- "brick=%s:%s",
- _private->hostname, _private->base_path);
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_VOLUME_ID_FETCH_FAILED,
- "%s: failed to fetch volume-id",
- dir_data->data);
- ret = -1;
- goto out;
- } else {
- ret = -1;
- gf_event (EVENT_POSIX_BRICK_VERIFICATION_FAILED,
- "brick=%s:%s",
- _private->hostname, _private->base_path);
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_VOLUME_ID_FETCH_FAILED,
- "failed to fetch proper volume id from export");
- goto out;
- }
+ tmp_data = dict_get(this->options, "volume-id");
+ if (tmp_data) {
+ op_ret = gf_uuid_parse(tmp_data->data, dict_uuid);
+ if (op_ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_VOLUME_ID,
+ "wrong volume-id (%s) set"
+ " in volume file",
+ tmp_data->data);
+ ret = -1;
+ goto out;
}
-
- /* Now check if the export directory has some other 'gfid',
- other than that of root '/' */
- size = sys_lgetxattr (dir_data->data, "trusted.gfid", gfid, 16);
+ size = sys_lgetxattr(dir_data->data, "trusted.glusterfs.volume-id",
+ old_uuid, 16);
if (size == 16) {
- if (!__is_root_gfid (gfid)) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_GFID_SET_FAILED,
- "%s: gfid (%s) is not that of glusterfs '/' ",
- dir_data->data, uuid_utoa (gfid));
- ret = -1;
- goto out;
- }
- } else if (size != -1) {
- /* Wrong 'gfid' is set, it should be error */
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_GFID_SET_FAILED,
- "%s: wrong value set as gfid",
- dir_data->data);
- ret = -1;
- goto out;
- } else if ((size == -1) && (errno != ENODATA) &&
- (errno != ENOATTR)) {
- /* Wrong 'gfid' is set, it should be error */
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_GFID_SET_FAILED,
- "%s: failed to fetch gfid",
- dir_data->data);
+ if (gf_uuid_compare(old_uuid, dict_uuid)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_VOLUME_ID,
+ "mismatching volume-id (%s) received. "
+ "already is a part of volume %s ",
+ tmp_data->data, uuid_utoa(old_uuid));
+ gf_event(EVENT_POSIX_ALREADY_PART_OF_VOLUME,
+ "volume-id=%s;brick=%s:%s", uuid_utoa(old_uuid),
+ _private->hostname, _private->base_path);
ret = -1;
goto out;
+ }
+ } else if ((size == -1) && (errno == ENODATA || errno == ENOATTR)) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_VOLUME_ID_ABSENT,
+ "Extended attribute trusted.glusterfs."
+ "volume-id is absent");
+ gf_event(EVENT_POSIX_BRICK_NOT_IN_VOLUME, "brick=%s:%s",
+ _private->hostname, _private->base_path);
+ ret = -1;
+ goto out;
+
+ } else if ((size == -1) && (errno != ENODATA) && (errno != ENOATTR)) {
+ /* Wrong 'volume-id' is set, it should be error */
+ gf_event(EVENT_POSIX_BRICK_VERIFICATION_FAILED, "brick=%s:%s",
+ _private->hostname, _private->base_path);
+ gf_msg(this->name, GF_LOG_WARNING, errno,
+ P_MSG_VOLUME_ID_FETCH_FAILED,
+ "%s: failed to fetch volume-id", dir_data->data);
+ ret = -1;
+ goto out;
} else {
- /* First time volume, set the GFID */
- size = sys_lsetxattr (dir_data->data, "trusted.gfid", rootgfid,
- 16, XATTR_CREATE);
- if (size == -1) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_GFID_SET_FAILED,
- "%s: failed to set gfid",
- dir_data->data);
- ret = -1;
- goto out;
- }
- }
-
- ret = 0;
-
- size = sys_lgetxattr (dir_data->data, POSIX_ACL_ACCESS_XATTR,
- NULL, 0);
- if ((size < 0) && (errno == ENOTSUP)) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_ACL_NOTSUP,
- "Posix access control list is not supported.");
- gf_event (EVENT_POSIX_ACL_NOT_SUPPORTED,
- "brick=%s:%s", _private->hostname, _private->base_path);
+ ret = -1;
+ gf_event(EVENT_POSIX_BRICK_VERIFICATION_FAILED, "brick=%s:%s",
+ _private->hostname, _private->base_path);
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_VOLUME_ID_FETCH_FAILED,
+ "failed to fetch proper volume id from export");
+ goto out;
}
-
- /*
- * _XOPEN_PATH_MAX is the longest file path len we MUST
- * support according to POSIX standard. When prepended
- * by the brick base path it may exceed backed filesystem
- * capacity (which MAY be bigger than _XOPEN_PATH_MAX). If
- * this is the case, chdir() to the brick base path and
- * use relative paths when they are too long. See also
- * MAKE_REAL_PATH in posix-handle.h
- */
- _private->path_max = pathconf(_private->base_path, _PC_PATH_MAX);
- if (_private->path_max != -1 &&
- _XOPEN_PATH_MAX + _private->base_path_length > _private->path_max) {
- ret = chdir(_private->base_path);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_BASEPATH_CHDIR_FAILED,
- "chdir() to \"%s\" failed",
- _private->base_path);
- goto out;
- }
-#ifdef __NetBSD__
- /*
- * At least on NetBSD, the chdir() above uncovers a
- * race condition which cause file lookup to fail
- * with ENODATA for a few seconds. The volume quickly
- * reaches a sane state, but regression tests are fast
- * enough to choke on it. The reason is obscure (as
- * often with race conditions), but sleeping here for
- * a second seems to workaround the problem.
- */
- sleep(1);
-#endif
+ }
+
+ /* Now check if the export directory has some other 'gfid',
+ other than that of root '/' */
+ size = sys_lgetxattr(dir_data->data, "trusted.gfid", gfid, 16);
+ if (size == 16) {
+ if (!__is_root_gfid(gfid)) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_GFID_SET_FAILED,
+ "%s: gfid (%s) is not that of glusterfs '/' ",
+ dir_data->data, uuid_utoa(gfid));
+ ret = -1;
+ goto out;
}
-
-
- LOCK_INIT (&_private->lock);
-
- _private->export_statfs = 1;
- tmp_data = dict_get (this->options, "export-statfs-size");
- if (tmp_data) {
- if (gf_string2boolean (tmp_data->data,
- &_private->export_statfs) == -1) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_INVALID_OPTION_VAL,
- "'export-statfs-size' takes only boolean "
- "options");
- goto out;
- }
- if (!_private->export_statfs)
- gf_msg_debug (this->name, 0,
- "'statfs()' returns dummy size");
+ } else if (size != -1) {
+ /* Wrong 'gfid' is set, it should be error */
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_GFID_SET_FAILED,
+ "%s: wrong value set as gfid", dir_data->data);
+ ret = -1;
+ goto out;
+ } else if ((size == -1) && (errno != ENODATA) && (errno != ENOATTR)) {
+ /* Wrong 'gfid' is set, it should be error */
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_GFID_SET_FAILED,
+ "%s: failed to fetch gfid", dir_data->data);
+ ret = -1;
+ goto out;
+ } else {
+ /* First time volume, set the GFID */
+ size = sys_lsetxattr(dir_data->data, "trusted.gfid", rootgfid, 16,
+ XATTR_CREATE);
+ if (size == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_GFID_SET_FAILED,
+ "%s: failed to set gfid", dir_data->data);
+ ret = -1;
+ goto out;
}
-
- _private->background_unlink = 0;
- tmp_data = dict_get (this->options, "background-unlink");
- if (tmp_data) {
- if (gf_string2boolean (tmp_data->data,
- &_private->background_unlink) == -1) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_INVALID_OPTION_VAL, "'background-unlink'"
- " takes only boolean options");
- goto out;
- }
-
- if (_private->background_unlink)
- gf_msg_debug (this->name, 0,
- "unlinks will be performed in background");
+ }
+
+ ret = 0;
+
+ size = sys_lgetxattr(dir_data->data, POSIX_ACL_ACCESS_XATTR, NULL, 0);
+ if ((size < 0) && (errno == ENOTSUP)) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_ACL_NOTSUP,
+ "Posix access control list is not supported.");
+ gf_event(EVENT_POSIX_ACL_NOT_SUPPORTED, "brick=%s:%s",
+ _private->hostname, _private->base_path);
+ }
+
+ /*
+ * _XOPEN_PATH_MAX is the longest file path len we MUST
+ * support according to POSIX standard. When prepended
+ * by the brick base path it may exceed backed filesystem
+ * capacity (which MAY be bigger than _XOPEN_PATH_MAX). If
+ * this is the case, chdir() to the brick base path and
+ * use relative paths when they are too long. See also
+ * MAKE_REAL_PATH in posix-handle.h
+ */
+ _private->path_max = pathconf(_private->base_path, _PC_PATH_MAX);
+ if (_private->path_max != -1 &&
+ _XOPEN_PATH_MAX + _private->base_path_length > _private->path_max) {
+ ret = chdir(_private->base_path);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_BASEPATH_CHDIR_FAILED,
+ "chdir() to \"%s\" failed", _private->base_path);
+ goto out;
}
-
- tmp_data = dict_get (this->options, "o-direct");
- if (tmp_data) {
- if (gf_string2boolean (tmp_data->data,
- &_private->o_direct) == -1) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_INVALID_OPTION_VAL,
- "wrong option provided for 'o-direct'");
- goto out;
- }
- if (_private->o_direct)
- gf_msg_debug (this->name, 0, "o-direct mode is enabled"
- " (O_DIRECT for every open)");
+#ifdef __NetBSD__
+ /*
+ * At least on NetBSD, the chdir() above uncovers a
+ * race condition which cause file lookup to fail
+ * with ENODATA for a few seconds. The volume quickly
+ * reaches a sane state, but regression tests are fast
+ * enough to choke on it. The reason is obscure (as
+ * often with race conditions), but sleeping here for
+ * a second seems to workaround the problem.
+ */
+ sleep(1);
+#endif
+ }
+
+ LOCK_INIT(&_private->lock);
+
+ _private->export_statfs = 1;
+ tmp_data = dict_get(this->options, "export-statfs-size");
+ if (tmp_data) {
+ if (gf_string2boolean(tmp_data->data, &_private->export_statfs) == -1) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_OPTION_VAL,
+ "'export-statfs-size' takes only boolean "
+ "options");
+ goto out;
}
-
- tmp_data = dict_get (this->options, "update-link-count-parent");
- if (tmp_data) {
- if (gf_string2boolean (tmp_data->data,
- &_private->update_pgfid_nlinks) == -1) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_INVALID_OPTION, "wrong value provided "
- "for 'update-link-count-parent'");
- goto out;
- }
- if (_private->update_pgfid_nlinks)
- gf_msg_debug (this->name, 0, "update-link-count-parent"
- " is enabled. Thus for each file an "
- "extended attribute representing the "
- "number of hardlinks for that file "
- "within the same parent directory is"
- " set.");
+ if (!_private->export_statfs)
+ gf_msg_debug(this->name, 0, "'statfs()' returns dummy size");
+ }
+
+ _private->background_unlink = 0;
+ tmp_data = dict_get(this->options, "background-unlink");
+ if (tmp_data) {
+ if (gf_string2boolean(tmp_data->data, &_private->background_unlink) ==
+ -1) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_OPTION_VAL,
+ "'background-unlink'"
+ " takes only boolean options");
+ goto out;
}
- ret = dict_get_str (this->options, "glusterd-uuid", &guuid);
- if (!ret) {
- if (gf_uuid_parse (guuid, _private->glusterd_uuid))
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_INVALID_NODE_UUID, "Cannot parse "
- "glusterd (node) UUID, node-uuid xattr "
- "request would return - \"No such attribute\"");
- } else {
- gf_msg_debug (this->name, 0, "No glusterd (node) UUID passed -"
- " node-uuid xattr request will return \"No such"
- " attribute\"");
+ if (_private->background_unlink)
+ gf_msg_debug(this->name, 0,
+ "unlinks will be performed in background");
+ }
+
+ tmp_data = dict_get(this->options, "o-direct");
+ if (tmp_data) {
+ if (gf_string2boolean(tmp_data->data, &_private->o_direct) == -1) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_OPTION_VAL,
+ "wrong option provided for 'o-direct'");
+ goto out;
}
- ret = 0;
-
- GF_OPTION_INIT ("janitor-sleep-duration",
- _private->janitor_sleep_duration, int32, out);
-
- /* performing open dir on brick dir locks the brick dir
- * and prevents it from being unmounted
- */
- _private->mount_lock = sys_opendir (dir_data->data);
- if (!_private->mount_lock) {
- ret = -1;
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_DIR_OPERATION_FAILED,
- "Could not lock brick directory (%s)",
- strerror (op_errno));
- goto out;
+ if (_private->o_direct)
+ gf_msg_debug(this->name, 0,
+ "o-direct mode is enabled"
+ " (O_DIRECT for every open)");
+ }
+
+ tmp_data = dict_get(this->options, "update-link-count-parent");
+ if (tmp_data) {
+ if (gf_string2boolean(tmp_data->data, &_private->update_pgfid_nlinks) ==
+ -1) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_OPTION,
+ "wrong value provided "
+ "for 'update-link-count-parent'");
+ goto out;
}
+ if (_private->update_pgfid_nlinks)
+ gf_msg_debug(this->name, 0,
+ "update-link-count-parent"
+ " is enabled. Thus for each file an "
+ "extended attribute representing the "
+ "number of hardlinks for that file "
+ "within the same parent directory is"
+ " set.");
+ }
+
+ ret = dict_get_str(this->options, "glusterd-uuid", &guuid);
+ if (!ret) {
+ if (gf_uuid_parse(guuid, _private->glusterd_uuid))
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_INVALID_NODE_UUID,
+ "Cannot parse "
+ "glusterd (node) UUID, node-uuid xattr "
+ "request would return - \"No such attribute\"");
+ } else {
+ gf_msg_debug(this->name, 0,
+ "No glusterd (node) UUID passed -"
+ " node-uuid xattr request will return \"No such"
+ " attribute\"");
+ }
+ ret = 0;
+
+ GF_OPTION_INIT("janitor-sleep-duration", _private->janitor_sleep_duration,
+ int32, out);
+
+ /* performing open dir on brick dir locks the brick dir
+ * and prevents it from being unmounted
+ */
+ _private->mount_lock = sys_opendir(dir_data->data);
+ if (!_private->mount_lock) {
+ ret = -1;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_DIR_OPERATION_FAILED,
+ "Could not lock brick directory (%s)", strerror(op_errno));
+ goto out;
+ }
#ifndef GF_DARWIN_HOST_OS
- {
- struct rlimit lim;
- lim.rlim_cur = 1048576;
- lim.rlim_max = 1048576;
-
- if (setrlimit (RLIMIT_NOFILE, &lim) == -1) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_SET_ULIMIT_FAILED,
- "Failed to set 'ulimit -n "
- " 1048576'");
- lim.rlim_cur = 65536;
- lim.rlim_max = 65536;
-
- if (setrlimit (RLIMIT_NOFILE, &lim) == -1) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_SET_FILE_MAX_FAILED,
- "Failed to set maximum allowed open "
- "file descriptors to 64k");
- }
- else {
- gf_msg (this->name, GF_LOG_INFO, 0,
- P_MSG_MAX_FILE_OPEN, "Maximum allowed "
- "open file descriptors set to 65536");
- }
- }
+ {
+ struct rlimit lim;
+ lim.rlim_cur = 1048576;
+ lim.rlim_max = 1048576;
+
+ if (setrlimit(RLIMIT_NOFILE, &lim) == -1) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_SET_ULIMIT_FAILED,
+ "Failed to set 'ulimit -n "
+ " 1048576'");
+ lim.rlim_cur = 65536;
+ lim.rlim_max = 65536;
+
+ if (setrlimit(RLIMIT_NOFILE, &lim) == -1) {
+ gf_msg(this->name, GF_LOG_WARNING, errno,
+ P_MSG_SET_FILE_MAX_FAILED,
+ "Failed to set maximum allowed open "
+ "file descriptors to 64k");
+ } else {
+ gf_msg(this->name, GF_LOG_INFO, 0, P_MSG_MAX_FILE_OPEN,
+ "Maximum allowed "
+ "open file descriptors set to 65536");
+ }
}
+ }
#endif
- _private->shared_brick_count = 1;
- ret = dict_get_int32 (this->options, "shared-brick-count",
- &_private->shared_brick_count);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_INVALID_OPTION_VAL,
- "'shared-brick-count' takes only integer "
- "values");
- goto out;
- }
+ _private->shared_brick_count = 1;
+ ret = dict_get_int32(this->options, "shared-brick-count",
+ &_private->shared_brick_count);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_OPTION_VAL,
+ "'shared-brick-count' takes only integer "
+ "values");
+ goto out;
+ }
+
+ this->private = (void *)_private;
+
+ op_ret = posix_handle_init(this);
+ if (op_ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_HANDLE_CREATE,
+ "Posix handle setup failed");
+ ret = -1;
+ goto out;
+ }
+
+ op_ret = posix_handle_trash_init(this);
+ if (op_ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_HANDLE_CREATE_TRASH,
+ "Posix landfill setup failed");
+ ret = -1;
+ goto out;
+ }
+
+ op_ret = posix_create_unlink_dir(this);
+ if (op_ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_HANDLE_CREATE,
+ "Creation of unlink directory failed");
+ ret = -1;
+ goto out;
+ }
+
+ _private->aio_init_done = _gf_false;
+ _private->aio_capable = _gf_false;
+
+ GF_OPTION_INIT("brick-uid", uid, int32, out);
+ GF_OPTION_INIT("brick-gid", gid, int32, out);
+ if (uid != -1 || gid != -1)
+ posix_set_owner(this, uid, gid);
+
+ GF_OPTION_INIT("linux-aio", _private->aio_configured, bool, out);
+
+ if (_private->aio_configured) {
+ op_ret = posix_aio_on(this);
- this->private = (void *)_private;
-
- op_ret = posix_handle_init (this);
if (op_ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_HANDLE_CREATE,
- "Posix handle setup failed");
- ret = -1;
- goto out;
- }
-
- op_ret = posix_handle_trash_init (this);
- if (op_ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_HANDLE_CREATE_TRASH,
- "Posix landfill setup failed");
- ret = -1;
- goto out;
- }
-
- op_ret = posix_create_unlink_dir (this);
- if (op_ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_HANDLE_CREATE,
- "Creation of unlink directory failed");
- ret = -1;
- goto out;
- }
-
- _private->aio_init_done = _gf_false;
- _private->aio_capable = _gf_false;
-
- GF_OPTION_INIT ("brick-uid", uid, int32, out);
- GF_OPTION_INIT ("brick-gid", gid, int32, out);
- if (uid != -1 || gid != -1)
- posix_set_owner (this, uid, gid);
-
- GF_OPTION_INIT ("linux-aio", _private->aio_configured, bool, out);
-
- if (_private->aio_configured) {
- op_ret = posix_aio_on (this);
-
- if (op_ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_POSIX_AIO,
- "Posix AIO init failed");
- ret = -1;
- goto out;
- }
- }
-
- GF_OPTION_INIT ("node-uuid-pathinfo",
- _private->node_uuid_pathinfo, bool, out);
- if (_private->node_uuid_pathinfo &&
- (gf_uuid_is_null (_private->glusterd_uuid))) {
- gf_msg (this->name, GF_LOG_INFO, 0, P_MSG_UUID_NULL,
- "glusterd uuid is NULL, pathinfo xattr would"
- " fallback to <hostname>:<export>");
- }
-
- _private->disk_space_check_active = _gf_false;
- _private->disk_space_full = 0;
- GF_OPTION_INIT ("reserve",
- _private->disk_reserve, uint32, out);
- if (_private->disk_reserve)
- posix_spawn_disk_space_check_thread (this);
-
- _private->health_check_active = _gf_false;
- GF_OPTION_INIT ("health-check-interval",
- _private->health_check_interval, uint32, out);
- GF_OPTION_INIT ("health-check-timeout",
- _private->health_check_timeout, uint32, out);
- if (_private->health_check_interval)
- posix_spawn_health_check_thread (this);
-
- pthread_mutex_init (&_private->janitor_lock, NULL);
- pthread_cond_init (&_private->janitor_cond, NULL);
- INIT_LIST_HEAD (&_private->janitor_fds);
-
- posix_spawn_janitor_thread (this);
-
- pthread_mutex_init (&_private->fsync_mutex, NULL);
- pthread_cond_init (&_private->fsync_cond, NULL);
- INIT_LIST_HEAD (&_private->fsyncs);
-
- ret = gf_thread_create (&_private->fsyncer, NULL, posix_fsyncer, this,
- "posixfsy");
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_FSYNCER_THREAD_CREATE_FAILED,
- "fsyncer thread creation failed");
- goto out;
- }
-
- GF_OPTION_INIT ("batch-fsync-mode", batch_fsync_mode_str, str, out);
-
- if (set_batch_fsync_mode (_private, batch_fsync_mode_str) != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_ARGUMENT,
- "Unknown mode string: %s", batch_fsync_mode_str);
- goto out;
- }
-
- GF_OPTION_INIT ("gfid2path", _private->gfid2path, bool, out);
-
- GF_OPTION_INIT ("gfid2path-separator", gfid2path_sep, str, out);
- if (set_gfid2path_separator (_private, gfid2path_sep) != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_ARGUMENT,
- "Length of separator exceeds 7: %s", gfid2path_sep);
- goto out;
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_POSIX_AIO,
+ "Posix AIO init failed");
+ ret = -1;
+ goto out;
}
+ }
+
+ GF_OPTION_INIT("node-uuid-pathinfo", _private->node_uuid_pathinfo, bool,
+ out);
+ if (_private->node_uuid_pathinfo &&
+ (gf_uuid_is_null(_private->glusterd_uuid))) {
+ gf_msg(this->name, GF_LOG_INFO, 0, P_MSG_UUID_NULL,
+ "glusterd uuid is NULL, pathinfo xattr would"
+ " fallback to <hostname>:<export>");
+ }
+
+ _private->disk_space_check_active = _gf_false;
+ _private->disk_space_full = 0;
+ GF_OPTION_INIT("reserve", _private->disk_reserve, uint32, out);
+ if (_private->disk_reserve)
+ posix_spawn_disk_space_check_thread(this);
+
+ _private->health_check_active = _gf_false;
+ GF_OPTION_INIT("health-check-interval", _private->health_check_interval,
+ uint32, out);
+ GF_OPTION_INIT("health-check-timeout", _private->health_check_timeout,
+ uint32, out);
+ if (_private->health_check_interval)
+ posix_spawn_health_check_thread(this);
+
+ pthread_mutex_init(&_private->janitor_lock, NULL);
+ pthread_cond_init(&_private->janitor_cond, NULL);
+ INIT_LIST_HEAD(&_private->janitor_fds);
+
+ posix_spawn_janitor_thread(this);
+
+ pthread_mutex_init(&_private->fsync_mutex, NULL);
+ pthread_cond_init(&_private->fsync_cond, NULL);
+ INIT_LIST_HEAD(&_private->fsyncs);
+
+ ret = gf_thread_create(&_private->fsyncer, NULL, posix_fsyncer, this,
+ "posixfsy");
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ P_MSG_FSYNCER_THREAD_CREATE_FAILED,
+ "fsyncer thread creation failed");
+ goto out;
+ }
+
+ GF_OPTION_INIT("batch-fsync-mode", batch_fsync_mode_str, str, out);
+
+ if (set_batch_fsync_mode(_private, batch_fsync_mode_str) != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_ARGUMENT,
+ "Unknown mode string: %s", batch_fsync_mode_str);
+ goto out;
+ }
+
+ GF_OPTION_INIT("gfid2path", _private->gfid2path, bool, out);
+
+ GF_OPTION_INIT("gfid2path-separator", gfid2path_sep, str, out);
+ if (set_gfid2path_separator(_private, gfid2path_sep) != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_ARGUMENT,
+ "Length of separator exceeds 7: %s", gfid2path_sep);
+ goto out;
+ }
#ifdef GF_DARWIN_HOST_OS
- char *xattr_user_namespace_mode_str = NULL;
+ char *xattr_user_namespace_mode_str = NULL;
- GF_OPTION_INIT ("xattr-user-namespace-mode",
- xattr_user_namespace_mode_str, str, out);
+ GF_OPTION_INIT("xattr-user-namespace-mode", xattr_user_namespace_mode_str,
+ str, out);
- if (set_xattr_user_namespace_mode (_private,
- xattr_user_namespace_mode_str) != 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_ARGUMENT,
- "Unknown xattr user namespace mode string: %s",
- xattr_user_namespace_mode_str);
- goto out;
- }
+ if (set_xattr_user_namespace_mode(_private,
+ xattr_user_namespace_mode_str) != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_INVALID_ARGUMENT,
+ "Unknown xattr user namespace mode string: %s",
+ xattr_user_namespace_mode_str);
+ goto out;
+ }
#endif
- GF_OPTION_INIT ("batch-fsync-delay-usec", _private->batch_fsync_delay_usec,
- uint32, out);
+ GF_OPTION_INIT("batch-fsync-delay-usec", _private->batch_fsync_delay_usec,
+ uint32, out);
- GF_OPTION_INIT ("disable-landfill-purge",
- _private->disable_landfill_purge, bool, out);
- if (_private->disable_landfill_purge) {
- gf_msg (this->name, GF_LOG_WARNING, 0, 0,
- "Janitor WILL NOT purge the landfill directory. "
- "Your landfill directory"
- " may fill up this brick.");
- }
+ GF_OPTION_INIT("disable-landfill-purge", _private->disable_landfill_purge,
+ bool, out);
+ if (_private->disable_landfill_purge) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, 0,
+ "Janitor WILL NOT purge the landfill directory. "
+ "Your landfill directory"
+ " may fill up this brick.");
+ }
- GF_OPTION_INIT ("force-create-mode", force_create, int32, out);
- _private->force_create_mode = force_create;
+ GF_OPTION_INIT("force-create-mode", force_create, int32, out);
+ _private->force_create_mode = force_create;
- GF_OPTION_INIT ("force-directory-mode", force_directory, int32, out);
- _private->force_directory_mode = force_directory;
+ GF_OPTION_INIT("force-directory-mode", force_directory, int32, out);
+ _private->force_directory_mode = force_directory;
- GF_OPTION_INIT ("create-mask",
- create_mask, int32, out);
- _private->create_mask = create_mask;
+ GF_OPTION_INIT("create-mask", create_mask, int32, out);
+ _private->create_mask = create_mask;
- GF_OPTION_INIT ("create-directory-mask",
- create_directory_mask, int32, out);
- _private->create_directory_mask = create_directory_mask;
+ GF_OPTION_INIT("create-directory-mask", create_directory_mask, int32, out);
+ _private->create_directory_mask = create_directory_mask;
- GF_OPTION_INIT ("max-hardlinks", _private->max_hardlinks, uint32, out);
+ GF_OPTION_INIT("max-hardlinks", _private->max_hardlinks, uint32, out);
- GF_OPTION_INIT ("fips-mode-rchecksum", _private->fips_mode_rchecksum,
- bool, out);
+ GF_OPTION_INIT("fips-mode-rchecksum", _private->fips_mode_rchecksum, bool,
+ out);
- GF_OPTION_INIT ("ctime", _private->ctime, bool, out);
+ GF_OPTION_INIT("ctime", _private->ctime, bool, out);
out:
- if (ret) {
- if (_private) {
- GF_FREE (_private->base_path);
+ if (ret) {
+ if (_private) {
+ GF_FREE(_private->base_path);
- GF_FREE (_private->hostname);
+ GF_FREE(_private->hostname);
- GF_FREE (_private->trash_path);
+ GF_FREE(_private->trash_path);
- GF_FREE (_private);
- }
-
- this->private = NULL;
+ GF_FREE(_private);
}
- return ret;
+
+ this->private = NULL;
+ }
+ return ret;
}
void
-posix_fini (xlator_t *this)
+posix_fini(xlator_t *this)
{
- struct posix_private *priv = this->private;
- if (!priv)
- return;
- LOCK (&priv->lock);
- if (priv->health_check_active) {
- priv->health_check_active = _gf_false;
- pthread_cancel (priv->health_check);
- priv->health_check = 0;
- }
- UNLOCK (&priv->lock);
- if (priv->disk_space_check) {
- priv->disk_space_check_active = _gf_false;
- pthread_cancel (priv->disk_space_check);
- priv->disk_space_check = 0;
- }
- if (priv->janitor) {
- (void) gf_thread_cleanup_xint (priv->janitor);
- priv->janitor = 0;
- }
- if (priv->fsyncer) {
- (void) gf_thread_cleanup_xint (priv->fsyncer);
- priv->fsyncer = 0;
- }
- /*unlock brick dir*/
- if (priv->mount_lock)
- (void) sys_closedir (priv->mount_lock);
-
- GF_FREE (priv->base_path);
- LOCK_DESTROY (&priv->lock);
- pthread_mutex_destroy (&priv->janitor_lock);
- pthread_mutex_destroy (&priv->fsync_mutex);
- GF_FREE (priv->hostname);
- GF_FREE (priv->trash_path);
- GF_FREE (priv);
- this->private = NULL;
-
+ struct posix_private *priv = this->private;
+ if (!priv)
return;
+ LOCK(&priv->lock);
+ if (priv->health_check_active) {
+ priv->health_check_active = _gf_false;
+ pthread_cancel(priv->health_check);
+ priv->health_check = 0;
+ }
+ UNLOCK(&priv->lock);
+ if (priv->disk_space_check) {
+ priv->disk_space_check_active = _gf_false;
+ pthread_cancel(priv->disk_space_check);
+ priv->disk_space_check = 0;
+ }
+ if (priv->janitor) {
+ (void)gf_thread_cleanup_xint(priv->janitor);
+ priv->janitor = 0;
+ }
+ if (priv->fsyncer) {
+ (void)gf_thread_cleanup_xint(priv->fsyncer);
+ priv->fsyncer = 0;
+ }
+ /*unlock brick dir*/
+ if (priv->mount_lock)
+ (void)sys_closedir(priv->mount_lock);
+
+ GF_FREE(priv->base_path);
+ LOCK_DESTROY(&priv->lock);
+ pthread_mutex_destroy(&priv->janitor_lock);
+ pthread_mutex_destroy(&priv->fsync_mutex);
+ GF_FREE(priv->hostname);
+ GF_FREE(priv->trash_path);
+ GF_FREE(priv);
+ this->private = NULL;
+
+ return;
}
struct volume_options options[] = {
- { .key = {"o-direct"},
- .type = GF_OPTION_TYPE_BOOL },
- { .key = {"directory"},
- .type = GF_OPTION_TYPE_PATH,
- .default_value = "{{brick.path}}"
- },
- { .key = {"hostname"},
- .type = GF_OPTION_TYPE_ANY },
- { .key = {"export-statfs-size"},
- .type = GF_OPTION_TYPE_BOOL },
- { .key = {"mandate-attribute"},
- .type = GF_OPTION_TYPE_BOOL },
- { .key = {"background-unlink"},
- .type = GF_OPTION_TYPE_BOOL },
- { .key = {"janitor-sleep-duration"},
- .type = GF_OPTION_TYPE_INT,
- .min = 1,
- .validate = GF_OPT_VALIDATE_MIN,
- .default_value = "10",
- .description = "Interval (in seconds) between times the internal "
- "'landfill' directory is emptied."
- },
- { .key = {"volume-id"},
- .type = GF_OPTION_TYPE_ANY,
- .default_value = "{{brick.volumeid}}"
- },
- { .key = {"glusterd-uuid"},
- .type = GF_OPTION_TYPE_STR },
- {
- .key = {"linux-aio"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .description = "Support for native Linux AIO",
- .op_version = {1},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
- {
- .key = {"brick-uid"},
- .type = GF_OPTION_TYPE_INT,
- .min = -1,
- .validate = GF_OPT_VALIDATE_MIN,
- .default_value = "-1",
- .description = "Support for setting uid of brick's owner",
- .op_version = {1},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
- {
- .key = {"brick-gid"},
- .type = GF_OPTION_TYPE_INT,
- .min = -1,
- .validate = GF_OPT_VALIDATE_MIN,
- .default_value = "-1",
- .description = "Support for setting gid of brick's owner",
- .op_version = {1},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
- { .key = {"node-uuid-pathinfo"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .description = "return glusterd's node-uuid in pathinfo xattr"
- " string instead of hostname",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
- {
- .key = {"health-check-interval"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0,
- .default_value = "30",
- .validate = GF_OPT_VALIDATE_MIN,
- .description = "Interval in seconds for a filesystem health check, "
- "set to 0 to disable",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
- {
- .key = {"health-check-timeout"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0,
- .default_value = "10",
- .validate = GF_OPT_VALIDATE_MIN,
- .description = "Interval in seconds to wait aio_write finish for health check, "
- "set to 0 to disable",
- .op_version = {GD_OP_VERSION_4_0_0},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
- {
- .key = {"reserve"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0,
- .default_value = "1",
- .validate = GF_OPT_VALIDATE_MIN,
- .description = "Percentage of disk space to be reserved."
- " Set to 0 to disable",
- .op_version = {GD_OP_VERSION_3_13_0},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
- { .key = {"batch-fsync-mode"},
- .type = GF_OPTION_TYPE_STR,
- .default_value = "reverse-fsync",
- .description = "Possible values:\n"
- "\t- syncfs: Perform one syncfs() on behalf oa batch"
- "of fsyncs.\n"
- "\t- syncfs-single-fsync: Perform one syncfs() on behalf of a batch"
- " of fsyncs and one fsync() per batch.\n"
- "\t- syncfs-reverse-fsync: Perform one syncfs() on behalf of a batch"
- " of fsyncs and fsync() each file in the batch in reverse order.\n"
- " in reverse order.\n"
- "\t- reverse-fsync: Perform fsync() of each file in the batch in"
- " reverse order.",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
- { .key = {"batch-fsync-delay-usec"},
- .type = GF_OPTION_TYPE_INT,
- .default_value = "0",
- .description = "Num of usecs to wait for aggregating fsync"
- " requests",
- .op_version = {3},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
- { .key = {"update-link-count-parent"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .description = "Enable placeholders for gfid to path conversion",
- .op_version = {GD_OP_VERSION_3_6_0},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
- { .key = {"gfid2path"},
- .type = GF_OPTION_TYPE_BOOL,
+ {.key = {"o-direct"}, .type = GF_OPTION_TYPE_BOOL},
+ {.key = {"directory"},
+ .type = GF_OPTION_TYPE_PATH,
+ .default_value = "{{brick.path}}"},
+ {.key = {"hostname"}, .type = GF_OPTION_TYPE_ANY},
+ {.key = {"export-statfs-size"}, .type = GF_OPTION_TYPE_BOOL},
+ {.key = {"mandate-attribute"}, .type = GF_OPTION_TYPE_BOOL},
+ {.key = {"background-unlink"}, .type = GF_OPTION_TYPE_BOOL},
+ {.key = {"janitor-sleep-duration"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 1,
+ .validate = GF_OPT_VALIDATE_MIN,
+ .default_value = "10",
+ .description = "Interval (in seconds) between times the internal "
+ "'landfill' directory is emptied."},
+ {.key = {"volume-id"},
+ .type = GF_OPTION_TYPE_ANY,
+ .default_value = "{{brick.volumeid}}"},
+ {.key = {"glusterd-uuid"}, .type = GF_OPTION_TYPE_STR},
+ {.key = {"linux-aio"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .description = "Support for native Linux AIO",
+ .op_version = {1},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
+ {.key = {"brick-uid"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = -1,
+ .validate = GF_OPT_VALIDATE_MIN,
+ .default_value = "-1",
+ .description = "Support for setting uid of brick's owner",
+ .op_version = {1},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
+ {.key = {"brick-gid"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = -1,
+ .validate = GF_OPT_VALIDATE_MIN,
+ .default_value = "-1",
+ .description = "Support for setting gid of brick's owner",
+ .op_version = {1},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
+ {.key = {"node-uuid-pathinfo"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .description = "return glusterd's node-uuid in pathinfo xattr"
+ " string instead of hostname",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
+ {.key = {"health-check-interval"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0,
+ .default_value = "30",
+ .validate = GF_OPT_VALIDATE_MIN,
+ .description = "Interval in seconds for a filesystem health check, "
+ "set to 0 to disable",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
+ {.key = {"health-check-timeout"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0,
+ .default_value = "10",
+ .validate = GF_OPT_VALIDATE_MIN,
+ .description =
+ "Interval in seconds to wait aio_write finish for health check, "
+ "set to 0 to disable",
+ .op_version = {GD_OP_VERSION_4_0_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
+ {.key = {"reserve"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0,
+ .default_value = "1",
+ .validate = GF_OPT_VALIDATE_MIN,
+ .description = "Percentage of disk space to be reserved."
+ " Set to 0 to disable",
+ .op_version = {GD_OP_VERSION_3_13_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
+ {.key = {"batch-fsync-mode"},
+ .type = GF_OPTION_TYPE_STR,
+ .default_value = "reverse-fsync",
+ .description =
+ "Possible values:\n"
+ "\t- syncfs: Perform one syncfs() on behalf oa batch"
+ "of fsyncs.\n"
+ "\t- syncfs-single-fsync: Perform one syncfs() on behalf of a batch"
+ " of fsyncs and one fsync() per batch.\n"
+ "\t- syncfs-reverse-fsync: Perform one syncfs() on behalf of a batch"
+ " of fsyncs and fsync() each file in the batch in reverse order.\n"
+ " in reverse order.\n"
+ "\t- reverse-fsync: Perform fsync() of each file in the batch in"
+ " reverse order.",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
+ {.key = {"batch-fsync-delay-usec"},
+ .type = GF_OPTION_TYPE_INT,
+ .default_value = "0",
+ .description = "Num of usecs to wait for aggregating fsync"
+ " requests",
+ .op_version = {3},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
+ {.key = {"update-link-count-parent"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .description = "Enable placeholders for gfid to path conversion",
+ .op_version = {GD_OP_VERSION_3_6_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
+ {.key = {"gfid2path"},
+ .type = GF_OPTION_TYPE_BOOL,
#ifdef __NetBSD__
- /*
- * NetBSD storage of extended attributes for UFS1 badly
- * scales when the list of extended attributes names rises.
- * This option can add as many extended attributes names
- * as we have files, hence we keep it disabled for performance
- * sake.
- */
- .default_value = "off",
+ /*
+ * NetBSD storage of extended attributes for UFS1 badly
+ * scales when the list of extended attributes names rises.
+ * This option can add as many extended attributes names
+ * as we have files, hence we keep it disabled for performance
+ * sake.
+ */
+ .default_value = "off",
#else
- .default_value = "on",
+ .default_value = "on",
#endif
- .description = "Enable logging metadata for gfid to path conversion",
- .op_version = {GD_OP_VERSION_3_12_0},
- .flags = OPT_FLAG_SETTABLE
- },
- { .key = {"gfid2path-separator"},
- .type = GF_OPTION_TYPE_STR,
- .default_value = ":",
- .description = "Path separator for glusterfs.gfidtopath virt xattr",
- .op_version = {GD_OP_VERSION_3_12_0},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
+ .description = "Enable logging metadata for gfid to path conversion",
+ .op_version = {GD_OP_VERSION_3_12_0},
+ .flags = OPT_FLAG_SETTABLE},
+ {.key = {"gfid2path-separator"},
+ .type = GF_OPTION_TYPE_STR,
+ .default_value = ":",
+ .description = "Path separator for glusterfs.gfidtopath virt xattr",
+ .op_version = {GD_OP_VERSION_3_12_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
#if GF_DARWIN_HOST_OS
- { .key = {"xattr-user-namespace-mode"},
- .type = GF_OPTION_TYPE_STR,
- .default_value = "none",
- .description = "Option to control XATTR user namespace on the raw filesystem: "
- "\t- None: Will use the user namespace, so files will be exchangeable with Linux.\n"
- " The raw filesystem will not be compatible with OS X Finder.\n"
- "\t- Strip: Will strip the user namespace before setting. The raw filesystem will work in OS X.\n",
- .op_version = {GD_OP_VERSION_3_6_0},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC
- },
+ {.key = {"xattr-user-namespace-mode"},
+ .type = GF_OPTION_TYPE_STR,
+ .default_value = "none",
+ .description =
+ "Option to control XATTR user namespace on the raw filesystem: "
+ "\t- None: Will use the user namespace, so files will be exchangeable "
+ "with Linux.\n"
+ " The raw filesystem will not be compatible with OS X Finder.\n"
+ "\t- Strip: Will strip the user namespace before setting. The raw "
+ "filesystem will work in OS X.\n",
+ .op_version = {GD_OP_VERSION_3_6_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC},
#endif
- { .key = {"shared-brick-count"},
- .type = GF_OPTION_TYPE_INT,
- .default_value = "1",
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
- .description = "Number of bricks sharing the same backend export."
- " Useful for displaying the proper usable size through statvfs() "
- "call (df command)",
- },
- {
- .key = {"disable-landfill-purge"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .description = "Disable glusterfs/landfill purges. "
- "WARNING: This can fill up a brick.",
- .op_version = {GD_OP_VERSION_4_0_0},
- .tags = {"diagnosis"},
- },
- { .key = {"force-create-mode"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0000,
- .max = 0777,
- .default_value = "0000",
- .validate = GF_OPT_VALIDATE_MIN,
- .validate = GF_OPT_VALIDATE_MAX,
- .description = "Mode bit permission that will always be set on a file."
- },
- { .key = {"force-directory-mode"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0000,
- .max = 0777,
- .default_value = "0000",
- .validate = GF_OPT_VALIDATE_MIN,
- .validate = GF_OPT_VALIDATE_MAX,
- .description = "Mode bit permission that will be always set on directory"
- },
- { .key = {"create-mask"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0000,
- .max = 0777,
- .default_value = "0777",
- .validate = GF_OPT_VALIDATE_MIN,
- .validate = GF_OPT_VALIDATE_MAX,
- .description = "Any bit not set here will be removed from the"
- "modes set on a file when it is created"
- },
- { .key = {"create-directory-mask"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0000,
- .max = 0777,
- .default_value = "0777",
- .validate = GF_OPT_VALIDATE_MIN,
- .validate = GF_OPT_VALIDATE_MAX,
- .description = "Any bit not set here will be removed from the"
- "modes set on a directory when it is created"
- },
- {
- .key = {"max-hardlinks"},
- .type = GF_OPTION_TYPE_INT,
- .min = 0,
- .default_value = "100",
- .op_version = {GD_OP_VERSION_4_0_0},
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
- .tags = {"posix"},
- .validate = GF_OPT_VALIDATE_MIN,
- .description = "max number of hardlinks allowed on any one inode.\n"
- "0 is unlimited, 1 prevents any hardlinking at all."
- },
- {
- .key = {"fips-mode-rchecksum"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .op_version = {GD_OP_VERSION_4_0_0},
- .flags = OPT_FLAG_SETTABLE,
- .tags = {"posix"},
- .description = "If enabled, posix_rchecksum uses the FIPS compliant"
- "SHA256 checksum. MD5 otherwise."
- },
- { .key = {"ctime"},
- .type = GF_OPTION_TYPE_BOOL,
- .default_value = "off",
- .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
- .op_version = { GD_OP_VERSION_4_1_0 },
- .tags = { "ctime" },
- .description = "When this option is enabled, time attributes (ctime,mtime,atime) "
- "are stored in xattr to keep it consistent across replica and "
- "distribute set. The time attributes stored at the backend are "
- "not considered "
- },
- { .key = {NULL} }
-};
+ {
+ .key = {"shared-brick-count"},
+ .type = GF_OPTION_TYPE_INT,
+ .default_value = "1",
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
+ .description =
+ "Number of bricks sharing the same backend export."
+ " Useful for displaying the proper usable size through statvfs() "
+ "call (df command)",
+ },
+ {
+ .key = {"disable-landfill-purge"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .description = "Disable glusterfs/landfill purges. "
+ "WARNING: This can fill up a brick.",
+ .op_version = {GD_OP_VERSION_4_0_0},
+ .tags = {"diagnosis"},
+ },
+ {.key = {"force-create-mode"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0000,
+ .max = 0777,
+ .default_value = "0000",
+ .validate = GF_OPT_VALIDATE_MIN,
+ .validate = GF_OPT_VALIDATE_MAX,
+ .description = "Mode bit permission that will always be set on a file."},
+ {.key = {"force-directory-mode"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0000,
+ .max = 0777,
+ .default_value = "0000",
+ .validate = GF_OPT_VALIDATE_MIN,
+ .validate = GF_OPT_VALIDATE_MAX,
+ .description = "Mode bit permission that will be always set on directory"},
+ {.key = {"create-mask"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0000,
+ .max = 0777,
+ .default_value = "0777",
+ .validate = GF_OPT_VALIDATE_MIN,
+ .validate = GF_OPT_VALIDATE_MAX,
+ .description = "Any bit not set here will be removed from the"
+ "modes set on a file when it is created"},
+ {.key = {"create-directory-mask"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0000,
+ .max = 0777,
+ .default_value = "0777",
+ .validate = GF_OPT_VALIDATE_MIN,
+ .validate = GF_OPT_VALIDATE_MAX,
+ .description = "Any bit not set here will be removed from the"
+ "modes set on a directory when it is created"},
+ {.key = {"max-hardlinks"},
+ .type = GF_OPTION_TYPE_INT,
+ .min = 0,
+ .default_value = "100",
+ .op_version = {GD_OP_VERSION_4_0_0},
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
+ .tags = {"posix"},
+ .validate = GF_OPT_VALIDATE_MIN,
+ .description = "max number of hardlinks allowed on any one inode.\n"
+ "0 is unlimited, 1 prevents any hardlinking at all."},
+ {.key = {"fips-mode-rchecksum"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .op_version = {GD_OP_VERSION_4_0_0},
+ .flags = OPT_FLAG_SETTABLE,
+ .tags = {"posix"},
+ .description = "If enabled, posix_rchecksum uses the FIPS compliant"
+ "SHA256 checksum. MD5 otherwise."},
+ {.key = {"ctime"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "off",
+ .flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
+ .op_version = {GD_OP_VERSION_4_1_0},
+ .tags = {"ctime"},
+ .description =
+ "When this option is enabled, time attributes (ctime,mtime,atime) "
+ "are stored in xattr to keep it consistent across replica and "
+ "distribute set. The time attributes stored at the backend are "
+ "not considered "},
+ {.key = {NULL}}};
diff --git a/xlators/storage/posix/src/posix-entry-ops.c b/xlators/storage/posix/src/posix-entry-ops.c
index 34dff4b..1888de7 100644
--- a/xlators/storage/posix/src/posix-entry-ops.c
+++ b/xlators/storage/posix/src/posix-entry-ops.c
@@ -69,17 +69,21 @@ extern char *marker_xattrs[];
#undef HAVE_SET_FSID
#ifdef HAVE_SET_FSID
-#define DECLARE_OLD_FS_ID_VAR uid_t old_fsuid; gid_t old_fsgid;
-
-#define SET_FS_ID(uid, gid) do { \
- old_fsuid = setfsuid (uid); \
- old_fsgid = setfsgid (gid); \
- } while (0)
-
-#define SET_TO_OLD_FS_ID() do { \
- setfsuid (old_fsuid); \
- setfsgid (old_fsgid); \
- } while (0)
+#define DECLARE_OLD_FS_ID_VAR \
+ uid_t old_fsuid; \
+ gid_t old_fsgid;
+
+#define SET_FS_ID(uid, gid) \
+ do { \
+ old_fsuid = setfsuid(uid); \
+ old_fsgid = setfsgid(gid); \
+ } while (0)
+
+#define SET_TO_OLD_FS_ID() \
+ do { \
+ setfsuid(old_fsuid); \
+ setfsgid(old_fsgid); \
+ } while (0)
#else
@@ -90,2174 +94,2139 @@ extern char *marker_xattrs[];
#endif
gf_boolean_t
-posix_symlinks_match (xlator_t *this, loc_t *loc, uuid_t gfid)
+posix_symlinks_match(xlator_t *this, loc_t *loc, uuid_t gfid)
{
- struct posix_private *priv = NULL;
- char linkname_actual[PATH_MAX] = {0,};
- char linkname_expected[PATH_MAX] = {0};
- char *dir_handle = NULL;
- ssize_t len = 0;
- size_t handle_size = 0;
- gf_boolean_t ret = _gf_false;
-
- priv = this->private;
- handle_size = POSIX_GFID_HANDLE_SIZE(priv->base_path_length);
- dir_handle = alloca0 (handle_size);
-
- snprintf (linkname_expected, PATH_MAX, "../../%02x/%02x/%s/%s",
- loc->pargfid[0], loc->pargfid[1], uuid_utoa (loc->pargfid),
- loc->name);
-
- MAKE_HANDLE_GFID_PATH (dir_handle, this, gfid, NULL);
- len = sys_readlink (dir_handle, linkname_actual, PATH_MAX);
- if (len < 0 || len == PATH_MAX) {
- if (len == PATH_MAX) {
- errno = EINVAL;
- }
-
- if (errno != ENOENT) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_LSTAT_FAILED, "readlink[%s] failed",
- dir_handle);
- }
- goto out;
- }
- linkname_actual[len] = '\0';
-
- if (!strcmp (linkname_actual, linkname_expected))
- ret = _gf_true;
+ struct posix_private *priv = NULL;
+ char linkname_actual[PATH_MAX] = {
+ 0,
+ };
+ char linkname_expected[PATH_MAX] = {0};
+ char *dir_handle = NULL;
+ ssize_t len = 0;
+ size_t handle_size = 0;
+ gf_boolean_t ret = _gf_false;
+
+ priv = this->private;
+ handle_size = POSIX_GFID_HANDLE_SIZE(priv->base_path_length);
+ dir_handle = alloca0(handle_size);
+
+ snprintf(linkname_expected, PATH_MAX, "../../%02x/%02x/%s/%s",
+ loc->pargfid[0], loc->pargfid[1], uuid_utoa(loc->pargfid),
+ loc->name);
+
+ MAKE_HANDLE_GFID_PATH(dir_handle, this, gfid, NULL);
+ len = sys_readlink(dir_handle, linkname_actual, PATH_MAX);
+ if (len < 0 || len == PATH_MAX) {
+ if (len == PATH_MAX) {
+ errno = EINVAL;
+ }
+
+ if (errno != ENOENT) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "readlink[%s] failed", dir_handle);
+ }
+ goto out;
+ }
+ linkname_actual[len] = '\0';
+
+ if (!strcmp(linkname_actual, linkname_expected))
+ ret = _gf_true;
out:
- return ret;
+ return ret;
}
-dict_t*
-posix_dict_set_nlink (dict_t *req, dict_t *res, int32_t nlink)
+dict_t *
+posix_dict_set_nlink(dict_t *req, dict_t *res, int32_t nlink)
{
- int ret = -1;
+ int ret = -1;
- if (req == NULL || !dict_get (req, GF_REQUEST_LINK_COUNT_XDATA))
- goto out;
+ if (req == NULL || !dict_get(req, GF_REQUEST_LINK_COUNT_XDATA))
+ goto out;
- if (res == NULL)
- res = dict_new ();
- if (res == NULL)
- goto out;
+ if (res == NULL)
+ res = dict_new();
+ if (res == NULL)
+ goto out;
- ret = dict_set_uint32 (res, GF_RESPONSE_LINK_COUNT_XDATA, nlink);
- if (ret == -1)
- gf_msg ("posix", GF_LOG_WARNING, 0, P_MSG_SET_XDATA_FAIL,
- "Failed to set GF_RESPONSE_LINK_COUNT_XDATA");
+ ret = dict_set_uint32(res, GF_RESPONSE_LINK_COUNT_XDATA, nlink);
+ if (ret == -1)
+ gf_msg("posix", GF_LOG_WARNING, 0, P_MSG_SET_XDATA_FAIL,
+ "Failed to set GF_RESPONSE_LINK_COUNT_XDATA");
out:
- return res;
+ return res;
}
/* Regular fops */
int32_t
-posix_lookup (call_frame_t *frame, xlator_t *this,
- loc_t *loc, dict_t *xdata)
+posix_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- struct iatt buf = {0, };
- int32_t op_ret = -1;
- int32_t entry_ret = 0;
- int32_t op_errno = 0;
- dict_t * xattr = NULL;
- char * real_path = NULL;
- char * par_path = NULL;
- char *gfid_path = NULL;
- uuid_t gfid = {0};
- struct iatt postparent = {0,};
- struct stat statbuf = {0};
- int32_t gfidless = 0;
- char *pgfid_xattr_key = NULL;
- int32_t nlink_samepgfid = 0;
- struct posix_private *priv = NULL;
- posix_inode_ctx_t *ctx = NULL;
- int ret = 0;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (loc, out);
- VALIDATE_OR_GOTO (this->private, out);
-
- priv = this->private;
-
- /* The Hidden directory should be for housekeeping purpose and it
- should not get any gfid on it */
- if (__is_root_gfid (loc->pargfid) && loc->name
- && (strcmp (loc->name, GF_HIDDEN_PATH) == 0)) {
- gf_msg (this->name, GF_LOG_WARNING, EPERM,
- P_MSG_LOOKUP_NOT_PERMITTED, "Lookup issued on %s,"
- " which is not permitted", GF_HIDDEN_PATH);
- op_errno = EPERM;
+ struct iatt buf = {
+ 0,
+ };
+ int32_t op_ret = -1;
+ int32_t entry_ret = 0;
+ int32_t op_errno = 0;
+ dict_t *xattr = NULL;
+ char *real_path = NULL;
+ char *par_path = NULL;
+ char *gfid_path = NULL;
+ uuid_t gfid = {0};
+ struct iatt postparent = {
+ 0,
+ };
+ struct stat statbuf = {0};
+ int32_t gfidless = 0;
+ char *pgfid_xattr_key = NULL;
+ int32_t nlink_samepgfid = 0;
+ struct posix_private *priv = NULL;
+ posix_inode_ctx_t *ctx = NULL;
+ int ret = 0;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(loc, out);
+ VALIDATE_OR_GOTO(this->private, out);
+
+ priv = this->private;
+
+ /* The Hidden directory should be for housekeeping purpose and it
+ should not get any gfid on it */
+ if (__is_root_gfid(loc->pargfid) && loc->name &&
+ (strcmp(loc->name, GF_HIDDEN_PATH) == 0)) {
+ gf_msg(this->name, GF_LOG_WARNING, EPERM, P_MSG_LOOKUP_NOT_PERMITTED,
+ "Lookup issued on %s,"
+ " which is not permitted",
+ GF_HIDDEN_PATH);
+ op_errno = EPERM;
+ op_ret = -1;
+ goto out;
+ }
+
+ op_ret = dict_get_int32(xdata, GF_GFIDLESS_LOOKUP, &gfidless);
+ op_ret = -1;
+ if (gf_uuid_is_null(loc->pargfid) || (loc->name == NULL)) {
+ /* nameless lookup */
+ MAKE_INODE_HANDLE(real_path, this, loc, &buf);
+ } else {
+ MAKE_ENTRY_HANDLE(real_path, par_path, this, loc, &buf);
+
+ if (gf_uuid_is_null(loc->inode->gfid)) {
+ op_ret = posix_gfid_heal(this, real_path, loc, xdata);
+ if (op_ret < 0) {
+ op_errno = -op_ret;
op_ret = -1;
goto out;
+ }
+ MAKE_ENTRY_HANDLE(real_path, par_path, this, loc, &buf);
}
+ }
- op_ret = dict_get_int32 (xdata, GF_GFIDLESS_LOOKUP, &gfidless);
- op_ret = -1;
- if (gf_uuid_is_null (loc->pargfid) || (loc->name == NULL)) {
- /* nameless lookup */
- MAKE_INODE_HANDLE (real_path, this, loc, &buf);
- } else {
- MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &buf);
-
- if (gf_uuid_is_null (loc->inode->gfid)) {
- op_ret = posix_gfid_heal (this, real_path, loc, xdata);
- if (op_ret < 0) {
- op_errno = -op_ret;
- op_ret = -1;
- goto out;
- }
- MAKE_ENTRY_HANDLE (real_path, par_path, this,
- loc, &buf);
- }
- }
-
- op_errno = errno;
-
- if (op_ret == -1) {
- if (op_errno != ENOENT) {
- gf_msg (this->name, GF_LOG_WARNING, op_errno,
- P_MSG_LSTAT_FAILED,
- "lstat on %s failed",
- real_path ? real_path : "null");
- }
- entry_ret = -1;
- if (loc_is_nameless(loc)) {
- if (!op_errno)
- op_errno = ESTALE;
- loc_gfid (loc, gfid);
- MAKE_HANDLE_ABSPATH (gfid_path, this, gfid);
- ret = sys_stat(gfid_path, &statbuf);
- if (ret == 0 && ((statbuf.st_mode & S_IFMT) == S_IFDIR))
- /*Don't unset if it was a symlink to a dir.*/
- goto parent;
- ret = sys_lstat(gfid_path, &statbuf);
- if (ret == 0 && statbuf.st_nlink == 1) {
- gf_msg (this->name, GF_LOG_WARNING, op_errno,
- P_MSG_HANDLE_DELETE, "Found stale gfid "
- "handle %s, removing it.", gfid_path);
- posix_handle_unset (this, gfid, NULL);
- }
- }
- goto parent;
- }
+ op_errno = errno;
- if (xdata && (op_ret == 0)) {
- xattr = posix_xattr_fill (this, real_path, loc, NULL, -1, xdata,
- &buf);
-
- posix_cs_maintenance (this, NULL, loc, NULL, &buf, real_path,
- xdata, &xattr, _gf_true);
-
- if (dict_get (xdata, GF_CLEAN_WRITE_PROTECTION)) {
- ret = sys_lremovexattr (real_path,
- GF_PROTECT_FROM_EXTERNAL_WRITES);
- if (ret == -1 && (errno != ENODATA && errno != ENOATTR))
- gf_msg (this->name, GF_LOG_ERROR,
- P_MSG_XATTR_NOT_REMOVED, errno,
- "removexattr failed. key %s path %s",
- GF_PROTECT_FROM_EXTERNAL_WRITES,
- loc->path);
- }
+ if (op_ret == -1) {
+ if (op_errno != ENOENT) {
+ gf_msg(this->name, GF_LOG_WARNING, op_errno, P_MSG_LSTAT_FAILED,
+ "lstat on %s failed", real_path ? real_path : "null");
}
+ entry_ret = -1;
+ if (loc_is_nameless(loc)) {
+ if (!op_errno)
+ op_errno = ESTALE;
+ loc_gfid(loc, gfid);
+ MAKE_HANDLE_ABSPATH(gfid_path, this, gfid);
+ ret = sys_stat(gfid_path, &statbuf);
+ if (ret == 0 && ((statbuf.st_mode & S_IFMT) == S_IFDIR))
+ /*Don't unset if it was a symlink to a dir.*/
+ goto parent;
+ ret = sys_lstat(gfid_path, &statbuf);
+ if (ret == 0 && statbuf.st_nlink == 1) {
+ gf_msg(this->name, GF_LOG_WARNING, op_errno,
+ P_MSG_HANDLE_DELETE,
+ "Found stale gfid "
+ "handle %s, removing it.",
+ gfid_path);
+ posix_handle_unset(this, gfid, NULL);
+ }
+ }
+ goto parent;
+ }
+
+ if (xdata && (op_ret == 0)) {
+ xattr = posix_xattr_fill(this, real_path, loc, NULL, -1, xdata, &buf);
+
+ posix_cs_maintenance(this, NULL, loc, NULL, &buf, real_path, xdata,
+ &xattr, _gf_true);
+
+ if (dict_get(xdata, GF_CLEAN_WRITE_PROTECTION)) {
+ ret = sys_lremovexattr(real_path, GF_PROTECT_FROM_EXTERNAL_WRITES);
+ if (ret == -1 && (errno != ENODATA && errno != ENOATTR))
+ gf_msg(this->name, GF_LOG_ERROR, P_MSG_XATTR_NOT_REMOVED, errno,
+ "removexattr failed. key %s path %s",
+ GF_PROTECT_FROM_EXTERNAL_WRITES, loc->path);
+ }
+ }
+
+ if (priv->update_pgfid_nlinks) {
+ if (!gf_uuid_is_null(loc->pargfid) && !IA_ISDIR(buf.ia_type)) {
+ MAKE_PGFID_XATTR_KEY(pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
+ loc->pargfid);
+
+ op_ret = posix_inode_ctx_get_all(loc->inode, this, &ctx);
+ if (op_ret < 0) {
+ op_errno = ENOMEM;
+ goto out;
+ }
- if (priv->update_pgfid_nlinks) {
- if (!gf_uuid_is_null (loc->pargfid) && !IA_ISDIR (buf.ia_type)) {
- MAKE_PGFID_XATTR_KEY (pgfid_xattr_key,
- PGFID_XATTR_KEY_PREFIX,
- loc->pargfid);
-
- op_ret = posix_inode_ctx_get_all (loc->inode, this,
- &ctx);
- if (op_ret < 0) {
- op_errno = ENOMEM;
- goto out;
- }
-
- pthread_mutex_lock (&ctx->pgfid_lock);
- {
- SET_PGFID_XATTR_IF_ABSENT (real_path,
- pgfid_xattr_key,
- nlink_samepgfid,
- XATTR_CREATE, op_ret,
- this, unlock);
- }
-unlock:
- pthread_mutex_unlock (&ctx->pgfid_lock);
- }
+ pthread_mutex_lock(&ctx->pgfid_lock);
+ {
+ SET_PGFID_XATTR_IF_ABSENT(real_path, pgfid_xattr_key,
+ nlink_samepgfid, XATTR_CREATE, op_ret,
+ this, unlock);
+ }
+ unlock:
+ pthread_mutex_unlock(&ctx->pgfid_lock);
}
+ }
parent:
- if (par_path) {
- op_ret = posix_pstat (this, loc->parent, loc->pargfid,
- par_path, &postparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_LSTAT_FAILED, "post-operation lstat on"
- " parent %s failed", par_path);
- if (op_errno == ENOENT)
- /* If parent directory is missing in a lookup,
- errno should be ESTALE (bad handle) and not
- ENOENT (missing entry)
- */
- op_errno = ESTALE;
- goto out;
- }
+ if (par_path) {
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path,
+ &postparent, _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on"
+ " parent %s failed",
+ par_path);
+ if (op_errno == ENOENT)
+ /* If parent directory is missing in a lookup,
+ errno should be ESTALE (bad handle) and not
+ ENOENT (missing entry)
+ */
+ op_errno = ESTALE;
+ goto out;
}
+ }
- op_ret = entry_ret;
+ op_ret = entry_ret;
out:
- if (!op_ret && !gfidless && gf_uuid_is_null (buf.ia_gfid)) {
- gf_msg (this->name, GF_LOG_ERROR, ENODATA, P_MSG_NULL_GFID,
- "buf->ia_gfid is null for "
- "%s", (real_path) ? real_path: "");
- op_ret = -1;
- op_errno = ENODATA;
- }
+ if (!op_ret && !gfidless && gf_uuid_is_null(buf.ia_gfid)) {
+ gf_msg(this->name, GF_LOG_ERROR, ENODATA, P_MSG_NULL_GFID,
+ "buf->ia_gfid is null for "
+ "%s",
+ (real_path) ? real_path : "");
+ op_ret = -1;
+ op_errno = ENODATA;
+ }
- if (op_ret == 0)
- op_errno = 0;
- STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno,
- (loc)?loc->inode:NULL, &buf, xattr, &postparent);
+ if (op_ret == 0)
+ op_errno = 0;
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno,
+ (loc) ? loc->inode : NULL, &buf, xattr, &postparent);
- if (xattr)
- dict_unref (xattr);
+ if (xattr)
+ dict_unref(xattr);
- return 0;
+ return 0;
}
int
-posix_mknod (call_frame_t *frame, xlator_t *this,
- loc_t *loc, mode_t mode, dev_t dev, mode_t umask, dict_t *xdata)
+posix_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ dev_t dev, mode_t umask, dict_t *xdata)
{
- int tmp_fd = 0;
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- char *real_path = 0;
- char *par_path = 0;
- struct iatt stbuf = { 0, };
- struct posix_private *priv = NULL;
- gid_t gid = 0;
- struct iatt preparent = {0,};
- struct iatt postparent = {0,};
- uuid_t uuid_req = {0,};
- int32_t nlink_samepgfid = 0;
- char *pgfid_xattr_key = NULL;
- gf_boolean_t entry_created = _gf_false, gfid_set = _gf_false;
- gf_boolean_t linked = _gf_false;
- gf_loglevel_t level = GF_LOG_NONE;
- mode_t mode_bit = 0;
- posix_inode_ctx_t *ctx = NULL;
-
- DECLARE_OLD_FS_ID_VAR;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (loc, out);
-
- priv = this->private;
- VALIDATE_OR_GOTO (priv, out);
- GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
- out);
- MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, NULL);
-
- mode_bit = (priv->create_mask & mode) | priv->force_create_mode;
- mode = posix_override_umask (mode, mode_bit);
-
- gid = frame->root->gid;
-
- SET_FS_ID (frame->root->uid, gid);
- DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
- if (!real_path || !par_path) {
- op_ret = -1;
- op_errno = ESTALE;
- goto out;
- }
-
-
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &preparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "pre-operation lstat on parent of %s failed",
- real_path);
- goto out;
- }
+ int tmp_fd = 0;
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ char *real_path = 0;
+ char *par_path = 0;
+ struct iatt stbuf = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
+ gid_t gid = 0;
+ struct iatt preparent = {
+ 0,
+ };
+ struct iatt postparent = {
+ 0,
+ };
+ uuid_t uuid_req = {
+ 0,
+ };
+ int32_t nlink_samepgfid = 0;
+ char *pgfid_xattr_key = NULL;
+ gf_boolean_t entry_created = _gf_false, gfid_set = _gf_false;
+ gf_boolean_t linked = _gf_false;
+ gf_loglevel_t level = GF_LOG_NONE;
+ mode_t mode_bit = 0;
+ posix_inode_ctx_t *ctx = NULL;
+
+ DECLARE_OLD_FS_ID_VAR;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(loc, out);
+
+ priv = this->private;
+ VALIDATE_OR_GOTO(priv, out);
+ GFID_NULL_CHECK_AND_GOTO(frame, this, loc, xdata, op_ret, op_errno, out);
+ MAKE_ENTRY_HANDLE(real_path, par_path, this, loc, NULL);
+
+ mode_bit = (priv->create_mask & mode) | priv->force_create_mode;
+ mode = posix_override_umask(mode, mode_bit);
+
+ gid = frame->root->gid;
+
+ SET_FS_ID(frame->root->uid, gid);
+ DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, op_ret, op_errno, out);
+ if (!real_path || !par_path) {
+ op_ret = -1;
+ op_errno = ESTALE;
+ goto out;
+ }
- if (preparent.ia_prot.sgid) {
- gid = preparent.ia_gid;
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &preparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "pre-operation lstat on parent of %s failed", real_path);
+ goto out;
+ }
+
+ if (preparent.ia_prot.sgid) {
+ gid = preparent.ia_gid;
+ }
+
+ /* Check if the 'gfid' already exists, because this mknod may be an
+ internal call from distribute for creating 'linkfile', and that
+ linkfile may be for a hardlinked file */
+ if (dict_get(xdata, GLUSTERFS_INTERNAL_FOP_KEY)) {
+ dict_del(xdata, GLUSTERFS_INTERNAL_FOP_KEY);
+ op_ret = dict_get_gfuuid(xdata, "gfid-req", &uuid_req);
+ if (op_ret) {
+ gf_msg_debug(this->name, 0,
+ "failed to get the gfid from "
+ "dict for %s",
+ loc->path);
+ goto real_op;
}
-
- /* Check if the 'gfid' already exists, because this mknod may be an
- internal call from distribute for creating 'linkfile', and that
- linkfile may be for a hardlinked file */
- if (dict_get (xdata, GLUSTERFS_INTERNAL_FOP_KEY)) {
- dict_del (xdata, GLUSTERFS_INTERNAL_FOP_KEY);
- op_ret = dict_get_gfuuid (xdata, "gfid-req", &uuid_req);
- if (op_ret) {
- gf_msg_debug (this->name, 0, "failed to get the gfid from "
- "dict for %s", loc->path);
- goto real_op;
- }
- op_ret = posix_create_link_if_gfid_exists (this, uuid_req,
- real_path,
- loc->inode->table);
- if (!op_ret) {
- linked = _gf_true;
- goto post_op;
- }
+ op_ret = posix_create_link_if_gfid_exists(this, uuid_req, real_path,
+ loc->inode->table);
+ if (!op_ret) {
+ linked = _gf_true;
+ goto post_op;
}
+ }
real_op:
#ifdef __NetBSD__
- if (S_ISFIFO(mode))
- op_ret = mkfifo (real_path, mode);
- else
+ if (S_ISFIFO(mode))
+ op_ret = mkfifo(real_path, mode);
+ else
#endif /* __NetBSD__ */
- op_ret = sys_mknod (real_path, mode, dev);
+ op_ret = sys_mknod(real_path, mode, dev);
- if (op_ret == -1) {
- op_errno = errno;
- if ((op_errno == EINVAL) && S_ISREG (mode)) {
- /* Over Darwin, mknod with (S_IFREG|mode)
- doesn't work */
- tmp_fd = sys_creat (real_path, mode);
- if (tmp_fd == -1) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_CREATE_FAILED, "create failed on"
- "%s", real_path);
- goto out;
- }
- sys_close (tmp_fd);
- } else {
- if (op_errno == EEXIST)
- level = GF_LOG_DEBUG;
- else
- level = GF_LOG_ERROR;
- gf_msg (this->name, level, errno, P_MSG_MKNOD_FAILED,
- "mknod on %s failed", real_path);
- goto out;
- }
+ if (op_ret == -1) {
+ op_errno = errno;
+ if ((op_errno == EINVAL) && S_ISREG(mode)) {
+ /* Over Darwin, mknod with (S_IFREG|mode)
+ doesn't work */
+ tmp_fd = sys_creat(real_path, mode);
+ if (tmp_fd == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_CREATE_FAILED,
+ "create failed on"
+ "%s",
+ real_path);
+ goto out;
+ }
+ sys_close(tmp_fd);
+ } else {
+ if (op_errno == EEXIST)
+ level = GF_LOG_DEBUG;
+ else
+ level = GF_LOG_ERROR;
+ gf_msg(this->name, level, errno, P_MSG_MKNOD_FAILED,
+ "mknod on %s failed", real_path);
+ goto out;
}
+ }
- entry_created = _gf_true;
+ entry_created = _gf_true;
#ifndef HAVE_SET_FSID
- op_ret = sys_lchown (real_path, frame->root->uid, gid);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LCHOWN_FAILED,
- "lchown on %s failed", real_path);
- goto out;
- }
+ op_ret = sys_lchown(real_path, frame->root->uid, gid);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LCHOWN_FAILED,
+ "lchown on %s failed", real_path);
+ goto out;
+ }
#endif
post_op:
- op_ret = posix_acl_xattr_set (this, real_path, xdata);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_ACL_FAILED,
- "setting ACLs on %s failed", real_path);
- }
-
- if (priv->update_pgfid_nlinks) {
- MAKE_PGFID_XATTR_KEY (pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
- loc->pargfid);
- op_ret = posix_inode_ctx_get_all (loc->inode, this, &ctx);
- if (op_ret < 0) {
- op_errno = ENOMEM;
- goto out;
- }
-
- pthread_mutex_lock (&ctx->pgfid_lock);
- {
- LINK_MODIFY_PGFID_XATTR (real_path, pgfid_xattr_key,
- nlink_samepgfid, 0, op_ret,
- this, unlock);
- }
-unlock:
- pthread_mutex_unlock (&ctx->pgfid_lock);
+ op_ret = posix_acl_xattr_set(this, real_path, xdata);
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_ACL_FAILED,
+ "setting ACLs on %s failed", real_path);
+ }
+
+ if (priv->update_pgfid_nlinks) {
+ MAKE_PGFID_XATTR_KEY(pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
+ loc->pargfid);
+ op_ret = posix_inode_ctx_get_all(loc->inode, this, &ctx);
+ if (op_ret < 0) {
+ op_errno = ENOMEM;
+ goto out;
}
- if (priv->gfid2path) {
- posix_set_gfid2path_xattr (this, real_path, loc->pargfid,
- loc->name);
- }
+ pthread_mutex_lock(&ctx->pgfid_lock);
+ {
+ LINK_MODIFY_PGFID_XATTR(real_path, pgfid_xattr_key, nlink_samepgfid,
+ 0, op_ret, this, unlock);
+ }
+ unlock:
+ pthread_mutex_unlock(&ctx->pgfid_lock);
+ }
+
+ if (priv->gfid2path) {
+ posix_set_gfid2path_xattr(this, real_path, loc->pargfid, loc->name);
+ }
+
+ op_ret = posix_entry_create_xattr_set(this, real_path, xdata);
+ if (op_ret) {
+ if (errno != EEXIST)
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "setting xattrs on %s failed", real_path);
+ else
+ gf_msg_debug(this->name, 0, "setting xattrs on %s failed",
+ real_path);
+ }
- op_ret = posix_entry_create_xattr_set (this, real_path, xdata);
+ if (!linked) {
+ op_ret = posix_gfid_set(this, real_path, loc, xdata, frame->root->pid,
+ &op_errno);
if (op_ret) {
- if (errno != EEXIST)
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_XATTR_FAILED,
- "setting xattrs on %s failed", real_path);
- else
- gf_msg_debug (this->name, 0,
- "setting xattrs on %s failed", real_path);
- }
-
- if (!linked) {
- op_ret = posix_gfid_set (this, real_path, loc, xdata,
- frame->root->pid, &op_errno);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- P_MSG_GFID_FAILED, "setting gfid on %s failed",
- real_path);
- goto out;
- } else {
- gfid_set = _gf_true;
- }
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_GFID_FAILED,
+ "setting gfid on %s failed", real_path);
+ goto out;
+ } else {
+ gfid_set = _gf_true;
}
+ }
- op_ret = posix_pstat (this, loc->inode, NULL, real_path, &stbuf, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_MKNOD_FAILED,
- "mknod on %s failed", real_path);
- goto out;
- }
+ op_ret = posix_pstat(this, loc->inode, NULL, real_path, &stbuf, _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_MKNOD_FAILED,
+ "mknod on %s failed", real_path);
+ goto out;
+ }
- posix_set_ctime (frame, this, real_path, -1, loc->inode, &stbuf);
+ posix_set_ctime(frame, this, real_path, -1, loc->inode, &stbuf);
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &postparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "post-operation lstat on parent %s failed",
- par_path);
- goto out;
- }
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &postparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
- posix_set_parent_ctime (frame, this, par_path, -1, loc->parent,
- &postparent);
+ posix_set_parent_ctime(frame, this, par_path, -1, loc->parent, &postparent);
- op_ret = 0;
+ op_ret = 0;
out:
- SET_TO_OLD_FS_ID ();
+ SET_TO_OLD_FS_ID();
- if (op_ret < 0) {
- if (entry_created) {
- if (S_ISREG (mode))
- sys_unlink (real_path);
- else
- sys_rmdir (real_path);
- }
-
- if (gfid_set)
- posix_gfid_unset (this, xdata);
+ if (op_ret < 0) {
+ if (entry_created) {
+ if (S_ISREG(mode))
+ sys_unlink(real_path);
+ else
+ sys_rmdir(real_path);
}
- STACK_UNWIND_STRICT (mknod, frame, op_ret, op_errno,
- (loc)?loc->inode:NULL, &stbuf, &preparent,
- &postparent, NULL);
+ if (gfid_set)
+ posix_gfid_unset(this, xdata);
+ }
- return 0;
+ STACK_UNWIND_STRICT(mknod, frame, op_ret, op_errno,
+ (loc) ? loc->inode : NULL, &stbuf, &preparent,
+ &postparent, NULL);
+
+ return 0;
}
int
-posix_mkdir (call_frame_t *frame, xlator_t *this,
- loc_t *loc, mode_t mode, mode_t umask, dict_t *xdata)
+posix_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ mode_t umask, dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- char *real_path = NULL, *gfid_path = NULL;
- char *par_path = NULL, *xattr_name = NULL;
- struct iatt stbuf = {0, };
- struct posix_private *priv = NULL;
- gid_t gid = 0;
- struct iatt preparent = {0,};
- struct iatt postparent = {0,};
- gf_boolean_t entry_created = _gf_false, gfid_set = _gf_false;
- uuid_t uuid_req = {0,};
- ssize_t size = 0;
- dict_t *xdata_rsp = NULL;
- void *disk_xattr = NULL;
- data_t *arg_data = NULL;
- char pgfid[GF_UUID_BUF_SIZE] = {0};
- char value_buf[4096] = {0,};
- gf_boolean_t have_val = _gf_false;
- mode_t mode_bit = 0;
-
- DECLARE_OLD_FS_ID_VAR;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (loc, out);
-
- /* The Hidden directory should be for housekeeping purpose and it
- should not get created from a user request */
- if (__is_root_gfid (loc->pargfid) &&
- (strcmp (loc->name, GF_HIDDEN_PATH) == 0)) {
- gf_msg (this->name, GF_LOG_WARNING, EPERM,
- P_MSG_MKDIR_NOT_PERMITTED, "mkdir issued on %s, which"
- "is not permitted", GF_HIDDEN_PATH);
- op_errno = EPERM;
- op_ret = -1;
- goto out;
- }
-
- priv = this->private;
- VALIDATE_OR_GOTO (priv, out);
- GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
- out);
- DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
-
- MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, NULL);
- if (!real_path || !par_path) {
- op_ret = -1;
- op_errno = ESTALE;
- goto out;
- }
-
- if (loc->parent)
- gf_uuid_unparse (loc->parent->gfid, pgfid);
- else
- gf_uuid_unparse (loc->pargfid, pgfid);
-
- gid = frame->root->gid;
-
- op_ret = posix_pstat (this, loc->inode, NULL, real_path, &stbuf, _gf_false);
-
- SET_FS_ID (frame->root->uid, gid);
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ char *real_path = NULL, *gfid_path = NULL;
+ char *par_path = NULL, *xattr_name = NULL;
+ struct iatt stbuf = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
+ gid_t gid = 0;
+ struct iatt preparent = {
+ 0,
+ };
+ struct iatt postparent = {
+ 0,
+ };
+ gf_boolean_t entry_created = _gf_false, gfid_set = _gf_false;
+ uuid_t uuid_req = {
+ 0,
+ };
+ ssize_t size = 0;
+ dict_t *xdata_rsp = NULL;
+ void *disk_xattr = NULL;
+ data_t *arg_data = NULL;
+ char pgfid[GF_UUID_BUF_SIZE] = {0};
+ char value_buf[4096] = {
+ 0,
+ };
+ gf_boolean_t have_val = _gf_false;
+ mode_t mode_bit = 0;
+
+ DECLARE_OLD_FS_ID_VAR;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(loc, out);
+
+ /* The Hidden directory should be for housekeeping purpose and it
+ should not get created from a user request */
+ if (__is_root_gfid(loc->pargfid) &&
+ (strcmp(loc->name, GF_HIDDEN_PATH) == 0)) {
+ gf_msg(this->name, GF_LOG_WARNING, EPERM, P_MSG_MKDIR_NOT_PERMITTED,
+ "mkdir issued on %s, which"
+ "is not permitted",
+ GF_HIDDEN_PATH);
+ op_errno = EPERM;
+ op_ret = -1;
+ goto out;
+ }
- mode_bit = (priv->create_directory_mask & mode)
- | priv->force_directory_mode;
- mode = posix_override_umask (mode, mode_bit);
+ priv = this->private;
+ VALIDATE_OR_GOTO(priv, out);
+ GFID_NULL_CHECK_AND_GOTO(frame, this, loc, xdata, op_ret, op_errno, out);
+ DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, op_ret, op_errno, out);
- if (xdata) {
- op_ret = dict_get_gfuuid (xdata, "gfid-req", &uuid_req);
- if (!op_ret && !gf_uuid_compare (stbuf.ia_gfid, uuid_req)) {
- op_ret = -1;
- op_errno = EEXIST;
- goto out;
+ MAKE_ENTRY_HANDLE(real_path, par_path, this, loc, NULL);
+ if (!real_path || !par_path) {
+ op_ret = -1;
+ op_errno = ESTALE;
+ goto out;
+ }
+
+ if (loc->parent)
+ gf_uuid_unparse(loc->parent->gfid, pgfid);
+ else
+ gf_uuid_unparse(loc->pargfid, pgfid);
+
+ gid = frame->root->gid;
+
+ op_ret = posix_pstat(this, loc->inode, NULL, real_path, &stbuf, _gf_false);
+
+ SET_FS_ID(frame->root->uid, gid);
+
+ mode_bit = (priv->create_directory_mask & mode) |
+ priv->force_directory_mode;
+ mode = posix_override_umask(mode, mode_bit);
+
+ if (xdata) {
+ op_ret = dict_get_gfuuid(xdata, "gfid-req", &uuid_req);
+ if (!op_ret && !gf_uuid_compare(stbuf.ia_gfid, uuid_req)) {
+ op_ret = -1;
+ op_errno = EEXIST;
+ goto out;
+ }
+ }
+
+ if (!gf_uuid_is_null(uuid_req)) {
+ op_ret = posix_istat(this, loc->inode, uuid_req, NULL, &stbuf);
+ if ((op_ret == 0) && IA_ISDIR(stbuf.ia_type)) {
+ size = posix_handle_path(this, uuid_req, NULL, NULL, 0);
+ if (size > 0)
+ gfid_path = alloca(size);
+
+ if (gfid_path)
+ posix_handle_path(this, uuid_req, NULL, gfid_path, size);
+
+ if (frame->root->pid != GF_CLIENT_PID_SELF_HEALD) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_DIR_OF_SAME_ID,
+ "mkdir (%s): "
+ "gfid (%s) is already associated with "
+ "directory (%s). Hence, both "
+ "directories will share same gfid and "
+ "this can lead to inconsistencies.",
+ loc->path, uuid_utoa(uuid_req),
+ gfid_path ? gfid_path : "<NULL>");
+
+ gf_event(EVENT_POSIX_SAME_GFID,
+ "gfid=%s;"
+ "path=%s;newpath=%s;brick=%s:%s",
+ uuid_utoa(uuid_req), gfid_path ? gfid_path : "<NULL>",
+ loc->path, priv->hostname, priv->base_path);
+ }
+ if (!posix_symlinks_match(this, loc, uuid_req))
+ /* For afr selfheal of dir renames, we need to
+ * remove the old symlink in order for
+ * posix_gfid_set to set the symlink to the
+ * new dir.*/
+ posix_handle_unset(this, stbuf.ia_gfid, NULL);
+ }
+ } else if (frame->root->pid != GF_SERVER_PID_TRASH) {
+ op_ret = -1;
+ op_errno = EPERM;
+ gf_msg_callingfn(this->name, GF_LOG_WARNING, op_errno, P_MSG_NULL_GFID,
+ "mkdir (%s): is issued without "
+ "gfid-req %p",
+ loc->path, xdata);
+ goto out;
+ }
+
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &preparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "pre-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
+
+ if (preparent.ia_prot.sgid) {
+ gid = preparent.ia_gid;
+ mode |= S_ISGID;
+ }
+
+ op_ret = dict_get_str(xdata, GF_PREOP_PARENT_KEY, &xattr_name);
+ if (xattr_name != NULL) {
+ arg_data = dict_get(xdata, xattr_name);
+ if (arg_data) {
+ size = sys_lgetxattr(par_path, xattr_name, value_buf,
+ sizeof(value_buf) - 1);
+ if (size >= 0) {
+ have_val = _gf_true;
+ } else {
+ if (errno == ERANGE) {
+ gf_msg(this->name, GF_LOG_INFO, errno,
+ P_MSG_PREOP_CHECK_FAILED,
+ "mkdir (%s/%s): getxattr on key "
+ "(%s) path (%s) failed due to "
+ " buffer overflow",
+ pgfid, loc->name, xattr_name, par_path);
+ size = sys_lgetxattr(par_path, xattr_name, NULL, 0);
}
- }
-
- if (!gf_uuid_is_null (uuid_req)) {
- op_ret = posix_istat (this, loc->inode, uuid_req, NULL, &stbuf);
- if ((op_ret == 0) && IA_ISDIR (stbuf.ia_type)) {
- size = posix_handle_path (this, uuid_req, NULL, NULL,
- 0);
- if (size > 0)
- gfid_path = alloca (size);
-
- if (gfid_path)
- posix_handle_path (this, uuid_req, NULL,
- gfid_path, size);
-
- if (frame->root->pid != GF_CLIENT_PID_SELF_HEALD) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_DIR_OF_SAME_ID, "mkdir (%s): "
- "gfid (%s) is already associated with "
- "directory (%s). Hence, both "
- "directories will share same gfid and "
- "this can lead to inconsistencies.",
- loc->path, uuid_utoa (uuid_req),
- gfid_path ? gfid_path : "<NULL>");
-
- gf_event (EVENT_POSIX_SAME_GFID, "gfid=%s;"
- "path=%s;newpath=%s;brick=%s:%s",
- uuid_utoa (uuid_req),
- gfid_path ? gfid_path : "<NULL>",
- loc->path, priv->hostname,
- priv->base_path);
- }
- if (!posix_symlinks_match (this, loc, uuid_req))
- /* For afr selfheal of dir renames, we need to
- * remove the old symlink in order for
- * posix_gfid_set to set the symlink to the
- * new dir.*/
- posix_handle_unset (this, stbuf.ia_gfid, NULL);
+ if (size < 0) {
+ op_ret = -1;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ P_MSG_PREOP_CHECK_FAILED,
+ "mkdir (%s/%s): getxattr on key (%s)"
+ " path (%s) failed ",
+ pgfid, loc->name, xattr_name, par_path);
+ goto out;
}
- } else if (frame->root->pid != GF_SERVER_PID_TRASH) {
+ }
+ disk_xattr = alloca(size);
+ if (disk_xattr == NULL) {
op_ret = -1;
- op_errno = EPERM;
- gf_msg_callingfn (this->name, GF_LOG_WARNING, op_errno,
- P_MSG_NULL_GFID, "mkdir (%s): is issued without "
- "gfid-req %p", loc->path, xdata);
- goto out;
- }
-
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &preparent, _gf_false);
- if (op_ret == -1) {
op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "pre-operation lstat on parent %s failed",
- par_path);
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ P_MSG_PREOP_CHECK_FAILED,
+ "mkdir (%s/%s): alloca failed during"
+ " preop of mkdir (%s)",
+ pgfid, loc->name, real_path);
+ goto out;
+ }
+ if (have_val) {
+ memcpy(disk_xattr, value_buf, size);
+ } else {
+ size = sys_lgetxattr(par_path, xattr_name, disk_xattr, size);
+ if (size < 0) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ P_MSG_PREOP_CHECK_FAILED,
+ "mkdir (%s/%s): getxattr on "
+ " key (%s) path (%s) failed "
+ "(%s)",
+ pgfid, loc->name, xattr_name, par_path,
+ strerror(errno));
+ goto out;
+ }
+ }
+ if ((arg_data->len != size) ||
+ (memcmp(arg_data->data, disk_xattr, size))) {
+ gf_msg(this->name, GF_LOG_INFO, EIO, P_MSG_PREOP_CHECK_FAILED,
+ "mkdir (%s/%s): failing preop of "
+ "mkdir (%s) as on-disk"
+ " xattr value differs from argument "
+ "value for key %s",
+ pgfid, loc->name, real_path, xattr_name);
+ op_ret = -1;
+ op_errno = EIO;
+
+ xdata_rsp = dict_new();
+ if (xdata_rsp == NULL) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM,
+ P_MSG_PREOP_CHECK_FAILED,
+ "mkdir (%s/%s): "
+ "dict allocation failed",
+ pgfid, loc->name);
+ op_errno = ENOMEM;
+ goto out;
+ }
+
+ op_errno = dict_set_int8(xdata_rsp, GF_PREOP_CHECK_FAILED, 1);
goto out;
- }
+ }
- if (preparent.ia_prot.sgid) {
- gid = preparent.ia_gid;
- mode |= S_ISGID;
+ dict_del(xdata, xattr_name);
}
- op_ret = dict_get_str (xdata, GF_PREOP_PARENT_KEY, &xattr_name);
- if (xattr_name != NULL) {
- arg_data = dict_get (xdata, xattr_name);
- if (arg_data) {
- size = sys_lgetxattr (par_path, xattr_name, value_buf,
- sizeof(value_buf) - 1);
- if (size >= 0) {
- have_val = _gf_true;
- } else {
- if (errno == ERANGE) {
- gf_msg (this->name, GF_LOG_INFO, errno,
- P_MSG_PREOP_CHECK_FAILED,
- "mkdir (%s/%s): getxattr on key "
- "(%s) path (%s) failed due to "
- " buffer overflow", pgfid,
- loc->name, xattr_name,
- par_path);
- size = sys_lgetxattr (par_path,
- xattr_name, NULL,
- 0);
- }
- if (size < 0) {
- op_ret = -1;
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_PREOP_CHECK_FAILED,
- "mkdir (%s/%s): getxattr on key (%s)"
- " path (%s) failed ", pgfid,
- loc->name, xattr_name,
- par_path);
- goto out;
- }
- }
- disk_xattr = alloca (size);
- if (disk_xattr == NULL) {
- op_ret = -1;
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_PREOP_CHECK_FAILED,
- "mkdir (%s/%s): alloca failed during"
- " preop of mkdir (%s)", pgfid,
- loc->name, real_path);
- goto out;
- }
- if (have_val) {
- memcpy (disk_xattr, value_buf, size);
- } else {
- size = sys_lgetxattr (par_path, xattr_name,
- disk_xattr, size);
- if (size < 0) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_PREOP_CHECK_FAILED,
- "mkdir (%s/%s): getxattr on "
- " key (%s) path (%s) failed "
- "(%s)", pgfid, loc->name,
- xattr_name, par_path,
- strerror (errno));
- goto out;
- }
- }
- if ((arg_data->len != size)
- || (memcmp (arg_data->data, disk_xattr, size))) {
- gf_msg (this->name, GF_LOG_INFO, EIO,
- P_MSG_PREOP_CHECK_FAILED,
- "mkdir (%s/%s): failing preop of "
- "mkdir (%s) as on-disk"
- " xattr value differs from argument "
- "value for key %s", pgfid, loc->name,
- real_path, xattr_name);
- op_ret = -1;
- op_errno = EIO;
-
- xdata_rsp = dict_new ();
- if (xdata_rsp == NULL) {
- gf_msg (this->name, GF_LOG_ERROR,
- ENOMEM,
- P_MSG_PREOP_CHECK_FAILED,
- "mkdir (%s/%s): "
- "dict allocation failed", pgfid,
- loc->name);
- op_errno = ENOMEM;
- goto out;
- }
-
- op_errno = dict_set_int8 (xdata_rsp,
- GF_PREOP_CHECK_FAILED, 1);
- goto out;
- }
-
- dict_del (xdata, xattr_name);
- }
-
- dict_del (xdata, GF_PREOP_PARENT_KEY);
- }
+ dict_del(xdata, GF_PREOP_PARENT_KEY);
+ }
- op_ret = sys_mkdir (real_path, mode);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_MKDIR_FAILED,
- "mkdir of %s failed", real_path);
- goto out;
- }
+ op_ret = sys_mkdir(real_path, mode);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_MKDIR_FAILED,
+ "mkdir of %s failed", real_path);
+ goto out;
+ }
- entry_created = _gf_true;
+ entry_created = _gf_true;
#ifndef HAVE_SET_FSID
- op_ret = sys_chown (real_path, frame->root->uid, gid);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_CHOWN_FAILED,
- "chown on %s failed", real_path);
- goto out;
- }
+ op_ret = sys_chown(real_path, frame->root->uid, gid);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_CHOWN_FAILED,
+ "chown on %s failed", real_path);
+ goto out;
+ }
#endif
- op_ret = posix_acl_xattr_set (this, real_path, xdata);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_ACL_FAILED,
- "setting ACLs on %s failed ", real_path);
- }
-
- op_ret = posix_entry_create_xattr_set (this, real_path, xdata);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
- "setting xattrs on %s failed", real_path);
- }
-
- op_ret = posix_gfid_set (this, real_path, loc, xdata, frame->root->pid,
- &op_errno);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, op_errno, P_MSG_GFID_FAILED,
- "setting gfid on %s failed", real_path);
- goto out;
- } else {
- gfid_set = _gf_true;
- }
-
- op_ret = posix_pstat (this, loc->inode, NULL, real_path, &stbuf, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "lstat on %s failed", real_path);
- goto out;
- }
+ op_ret = posix_acl_xattr_set(this, real_path, xdata);
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_ACL_FAILED,
+ "setting ACLs on %s failed ", real_path);
+ }
+
+ op_ret = posix_entry_create_xattr_set(this, real_path, xdata);
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "setting xattrs on %s failed", real_path);
+ }
+
+ op_ret = posix_gfid_set(this, real_path, loc, xdata, frame->root->pid,
+ &op_errno);
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_GFID_FAILED,
+ "setting gfid on %s failed", real_path);
+ goto out;
+ } else {
+ gfid_set = _gf_true;
+ }
+
+ op_ret = posix_pstat(this, loc->inode, NULL, real_path, &stbuf, _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "lstat on %s failed", real_path);
+ goto out;
+ }
- posix_set_ctime (frame, this, real_path, -1, loc->inode, &stbuf);
+ posix_set_ctime(frame, this, real_path, -1, loc->inode, &stbuf);
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &postparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "post-operation lstat on parent of %s failed",
- real_path);
- goto out;
- }
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &postparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on parent of %s failed", real_path);
+ goto out;
+ }
- posix_set_parent_ctime (frame, this, par_path, -1, loc->parent,
- &postparent);
+ posix_set_parent_ctime(frame, this, par_path, -1, loc->parent, &postparent);
- op_ret = 0;
+ op_ret = 0;
out:
- SET_TO_OLD_FS_ID ();
+ SET_TO_OLD_FS_ID();
- if (op_ret < 0) {
- if (entry_created)
- sys_rmdir (real_path);
+ if (op_ret < 0) {
+ if (entry_created)
+ sys_rmdir(real_path);
- if (gfid_set)
- posix_gfid_unset (this, xdata);
- }
+ if (gfid_set)
+ posix_gfid_unset(this, xdata);
+ }
- STACK_UNWIND_STRICT (mkdir, frame, op_ret, op_errno,
- (loc)?loc->inode:NULL, &stbuf, &preparent,
- &postparent, xdata_rsp);
+ STACK_UNWIND_STRICT(mkdir, frame, op_ret, op_errno,
+ (loc) ? loc->inode : NULL, &stbuf, &preparent,
+ &postparent, xdata_rsp);
- if (xdata_rsp)
- dict_unref (xdata_rsp);
+ if (xdata_rsp)
+ dict_unref(xdata_rsp);
- return 0;
+ return 0;
}
int
-posix_add_unlink_to_ctx (inode_t *inode, xlator_t *this, char *unlink_path)
+posix_add_unlink_to_ctx(inode_t *inode, xlator_t *this, char *unlink_path)
{
- uint64_t ctx = GF_UNLINK_FALSE;
- int ret = 0;
-
- if (!unlink_path) {
- gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
- P_MSG_UNLINK_FAILED,
- "Creation of unlink entry failed for gfid: %s",
- unlink_path);
- ret = -1;
- goto out;
- }
-
- ctx = GF_UNLINK_TRUE;
- ret = posix_inode_ctx_set_unlink_flag (inode, this, ctx);
- if (ret < 0) {
- goto out;
- }
+ uint64_t ctx = GF_UNLINK_FALSE;
+ int ret = 0;
+
+ if (!unlink_path) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, P_MSG_UNLINK_FAILED,
+ "Creation of unlink entry failed for gfid: %s", unlink_path);
+ ret = -1;
+ goto out;
+ }
+
+ ctx = GF_UNLINK_TRUE;
+ ret = posix_inode_ctx_set_unlink_flag(inode, this, ctx);
+ if (ret < 0) {
+ goto out;
+ }
out:
- return ret;
+ return ret;
}
int32_t
-posix_move_gfid_to_unlink (xlator_t *this, uuid_t gfid, loc_t *loc)
+posix_move_gfid_to_unlink(xlator_t *this, uuid_t gfid, loc_t *loc)
{
- char *unlink_path = NULL;
- char *gfid_path = NULL;
- int ret = 0;
- struct posix_private *priv_posix = NULL;
-
- priv_posix = (struct posix_private *) this->private;
-
- MAKE_HANDLE_GFID_PATH (gfid_path, this, gfid, NULL);
-
- POSIX_GET_FILE_UNLINK_PATH (priv_posix->base_path,
- loc->inode->gfid, unlink_path);
- if (!unlink_path) {
- ret = -1;
- goto out;
- }
- gf_msg_debug (this->name, 0,
- "Moving gfid: %s to unlink_path : %s",
- gfid_path, unlink_path);
- ret = sys_rename (gfid_path, unlink_path);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_UNLINK_FAILED,
- "Creation of unlink entry failed for gfid: %s",
- unlink_path);
- goto out;
- }
- ret = posix_add_unlink_to_ctx (loc->inode, this, unlink_path);
- if (ret < 0)
- goto out;
+ char *unlink_path = NULL;
+ char *gfid_path = NULL;
+ int ret = 0;
+ struct posix_private *priv_posix = NULL;
+
+ priv_posix = (struct posix_private *)this->private;
+
+ MAKE_HANDLE_GFID_PATH(gfid_path, this, gfid, NULL);
+
+ POSIX_GET_FILE_UNLINK_PATH(priv_posix->base_path, loc->inode->gfid,
+ unlink_path);
+ if (!unlink_path) {
+ ret = -1;
+ goto out;
+ }
+ gf_msg_debug(this->name, 0, "Moving gfid: %s to unlink_path : %s",
+ gfid_path, unlink_path);
+ ret = sys_rename(gfid_path, unlink_path);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_UNLINK_FAILED,
+ "Creation of unlink entry failed for gfid: %s", unlink_path);
+ goto out;
+ }
+ ret = posix_add_unlink_to_ctx(loc->inode, this, unlink_path);
+ if (ret < 0)
+ goto out;
out:
- return ret;
+ return ret;
}
int32_t
-posix_unlink_gfid_handle_and_entry (call_frame_t *frame, xlator_t *this,
- const char *real_path, struct iatt *stbuf,
- int32_t *op_errno, loc_t *loc,
- gf_boolean_t get_link_count,
- dict_t *rsp_dict)
+posix_unlink_gfid_handle_and_entry(call_frame_t *frame, xlator_t *this,
+ const char *real_path, struct iatt *stbuf,
+ int32_t *op_errno, loc_t *loc,
+ gf_boolean_t get_link_count,
+ dict_t *rsp_dict)
{
- int32_t ret = 0;
- struct iatt prebuf = {0,};
- gf_boolean_t locked = _gf_false;
- gf_boolean_t update_ctime = _gf_false;
-
- /* Unlink the gfid_handle_first */
- if (stbuf && stbuf->ia_nlink == 1) {
-
- LOCK (&loc->inode->lock);
-
- if (loc->inode->fd_count == 0) {
- UNLOCK (&loc->inode->lock);
- ret = posix_handle_unset (this, stbuf->ia_gfid, NULL);
- } else {
- UNLOCK (&loc->inode->lock);
- ret = posix_move_gfid_to_unlink (this, stbuf->ia_gfid,
- loc);
- }
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_UNLINK_FAILED, "unlink of gfid handle "
- "failed for path:%s with gfid %s",
- real_path, uuid_utoa (stbuf->ia_gfid));
- }
+ int32_t ret = 0;
+ struct iatt prebuf = {
+ 0,
+ };
+ gf_boolean_t locked = _gf_false;
+ gf_boolean_t update_ctime = _gf_false;
+
+ /* Unlink the gfid_handle_first */
+ if (stbuf && stbuf->ia_nlink == 1) {
+ LOCK(&loc->inode->lock);
+
+ if (loc->inode->fd_count == 0) {
+ UNLOCK(&loc->inode->lock);
+ ret = posix_handle_unset(this, stbuf->ia_gfid, NULL);
} else {
- update_ctime = _gf_true;
- }
-
- if (get_link_count) {
- LOCK (&loc->inode->lock);
- locked = _gf_true;
- /* Since this stat is to get link count and not for time
- * attributes, intentionally passing inode as NULL
- */
- ret = posix_pstat (this, NULL, loc->gfid, real_path,
- &prebuf, _gf_true);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_LSTAT_FAILED, "lstat on %s failed",
- real_path);
- goto err;
- }
- }
-
- /* Unlink the actual file */
- ret = sys_unlink (real_path);
- if (ret == -1) {
- if (op_errno)
- *op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_UNLINK_FAILED,
- "unlink of %s failed", real_path);
- goto err;
- }
-
- if (locked) {
- UNLOCK (&loc->inode->lock);
- locked = _gf_false;
- }
-
- if (update_ctime) {
- posix_set_ctime (frame, this, NULL, -1, loc->inode, stbuf);
- }
-
- ret = dict_set_uint32 (rsp_dict, GET_LINK_COUNT, prebuf.ia_nlink);
- if (ret)
- gf_msg (this->name, GF_LOG_WARNING, 0, P_MSG_SET_XDATA_FAIL,
- "failed to set "GET_LINK_COUNT" for %s", real_path);
-
- return 0;
+ UNLOCK(&loc->inode->lock);
+ ret = posix_move_gfid_to_unlink(this, stbuf->ia_gfid, loc);
+ }
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_UNLINK_FAILED,
+ "unlink of gfid handle "
+ "failed for path:%s with gfid %s",
+ real_path, uuid_utoa(stbuf->ia_gfid));
+ }
+ } else {
+ update_ctime = _gf_true;
+ }
+
+ if (get_link_count) {
+ LOCK(&loc->inode->lock);
+ locked = _gf_true;
+ /* Since this stat is to get link count and not for time
+ * attributes, intentionally passing inode as NULL
+ */
+ ret = posix_pstat(this, NULL, loc->gfid, real_path, &prebuf, _gf_true);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "lstat on %s failed", real_path);
+ goto err;
+ }
+ }
+
+ /* Unlink the actual file */
+ ret = sys_unlink(real_path);
+ if (ret == -1) {
+ if (op_errno)
+ *op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_UNLINK_FAILED,
+ "unlink of %s failed", real_path);
+ goto err;
+ }
+
+ if (locked) {
+ UNLOCK(&loc->inode->lock);
+ locked = _gf_false;
+ }
+
+ if (update_ctime) {
+ posix_set_ctime(frame, this, NULL, -1, loc->inode, stbuf);
+ }
+
+ ret = dict_set_uint32(rsp_dict, GET_LINK_COUNT, prebuf.ia_nlink);
+ if (ret)
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_SET_XDATA_FAIL,
+ "failed to set " GET_LINK_COUNT " for %s", real_path);
+
+ return 0;
err:
- if (locked) {
- UNLOCK (&loc->inode->lock);
- locked = _gf_false;
- }
- return -1;
+ if (locked) {
+ UNLOCK(&loc->inode->lock);
+ locked = _gf_false;
+ }
+ return -1;
}
gf_boolean_t
-posix_skip_non_linkto_unlink (dict_t *xdata, loc_t *loc, char *key,
- const char *linkto_xattr, struct iatt *stbuf,
- const char *real_path)
+posix_skip_non_linkto_unlink(dict_t *xdata, loc_t *loc, char *key,
+ const char *linkto_xattr, struct iatt *stbuf,
+ const char *real_path)
{
- gf_boolean_t skip_unlink = _gf_false;
- gf_boolean_t is_dht_linkto_file = _gf_false;
- int unlink_if_linkto = 0;
- ssize_t xattr_size = -1;
- int op_ret = -1;
-
- op_ret = dict_get_int32 (xdata, key,
- &unlink_if_linkto);
+ gf_boolean_t skip_unlink = _gf_false;
+ gf_boolean_t is_dht_linkto_file = _gf_false;
+ int unlink_if_linkto = 0;
+ ssize_t xattr_size = -1;
+ int op_ret = -1;
- if (!op_ret && unlink_if_linkto) {
+ op_ret = dict_get_int32(xdata, key, &unlink_if_linkto);
- is_dht_linkto_file = IS_DHT_LINKFILE_MODE (stbuf);
- if (!is_dht_linkto_file)
- return _gf_true;
+ if (!op_ret && unlink_if_linkto) {
+ is_dht_linkto_file = IS_DHT_LINKFILE_MODE(stbuf);
+ if (!is_dht_linkto_file)
+ return _gf_true;
- LOCK (&loc->inode->lock);
+ LOCK(&loc->inode->lock);
- xattr_size = sys_lgetxattr (real_path, linkto_xattr, NULL, 0);
+ xattr_size = sys_lgetxattr(real_path, linkto_xattr, NULL, 0);
- if (xattr_size <= 0)
- skip_unlink = _gf_true;
+ if (xattr_size <= 0)
+ skip_unlink = _gf_true;
- UNLOCK (&loc->inode->lock);
-
- gf_msg ("posix", GF_LOG_INFO, 0, P_MSG_XATTR_STATUS,
- "linkto_xattr status: %"PRIu32" for %s", skip_unlink,
- real_path);
- }
- return skip_unlink;
+ UNLOCK(&loc->inode->lock);
+ gf_msg("posix", GF_LOG_INFO, 0, P_MSG_XATTR_STATUS,
+ "linkto_xattr status: %" PRIu32 " for %s", skip_unlink,
+ real_path);
+ }
+ return skip_unlink;
}
int32_t
-posix_unlink (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int xflag, dict_t *xdata)
+posix_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
+ dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- char *real_path = NULL;
- char *par_path = NULL;
- int32_t fd = -1;
- struct iatt stbuf = {0,};
- struct iatt postbuf = {0,};
- struct posix_private *priv = NULL;
- struct iatt preparent = {0,};
- struct iatt postparent = {0,};
- char *pgfid_xattr_key = NULL;
- int32_t nlink_samepgfid = 0;
- int32_t check_open_fd = 0;
- int32_t skip_unlink = 0;
- int32_t fdstat_requested = 0;
- dict_t *unwind_dict = NULL;
- void *uuid = NULL;
- char uuid_str[GF_UUID_BUF_SIZE] = {0};
- char gfid_str[GF_UUID_BUF_SIZE] = {0};
- gf_boolean_t get_link_count = _gf_false;
- posix_inode_ctx_t *ctx = NULL;
-
- DECLARE_OLD_FS_ID_VAR;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (this->private, out);
- VALIDATE_OR_GOTO (loc, out);
-
- SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
- if (!real_path || !par_path) {
- op_ret = -1;
- op_errno = ESTALE;
- goto out;
- }
-
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &preparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "pre-operation lstat on parent %s failed",
- par_path);
- goto out;
- }
-
- priv = this->private;
-
- op_ret = dict_get_ptr (xdata, TIER_LINKFILE_GFID, &uuid);
-
- if (!op_ret && gf_uuid_compare (uuid, stbuf.ia_gfid)) {
- op_errno = ENOENT;
- op_ret = -1;
- gf_uuid_unparse (uuid, uuid_str);
- gf_uuid_unparse (stbuf.ia_gfid, gfid_str);
- gf_msg_debug (this->name, op_errno, "Mismatch in gfid for path "
- "%s. Aborting the unlink. loc->gfid = %s, "
- "stbuf->ia_gfid = %s", real_path,
- uuid_str, gfid_str);
- goto out;
- }
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ char *real_path = NULL;
+ char *par_path = NULL;
+ int32_t fd = -1;
+ struct iatt stbuf = {
+ 0,
+ };
+ struct iatt postbuf = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
+ struct iatt preparent = {
+ 0,
+ };
+ struct iatt postparent = {
+ 0,
+ };
+ char *pgfid_xattr_key = NULL;
+ int32_t nlink_samepgfid = 0;
+ int32_t check_open_fd = 0;
+ int32_t skip_unlink = 0;
+ int32_t fdstat_requested = 0;
+ dict_t *unwind_dict = NULL;
+ void *uuid = NULL;
+ char uuid_str[GF_UUID_BUF_SIZE] = {0};
+ char gfid_str[GF_UUID_BUF_SIZE] = {0};
+ gf_boolean_t get_link_count = _gf_false;
+ posix_inode_ctx_t *ctx = NULL;
+
+ DECLARE_OLD_FS_ID_VAR;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(this->private, out);
+ VALIDATE_OR_GOTO(loc, out);
+
+ SET_FS_ID(frame->root->uid, frame->root->gid);
+ MAKE_ENTRY_HANDLE(real_path, par_path, this, loc, &stbuf);
+ if (!real_path || !par_path) {
+ op_ret = -1;
+ op_errno = ESTALE;
+ goto out;
+ }
- op_ret = dict_get_int32 (xdata, DHT_SKIP_OPEN_FD_UNLINK,
- &check_open_fd);
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &preparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "pre-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
- if (!op_ret && check_open_fd) {
+ priv = this->private;
- LOCK (&loc->inode->lock);
+ op_ret = dict_get_ptr(xdata, TIER_LINKFILE_GFID, &uuid);
- if (loc->inode->fd_count) {
- skip_unlink = 1;
- }
+ if (!op_ret && gf_uuid_compare(uuid, stbuf.ia_gfid)) {
+ op_errno = ENOENT;
+ op_ret = -1;
+ gf_uuid_unparse(uuid, uuid_str);
+ gf_uuid_unparse(stbuf.ia_gfid, gfid_str);
+ gf_msg_debug(this->name, op_errno,
+ "Mismatch in gfid for path "
+ "%s. Aborting the unlink. loc->gfid = %s, "
+ "stbuf->ia_gfid = %s",
+ real_path, uuid_str, gfid_str);
+ goto out;
+ }
- UNLOCK (&loc->inode->lock);
+ op_ret = dict_get_int32(xdata, DHT_SKIP_OPEN_FD_UNLINK, &check_open_fd);
- gf_msg (this->name, GF_LOG_INFO, 0, P_MSG_KEY_STATUS_INFO,
- "open-fd-key-status: %"PRIu32" for %s", skip_unlink,
- real_path);
+ if (!op_ret && check_open_fd) {
+ LOCK(&loc->inode->lock);
- if (skip_unlink) {
- op_ret = -1;
- op_errno = EBUSY;
- goto out;
- }
- }
- /*
- * If either of the function return true, skip_unlink.
- * If first first function itself return true,
- * we don't need to call second function, skip unlink.
- */
- skip_unlink = posix_skip_non_linkto_unlink (xdata, loc,
- DHT_SKIP_NON_LINKTO_UNLINK,
- DHT_LINKTO, &stbuf,
- real_path);
- skip_unlink = skip_unlink || posix_skip_non_linkto_unlink (xdata, loc,
- TIER_SKIP_NON_LINKTO_UNLINK,
- TIER_LINKTO, &stbuf,
- real_path);
- if (skip_unlink) {
- op_ret = -1;
- op_errno = EBUSY;
- goto out;
+ if (loc->inode->fd_count) {
+ skip_unlink = 1;
}
- if (IA_ISREG (loc->inode->ia_type) &&
- xdata && dict_get (xdata, DHT_IATT_IN_XDATA_KEY)) {
- fdstat_requested = 1;
- }
+ UNLOCK(&loc->inode->lock);
- if (fdstat_requested ||
- (priv->background_unlink && IA_ISREG (loc->inode->ia_type))) {
- fd = sys_open (real_path, O_RDONLY, 0);
- if (fd == -1) {
- op_ret = -1;
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_OPEN_FAILED,
- "open of %s failed", real_path);
- goto out;
- }
- }
+ gf_msg(this->name, GF_LOG_INFO, 0, P_MSG_KEY_STATUS_INFO,
+ "open-fd-key-status: %" PRIu32 " for %s", skip_unlink,
+ real_path);
- if (priv->update_pgfid_nlinks && (stbuf.ia_nlink > 1)) {
- MAKE_PGFID_XATTR_KEY (pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
- loc->pargfid);
- op_ret = posix_inode_ctx_get_all (loc->inode, this, &ctx);
- if (op_ret < 0) {
- op_errno = ENOMEM;
- goto out;
- }
- pthread_mutex_lock (&ctx->pgfid_lock);
- {
- UNLINK_MODIFY_PGFID_XATTR (real_path, pgfid_xattr_key,
- nlink_samepgfid, 0, op_ret,
- this, unlock);
- }
- unlock:
- pthread_mutex_unlock (&ctx->pgfid_lock);
-
- if (op_ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_XATTR_FAILED, "modification of "
- "parent gfid xattr failed (path:%s gfid:%s)",
- real_path, uuid_utoa (loc->inode->gfid));
- if (op_errno != ENOATTR)
- /* Allow unlink if pgfid xattr is not set. */
- goto out;
- }
+ if (skip_unlink) {
+ op_ret = -1;
+ op_errno = EBUSY;
+ goto out;
+ }
+ }
+ /*
+ * If either of the function return true, skip_unlink.
+ * If first first function itself return true,
+ * we don't need to call second function, skip unlink.
+ */
+ skip_unlink = posix_skip_non_linkto_unlink(
+ xdata, loc, DHT_SKIP_NON_LINKTO_UNLINK, DHT_LINKTO, &stbuf, real_path);
+ skip_unlink = skip_unlink || posix_skip_non_linkto_unlink(
+ xdata, loc, TIER_SKIP_NON_LINKTO_UNLINK,
+ TIER_LINKTO, &stbuf, real_path);
+ if (skip_unlink) {
+ op_ret = -1;
+ op_errno = EBUSY;
+ goto out;
+ }
+
+ if (IA_ISREG(loc->inode->ia_type) && xdata &&
+ dict_get(xdata, DHT_IATT_IN_XDATA_KEY)) {
+ fdstat_requested = 1;
+ }
+
+ if (fdstat_requested ||
+ (priv->background_unlink && IA_ISREG(loc->inode->ia_type))) {
+ fd = sys_open(real_path, O_RDONLY, 0);
+ if (fd == -1) {
+ op_ret = -1;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_OPEN_FAILED,
+ "open of %s failed", real_path);
+ goto out;
+ }
+ }
+
+ if (priv->update_pgfid_nlinks && (stbuf.ia_nlink > 1)) {
+ MAKE_PGFID_XATTR_KEY(pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
+ loc->pargfid);
+ op_ret = posix_inode_ctx_get_all(loc->inode, this, &ctx);
+ if (op_ret < 0) {
+ op_errno = ENOMEM;
+ goto out;
}
-
- if (priv->gfid2path && (stbuf.ia_nlink > 1)) {
- op_ret = posix_remove_gfid2path_xattr (this, real_path,
- loc->pargfid,
- loc->name);
- if (op_ret < 0) {
- /* Allow unlink if pgfid xattr is not set. */
- if (errno != ENOATTR)
- goto out;
- }
+ pthread_mutex_lock(&ctx->pgfid_lock);
+ {
+ UNLINK_MODIFY_PGFID_XATTR(real_path, pgfid_xattr_key,
+ nlink_samepgfid, 0, op_ret, this, unlock);
}
+ unlock:
+ pthread_mutex_unlock(&ctx->pgfid_lock);
- unwind_dict = dict_new ();
- if (!unwind_dict) {
- op_errno = -ENOMEM;
- op_ret = -1;
+ if (op_ret < 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_XATTR_FAILED,
+ "modification of "
+ "parent gfid xattr failed (path:%s gfid:%s)",
+ real_path, uuid_utoa(loc->inode->gfid));
+ if (op_errno != ENOATTR)
+ /* Allow unlink if pgfid xattr is not set. */
goto out;
}
+ }
- if (xdata && dict_get (xdata, GET_LINK_COUNT))
- get_link_count = _gf_true;
- op_ret = posix_unlink_gfid_handle_and_entry (frame, this, real_path,
- &stbuf, &op_errno, loc,
- get_link_count,
- unwind_dict);
- if (op_ret == -1) {
+ if (priv->gfid2path && (stbuf.ia_nlink > 1)) {
+ op_ret = posix_remove_gfid2path_xattr(this, real_path, loc->pargfid,
+ loc->name);
+ if (op_ret < 0) {
+ /* Allow unlink if pgfid xattr is not set. */
+ if (errno != ENOATTR)
goto out;
}
+ }
- if (fdstat_requested) {
- op_ret = posix_fdstat (this, loc->inode, fd, &postbuf);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_FSTAT_FAILED, "post operation "
- "fstat failed on fd=%d", fd);
- goto out;
- }
- op_ret = posix_set_iatt_in_dict (unwind_dict, NULL, &postbuf);
- }
-
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &postparent, _gf_false);
+ unwind_dict = dict_new();
+ if (!unwind_dict) {
+ op_errno = -ENOMEM;
+ op_ret = -1;
+ goto out;
+ }
+
+ if (xdata && dict_get(xdata, GET_LINK_COUNT))
+ get_link_count = _gf_true;
+ op_ret = posix_unlink_gfid_handle_and_entry(frame, this, real_path, &stbuf,
+ &op_errno, loc, get_link_count,
+ unwind_dict);
+ if (op_ret == -1) {
+ goto out;
+ }
+
+ if (fdstat_requested) {
+ op_ret = posix_fdstat(this, loc->inode, fd, &postbuf);
if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "post-operation lstat on parent %s failed",
- par_path);
- goto out;
- }
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
+ "post operation "
+ "fstat failed on fd=%d",
+ fd);
+ goto out;
+ }
+ op_ret = posix_set_iatt_in_dict(unwind_dict, NULL, &postbuf);
+ }
+
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &postparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
- posix_set_parent_ctime (frame, this, par_path, -1, loc->parent,
- &postparent);
+ posix_set_parent_ctime(frame, this, par_path, -1, loc->parent, &postparent);
- unwind_dict = posix_dict_set_nlink (xdata, unwind_dict, stbuf.ia_nlink);
- op_ret = 0;
+ unwind_dict = posix_dict_set_nlink(xdata, unwind_dict, stbuf.ia_nlink);
+ op_ret = 0;
out:
- SET_TO_OLD_FS_ID ();
+ SET_TO_OLD_FS_ID();
- STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno,
- &preparent, &postparent, unwind_dict);
+ STACK_UNWIND_STRICT(unlink, frame, op_ret, op_errno, &preparent,
+ &postparent, unwind_dict);
- if (fd != -1) {
- sys_close (fd);
- }
+ if (fd != -1) {
+ sys_close(fd);
+ }
- /* unref unwind_dict*/
- if (unwind_dict) {
- dict_unref (unwind_dict);
- }
+ /* unref unwind_dict*/
+ if (unwind_dict) {
+ dict_unref(unwind_dict);
+ }
- return 0;
+ return 0;
}
-
int
-posix_rmdir (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int flags, dict_t *xdata)
+posix_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
+ dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- char *real_path = NULL;
- char *par_path = NULL;
- char *gfid_str = NULL;
- struct iatt preparent = {0,};
- struct iatt postparent = {0,};
- struct iatt stbuf = {0,};
- struct posix_private *priv = NULL;
- char tmp_path[PATH_MAX] = {0,};
-
- DECLARE_OLD_FS_ID_VAR;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (loc, out);
-
- SET_FS_ID (frame->root->uid, frame->root->gid);
-
- /* The Hidden directory should be for housekeeping purpose and it
- should not get deleted from inside process */
- if (__is_root_gfid (loc->pargfid) &&
- (strcmp (loc->name, GF_HIDDEN_PATH) == 0)) {
- gf_msg (this->name, GF_LOG_WARNING, EPERM,
- P_MSG_RMDIR_NOT_PERMITTED, "rmdir issued on %s, which"
- "is not permitted", GF_HIDDEN_PATH);
- op_errno = EPERM;
- op_ret = -1;
- goto out;
- }
-
- priv = this->private;
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ char *real_path = NULL;
+ char *par_path = NULL;
+ char *gfid_str = NULL;
+ struct iatt preparent = {
+ 0,
+ };
+ struct iatt postparent = {
+ 0,
+ };
+ struct iatt stbuf = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
+ char tmp_path[PATH_MAX] = {
+ 0,
+ };
+
+ DECLARE_OLD_FS_ID_VAR;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(loc, out);
+
+ SET_FS_ID(frame->root->uid, frame->root->gid);
+
+ /* The Hidden directory should be for housekeeping purpose and it
+ should not get deleted from inside process */
+ if (__is_root_gfid(loc->pargfid) &&
+ (strcmp(loc->name, GF_HIDDEN_PATH) == 0)) {
+ gf_msg(this->name, GF_LOG_WARNING, EPERM, P_MSG_RMDIR_NOT_PERMITTED,
+ "rmdir issued on %s, which"
+ "is not permitted",
+ GF_HIDDEN_PATH);
+ op_errno = EPERM;
+ op_ret = -1;
+ goto out;
+ }
- MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
- if (!real_path || !par_path) {
- op_ret = -1;
- op_errno = ESTALE;
- goto out;
- }
+ priv = this->private;
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &preparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "pre-operation lstat on parent %s failed",
- par_path);
- goto out;
- }
+ MAKE_ENTRY_HANDLE(real_path, par_path, this, loc, &stbuf);
+ if (!real_path || !par_path) {
+ op_ret = -1;
+ op_errno = ESTALE;
+ goto out;
+ }
- if (flags) {
- gfid_str = uuid_utoa (stbuf.ia_gfid);
-
- op_ret = sys_mkdir (priv->trash_path, 0755);
- if (errno != EEXIST && op_ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_MKDIR_FAILED,
- "mkdir of %s failed", priv->trash_path);
- } else {
- (void) snprintf (tmp_path, sizeof(tmp_path), "%s/%s",
- priv->trash_path, gfid_str);
- gf_msg_debug (this->name, 0,
- "Moving %s to %s", real_path, tmp_path);
- op_ret = sys_rename (real_path, tmp_path);
- pthread_cond_signal (&priv->janitor_cond);
- }
- } else {
- op_ret = sys_rmdir (real_path);
- }
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &preparent,
+ _gf_false);
+ if (op_ret == -1) {
op_errno = errno;
-
- if (op_ret == 0) {
- if (posix_symlinks_match (this, loc, stbuf.ia_gfid))
- posix_handle_unset (this, stbuf.ia_gfid, NULL);
- }
-
- if (op_errno == EEXIST)
- /* Solaris sets errno = EEXIST instead of ENOTEMPTY */
- op_errno = ENOTEMPTY;
-
- /* No need to log a common error as ENOTEMPTY */
- if (op_ret == -1 && op_errno != ENOTEMPTY) {
- gf_msg (this->name, GF_LOG_ERROR, op_errno, P_MSG_RMDIR_FAILED,
- "rmdir of %s failed", real_path);
- }
-
- if (op_ret == -1) {
- if (op_errno == ENOTEMPTY) {
- gf_msg_debug (this->name, 0, "%s on %s failed", (flags)
- ? "rename" : "rmdir", real_path);
- } else {
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- P_MSG_DIR_OPERATION_FAILED, "%s on %s failed",
- (flags) ? "rename" : "rmdir", real_path);
- }
- goto out;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "pre-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
+
+ if (flags) {
+ gfid_str = uuid_utoa(stbuf.ia_gfid);
+
+ op_ret = sys_mkdir(priv->trash_path, 0755);
+ if (errno != EEXIST && op_ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_MKDIR_FAILED,
+ "mkdir of %s failed", priv->trash_path);
+ } else {
+ (void)snprintf(tmp_path, sizeof(tmp_path), "%s/%s",
+ priv->trash_path, gfid_str);
+ gf_msg_debug(this->name, 0, "Moving %s to %s", real_path, tmp_path);
+ op_ret = sys_rename(real_path, tmp_path);
+ pthread_cond_signal(&priv->janitor_cond);
+ }
+ } else {
+ op_ret = sys_rmdir(real_path);
+ }
+ op_errno = errno;
+
+ if (op_ret == 0) {
+ if (posix_symlinks_match(this, loc, stbuf.ia_gfid))
+ posix_handle_unset(this, stbuf.ia_gfid, NULL);
+ }
+
+ if (op_errno == EEXIST)
+ /* Solaris sets errno = EEXIST instead of ENOTEMPTY */
+ op_errno = ENOTEMPTY;
+
+ /* No need to log a common error as ENOTEMPTY */
+ if (op_ret == -1 && op_errno != ENOTEMPTY) {
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_RMDIR_FAILED,
+ "rmdir of %s failed", real_path);
+ }
+
+ if (op_ret == -1) {
+ if (op_errno == ENOTEMPTY) {
+ gf_msg_debug(this->name, 0, "%s on %s failed",
+ (flags) ? "rename" : "rmdir", real_path);
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, op_errno,
+ P_MSG_DIR_OPERATION_FAILED, "%s on %s failed",
+ (flags) ? "rename" : "rmdir", real_path);
}
+ goto out;
+ }
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &postparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "post-operation lstat on parent of %s failed",
- par_path);
- goto out;
- }
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &postparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on parent of %s failed", par_path);
+ goto out;
+ }
- posix_set_parent_ctime (frame, this, par_path, -1, loc->parent,
- &postparent);
+ posix_set_parent_ctime(frame, this, par_path, -1, loc->parent, &postparent);
out:
- SET_TO_OLD_FS_ID ();
+ SET_TO_OLD_FS_ID();
- STACK_UNWIND_STRICT (rmdir, frame, op_ret, op_errno,
- &preparent, &postparent, NULL);
+ STACK_UNWIND_STRICT(rmdir, frame, op_ret, op_errno, &preparent, &postparent,
+ NULL);
- return 0;
+ return 0;
}
-
int
-posix_symlink (call_frame_t *frame, xlator_t *this,
- const char *linkname, loc_t *loc, mode_t umask, dict_t *xdata)
+posix_symlink(call_frame_t *frame, xlator_t *this, const char *linkname,
+ loc_t *loc, mode_t umask, dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- char * real_path = 0;
- char * par_path = 0;
- struct iatt stbuf = { 0, };
- struct posix_private *priv = NULL;
- gid_t gid = 0;
- struct iatt preparent = {0,};
- struct iatt postparent = {0,};
- char *pgfid_xattr_key = NULL;
- int32_t nlink_samepgfid = 0;
- gf_boolean_t entry_created = _gf_false, gfid_set = _gf_false;
-
- DECLARE_OLD_FS_ID_VAR;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (linkname, out);
- VALIDATE_OR_GOTO (loc, out);
-
- priv = this->private;
- VALIDATE_OR_GOTO (priv, out);
- GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
- out);
- DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
-
- MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
-
- gid = frame->root->gid;
- if (!real_path || !par_path) {
- op_ret = -1;
- op_errno = ESTALE;
- goto out;
- }
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ char *real_path = 0;
+ char *par_path = 0;
+ struct iatt stbuf = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
+ gid_t gid = 0;
+ struct iatt preparent = {
+ 0,
+ };
+ struct iatt postparent = {
+ 0,
+ };
+ char *pgfid_xattr_key = NULL;
+ int32_t nlink_samepgfid = 0;
+ gf_boolean_t entry_created = _gf_false, gfid_set = _gf_false;
+
+ DECLARE_OLD_FS_ID_VAR;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(linkname, out);
+ VALIDATE_OR_GOTO(loc, out);
+
+ priv = this->private;
+ VALIDATE_OR_GOTO(priv, out);
+ GFID_NULL_CHECK_AND_GOTO(frame, this, loc, xdata, op_ret, op_errno, out);
+ DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, op_ret, op_errno, out);
+
+ MAKE_ENTRY_HANDLE(real_path, par_path, this, loc, &stbuf);
+
+ gid = frame->root->gid;
+ if (!real_path || !par_path) {
+ op_ret = -1;
+ op_errno = ESTALE;
+ goto out;
+ }
- SET_FS_ID (frame->root->uid, gid);
+ SET_FS_ID(frame->root->uid, gid);
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &preparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "pre-operation lstat on parent %s failed",
- par_path);
- goto out;
- }
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &preparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "pre-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
- if (preparent.ia_prot.sgid) {
- gid = preparent.ia_gid;
- }
+ if (preparent.ia_prot.sgid) {
+ gid = preparent.ia_gid;
+ }
- op_ret = sys_symlink (linkname, real_path);
+ op_ret = sys_symlink(linkname, real_path);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_SYMLINK_FAILED,
- "symlink of %s --> %s failed",
- real_path, linkname);
- goto out;
- }
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_SYMLINK_FAILED,
+ "symlink of %s --> %s failed", real_path, linkname);
+ goto out;
+ }
- entry_created = _gf_true;
+ entry_created = _gf_true;
- posix_set_ctime (frame, this, real_path, -1, loc->inode, &stbuf);
+ posix_set_ctime(frame, this, real_path, -1, loc->inode, &stbuf);
#ifndef HAVE_SET_FSID
- op_ret = sys_lchown (real_path, frame->root->uid, gid);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LCHOWN_FAILED,
- "lchown failed on %s", real_path);
- goto out;
- }
+ op_ret = sys_lchown(real_path, frame->root->uid, gid);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LCHOWN_FAILED,
+ "lchown failed on %s", real_path);
+ goto out;
+ }
#endif
- op_ret = posix_acl_xattr_set (this, real_path, xdata);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_ACL_FAILED,
- "setting ACLs on %s failed", real_path);
- }
-
- if (priv->update_pgfid_nlinks) {
- MAKE_PGFID_XATTR_KEY (pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
- loc->pargfid);
- nlink_samepgfid = 1;
- SET_PGFID_XATTR (real_path, pgfid_xattr_key, nlink_samepgfid,
- XATTR_CREATE, op_ret, this, ignore);
- }
-
- if (priv->gfid2path) {
- posix_set_gfid2path_xattr (this, real_path, loc->pargfid,
- loc->name);
- }
+ op_ret = posix_acl_xattr_set(this, real_path, xdata);
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_ACL_FAILED,
+ "setting ACLs on %s failed", real_path);
+ }
+
+ if (priv->update_pgfid_nlinks) {
+ MAKE_PGFID_XATTR_KEY(pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
+ loc->pargfid);
+ nlink_samepgfid = 1;
+ SET_PGFID_XATTR(real_path, pgfid_xattr_key, nlink_samepgfid,
+ XATTR_CREATE, op_ret, this, ignore);
+ }
+
+ if (priv->gfid2path) {
+ posix_set_gfid2path_xattr(this, real_path, loc->pargfid, loc->name);
+ }
ignore:
- op_ret = posix_entry_create_xattr_set (this, real_path, xdata);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
- "setting xattrs on %s failed ", real_path);
- }
-
- op_ret = posix_gfid_set (this, real_path, loc, xdata, frame->root->pid,
- &op_errno);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, op_errno, P_MSG_GFID_FAILED,
- "setting gfid on %s failed", real_path);
- goto out;
- } else {
- gfid_set = _gf_true;
- }
-
- op_ret = posix_pstat (this, loc->inode, NULL, real_path, &stbuf, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "lstat failed on %s", real_path);
- goto out;
- }
-
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &postparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "post-operation lstat on parent %s failed",
- par_path);
- goto out;
- }
+ op_ret = posix_entry_create_xattr_set(this, real_path, xdata);
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "setting xattrs on %s failed ", real_path);
+ }
+
+ op_ret = posix_gfid_set(this, real_path, loc, xdata, frame->root->pid,
+ &op_errno);
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_GFID_FAILED,
+ "setting gfid on %s failed", real_path);
+ goto out;
+ } else {
+ gfid_set = _gf_true;
+ }
+
+ op_ret = posix_pstat(this, loc->inode, NULL, real_path, &stbuf, _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "lstat failed on %s", real_path);
+ goto out;
+ }
+
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &postparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
- posix_set_parent_ctime (frame, this, par_path, -1, loc->parent,
- &postparent);
+ posix_set_parent_ctime(frame, this, par_path, -1, loc->parent, &postparent);
- op_ret = 0;
+ op_ret = 0;
out:
- SET_TO_OLD_FS_ID ();
+ SET_TO_OLD_FS_ID();
- if (op_ret < 0) {
- if (entry_created)
- sys_unlink (real_path);
+ if (op_ret < 0) {
+ if (entry_created)
+ sys_unlink(real_path);
- if (gfid_set)
- posix_gfid_unset (this, xdata);
- }
+ if (gfid_set)
+ posix_gfid_unset(this, xdata);
+ }
- STACK_UNWIND_STRICT (symlink, frame, op_ret, op_errno,
- (loc)?loc->inode:NULL, &stbuf, &preparent,
- &postparent, NULL);
+ STACK_UNWIND_STRICT(symlink, frame, op_ret, op_errno,
+ (loc) ? loc->inode : NULL, &stbuf, &preparent,
+ &postparent, NULL);
- return 0;
+ return 0;
}
-
int
-posix_rename (call_frame_t *frame, xlator_t *this,
- loc_t *oldloc, loc_t *newloc, dict_t *xdata)
+posix_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
+ dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- char *real_oldpath = NULL;
- char *real_newpath = NULL;
- char *par_oldpath = NULL;
- char *par_newpath = NULL;
- struct iatt stbuf = {0, };
- struct posix_private *priv = NULL;
- char was_present = 1;
- struct iatt preoldparent = {0, };
- struct iatt postoldparent = {0, };
- struct iatt prenewparent = {0, };
- struct iatt postnewparent = {0, };
- char olddirid[64];
- char newdirid[64];
- uuid_t victim = {0};
- int was_dir = 0;
- int nlink = 0;
- char *pgfid_xattr_key = NULL;
- int32_t nlink_samepgfid = 0;
- char *gfid_path = NULL;
- dict_t *unwind_dict = NULL;
- gf_boolean_t locked = _gf_false;
- gf_boolean_t get_link_count = _gf_false;
- posix_inode_ctx_t *ctx_old = NULL;
- posix_inode_ctx_t *ctx_new = NULL;
-
- DECLARE_OLD_FS_ID_VAR;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (oldloc, out);
- VALIDATE_OR_GOTO (newloc, out);
-
- priv = this->private;
- VALIDATE_OR_GOTO (priv, out);
- DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
-
- SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_ENTRY_HANDLE (real_oldpath, par_oldpath, this, oldloc, NULL);
- if (!real_oldpath || !par_oldpath) {
- op_ret = -1;
- op_errno = ESTALE;
- goto out;
- }
-
- MAKE_ENTRY_HANDLE (real_newpath, par_newpath, this, newloc, &stbuf);
- if (!real_newpath || !par_newpath) {
- op_ret = -1;
- op_errno = ESTALE;
- goto out;
- }
-
- unwind_dict = dict_new ();
- if (!unwind_dict) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto out;
- }
-
- op_ret = posix_pstat (this, oldloc->parent, oldloc->pargfid,
- par_oldpath, &preoldparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "pre-operation lstat on parent %s failed",
- par_oldpath);
- goto out;
- }
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ char *real_oldpath = NULL;
+ char *real_newpath = NULL;
+ char *par_oldpath = NULL;
+ char *par_newpath = NULL;
+ struct iatt stbuf = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
+ char was_present = 1;
+ struct iatt preoldparent = {
+ 0,
+ };
+ struct iatt postoldparent = {
+ 0,
+ };
+ struct iatt prenewparent = {
+ 0,
+ };
+ struct iatt postnewparent = {
+ 0,
+ };
+ char olddirid[64];
+ char newdirid[64];
+ uuid_t victim = {0};
+ int was_dir = 0;
+ int nlink = 0;
+ char *pgfid_xattr_key = NULL;
+ int32_t nlink_samepgfid = 0;
+ char *gfid_path = NULL;
+ dict_t *unwind_dict = NULL;
+ gf_boolean_t locked = _gf_false;
+ gf_boolean_t get_link_count = _gf_false;
+ posix_inode_ctx_t *ctx_old = NULL;
+ posix_inode_ctx_t *ctx_new = NULL;
+
+ DECLARE_OLD_FS_ID_VAR;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(oldloc, out);
+ VALIDATE_OR_GOTO(newloc, out);
+
+ priv = this->private;
+ VALIDATE_OR_GOTO(priv, out);
+ DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, op_ret, op_errno, out);
+
+ SET_FS_ID(frame->root->uid, frame->root->gid);
+ MAKE_ENTRY_HANDLE(real_oldpath, par_oldpath, this, oldloc, NULL);
+ if (!real_oldpath || !par_oldpath) {
+ op_ret = -1;
+ op_errno = ESTALE;
+ goto out;
+ }
- op_ret = posix_pstat (this, newloc->parent, newloc->pargfid,
- par_newpath, &prenewparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "pre-operation lstat on parent of %s failed",
- par_newpath);
- goto out;
- }
+ MAKE_ENTRY_HANDLE(real_newpath, par_newpath, this, newloc, &stbuf);
+ if (!real_newpath || !par_newpath) {
+ op_ret = -1;
+ op_errno = ESTALE;
+ goto out;
+ }
- op_ret = posix_pstat (this, newloc->inode, NULL, real_newpath, &stbuf,
- _gf_false);
- if ((op_ret == -1) && (errno == ENOENT)){
- was_present = 0;
- } else {
- gf_uuid_copy (victim, stbuf.ia_gfid);
- if (IA_ISDIR (stbuf.ia_type))
- was_dir = 1;
- nlink = stbuf.ia_nlink;
- }
+ unwind_dict = dict_new();
+ if (!unwind_dict) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto out;
+ }
- if (was_present && IA_ISDIR(stbuf.ia_type) && !newloc->inode) {
- gf_msg (this->name, GF_LOG_WARNING, EEXIST, P_MSG_DIR_FOUND,
- "found directory at %s while expecting ENOENT",
- real_newpath);
- op_ret = -1;
- op_errno = EEXIST;
- goto out;
- }
+ op_ret = posix_pstat(this, oldloc->parent, oldloc->pargfid, par_oldpath,
+ &preoldparent, _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "pre-operation lstat on parent %s failed", par_oldpath);
+ goto out;
+ }
+
+ op_ret = posix_pstat(this, newloc->parent, newloc->pargfid, par_newpath,
+ &prenewparent, _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "pre-operation lstat on parent of %s failed", par_newpath);
+ goto out;
+ }
+
+ op_ret = posix_pstat(this, newloc->inode, NULL, real_newpath, &stbuf,
+ _gf_false);
+ if ((op_ret == -1) && (errno == ENOENT)) {
+ was_present = 0;
+ } else {
+ gf_uuid_copy(victim, stbuf.ia_gfid);
+ if (IA_ISDIR(stbuf.ia_type))
+ was_dir = 1;
+ nlink = stbuf.ia_nlink;
+ }
+
+ if (was_present && IA_ISDIR(stbuf.ia_type) && !newloc->inode) {
+ gf_msg(this->name, GF_LOG_WARNING, EEXIST, P_MSG_DIR_FOUND,
+ "found directory at %s while expecting ENOENT", real_newpath);
+ op_ret = -1;
+ op_errno = EEXIST;
+ goto out;
+ }
+
+ if (was_present && IA_ISDIR(stbuf.ia_type) &&
+ gf_uuid_compare(newloc->inode->gfid, stbuf.ia_gfid)) {
+ gf_msg(this->name, GF_LOG_WARNING, EEXIST, P_MSG_DIR_FOUND,
+ "found directory %s at %s while renaming %s",
+ uuid_utoa_r(newloc->inode->gfid, olddirid), real_newpath,
+ uuid_utoa_r(stbuf.ia_gfid, newdirid));
+ op_ret = -1;
+ op_errno = EEXIST;
+ goto out;
+ }
- if (was_present && IA_ISDIR(stbuf.ia_type) &&
- gf_uuid_compare (newloc->inode->gfid, stbuf.ia_gfid)) {
- gf_msg (this->name, GF_LOG_WARNING, EEXIST, P_MSG_DIR_FOUND,
- "found directory %s at %s while renaming %s",
- uuid_utoa_r (newloc->inode->gfid, olddirid),
- real_newpath,
- uuid_utoa_r (stbuf.ia_gfid, newdirid));
- op_ret = -1;
- op_errno = EEXIST;
- goto out;
- }
+ op_ret = posix_inode_ctx_get_all(oldloc->inode, this, &ctx_old);
+ if (op_ret < 0) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto out;
+ }
- op_ret = posix_inode_ctx_get_all (oldloc->inode, this, &ctx_old);
+ if (newloc->inode) {
+ op_ret = posix_inode_ctx_get_all(newloc->inode, this, &ctx_new);
if (op_ret < 0) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto out;
- }
-
- if (newloc->inode) {
- op_ret = posix_inode_ctx_get_all (newloc->inode, this, &ctx_new);
- if (op_ret < 0) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto out;
- }
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto out;
+ }
+ }
+
+ if (IA_ISDIR(oldloc->inode->ia_type))
+ posix_handle_unset(this, oldloc->inode->gfid, NULL);
+
+ pthread_mutex_lock(&ctx_old->pgfid_lock);
+ {
+ if (!IA_ISDIR(oldloc->inode->ia_type) && priv->update_pgfid_nlinks) {
+ MAKE_PGFID_XATTR_KEY(pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
+ oldloc->pargfid);
+ UNLINK_MODIFY_PGFID_XATTR(real_oldpath, pgfid_xattr_key,
+ nlink_samepgfid, 0, op_ret, this, unlock);
+ }
+
+ if ((xdata) && (dict_get(xdata, GET_LINK_COUNT)) && (real_newpath) &&
+ (was_present) && ctx_new) {
+ pthread_mutex_lock(&ctx_new->pgfid_lock);
+ locked = _gf_true;
+ get_link_count = _gf_true;
+ op_ret = posix_pstat(this, newloc->inode, newloc->gfid,
+ real_newpath, &stbuf, _gf_false);
+ if ((op_ret == -1) && (errno != ENOENT)) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "lstat on %s failed", real_newpath);
+ goto unlock;
+ }
}
- if (IA_ISDIR (oldloc->inode->ia_type))
- posix_handle_unset (this, oldloc->inode->gfid, NULL);
-
- pthread_mutex_lock (&ctx_old->pgfid_lock);
- {
- if (!IA_ISDIR (oldloc->inode->ia_type)
- && priv->update_pgfid_nlinks) {
- MAKE_PGFID_XATTR_KEY (pgfid_xattr_key,
- PGFID_XATTR_KEY_PREFIX,
- oldloc->pargfid);
- UNLINK_MODIFY_PGFID_XATTR (real_oldpath,
- pgfid_xattr_key,
- nlink_samepgfid, 0,
- op_ret,
- this, unlock);
- }
-
- if ((xdata) && (dict_get (xdata, GET_LINK_COUNT))
- && (real_newpath) && (was_present) && ctx_new) {
- pthread_mutex_lock (&ctx_new->pgfid_lock);
- locked = _gf_true;
- get_link_count = _gf_true;
- op_ret = posix_pstat (this, newloc->inode, newloc->gfid,
- real_newpath, &stbuf, _gf_false);
- if ((op_ret == -1) && (errno != ENOENT)) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_LSTAT_FAILED,
- "lstat on %s failed", real_newpath);
- goto unlock;
- }
- }
-
- op_ret = sys_rename (real_oldpath, real_newpath);
- if (op_ret == -1) {
- op_errno = errno;
- if (op_errno == ENOTEMPTY) {
- gf_msg_debug (this->name, 0, "rename of %s to"
- " %s failed: %s", real_oldpath,
- real_newpath,
- strerror (op_errno));
- } else {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_RENAME_FAILED,
- "rename of %s to %s failed",
- real_oldpath, real_newpath);
- }
-
- if (priv->update_pgfid_nlinks
- && !IA_ISDIR (oldloc->inode->ia_type)) {
- LINK_MODIFY_PGFID_XATTR (real_oldpath,
- pgfid_xattr_key,
- nlink_samepgfid, 0,
- op_ret,
- this, unlock);
- }
-
- goto unlock;
- }
-
- if (locked) {
- pthread_mutex_unlock (&ctx_new->pgfid_lock);
- locked = _gf_false;
- }
-
- if ((get_link_count) &&
- (dict_set_uint32 (unwind_dict, GET_LINK_COUNT,
- stbuf.ia_nlink)))
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_SET_XDATA_FAIL, "failed to set "
- GET_LINK_COUNT" for %s", real_newpath);
-
- if (!IA_ISDIR (oldloc->inode->ia_type)
- && priv->update_pgfid_nlinks) {
- MAKE_PGFID_XATTR_KEY (pgfid_xattr_key,
- PGFID_XATTR_KEY_PREFIX,
- newloc->pargfid);
- LINK_MODIFY_PGFID_XATTR (real_newpath,
- pgfid_xattr_key,
- nlink_samepgfid, 0,
- op_ret,
- this, unlock);
- }
-
- if (!IA_ISDIR (oldloc->inode->ia_type) && priv->gfid2path) {
- MAKE_HANDLE_ABSPATH (gfid_path, this,
- oldloc->inode->gfid);
-
- posix_remove_gfid2path_xattr (this, gfid_path,
- oldloc->pargfid,
- oldloc->name);
- posix_set_gfid2path_xattr (this, gfid_path,
- newloc->pargfid,
- newloc->name);
- }
+ op_ret = sys_rename(real_oldpath, real_newpath);
+ if (op_ret == -1) {
+ op_errno = errno;
+ if (op_errno == ENOTEMPTY) {
+ gf_msg_debug(this->name, 0,
+ "rename of %s to"
+ " %s failed: %s",
+ real_oldpath, real_newpath, strerror(op_errno));
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_RENAME_FAILED,
+ "rename of %s to %s failed", real_oldpath, real_newpath);
+ }
+
+ if (priv->update_pgfid_nlinks &&
+ !IA_ISDIR(oldloc->inode->ia_type)) {
+ LINK_MODIFY_PGFID_XATTR(real_oldpath, pgfid_xattr_key,
+ nlink_samepgfid, 0, op_ret, this,
+ unlock);
+ }
+
+ goto unlock;
}
-unlock:
if (locked) {
- pthread_mutex_unlock (&ctx_new->pgfid_lock);
- locked = _gf_false;
- }
- pthread_mutex_unlock (&ctx_old->pgfid_lock);
-
- if (op_ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0, P_MSG_XATTR_FAILED,
- "modification of "
- "parent gfid xattr failed (gfid:%s)",
- uuid_utoa (oldloc->inode->gfid));
- goto out;
+ pthread_mutex_unlock(&ctx_new->pgfid_lock);
+ locked = _gf_false;
}
- if (was_dir)
- posix_handle_unset (this, victim, NULL);
-
- if (was_present && !was_dir && nlink == 1)
- posix_handle_unset (this, victim, NULL);
+ if ((get_link_count) &&
+ (dict_set_uint32(unwind_dict, GET_LINK_COUNT, stbuf.ia_nlink)))
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_SET_XDATA_FAIL,
+ "failed to set " GET_LINK_COUNT " for %s", real_newpath);
- if (IA_ISDIR (oldloc->inode->ia_type)) {
- posix_handle_soft (this, real_newpath, newloc,
- oldloc->inode->gfid, NULL);
+ if (!IA_ISDIR(oldloc->inode->ia_type) && priv->update_pgfid_nlinks) {
+ MAKE_PGFID_XATTR_KEY(pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
+ newloc->pargfid);
+ LINK_MODIFY_PGFID_XATTR(real_newpath, pgfid_xattr_key,
+ nlink_samepgfid, 0, op_ret, this, unlock);
}
- op_ret = posix_pstat (this, newloc->inode, NULL, real_newpath, &stbuf,
- _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "lstat on %s failed", real_newpath);
- goto out;
- }
-
- /* Since the same inode is later used and dst inode is not present,
- * update ctime on source inode. It can't use old path because it
- * doesn't exist and xattr has to be stored on disk */
- posix_set_ctime (frame, this, real_newpath, -1, oldloc->inode, &stbuf);
+ if (!IA_ISDIR(oldloc->inode->ia_type) && priv->gfid2path) {
+ MAKE_HANDLE_ABSPATH(gfid_path, this, oldloc->inode->gfid);
- op_ret = posix_pstat (this, oldloc->parent, oldloc->pargfid,
- par_oldpath, &postoldparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "post-operation lstat on parent %s failed",
- par_oldpath);
- goto out;
+ posix_remove_gfid2path_xattr(this, gfid_path, oldloc->pargfid,
+ oldloc->name);
+ posix_set_gfid2path_xattr(this, gfid_path, newloc->pargfid,
+ newloc->name);
}
+ }
- posix_set_parent_ctime (frame, this, par_oldpath, -1, oldloc->parent,
- &postoldparent);
+unlock:
+ if (locked) {
+ pthread_mutex_unlock(&ctx_new->pgfid_lock);
+ locked = _gf_false;
+ }
+ pthread_mutex_unlock(&ctx_old->pgfid_lock);
+
+ if (op_ret < 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_XATTR_FAILED,
+ "modification of "
+ "parent gfid xattr failed (gfid:%s)",
+ uuid_utoa(oldloc->inode->gfid));
+ goto out;
+ }
+
+ if (was_dir)
+ posix_handle_unset(this, victim, NULL);
+
+ if (was_present && !was_dir && nlink == 1)
+ posix_handle_unset(this, victim, NULL);
+
+ if (IA_ISDIR(oldloc->inode->ia_type)) {
+ posix_handle_soft(this, real_newpath, newloc, oldloc->inode->gfid,
+ NULL);
+ }
+
+ op_ret = posix_pstat(this, newloc->inode, NULL, real_newpath, &stbuf,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "lstat on %s failed", real_newpath);
+ goto out;
+ }
+
+ /* Since the same inode is later used and dst inode is not present,
+ * update ctime on source inode. It can't use old path because it
+ * doesn't exist and xattr has to be stored on disk */
+ posix_set_ctime(frame, this, real_newpath, -1, oldloc->inode, &stbuf);
+
+ op_ret = posix_pstat(this, oldloc->parent, oldloc->pargfid, par_oldpath,
+ &postoldparent, _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on parent %s failed", par_oldpath);
+ goto out;
+ }
- op_ret = posix_pstat (this, newloc->parent, newloc->pargfid,
- par_newpath, &postnewparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "post-operation lstat on parent %s failed",
- par_newpath);
- goto out;
- }
+ posix_set_parent_ctime(frame, this, par_oldpath, -1, oldloc->parent,
+ &postoldparent);
+
+ op_ret = posix_pstat(this, newloc->parent, newloc->pargfid, par_newpath,
+ &postnewparent, _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on parent %s failed", par_newpath);
+ goto out;
+ }
- posix_set_parent_ctime (frame, this, par_newpath, -1, newloc->parent,
- &postnewparent);
+ posix_set_parent_ctime(frame, this, par_newpath, -1, newloc->parent,
+ &postnewparent);
- if (was_present)
- unwind_dict = posix_dict_set_nlink (xdata, unwind_dict, nlink);
- op_ret = 0;
+ if (was_present)
+ unwind_dict = posix_dict_set_nlink(xdata, unwind_dict, nlink);
+ op_ret = 0;
out:
- SET_TO_OLD_FS_ID ();
+ SET_TO_OLD_FS_ID();
- STACK_UNWIND_STRICT (rename, frame, op_ret, op_errno, &stbuf,
- &preoldparent, &postoldparent,
- &prenewparent, &postnewparent, unwind_dict);
+ STACK_UNWIND_STRICT(rename, frame, op_ret, op_errno, &stbuf, &preoldparent,
+ &postoldparent, &prenewparent, &postnewparent,
+ unwind_dict);
- if (unwind_dict)
- dict_unref (unwind_dict);
+ if (unwind_dict)
+ dict_unref(unwind_dict);
- return 0;
+ return 0;
}
-
int
-posix_link (call_frame_t *frame, xlator_t *this,
- loc_t *oldloc, loc_t *newloc, dict_t *xdata)
+posix_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
+ dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- char *real_oldpath = 0;
- char *real_newpath = 0;
- char *par_newpath = 0;
- struct iatt stbuf = {0, };
- struct posix_private *priv = NULL;
- struct iatt preparent = {0,};
- struct iatt postparent = {0,};
- int32_t nlink_samepgfid = 0;
- char *pgfid_xattr_key = NULL;
- gf_boolean_t entry_created = _gf_false;
- posix_inode_ctx_t *ctx = NULL;
-
- DECLARE_OLD_FS_ID_VAR;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (oldloc, out);
- VALIDATE_OR_GOTO (newloc, out);
-
- priv = this->private;
- VALIDATE_OR_GOTO (priv, out);
- DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
-
- SET_FS_ID (frame->root->uid, frame->root->gid);
- MAKE_INODE_HANDLE (real_oldpath, this, oldloc, &stbuf);
- if (!real_oldpath) {
- op_errno = errno;
- goto out;
- }
-
- if (priv->max_hardlinks && stbuf.ia_nlink >= priv->max_hardlinks) {
- op_ret = -1;
- op_errno = EMLINK;
- gf_log (this->name, GF_LOG_ERROR,
- "hardlink failed: %s exceeds max link count (%u/%u).",
- real_oldpath, stbuf.ia_nlink, priv->max_hardlinks);
- goto out;
- }
-
- MAKE_ENTRY_HANDLE (real_newpath, par_newpath, this, newloc, &stbuf);
- if (!real_newpath || !par_newpath) {
- op_ret = -1;
- op_errno = ESTALE;
- goto out;
- }
-
- op_ret = posix_pstat (this, newloc->parent, newloc->pargfid,
- par_newpath, &preparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "lstat failed: %s", par_newpath);
- goto out;
- }
-
-
- op_ret = sys_link (real_oldpath, real_newpath);
-
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LINK_FAILED,
- "link %s to %s failed",
- real_oldpath, real_newpath);
- goto out;
- }
-
- entry_created = _gf_true;
-
- op_ret = posix_pstat (this, newloc->inode, NULL, real_newpath, &stbuf,
- _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "lstat on %s failed", real_newpath);
- goto out;
- }
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ char *real_oldpath = 0;
+ char *real_newpath = 0;
+ char *par_newpath = 0;
+ struct iatt stbuf = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
+ struct iatt preparent = {
+ 0,
+ };
+ struct iatt postparent = {
+ 0,
+ };
+ int32_t nlink_samepgfid = 0;
+ char *pgfid_xattr_key = NULL;
+ gf_boolean_t entry_created = _gf_false;
+ posix_inode_ctx_t *ctx = NULL;
+
+ DECLARE_OLD_FS_ID_VAR;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(oldloc, out);
+ VALIDATE_OR_GOTO(newloc, out);
+
+ priv = this->private;
+ VALIDATE_OR_GOTO(priv, out);
+ DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, op_ret, op_errno, out);
+
+ SET_FS_ID(frame->root->uid, frame->root->gid);
+ MAKE_INODE_HANDLE(real_oldpath, this, oldloc, &stbuf);
+ if (!real_oldpath) {
+ op_errno = errno;
+ goto out;
+ }
- posix_set_ctime (frame, this, real_newpath, -1, newloc->inode, &stbuf);
+ if (priv->max_hardlinks && stbuf.ia_nlink >= priv->max_hardlinks) {
+ op_ret = -1;
+ op_errno = EMLINK;
+ gf_log(this->name, GF_LOG_ERROR,
+ "hardlink failed: %s exceeds max link count (%u/%u).",
+ real_oldpath, stbuf.ia_nlink, priv->max_hardlinks);
+ goto out;
+ }
+
+ MAKE_ENTRY_HANDLE(real_newpath, par_newpath, this, newloc, &stbuf);
+ if (!real_newpath || !par_newpath) {
+ op_ret = -1;
+ op_errno = ESTALE;
+ goto out;
+ }
- op_ret = posix_pstat (this, newloc->parent, newloc->pargfid,
- par_newpath, &postparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "lstat failed: %s", par_newpath);
- goto out;
- }
+ op_ret = posix_pstat(this, newloc->parent, newloc->pargfid, par_newpath,
+ &preparent, _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "lstat failed: %s", par_newpath);
+ goto out;
+ }
- posix_set_parent_ctime (frame, this, par_newpath, -1, newloc->parent,
- &postparent);
+ op_ret = sys_link(real_oldpath, real_newpath);
- if (priv->update_pgfid_nlinks) {
- MAKE_PGFID_XATTR_KEY (pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
- newloc->pargfid);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LINK_FAILED,
+ "link %s to %s failed", real_oldpath, real_newpath);
+ goto out;
+ }
- op_ret = posix_inode_ctx_get_all (newloc->inode, this, &ctx);
- if (op_ret < 0) {
- op_errno = ENOMEM;
- goto out;
- }
+ entry_created = _gf_true;
- pthread_mutex_lock (&ctx->pgfid_lock);
- {
- LINK_MODIFY_PGFID_XATTR (real_newpath, pgfid_xattr_key,
- nlink_samepgfid, 0, op_ret,
- this, unlock);
- }
- unlock:
- pthread_mutex_unlock (&ctx->pgfid_lock);
-
- if (op_ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_XATTR_FAILED, "modification of "
- "parent gfid xattr failed (path:%s gfid:%s)",
- real_newpath, uuid_utoa (newloc->inode->gfid));
- goto out;
- }
- }
+ op_ret = posix_pstat(this, newloc->inode, NULL, real_newpath, &stbuf,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "lstat on %s failed", real_newpath);
+ goto out;
+ }
- if (priv->gfid2path) {
- if (stbuf.ia_nlink <= MAX_GFID2PATH_LINK_SUP) {
- op_ret = posix_set_gfid2path_xattr (this, real_newpath,
- newloc->pargfid,
- newloc->name);
- if (op_ret) {
- op_errno = errno;
- goto out;
- }
- } else {
- gf_msg (this->name, GF_LOG_INFO, 0,
- P_MSG_XATTR_NOTSUP, "Link count exceeded. "
- "gfid2path xattr not set (path:%s gfid:%s)",
- real_newpath, uuid_utoa (newloc->inode->gfid));
- }
- }
+ posix_set_ctime(frame, this, real_newpath, -1, newloc->inode, &stbuf);
- op_ret = 0;
+ op_ret = posix_pstat(this, newloc->parent, newloc->pargfid, par_newpath,
+ &postparent, _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "lstat failed: %s", par_newpath);
+ goto out;
+ }
-out:
- SET_TO_OLD_FS_ID ();
+ posix_set_parent_ctime(frame, this, par_newpath, -1, newloc->parent,
+ &postparent);
- STACK_UNWIND_STRICT (link, frame, op_ret, op_errno,
- (oldloc)?oldloc->inode:NULL, &stbuf, &preparent,
- &postparent, NULL);
+ if (priv->update_pgfid_nlinks) {
+ MAKE_PGFID_XATTR_KEY(pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
+ newloc->pargfid);
+ op_ret = posix_inode_ctx_get_all(newloc->inode, this, &ctx);
if (op_ret < 0) {
- if (entry_created)
- sys_unlink (real_newpath);
+ op_errno = ENOMEM;
+ goto out;
}
- return 0;
-}
-
-int
-posix_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)
-{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- int32_t _fd = -1;
- int _flags = 0;
- char * real_path = NULL;
- char * par_path = NULL;
- struct iatt stbuf = {0, };
- struct posix_fd * pfd = NULL;
- struct posix_private * priv = NULL;
- char was_present = 1;
-
- gid_t gid = 0;
- struct iatt preparent = {0,};
- struct iatt postparent = {0,};
-
- int nlink_samepgfid = 0;
- char * pgfid_xattr_key = NULL;
- gf_boolean_t entry_created = _gf_false, gfid_set = _gf_false;
- mode_t mode_bit = 0;
-
- DECLARE_OLD_FS_ID_VAR;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (this->private, out);
- VALIDATE_OR_GOTO (loc, out);
- VALIDATE_OR_GOTO (fd, out);
-
- priv = this->private;
- VALIDATE_OR_GOTO (priv, out);
- GFID_NULL_CHECK_AND_GOTO (frame, this, loc, xdata, op_ret, op_errno,
- out);
- DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
-
- MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
-
- gid = frame->root->gid;
-
- SET_FS_ID (frame->root->uid, gid);
- if (!real_path || !par_path) {
- op_ret = -1;
- op_errno = ESTALE;
- goto out;
+ pthread_mutex_lock(&ctx->pgfid_lock);
+ {
+ LINK_MODIFY_PGFID_XATTR(real_newpath, pgfid_xattr_key,
+ nlink_samepgfid, 0, op_ret, this, unlock);
}
+ unlock:
+ pthread_mutex_unlock(&ctx->pgfid_lock);
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &preparent, _gf_false);
- if (op_ret == -1) {
+ if (op_ret < 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_XATTR_FAILED,
+ "modification of "
+ "parent gfid xattr failed (path:%s gfid:%s)",
+ real_newpath, uuid_utoa(newloc->inode->gfid));
+ goto out;
+ }
+ }
+
+ if (priv->gfid2path) {
+ if (stbuf.ia_nlink <= MAX_GFID2PATH_LINK_SUP) {
+ op_ret = posix_set_gfid2path_xattr(this, real_newpath,
+ newloc->pargfid, newloc->name);
+ if (op_ret) {
op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "pre-operation lstat on parent %s failed",
- par_path);
goto out;
+ }
+ } else {
+ gf_msg(this->name, GF_LOG_INFO, 0, P_MSG_XATTR_NOTSUP,
+ "Link count exceeded. "
+ "gfid2path xattr not set (path:%s gfid:%s)",
+ real_newpath, uuid_utoa(newloc->inode->gfid));
}
+ }
- if (preparent.ia_prot.sgid) {
- gid = preparent.ia_gid;
- }
+ op_ret = 0;
- if (!flags) {
- _flags = O_CREAT | O_RDWR | O_EXCL;
- }
- else {
- _flags = flags | O_CREAT;
- }
+out:
+ SET_TO_OLD_FS_ID();
- op_ret = posix_pstat (this, loc->inode, NULL, real_path, &stbuf,
- _gf_false);
- if ((op_ret == -1) && (errno == ENOENT)) {
- was_present = 0;
- }
+ STACK_UNWIND_STRICT(link, frame, op_ret, op_errno,
+ (oldloc) ? oldloc->inode : NULL, &stbuf, &preparent,
+ &postparent, NULL);
- if (priv->o_direct)
- _flags |= O_DIRECT;
+ if (op_ret < 0) {
+ if (entry_created)
+ sys_unlink(real_newpath);
+ }
- mode_bit = (priv->create_mask & mode) | priv->force_create_mode;
- mode = posix_override_umask (mode, mode_bit);
- _fd = sys_open (real_path, _flags, mode);
+ return 0;
+}
- if (_fd == -1) {
- op_errno = errno;
- op_ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_OPEN_FAILED,
- "open on %s failed", real_path);
- goto out;
- }
+int
+posix_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)
+{
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ int32_t _fd = -1;
+ int _flags = 0;
+ char *real_path = NULL;
+ char *par_path = NULL;
+ struct iatt stbuf = {
+ 0,
+ };
+ struct posix_fd *pfd = NULL;
+ struct posix_private *priv = NULL;
+ char was_present = 1;
+
+ gid_t gid = 0;
+ struct iatt preparent = {
+ 0,
+ };
+ struct iatt postparent = {
+ 0,
+ };
+
+ int nlink_samepgfid = 0;
+ char *pgfid_xattr_key = NULL;
+ gf_boolean_t entry_created = _gf_false, gfid_set = _gf_false;
+ mode_t mode_bit = 0;
+
+ DECLARE_OLD_FS_ID_VAR;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(this->private, out);
+ VALIDATE_OR_GOTO(loc, out);
+ VALIDATE_OR_GOTO(fd, out);
+
+ priv = this->private;
+ VALIDATE_OR_GOTO(priv, out);
+ GFID_NULL_CHECK_AND_GOTO(frame, this, loc, xdata, op_ret, op_errno, out);
+ DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, op_ret, op_errno, out);
+
+ MAKE_ENTRY_HANDLE(real_path, par_path, this, loc, &stbuf);
+
+ gid = frame->root->gid;
+
+ SET_FS_ID(frame->root->uid, gid);
+ if (!real_path || !par_path) {
+ op_ret = -1;
+ op_errno = ESTALE;
+ goto out;
+ }
- if ((_flags & O_CREAT) && (_flags & O_EXCL)) {
- entry_created = _gf_true;
- }
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &preparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "pre-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
+
+ if (preparent.ia_prot.sgid) {
+ gid = preparent.ia_gid;
+ }
+
+ if (!flags) {
+ _flags = O_CREAT | O_RDWR | O_EXCL;
+ } else {
+ _flags = flags | O_CREAT;
+ }
+
+ op_ret = posix_pstat(this, loc->inode, NULL, real_path, &stbuf, _gf_false);
+ if ((op_ret == -1) && (errno == ENOENT)) {
+ was_present = 0;
+ }
+
+ if (priv->o_direct)
+ _flags |= O_DIRECT;
+
+ mode_bit = (priv->create_mask & mode) | priv->force_create_mode;
+ mode = posix_override_umask(mode, mode_bit);
+ _fd = sys_open(real_path, _flags, mode);
+
+ if (_fd == -1) {
+ op_errno = errno;
+ op_ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_OPEN_FAILED,
+ "open on %s failed", real_path);
+ goto out;
+ }
+ if ((_flags & O_CREAT) && (_flags & O_EXCL)) {
+ entry_created = _gf_true;
+ }
- if (was_present)
- goto fill_stat;
+ if (was_present)
+ goto fill_stat;
#ifndef HAVE_SET_FSID
- op_ret = sys_chown (real_path, frame->root->uid, gid);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_CHOWN_FAILED,
- "chown on %s failed", real_path);
- }
+ op_ret = sys_chown(real_path, frame->root->uid, gid);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_CHOWN_FAILED,
+ "chown on %s failed", real_path);
+ }
#endif
- op_ret = posix_acl_xattr_set (this, real_path, xdata);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_ACL_FAILED,
- "setting ACLs on %s failed", real_path);
- }
-
- if (priv->update_pgfid_nlinks) {
- MAKE_PGFID_XATTR_KEY (pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
- loc->pargfid);
- nlink_samepgfid = 1;
- SET_PGFID_XATTR (real_path, pgfid_xattr_key, nlink_samepgfid,
- XATTR_CREATE, op_ret, this, ignore);
- }
-
- if (priv->gfid2path) {
- posix_set_gfid2path_xattr (this, real_path, loc->pargfid,
- loc->name);
- }
+ op_ret = posix_acl_xattr_set(this, real_path, xdata);
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_ACL_FAILED,
+ "setting ACLs on %s failed", real_path);
+ }
+
+ if (priv->update_pgfid_nlinks) {
+ MAKE_PGFID_XATTR_KEY(pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
+ loc->pargfid);
+ nlink_samepgfid = 1;
+ SET_PGFID_XATTR(real_path, pgfid_xattr_key, nlink_samepgfid,
+ XATTR_CREATE, op_ret, this, ignore);
+ }
+
+ if (priv->gfid2path) {
+ posix_set_gfid2path_xattr(this, real_path, loc->pargfid, loc->name);
+ }
ignore:
- op_ret = posix_entry_create_xattr_set (this, real_path, xdata);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
- "setting xattrs on %s failed ", real_path);
- }
+ op_ret = posix_entry_create_xattr_set(this, real_path, xdata);
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "setting xattrs on %s failed ", real_path);
+ }
fill_stat:
- op_ret = posix_gfid_set (this, real_path, loc, xdata, frame->root->pid,
- &op_errno);
- if (op_ret) {
- gf_msg (this->name, GF_LOG_ERROR, op_errno, P_MSG_GFID_FAILED,
- "setting gfid on %s failed", real_path);
- goto out;
- } else {
- gfid_set = _gf_true;
- }
-
- op_ret = posix_fdstat (this, loc->inode, _fd, &stbuf);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
- "fstat on %d failed", _fd);
- goto out;
- }
+ op_ret = posix_gfid_set(this, real_path, loc, xdata, frame->root->pid,
+ &op_errno);
+ if (op_ret) {
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_GFID_FAILED,
+ "setting gfid on %s failed", real_path);
+ goto out;
+ } else {
+ gfid_set = _gf_true;
+ }
+
+ op_ret = posix_fdstat(this, loc->inode, _fd, &stbuf);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
+ "fstat on %d failed", _fd);
+ goto out;
+ }
- posix_set_ctime (frame, this, real_path, -1, loc->inode, &stbuf);
+ posix_set_ctime(frame, this, real_path, -1, loc->inode, &stbuf);
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &postparent, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "post-operation lstat on parent %s failed",
- par_path);
- goto out;
- }
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &postparent,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
- posix_set_parent_ctime (frame, this, par_path, -1, loc->parent,
- &postparent);
+ posix_set_parent_ctime(frame, this, par_path, -1, loc->parent, &postparent);
- op_ret = -1;
- pfd = GF_CALLOC (1, sizeof (*pfd), gf_posix_mt_posix_fd);
- if (!pfd) {
- op_errno = errno;
- goto out;
- }
+ op_ret = -1;
+ pfd = GF_CALLOC(1, sizeof(*pfd), gf_posix_mt_posix_fd);
+ if (!pfd) {
+ op_errno = errno;
+ goto out;
+ }
- pfd->flags = flags;
- pfd->fd = _fd;
+ pfd->flags = flags;
+ pfd->fd = _fd;
- op_ret = fd_ctx_set (fd, this, (uint64_t)(long)pfd);
- if (op_ret)
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_FD_PATH_SETTING_FAILED,
- "failed to set the fd context path=%s fd=%p",
- real_path, fd);
+ op_ret = fd_ctx_set(fd, this, (uint64_t)(long)pfd);
+ if (op_ret)
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_FD_PATH_SETTING_FAILED,
+ "failed to set the fd context path=%s fd=%p", real_path, fd);
- LOCK (&priv->lock);
- {
- priv->nr_files++;
- }
- UNLOCK (&priv->lock);
+ LOCK(&priv->lock);
+ {
+ priv->nr_files++;
+ }
+ UNLOCK(&priv->lock);
- op_ret = 0;
+ op_ret = 0;
out:
- SET_TO_OLD_FS_ID ();
+ SET_TO_OLD_FS_ID();
- if (op_ret < 0) {
- if (_fd != -1)
- sys_close (_fd);
+ if (op_ret < 0) {
+ if (_fd != -1)
+ sys_close(_fd);
- if (entry_created)
- sys_unlink (real_path);
+ if (entry_created)
+ sys_unlink(real_path);
- if (gfid_set)
- posix_gfid_unset (this, xdata);
- }
+ if (gfid_set)
+ posix_gfid_unset(this, xdata);
+ }
- STACK_UNWIND_STRICT (create, frame, op_ret, op_errno,
- fd, (loc)?loc->inode:NULL, &stbuf, &preparent,
- &postparent, xdata);
+ STACK_UNWIND_STRICT(create, frame, op_ret, op_errno, fd,
+ (loc) ? loc->inode : NULL, &stbuf, &preparent,
+ &postparent, xdata);
- return 0;
+ return 0;
}
/* TODO: Ensure atomocity of put, and rollback in case of failure
@@ -2265,97 +2234,101 @@ out:
* and rename it to the specified location, if the put was successful
*/
int32_t
-posix_put (call_frame_t *frame, xlator_t *this, loc_t *loc,
- mode_t mode, mode_t umask, uint32_t flags,
- struct iovec *vector, int32_t count, off_t offset,
- struct iobref *iobref, dict_t *xattr, dict_t *xdata)
+posix_put(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ mode_t umask, uint32_t flags, struct iovec *vector, int32_t count,
+ off_t offset, struct iobref *iobref, dict_t *xattr, dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- fd_t *fd = NULL;
- char *real_path = NULL;
- char *par_path = NULL;
- struct iatt stbuf = {0, };
- struct iatt preparent = {0,};
- struct iatt postparent = {0,};
-
- MAKE_ENTRY_HANDLE (real_path, par_path, this, loc, &stbuf);
-
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &preparent, _gf_false);
- if (op_ret < 0) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "pre-operation lstat on parent %s failed",
- par_path);
- goto out;
- }
- fd = fd_create (loc->inode, getpid());
- if (!fd) {
- op_ret = -1;
- op_errno = ENOMEM;
- goto out;
- }
- fd->flags = flags;
-
- /* No xlators are expected below posix, but we cannot still call sys_create()
- * directly here, as posix_create does many other things like chmod, setxattr
- * etc. along with sys_create(). But we cannot also directly call posix_create()
- * as it calls STACK_UNWIND. Hence using syncop()
- */
- op_ret = syncop_create (this, loc, flags, mode, fd, &stbuf, xdata, NULL);
- if (op_ret < 0) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_CREATE_FAILED,
- "create of %s failed", loc->path);
- goto out;
- }
-
- op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path,
- &postparent, _gf_false);
- if (op_ret < 0) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "post-operation lstat on parent %s failed",
- par_path);
- goto out;
- }
-
- op_ret = syncop_writev (this, fd, vector, count, offset, iobref,
- flags, NULL, NULL, xdata, NULL);
- if (op_ret < 0) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_WRITE_FAILED,
- "write on file %s failed", loc->path);
- goto out;
- }
-
- op_ret = syncop_fsetxattr (this, fd, xattr, flags, xdata, NULL);
- if (op_ret < 0) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
- "setxattr on file %s failed", loc->path);
- goto out;
- }
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ fd_t *fd = NULL;
+ char *real_path = NULL;
+ char *par_path = NULL;
+ struct iatt stbuf = {
+ 0,
+ };
+ struct iatt preparent = {
+ 0,
+ };
+ struct iatt postparent = {
+ 0,
+ };
+
+ MAKE_ENTRY_HANDLE(real_path, par_path, this, loc, &stbuf);
+
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &preparent,
+ _gf_false);
+ if (op_ret < 0) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "pre-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
+ fd = fd_create(loc->inode, getpid());
+ if (!fd) {
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto out;
+ }
+ fd->flags = flags;
+
+ /* No xlators are expected below posix, but we cannot still call
+ * sys_create() directly here, as posix_create does many other things like
+ * chmod, setxattr etc. along with sys_create(). But we cannot also directly
+ * call posix_create() as it calls STACK_UNWIND. Hence using syncop()
+ */
+ op_ret = syncop_create(this, loc, flags, mode, fd, &stbuf, xdata, NULL);
+ if (op_ret < 0) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_CREATE_FAILED,
+ "create of %s failed", loc->path);
+ goto out;
+ }
+
+ op_ret = posix_pstat(this, loc->parent, loc->pargfid, par_path, &postparent,
+ _gf_false);
+ if (op_ret < 0) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on parent %s failed", par_path);
+ goto out;
+ }
+
+ op_ret = syncop_writev(this, fd, vector, count, offset, iobref, flags, NULL,
+ NULL, xdata, NULL);
+ if (op_ret < 0) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_WRITE_FAILED,
+ "write on file %s failed", loc->path);
+ goto out;
+ }
- op_ret = syncop_flush (this, fd, xdata, NULL);
- if (op_ret < 0) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_CLOSE_FAILED,
- "setxattr on file %s failed", loc->path);
- goto out;
- }
+ op_ret = syncop_fsetxattr(this, fd, xattr, flags, xdata, NULL);
+ if (op_ret < 0) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "setxattr on file %s failed", loc->path);
+ goto out;
+ }
- op_ret = posix_pstat (this, loc->inode, loc->gfid, real_path, &stbuf, _gf_false);
- if (op_ret < 0) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "post-operation lstat on %s failed", real_path);
- goto out;
- }
+ op_ret = syncop_flush(this, fd, xdata, NULL);
+ if (op_ret < 0) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_CLOSE_FAILED,
+ "setxattr on file %s failed", loc->path);
+ goto out;
+ }
+
+ op_ret = posix_pstat(this, loc->inode, loc->gfid, real_path, &stbuf,
+ _gf_false);
+ if (op_ret < 0) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "post-operation lstat on %s failed", real_path);
+ goto out;
+ }
out:
- STACK_UNWIND_STRICT (put, frame, op_ret, op_errno, loc->inode, &stbuf,
- &preparent, &postparent, NULL);
+ STACK_UNWIND_STRICT(put, frame, op_ret, op_errno, loc->inode, &stbuf,
+ &preparent, &postparent, NULL);
- return 0;
+ return 0;
}
diff --git a/xlators/storage/posix/src/posix-gfid-path.c b/xlators/storage/posix/src/posix-gfid-path.c
index a08168a..4a81be2 100644
--- a/xlators/storage/posix/src/posix-gfid-path.c
+++ b/xlators/storage/posix/src/posix-gfid-path.c
@@ -18,291 +18,300 @@
#include "posix.h"
int32_t
-posix_set_gfid2path_xattr (xlator_t *this, const char *path, uuid_t pgfid,
- const char *bname)
+posix_set_gfid2path_xattr(xlator_t *this, const char *path, uuid_t pgfid,
+ const char *bname)
{
- char xxh64[GF_XXH64_DIGEST_LENGTH*2+1] = {0,};
- char pgfid_bname[1024] = {0,};
- char *key = NULL;
- char *val = NULL;
- size_t key_size = 0;
- size_t val_size = 0;
- int ret = 0;
+ char xxh64[GF_XXH64_DIGEST_LENGTH * 2 + 1] = {
+ 0,
+ };
+ char pgfid_bname[1024] = {
+ 0,
+ };
+ char *key = NULL;
+ char *val = NULL;
+ size_t key_size = 0;
+ size_t val_size = 0;
+ int ret = 0;
- GF_VALIDATE_OR_GOTO ("posix", this, err);
+ GF_VALIDATE_OR_GOTO("posix", this, err);
- snprintf (pgfid_bname, sizeof (pgfid_bname), "%s/%s", uuid_utoa (pgfid),
- bname);
- gf_xxh64_wrapper ((unsigned char *) pgfid_bname,
- strlen(pgfid_bname), GF_XXHSUM64_DEFAULT_SEED, xxh64);
- key_size = GFID2PATH_XATTR_KEY_PREFIX_LENGTH +
- GF_XXH64_DIGEST_LENGTH*2 + 1;
- key = alloca (key_size);
- snprintf (key, key_size, GFID2PATH_XATTR_KEY_PREFIX"%s", xxh64);
+ snprintf(pgfid_bname, sizeof(pgfid_bname), "%s/%s", uuid_utoa(pgfid),
+ bname);
+ gf_xxh64_wrapper((unsigned char *)pgfid_bname, strlen(pgfid_bname),
+ GF_XXHSUM64_DEFAULT_SEED, xxh64);
+ key_size = GFID2PATH_XATTR_KEY_PREFIX_LENGTH + GF_XXH64_DIGEST_LENGTH * 2 +
+ 1;
+ key = alloca(key_size);
+ snprintf(key, key_size, GFID2PATH_XATTR_KEY_PREFIX "%s", xxh64);
- val_size = UUID_CANONICAL_FORM_LEN + NAME_MAX + 2;
- val = alloca (val_size);
- snprintf (val, val_size, "%s/%s", uuid_utoa (pgfid), bname);
+ val_size = UUID_CANONICAL_FORM_LEN + NAME_MAX + 2;
+ val = alloca(val_size);
+ snprintf(val, val_size, "%s/%s", uuid_utoa(pgfid), bname);
- ret = sys_lsetxattr (path, key, val, strlen(val), XATTR_CREATE);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP,
- "setting gfid2path xattr failed on %s: key = %s ",
- path, key);
- goto err;
- }
- return 0;
- err:
- return -1;
+ ret = sys_lsetxattr(path, key, val, strlen(val), XATTR_CREATE);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP,
+ "setting gfid2path xattr failed on %s: key = %s ", path, key);
+ goto err;
+ }
+ return 0;
+err:
+ return -1;
}
int32_t
-posix_remove_gfid2path_xattr (xlator_t *this, const char *path,
- uuid_t pgfid, const char *bname)
+posix_remove_gfid2path_xattr(xlator_t *this, const char *path, uuid_t pgfid,
+ const char *bname)
{
- char xxh64[GF_XXH64_DIGEST_LENGTH*2+1] = {0,};
- char pgfid_bname[1024] = {0,};
- int ret = 0;
- char *key = NULL;
- size_t key_size = 0;
+ char xxh64[GF_XXH64_DIGEST_LENGTH * 2 + 1] = {
+ 0,
+ };
+ char pgfid_bname[1024] = {
+ 0,
+ };
+ int ret = 0;
+ char *key = NULL;
+ size_t key_size = 0;
- GF_VALIDATE_OR_GOTO ("posix", this, err);
+ GF_VALIDATE_OR_GOTO("posix", this, err);
- snprintf (pgfid_bname, sizeof (pgfid_bname), "%s/%s", uuid_utoa (pgfid),
- bname);
- gf_xxh64_wrapper ((unsigned char *) pgfid_bname,
- strlen(pgfid_bname), GF_XXHSUM64_DEFAULT_SEED, xxh64);
- key_size = GFID2PATH_XATTR_KEY_PREFIX_LENGTH +
- GF_XXH64_DIGEST_LENGTH*2 + 1;
- key = alloca (key_size);
- snprintf (key, key_size, GFID2PATH_XATTR_KEY_PREFIX"%s", xxh64);
+ snprintf(pgfid_bname, sizeof(pgfid_bname), "%s/%s", uuid_utoa(pgfid),
+ bname);
+ gf_xxh64_wrapper((unsigned char *)pgfid_bname, strlen(pgfid_bname),
+ GF_XXHSUM64_DEFAULT_SEED, xxh64);
+ key_size = GFID2PATH_XATTR_KEY_PREFIX_LENGTH + GF_XXH64_DIGEST_LENGTH * 2 +
+ 1;
+ key = alloca(key_size);
+ snprintf(key, key_size, GFID2PATH_XATTR_KEY_PREFIX "%s", xxh64);
- ret = sys_lremovexattr (path, key);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP,
- "removing gfid2path xattr failed on %s: key = %s",
- path, key);
- goto err;
- }
- return 0;
- err:
- return -1;
+ ret = sys_lremovexattr(path, key);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP,
+ "removing gfid2path xattr failed on %s: key = %s", path, key);
+ goto err;
+ }
+ return 0;
+err:
+ return -1;
}
gf_boolean_t
-posix_is_gfid2path_xattr (const char *name)
+posix_is_gfid2path_xattr(const char *name)
{
- if (name && strncmp (GFID2PATH_XATTR_KEY_PREFIX, name,
- GFID2PATH_XATTR_KEY_PREFIX_LENGTH) == 0) {
- return _gf_true;
- } else {
- return _gf_false;
- }
+ if (name && strncmp(GFID2PATH_XATTR_KEY_PREFIX, name,
+ GFID2PATH_XATTR_KEY_PREFIX_LENGTH) == 0) {
+ return _gf_true;
+ } else {
+ return _gf_false;
+ }
}
static int gf_posix_xattr_enotsup_log;
int32_t
-posix_get_gfid2path (xlator_t *this, inode_t *inode, const char *real_path,
- int *op_errno, dict_t *dict)
+posix_get_gfid2path(xlator_t *this, inode_t *inode, const char *real_path,
+ int *op_errno, dict_t *dict)
{
- int ret = 0;
- char *path = NULL;
- ssize_t size = 0;
- char *list = NULL;
- int32_t list_offset = 0;
- int32_t i = 0;
- int32_t j = 0;
- char *paths[MAX_GFID2PATH_LINK_SUP] = {NULL,};
- char *value = NULL;
- size_t remaining_size = 0;
- size_t bytes = 0;
- char keybuffer[4096] = {0,};
- char value_buf[8192] = {0,};
- uuid_t pargfid = {0,};
- gf_boolean_t have_val = _gf_false;
- struct posix_private *priv = NULL;
- char pargfid_str[UUID_CANONICAL_FORM_LEN + 1] = {0,};
- gf_boolean_t found = _gf_false;
- int len;
+ int ret = 0;
+ char *path = NULL;
+ ssize_t size = 0;
+ char *list = NULL;
+ int32_t list_offset = 0;
+ int32_t i = 0;
+ int32_t j = 0;
+ char *paths[MAX_GFID2PATH_LINK_SUP] = {
+ NULL,
+ };
+ char *value = NULL;
+ size_t remaining_size = 0;
+ size_t bytes = 0;
+ char keybuffer[4096] = {
+ 0,
+ };
+ char value_buf[8192] = {
+ 0,
+ };
+ uuid_t pargfid = {
+ 0,
+ };
+ gf_boolean_t have_val = _gf_false;
+ struct posix_private *priv = NULL;
+ char pargfid_str[UUID_CANONICAL_FORM_LEN + 1] = {
+ 0,
+ };
+ gf_boolean_t found = _gf_false;
+ int len;
- priv = this->private;
+ priv = this->private;
- if (IA_ISDIR (inode->ia_type)) {
- ret = posix_resolve_dirgfid_to_path (inode->gfid,
- priv->base_path,
- NULL, &path);
- if (ret < 0) {
- ret = -1;
- goto err;
- }
- ret = dict_set_dynstr (dict, GFID2PATH_VIRT_XATTR_KEY, path);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_WARNING, -ret,
- P_MSG_DICT_SET_FAILED, "could not set "
- "value for key (%s)", GFID2PATH_VIRT_XATTR_KEY);
- goto err;
- }
- found = _gf_true;
+ if (IA_ISDIR(inode->ia_type)) {
+ ret = posix_resolve_dirgfid_to_path(inode->gfid, priv->base_path, NULL,
+ &path);
+ if (ret < 0) {
+ ret = -1;
+ goto err;
+ }
+ ret = dict_set_dynstr(dict, GFID2PATH_VIRT_XATTR_KEY, path);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_WARNING, -ret, P_MSG_DICT_SET_FAILED,
+ "could not set "
+ "value for key (%s)",
+ GFID2PATH_VIRT_XATTR_KEY);
+ goto err;
+ }
+ found = _gf_true;
+ } else {
+ have_val = _gf_false;
+ size = sys_llistxattr(real_path, value_buf, sizeof(value_buf) - 1);
+ if (size > 0) {
+ have_val = _gf_true;
} else {
- have_val = _gf_false;
- size = sys_llistxattr (real_path, value_buf,
- sizeof (value_buf) - 1);
- if (size > 0) {
- have_val = _gf_true;
+ if (errno == ERANGE) {
+ gf_msg(this->name, GF_LOG_DEBUG, errno, P_MSG_XATTR_FAILED,
+ "listxattr failed due to overflow of"
+ " buffer on %s ",
+ real_path);
+ size = sys_llistxattr(real_path, NULL, 0);
+ }
+ if (size == -1) {
+ *op_errno = errno;
+ if ((errno == ENOTSUP) || (errno == ENOSYS)) {
+ GF_LOG_OCCASIONALLY(gf_posix_xattr_enotsup_log, this->name,
+ GF_LOG_WARNING,
+ "Extended attributes not "
+ "supported (try remounting"
+ " brick with 'user_xattr' "
+ "flag)");
} else {
- if (errno == ERANGE) {
- gf_msg (this->name, GF_LOG_DEBUG, errno,
- P_MSG_XATTR_FAILED,
- "listxattr failed due to overflow of"
- " buffer on %s ", real_path);
- size = sys_llistxattr (real_path, NULL, 0);
- }
- if (size == -1) {
- *op_errno = errno;
- if ((errno == ENOTSUP) || (errno == ENOSYS)) {
- GF_LOG_OCCASIONALLY (
- gf_posix_xattr_enotsup_log,
- this->name, GF_LOG_WARNING,
- "Extended attributes not "
- "supported (try remounting"
- " brick with 'user_xattr' "
- "flag)");
- } else {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_XATTR_FAILED,
- "listxattr failed on %s",
- real_path);
- }
- goto err;
- }
- if (size == 0)
- goto done;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "listxattr failed on %s", real_path);
}
- list = alloca (size);
- if (!list) {
- *op_errno = errno;
- goto err;
- }
- if (have_val) {
- memcpy (list, value_buf, size);
- } else {
- size = sys_llistxattr (real_path, list, size);
- if (size < 0) {
- ret = -1;
- *op_errno = errno;
- goto err;
- }
- }
- remaining_size = size;
- list_offset = 0;
- while (remaining_size > 0) {
- snprintf (keybuffer, sizeof (keybuffer), "%s",
- list + list_offset);
+ goto err;
+ }
+ if (size == 0)
+ goto done;
+ }
+ list = alloca(size);
+ if (!list) {
+ *op_errno = errno;
+ goto err;
+ }
+ if (have_val) {
+ memcpy(list, value_buf, size);
+ } else {
+ size = sys_llistxattr(real_path, list, size);
+ if (size < 0) {
+ ret = -1;
+ *op_errno = errno;
+ goto err;
+ }
+ }
+ remaining_size = size;
+ list_offset = 0;
+ while (remaining_size > 0) {
+ snprintf(keybuffer, sizeof(keybuffer), "%s", list + list_offset);
- if (!posix_is_gfid2path_xattr (keybuffer)) {
- goto ignore;
- }
+ if (!posix_is_gfid2path_xattr(keybuffer)) {
+ goto ignore;
+ }
- found = _gf_true;
- size = sys_lgetxattr (real_path, keybuffer, value_buf,
- sizeof (value_buf) - 1);
- if (size == -1) {
- ret = -1;
- *op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_XATTR_FAILED, "getxattr failed on"
- " %s: key = %s ", real_path, keybuffer);
- break;
- }
+ found = _gf_true;
+ size = sys_lgetxattr(real_path, keybuffer, value_buf,
+ sizeof(value_buf) - 1);
+ if (size == -1) {
+ ret = -1;
+ *op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "getxattr failed on"
+ " %s: key = %s ",
+ real_path, keybuffer);
+ break;
+ }
- /* Parse pargfid from xattr value*/
- strncpy (pargfid_str, value_buf, 36);
- pargfid_str[36] = '\0';
- gf_uuid_parse (pargfid_str, pargfid);
+ /* Parse pargfid from xattr value*/
+ strncpy(pargfid_str, value_buf, 36);
+ pargfid_str[36] = '\0';
+ gf_uuid_parse(pargfid_str, pargfid);
- /* Convert pargfid to path */
- ret = posix_resolve_dirgfid_to_path (pargfid,
- priv->base_path,
- &value_buf[37],
- &paths[i]);
- i++;
+ /* Convert pargfid to path */
+ ret = posix_resolve_dirgfid_to_path(pargfid, priv->base_path,
+ &value_buf[37], &paths[i]);
+ i++;
-ignore:
- len = strlen (keybuffer);
- remaining_size -= (len + 1);
- list_offset += (len + 1);
- } /* while (remaining_size > 0) */
+ ignore:
+ len = strlen(keybuffer);
+ remaining_size -= (len + 1);
+ list_offset += (len + 1);
+ } /* while (remaining_size > 0) */
- /* gfid2path xattr is absent in the list of xattrs */
- if (!found) {
- ret = -1;
- /*
- * ENODATA because xattr is not present in the
- * list of xattrs. Thus the consumer should
- * face error instead of a success and a empty
- * string in the dict for the key.
- */
- *op_errno = ENODATA;
- goto err;
- }
+ /* gfid2path xattr is absent in the list of xattrs */
+ if (!found) {
+ ret = -1;
+ /*
+ * ENODATA because xattr is not present in the
+ * list of xattrs. Thus the consumer should
+ * face error instead of a success and a empty
+ * string in the dict for the key.
+ */
+ *op_errno = ENODATA;
+ goto err;
+ }
- /*
- * gfid2path xattr is found in list of xattrs, but getxattr
- * on the 1st gfid2path xattr itself failed and the while
- * loop above broke. So there is nothing in the value. So
- * it would be better not to send "" as the value for any
- * key, as it is not true.
- */
- if (found && !i)
- goto err; /* both errno and ret are set before beak */
+ /*
+ * gfid2path xattr is found in list of xattrs, but getxattr
+ * on the 1st gfid2path xattr itself failed and the while
+ * loop above broke. So there is nothing in the value. So
+ * it would be better not to send "" as the value for any
+ * key, as it is not true.
+ */
+ if (found && !i)
+ goto err; /* both errno and ret are set before beak */
- /* Calculate memory to be allocated */
- for (j = 0; j < i; j++) {
- bytes += strlen(paths[j]);
- if (j < i-1)
- bytes += strlen(priv->gfid2path_sep);
- }
- value = GF_CALLOC (bytes + 1, sizeof(char), gf_posix_mt_char);
- if (!value) {
- ret = -1;
- *op_errno = errno;
- goto err;
- }
+ /* Calculate memory to be allocated */
+ for (j = 0; j < i; j++) {
+ bytes += strlen(paths[j]);
+ if (j < i - 1)
+ bytes += strlen(priv->gfid2path_sep);
+ }
+ value = GF_CALLOC(bytes + 1, sizeof(char), gf_posix_mt_char);
+ if (!value) {
+ ret = -1;
+ *op_errno = errno;
+ goto err;
+ }
- for (j = 0; j < i; j++) {
- strcat (value, paths[j]);
- if (j != i - 1)
- strcat (value, priv->gfid2path_sep);
- }
- value[bytes] = '\0';
+ for (j = 0; j < i; j++) {
+ strcat(value, paths[j]);
+ if (j != i - 1)
+ strcat(value, priv->gfid2path_sep);
+ }
+ value[bytes] = '\0';
- ret = dict_set_dynptr (dict, GFID2PATH_VIRT_XATTR_KEY,
- value, bytes);
- if (ret < 0) {
- *op_errno = -ret;
- gf_msg (this->name, GF_LOG_ERROR, *op_errno,
- P_MSG_DICT_SET_FAILED, "dict set operation "
- "on %s for the key %s failed.",
- real_path, GFID2PATH_VIRT_XATTR_KEY);
- GF_FREE (value);
- goto err;
- }
+ ret = dict_set_dynptr(dict, GFID2PATH_VIRT_XATTR_KEY, value, bytes);
+ if (ret < 0) {
+ *op_errno = -ret;
+ gf_msg(this->name, GF_LOG_ERROR, *op_errno, P_MSG_DICT_SET_FAILED,
+ "dict set operation "
+ "on %s for the key %s failed.",
+ real_path, GFID2PATH_VIRT_XATTR_KEY);
+ GF_FREE(value);
+ goto err;
}
+ }
done:
- for (j = 0; j < i; j++) {
- if (paths[j])
- GF_FREE (paths[j]);
- }
- ret = 0;
- return ret;
+ for (j = 0; j < i; j++) {
+ if (paths[j])
+ GF_FREE(paths[j]);
+ }
+ ret = 0;
+ return ret;
err:
- if (path)
- GF_FREE (path);
- for (j = 0; j < i; j++) {
- if (paths[j])
- GF_FREE (paths[j]);
- }
- return ret;
+ if (path)
+ GF_FREE(path);
+ for (j = 0; j < i; j++) {
+ if (paths[j])
+ GF_FREE(paths[j]);
+ }
+ return ret;
}
diff --git a/xlators/storage/posix/src/posix-handle.c b/xlators/storage/posix/src/posix-handle.c
index 802dcf1..bc34e3e 100644
--- a/xlators/storage/posix/src/posix-handle.c
+++ b/xlators/storage/posix/src/posix-handle.c
@@ -28,366 +28,358 @@
#include "compat-errno.h"
int
-posix_handle_mkdir_hashes (xlator_t *this, const char *newpath);
+posix_handle_mkdir_hashes(xlator_t *this, const char *newpath);
inode_t *
-posix_resolve (xlator_t *this, inode_table_t *itable, inode_t *parent,
- char *bname, struct iatt *iabuf)
+posix_resolve(xlator_t *this, inode_table_t *itable, inode_t *parent,
+ char *bname, struct iatt *iabuf)
{
- inode_t *inode = NULL;
- int ret = -1;
-
- ret = posix_istat (this, NULL, parent->gfid, bname, iabuf);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING, "gfid: %s, bname: %s "
- "failed", uuid_utoa (parent->gfid), bname);
- goto out;
- }
-
- if (__is_root_gfid (iabuf->ia_gfid) && !strcmp (bname, "/")) {
- inode = itable->root;
- } else {
- inode = inode_find (itable, iabuf->ia_gfid);
- if (inode == NULL) {
- inode = inode_new (itable);
- gf_uuid_copy (inode->gfid, iabuf->ia_gfid);
- }
- }
-
- /* posix_istat wouldn't have fetched posix_mdata_t i.e.,
- * time attributes as inode is passed as NULL, hence get
- * here once you got the inode
- */
- ret = posix_get_mdata_xattr (this, NULL, -1, inode, iabuf);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_GETMDATA_FAILED,
- "posix get mdata failed on gfid:%s",
- uuid_utoa (inode->gfid));
- goto out;
- }
-
- /* Linking an inode here, can cause a race in posix_acl.
- Parent inode gets linked here, but before
- it reaches posix_acl_readdirp_cbk, create/lookup can
- come on a leaf-inode, as parent-inode-ctx not yet updated
- in posix_acl_readdirp_cbk, create and lookup can fail
- with EACCESS. So do the inode linking in the quota xlator
-
- if (__is_root_gfid (iabuf->ia_gfid) && !strcmp (bname, "/"))
- linked_inode = itable->root;
- else
- linked_inode = inode_link (inode, parent, bname, iabuf);
-
- inode_unref (inode);*/
+ inode_t *inode = NULL;
+ int ret = -1;
+
+ ret = posix_istat(this, NULL, parent->gfid, bname, iabuf);
+ if (ret < 0) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "gfid: %s, bname: %s "
+ "failed",
+ uuid_utoa(parent->gfid), bname);
+ goto out;
+ }
+
+ if (__is_root_gfid(iabuf->ia_gfid) && !strcmp(bname, "/")) {
+ inode = itable->root;
+ } else {
+ inode = inode_find(itable, iabuf->ia_gfid);
+ if (inode == NULL) {
+ inode = inode_new(itable);
+ gf_uuid_copy(inode->gfid, iabuf->ia_gfid);
+ }
+ }
+
+ /* posix_istat wouldn't have fetched posix_mdata_t i.e.,
+ * time attributes as inode is passed as NULL, hence get
+ * here once you got the inode
+ */
+ ret = posix_get_mdata_xattr(this, NULL, -1, inode, iabuf);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_GETMDATA_FAILED,
+ "posix get mdata failed on gfid:%s", uuid_utoa(inode->gfid));
+ goto out;
+ }
+
+ /* Linking an inode here, can cause a race in posix_acl.
+ Parent inode gets linked here, but before
+ it reaches posix_acl_readdirp_cbk, create/lookup can
+ come on a leaf-inode, as parent-inode-ctx not yet updated
+ in posix_acl_readdirp_cbk, create and lookup can fail
+ with EACCESS. So do the inode linking in the quota xlator
+
+ if (__is_root_gfid (iabuf->ia_gfid) && !strcmp (bname, "/"))
+ linked_inode = itable->root;
+ else
+ linked_inode = inode_link (inode, parent, bname, iabuf);
+
+ inode_unref (inode);*/
out:
- return inode;
+ return inode;
}
int
-posix_make_ancestral_node (const char *priv_base_path, char *path, int pathsize,
- gf_dirent_t *head,
- char *dir_name, struct iatt *iabuf, inode_t *inode,
- int type, dict_t *xdata)
+posix_make_ancestral_node(const char *priv_base_path, char *path, int pathsize,
+ gf_dirent_t *head, char *dir_name, struct iatt *iabuf,
+ inode_t *inode, int type, dict_t *xdata)
{
- gf_dirent_t *entry = NULL;
- char real_path[PATH_MAX + 1] = {0, }, len = 0;
- loc_t loc = {0, };
- int ret = -1;
-
- len = strlen (path) + strlen (dir_name) + 1;
- if (len > pathsize) {
- goto out;
- }
-
- strcat (path, dir_name);
- if (*dir_name != '/')
- strcat (path, "/");
-
- if (type & POSIX_ANCESTRY_DENTRY) {
- entry = gf_dirent_for_name (dir_name);
- if (!entry)
- goto out;
-
- entry->d_stat = *iabuf;
- entry->inode = inode_ref (inode);
-
- list_add_tail (&entry->list, &head->list);
- snprintf(real_path, sizeof (real_path), "%s/%s", priv_base_path, path);
- loc.inode = inode_ref (inode);
- gf_uuid_copy (loc.gfid, inode->gfid);
-
- entry->dict = posix_xattr_fill (THIS, real_path, &loc, NULL, -1,
- xdata, iabuf);
- loc_wipe (&loc);
- }
-
- ret = 0;
+ gf_dirent_t *entry = NULL;
+ char real_path[PATH_MAX + 1] =
+ {
+ 0,
+ },
+ len = 0;
+ loc_t loc = {
+ 0,
+ };
+ int ret = -1;
+
+ len = strlen(path) + strlen(dir_name) + 1;
+ if (len > pathsize) {
+ goto out;
+ }
+
+ strcat(path, dir_name);
+ if (*dir_name != '/')
+ strcat(path, "/");
+
+ if (type & POSIX_ANCESTRY_DENTRY) {
+ entry = gf_dirent_for_name(dir_name);
+ if (!entry)
+ goto out;
+
+ entry->d_stat = *iabuf;
+ entry->inode = inode_ref(inode);
+
+ list_add_tail(&entry->list, &head->list);
+ snprintf(real_path, sizeof(real_path), "%s/%s", priv_base_path, path);
+ loc.inode = inode_ref(inode);
+ gf_uuid_copy(loc.gfid, inode->gfid);
+
+ entry->dict = posix_xattr_fill(THIS, real_path, &loc, NULL, -1, xdata,
+ iabuf);
+ loc_wipe(&loc);
+ }
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
int
-posix_make_ancestryfromgfid (xlator_t *this, char *path, int pathsize,
- gf_dirent_t *head, int type, uuid_t gfid,
- const size_t handle_size,
- const char *priv_base_path, inode_table_t *itable,
- inode_t **parent, dict_t *xdata, int32_t *op_errno)
+posix_make_ancestryfromgfid(xlator_t *this, char *path, int pathsize,
+ gf_dirent_t *head, int type, uuid_t gfid,
+ const size_t handle_size,
+ const char *priv_base_path, inode_table_t *itable,
+ inode_t **parent, dict_t *xdata, int32_t *op_errno)
{
- char *linkname = NULL; /* "../../<gfid[0]>/<gfid[1]/"
- "<gfidstr>/<NAME_MAX>" */
- char *dir_handle = NULL;
- char *pgfidstr = NULL;
- char *saveptr = NULL;
- ssize_t len = 0;
- inode_t *inode = NULL;
- struct iatt iabuf = {0, };
- int ret = -1;
- uuid_t tmp_gfid = {0, };
- char *dir_stack[PATH_MAX/2 + 1]; /* Since PATH_MAX/2 also gives
- an upper bound on depth of
- directories tree */
- uuid_t gfid_stack[PATH_MAX/2 + 1];
-
- char *dir_name = NULL;
- char *saved_dir = NULL;
- int top = -1;
-
- if (!path || !parent || !priv_base_path || gf_uuid_is_null (gfid)) {
- *op_errno = EINVAL;
- goto out;
- }
-
- dir_handle = alloca (handle_size);
- linkname = alloca (PATH_MAX);
- gf_uuid_copy(tmp_gfid, gfid);
-
- while (top < PATH_MAX/2) {
-
- gf_uuid_copy(gfid_stack[++top], tmp_gfid);
- if (__is_root_gfid (tmp_gfid)) {
-
- *parent = inode_ref (itable->root);
-
- saved_dir = alloca(sizeof ("/"));
- strcpy(saved_dir, "/");
- dir_stack[top] = saved_dir;
- break;
- } else {
- snprintf (dir_handle, handle_size, "%s/%s/%02x/%02x/%s",
- priv_base_path, GF_HIDDEN_PATH, tmp_gfid[0],
- tmp_gfid[1], uuid_utoa (tmp_gfid));
-
- len = sys_readlink (dir_handle, linkname, PATH_MAX);
- if (len < 0) {
- *op_errno = errno;
- gf_msg (this->name, (errno == ENOENT ||
- errno == ESTALE)
- ? GF_LOG_DEBUG:GF_LOG_ERROR, errno,
- P_MSG_READLINK_FAILED, "could not read"
- " the link from the gfid handle %s ",
- dir_handle);
- ret = -1;
- goto out;
- }
-
- linkname[len] = '\0';
-
- pgfidstr = strtok_r (linkname + SLEN("../../00/00/"),
- "/", &saveptr);
- dir_name = strtok_r (NULL, "/", &saveptr);
- saved_dir = alloca(strlen(dir_name) + 1);
- gf_uuid_parse (pgfidstr, tmp_gfid);
- strcpy(saved_dir, dir_name);
- dir_stack[top] = saved_dir;
- }
- }
- if (top == PATH_MAX/2) {
- gf_msg (this->name, GF_LOG_ERROR,
- P_MSG_ANCESTORY_FAILED,
- 0, "build ancestry failed due to "
- "deep directory hierarchy, depth: %d.", top);
- *op_errno = EINVAL;
+ char *linkname = NULL; /* "../../<gfid[0]>/<gfid[1]/"
+ "<gfidstr>/<NAME_MAX>" */
+ char *dir_handle = NULL;
+ char *pgfidstr = NULL;
+ char *saveptr = NULL;
+ ssize_t len = 0;
+ inode_t *inode = NULL;
+ struct iatt iabuf = {
+ 0,
+ };
+ int ret = -1;
+ uuid_t tmp_gfid = {
+ 0,
+ };
+ char *dir_stack[PATH_MAX / 2 + 1]; /* Since PATH_MAX/2 also gives
+ an upper bound on depth of
+ directories tree */
+ uuid_t gfid_stack[PATH_MAX / 2 + 1];
+
+ char *dir_name = NULL;
+ char *saved_dir = NULL;
+ int top = -1;
+
+ if (!path || !parent || !priv_base_path || gf_uuid_is_null(gfid)) {
+ *op_errno = EINVAL;
+ goto out;
+ }
+
+ dir_handle = alloca(handle_size);
+ linkname = alloca(PATH_MAX);
+ gf_uuid_copy(tmp_gfid, gfid);
+
+ while (top < PATH_MAX / 2) {
+ gf_uuid_copy(gfid_stack[++top], tmp_gfid);
+ if (__is_root_gfid(tmp_gfid)) {
+ *parent = inode_ref(itable->root);
+
+ saved_dir = alloca(sizeof("/"));
+ strcpy(saved_dir, "/");
+ dir_stack[top] = saved_dir;
+ break;
+ } else {
+ snprintf(dir_handle, handle_size, "%s/%s/%02x/%02x/%s",
+ priv_base_path, GF_HIDDEN_PATH, tmp_gfid[0], tmp_gfid[1],
+ uuid_utoa(tmp_gfid));
+
+ len = sys_readlink(dir_handle, linkname, PATH_MAX);
+ if (len < 0) {
+ *op_errno = errno;
+ gf_msg(this->name,
+ (errno == ENOENT || errno == ESTALE) ? GF_LOG_DEBUG
+ : GF_LOG_ERROR,
+ errno, P_MSG_READLINK_FAILED,
+ "could not read"
+ " the link from the gfid handle %s ",
+ dir_handle);
ret = -1;
goto out;
+ }
+
+ linkname[len] = '\0';
+
+ pgfidstr = strtok_r(linkname + SLEN("../../00/00/"), "/", &saveptr);
+ dir_name = strtok_r(NULL, "/", &saveptr);
+ saved_dir = alloca(strlen(dir_name) + 1);
+ gf_uuid_parse(pgfidstr, tmp_gfid);
+ strcpy(saved_dir, dir_name);
+ dir_stack[top] = saved_dir;
+ }
+ }
+ if (top == PATH_MAX / 2) {
+ gf_msg(this->name, GF_LOG_ERROR, P_MSG_ANCESTORY_FAILED, 0,
+ "build ancestry failed due to "
+ "deep directory hierarchy, depth: %d.",
+ top);
+ *op_errno = EINVAL;
+ ret = -1;
+ goto out;
+ }
+
+ while (top >= 0) {
+ if (!*parent) {
+ /* There's no real "root" cause for how we end up here,
+ * so for now let's log this and bail out to prevent
+ * crashes.
+ */
+ gf_msg(this->name, GF_LOG_WARNING, P_MSG_INODE_RESOLVE_FAILED, 0,
+ "OOPS: *parent is null (path: %s), bailing!", path);
+ goto out;
+ }
+
+ memset(&iabuf, 0, sizeof(iabuf));
+ inode = posix_resolve(this, itable, *parent, dir_stack[top], &iabuf);
+ if (inode == NULL) {
+ gf_msg(this->name, GF_LOG_ERROR, P_MSG_INODE_RESOLVE_FAILED, 0,
+ "posix resolve on the inode %s failed",
+ uuid_utoa(gfid_stack[top]));
+ *op_errno = ESTALE;
+ ret = -1;
+ goto out;
+ }
+
+ ret = posix_make_ancestral_node(priv_base_path, path, pathsize, head,
+ dir_stack[top], &iabuf, inode, type,
+ xdata);
+ if (ret < 0) {
+ *op_errno = ENOMEM;
+ goto out;
}
- while (top >= 0) {
-
- if (!*parent) {
- /* There's no real "root" cause for how we end up here,
- * so for now let's log this and bail out to prevent
- * crashes.
- */
- gf_msg (this->name, GF_LOG_WARNING,
- P_MSG_INODE_RESOLVE_FAILED, 0,
- "OOPS: *parent is null (path: %s), bailing!",
- path);
- goto out;
- }
-
- memset (&iabuf, 0, sizeof (iabuf));
- inode = posix_resolve (this, itable, *parent,
- dir_stack[top], &iabuf);
- if (inode == NULL) {
- gf_msg (this->name, GF_LOG_ERROR,
- P_MSG_INODE_RESOLVE_FAILED,
- 0, "posix resolve on the inode %s failed",
- uuid_utoa (gfid_stack[top]));
- *op_errno = ESTALE;
- ret = -1;
- goto out;
- }
-
- ret = posix_make_ancestral_node (priv_base_path, path,
- pathsize, head,
- dir_stack[top], &iabuf,
- inode, type, xdata);
- if (ret < 0) {
- *op_errno = ENOMEM;
- goto out;
- }
-
- inode_unref (*parent);
- *parent = inode;
- top--;
- }
+ inode_unref(*parent);
+ *parent = inode;
+ top--;
+ }
out:
- return ret;
+ return ret;
}
int
-posix_handle_relpath (xlator_t *this, uuid_t gfid, const char *basename,
- char *buf, size_t buflen)
+posix_handle_relpath(xlator_t *this, uuid_t gfid, const char *basename,
+ char *buf, size_t buflen)
{
- char *uuid_str = NULL;
- int len = 0;
+ char *uuid_str = NULL;
+ int len = 0;
- len = SLEN("../")
- + SLEN("../")
- + SLEN("00/")
- + SLEN("00/")
- + SLEN(UUID0_STR)
- + 1 /* '\0' */
- ;
+ len = SLEN("../") + SLEN("../") + SLEN("00/") + SLEN("00/") +
+ SLEN(UUID0_STR) + 1 /* '\0' */
+ ;
- if (basename) {
- len += (strlen (basename) + 1);
- }
+ if (basename) {
+ len += (strlen(basename) + 1);
+ }
- if (buflen < len || !buf)
- return len;
+ if (buflen < len || !buf)
+ return len;
- uuid_str = uuid_utoa (gfid);
+ uuid_str = uuid_utoa(gfid);
- if (basename) {
- len = snprintf (buf, buflen, "../../%02x/%02x/%s/%s",
- gfid[0], gfid[1], uuid_str, basename);
- } else {
- len = snprintf (buf, buflen, "../../%02x/%02x/%s",
- gfid[0], gfid[1], uuid_str);
- }
+ if (basename) {
+ len = snprintf(buf, buflen, "../../%02x/%02x/%s/%s", gfid[0], gfid[1],
+ uuid_str, basename);
+ } else {
+ len = snprintf(buf, buflen, "../../%02x/%02x/%s", gfid[0], gfid[1],
+ uuid_str);
+ }
- return len;
+ return len;
}
-
/*
TODO: explain how this pump fixes ELOOP
*/
gf_boolean_t
-posix_is_malformed_link (xlator_t *this, char *base_str, char *linkname,
- size_t len)
+posix_is_malformed_link(xlator_t *this, char *base_str, char *linkname,
+ size_t len)
{
- if ((len == 8) && strcmp (linkname, "../../..")) /*for root*/
- goto err;
+ if ((len == 8) && strcmp(linkname, "../../..")) /*for root*/
+ goto err;
- if (len < 50 || len >= 512)
- goto err;
+ if (len < 50 || len >= 512)
+ goto err;
- if (memcmp (linkname, "../../", 6) != 0)
- goto err;
+ if (memcmp(linkname, "../../", 6) != 0)
+ goto err;
- if ((linkname[2] != '/') ||
- (linkname[5] != '/') ||
- (linkname[8] != '/') ||
- (linkname[11] != '/') ||
- (linkname[48] != '/')) {
- goto err;
- }
+ if ((linkname[2] != '/') || (linkname[5] != '/') || (linkname[8] != '/') ||
+ (linkname[11] != '/') || (linkname[48] != '/')) {
+ goto err;
+ }
- if ((linkname[20] != '-') ||
- (linkname[25] != '-') ||
- (linkname[30] != '-') ||
- (linkname[35] != '-')) {
- goto err;
- }
+ if ((linkname[20] != '-') || (linkname[25] != '-') ||
+ (linkname[30] != '-') || (linkname[35] != '-')) {
+ goto err;
+ }
- return _gf_false;
+ return _gf_false;
err:
- gf_log_callingfn (this->name, GF_LOG_ERROR, "malformed internal link "
- "%s for %s", linkname, base_str);
- return _gf_true;
+ gf_log_callingfn(this->name, GF_LOG_ERROR,
+ "malformed internal link "
+ "%s for %s",
+ linkname, base_str);
+ return _gf_true;
}
int
-posix_handle_pump (xlator_t *this, char *buf, int len, int maxlen,
- char *base_str, int base_len, int pfx_len)
+posix_handle_pump(xlator_t *this, char *buf, int len, int maxlen,
+ char *base_str, int base_len, int pfx_len)
{
- char linkname[512] = {0,}; /* "../../<gfid>/<NAME_MAX>" */
- int ret = 0;
- int blen = 0;
- int link_len = 0;
-
- /* is a directory's symlink-handle */
- ret = sys_readlink (base_str, linkname, 512);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_READLINK_FAILED,
- "internal readlink failed on %s ",
- base_str);
- goto err;
- }
+ char linkname[512] = {
+ 0,
+ }; /* "../../<gfid>/<NAME_MAX>" */
+ int ret = 0;
+ int blen = 0;
+ int link_len = 0;
- if (ret < 512)
- linkname[ret] = 0;
+ /* is a directory's symlink-handle */
+ ret = sys_readlink(base_str, linkname, 512);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_READLINK_FAILED,
+ "internal readlink failed on %s ", base_str);
+ goto err;
+ }
- link_len = ret;
+ if (ret < 512)
+ linkname[ret] = 0;
- if ((ret == 8) && memcmp (linkname, "../../..", 8) == 0) {
- if (strcmp (base_str, buf) == 0) {
- strcpy (buf + pfx_len, "..");
- }
- goto out;
+ link_len = ret;
+
+ if ((ret == 8) && memcmp(linkname, "../../..", 8) == 0) {
+ if (strcmp(base_str, buf) == 0) {
+ strcpy(buf + pfx_len, "..");
}
+ goto out;
+ }
- if (posix_is_malformed_link (this, base_str, linkname, ret))
- goto err;
+ if (posix_is_malformed_link(this, base_str, linkname, ret))
+ goto err;
- blen = link_len - 48;
+ blen = link_len - 48;
- if (len + blen >= maxlen) {
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_HANDLEPATH_FAILED,
- "Unable to form handle path for %s (maxlen = %d)",
- buf, maxlen);
- goto err;
- }
+ if (len + blen >= maxlen) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_HANDLEPATH_FAILED,
+ "Unable to form handle path for %s (maxlen = %d)", buf, maxlen);
+ goto err;
+ }
- memmove (buf + base_len + blen, buf + base_len,
- (strlen (buf) - base_len) + 1);
+ memmove(buf + base_len + blen, buf + base_len,
+ (strlen(buf) - base_len) + 1);
- strncpy (base_str + pfx_len, linkname + 6, 42);
+ strncpy(base_str + pfx_len, linkname + 6, 42);
- strncpy (buf + pfx_len, linkname + 6, link_len - 6);
+ strncpy(buf + pfx_len, linkname + 6, link_len - 6);
out:
- return len + blen;
+ return len + blen;
err:
- return -1;
+ return -1;
}
-
/*
posix_handle_path differs from posix_handle_gfid_path in the way that the
path filled in @buf by posix_handle_path will return type IA_IFDIR when
@@ -398,651 +390,606 @@ err:
*/
int
-posix_handle_path (xlator_t *this, uuid_t gfid, const char *basename,
- char *ubuf, size_t size)
+posix_handle_path(xlator_t *this, uuid_t gfid, const char *basename, char *ubuf,
+ size_t size)
{
- struct posix_private *priv = NULL;
- char *uuid_str = NULL;
- int len = 0;
- int ret = -1;
- struct stat stat;
- char *base_str = NULL;
- int base_len = 0;
- int pfx_len;
- int maxlen;
- char *buf;
-
- priv = this->private;
-
- uuid_str = uuid_utoa (gfid);
-
- if (ubuf) {
- buf = ubuf;
- maxlen = size;
- } else {
- maxlen = PATH_MAX;
- buf = alloca (maxlen);
- }
-
- base_len = (priv->base_path_length + SLEN(GF_HIDDEN_PATH) + 45);
- base_str = alloca (base_len + 1);
- base_len = snprintf (base_str, base_len + 1, "%s/%s/%02x/%02x/%s",
- priv->base_path, GF_HIDDEN_PATH, gfid[0], gfid[1],
- uuid_str);
-
- pfx_len = priv->base_path_length + 1 + SLEN(GF_HIDDEN_PATH) + 1;
-
- if (basename) {
- len = snprintf (buf, maxlen, "%s/%s", base_str, basename);
- } else {
- len = snprintf (buf, maxlen, "%s", base_str);
- }
-
- ret = sys_lstat (base_str, &stat);
-
- if (!(ret == 0 && S_ISLNK(stat.st_mode) && stat.st_nlink == 1))
- goto out;
-
- do {
- errno = 0;
- ret = posix_handle_pump (this, buf, len, maxlen,
- base_str, base_len, pfx_len);
- len = ret;
-
- if (ret == -1)
- break;
-
- ret = sys_lstat (buf, &stat);
- } while ((ret == -1) && errno == ELOOP);
+ struct posix_private *priv = NULL;
+ char *uuid_str = NULL;
+ int len = 0;
+ int ret = -1;
+ struct stat stat;
+ char *base_str = NULL;
+ int base_len = 0;
+ int pfx_len;
+ int maxlen;
+ char *buf;
+
+ priv = this->private;
+
+ uuid_str = uuid_utoa(gfid);
+
+ if (ubuf) {
+ buf = ubuf;
+ maxlen = size;
+ } else {
+ maxlen = PATH_MAX;
+ buf = alloca(maxlen);
+ }
+
+ base_len = (priv->base_path_length + SLEN(GF_HIDDEN_PATH) + 45);
+ base_str = alloca(base_len + 1);
+ base_len = snprintf(base_str, base_len + 1, "%s/%s/%02x/%02x/%s",
+ priv->base_path, GF_HIDDEN_PATH, gfid[0], gfid[1],
+ uuid_str);
+
+ pfx_len = priv->base_path_length + 1 + SLEN(GF_HIDDEN_PATH) + 1;
+
+ if (basename) {
+ len = snprintf(buf, maxlen, "%s/%s", base_str, basename);
+ } else {
+ len = snprintf(buf, maxlen, "%s", base_str);
+ }
+
+ ret = sys_lstat(base_str, &stat);
+
+ if (!(ret == 0 && S_ISLNK(stat.st_mode) && stat.st_nlink == 1))
+ goto out;
+
+ do {
+ errno = 0;
+ ret = posix_handle_pump(this, buf, len, maxlen, base_str, base_len,
+ pfx_len);
+ len = ret;
+
+ if (ret == -1)
+ break;
+
+ ret = sys_lstat(buf, &stat);
+ } while ((ret == -1) && errno == ELOOP);
out:
- return len + 1;
+ return len + 1;
}
-
int
-posix_handle_gfid_path (xlator_t *this, uuid_t gfid, const char *basename,
- char *buf, size_t buflen)
+posix_handle_gfid_path(xlator_t *this, uuid_t gfid, const char *basename,
+ char *buf, size_t buflen)
{
- struct posix_private *priv = NULL;
- char *uuid_str = NULL;
- int len = 0;
-
- priv = this->private;
-
- len = priv->base_path_length /* option directory "/export" */
- + SLEN("/")
- + SLEN(GF_HIDDEN_PATH)
- + SLEN("/")
- + SLEN("00/")
- + SLEN("00/")
- + SLEN(UUID0_STR)
- + 1 /* '\0' */
- ;
+ struct posix_private *priv = NULL;
+ char *uuid_str = NULL;
+ int len = 0;
- if (basename) {
- len += (strlen (basename) + 1);
- } else {
- len += 256; /* worst-case for directory's symlink-handle expansion */
- }
+ priv = this->private;
- if ((buflen < len) || !buf)
- return len;
+ len = priv->base_path_length /* option directory "/export" */
+ + SLEN("/") + SLEN(GF_HIDDEN_PATH) + SLEN("/") + SLEN("00/") +
+ SLEN("00/") + SLEN(UUID0_STR) + 1 /* '\0' */
+ ;
- uuid_str = uuid_utoa (gfid);
+ if (basename) {
+ len += (strlen(basename) + 1);
+ } else {
+ len += 256; /* worst-case for directory's symlink-handle expansion */
+ }
- if (__is_root_gfid (gfid)) {
- if (basename) {
- len = snprintf (buf, buflen, "%s/%s", priv->base_path,
- basename);
- } else {
- len = snprintf (buf, buflen, "%s", priv->base_path);
- }
- goto out;
- }
+ if ((buflen < len) || !buf)
+ return len;
+ uuid_str = uuid_utoa(gfid);
+
+ if (__is_root_gfid(gfid)) {
if (basename) {
- len = snprintf (buf, buflen, "%s/%s/%02x/%02x/%s/%s", priv->base_path,
- GF_HIDDEN_PATH, gfid[0], gfid[1], uuid_str, basename);
+ len = snprintf(buf, buflen, "%s/%s", priv->base_path, basename);
} else {
- len = snprintf (buf, buflen, "%s/%s/%02x/%02x/%s", priv->base_path,
- GF_HIDDEN_PATH, gfid[0], gfid[1], uuid_str);
- }
+ len = snprintf(buf, buflen, "%s", priv->base_path);
+ }
+ goto out;
+ }
+
+ if (basename) {
+ len = snprintf(buf, buflen, "%s/%s/%02x/%02x/%s/%s", priv->base_path,
+ GF_HIDDEN_PATH, gfid[0], gfid[1], uuid_str, basename);
+ } else {
+ len = snprintf(buf, buflen, "%s/%s/%02x/%02x/%s", priv->base_path,
+ GF_HIDDEN_PATH, gfid[0], gfid[1], uuid_str);
+ }
out:
- return len;
+ return len;
}
int
-posix_handle_init (xlator_t *this)
+posix_handle_init(xlator_t *this)
{
- struct posix_private *priv = NULL;
- char *handle_pfx = NULL;
- int ret = 0;
- struct stat stbuf;
- struct stat rootbuf;
- struct stat exportbuf;
- char *rootstr = NULL;
- uuid_t gfid = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
-
- priv = this->private;
-
- ret = sys_stat (priv->base_path, &exportbuf);
- if (ret || !S_ISDIR (exportbuf.st_mode)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_HANDLE_CREATE,
- "Not a directory: %s", priv->base_path);
- return -1;
- }
+ struct posix_private *priv = NULL;
+ char *handle_pfx = NULL;
+ int ret = 0;
+ struct stat stbuf;
+ struct stat rootbuf;
+ struct stat exportbuf;
+ char *rootstr = NULL;
+ uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
+
+ priv = this->private;
+
+ ret = sys_stat(priv->base_path, &exportbuf);
+ if (ret || !S_ISDIR(exportbuf.st_mode)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_HANDLE_CREATE,
+ "Not a directory: %s", priv->base_path);
+ return -1;
+ }
- handle_pfx = alloca (priv->base_path_length + 1 +
- SLEN (GF_HIDDEN_PATH) + 1);
+ handle_pfx = alloca(priv->base_path_length + 1 + SLEN(GF_HIDDEN_PATH) + 1);
- sprintf (handle_pfx, "%s/%s", priv->base_path, GF_HIDDEN_PATH);
+ sprintf(handle_pfx, "%s/%s", priv->base_path, GF_HIDDEN_PATH);
- ret = sys_stat (handle_pfx, &stbuf);
- switch (ret) {
+ ret = sys_stat(handle_pfx, &stbuf);
+ switch (ret) {
case -1:
- if (errno == ENOENT) {
- ret = sys_mkdir (handle_pfx, 0600);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_CREATE,
- "Creating directory %s failed",
- handle_pfx);
- return -1;
- }
- } else {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_CREATE,
- "Checking for %s failed",
- handle_pfx);
- return -1;
+ if (errno == ENOENT) {
+ ret = sys_mkdir(handle_pfx, 0600);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_CREATE,
+ "Creating directory %s failed", handle_pfx);
+ return -1;
}
- break;
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_CREATE,
+ "Checking for %s failed", handle_pfx);
+ return -1;
+ }
+ break;
case 0:
- if (!S_ISDIR (stbuf.st_mode)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_HANDLE_CREATE,
- "Not a directory: %s",
- handle_pfx);
- return -1;
- }
- break;
+ if (!S_ISDIR(stbuf.st_mode)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_HANDLE_CREATE,
+ "Not a directory: %s", handle_pfx);
+ return -1;
+ }
+ break;
default:
- break;
- }
-
- ret = sys_stat (handle_pfx, &priv->handledir);
+ break;
+ }
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_CREATE,
- "stat for %s failed", handle_pfx);
- return -1;
- }
+ ret = sys_stat(handle_pfx, &priv->handledir);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_CREATE,
+ "stat for %s failed", handle_pfx);
+ return -1;
+ }
- MAKE_HANDLE_ABSPATH(rootstr, this, gfid);
+ MAKE_HANDLE_ABSPATH(rootstr, this, gfid);
- ret = sys_stat (rootstr, &rootbuf);
- switch (ret) {
+ ret = sys_stat(rootstr, &rootbuf);
+ switch (ret) {
case -1:
- if (errno != ENOENT) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_CREATE,
- "%s", priv->base_path);
- return -1;
- }
+ if (errno != ENOENT) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_CREATE,
+ "%s", priv->base_path);
+ return -1;
+ }
- ret = posix_handle_mkdir_hashes (this, rootstr);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE,
- "mkdir %s failed", rootstr);
- return -1;
- }
+ ret = posix_handle_mkdir_hashes(this, rootstr);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE,
+ "mkdir %s failed", rootstr);
+ return -1;
+ }
- ret = sys_symlink ("../../..", rootstr);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_CREATE,
- "symlink %s creation failed",
- rootstr);
- return -1;
- }
- break;
- case 0:
- if ((exportbuf.st_ino == rootbuf.st_ino) &&
- (exportbuf.st_dev == rootbuf.st_dev))
- return 0;
-
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_HANDLE_CREATE,
- "Different dirs %s (%lld/%lld) != %s (%lld/%lld)",
- priv->base_path, (long long) exportbuf.st_ino,
- (long long) exportbuf.st_dev, rootstr,
- (long long) rootbuf.st_ino, (long long) rootbuf.st_dev);
+ ret = sys_symlink("../../..", rootstr);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_CREATE,
+ "symlink %s creation failed", rootstr);
return -1;
+ }
+ break;
+ case 0:
+ if ((exportbuf.st_ino == rootbuf.st_ino) &&
+ (exportbuf.st_dev == rootbuf.st_dev))
+ return 0;
- break;
- }
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_HANDLE_CREATE,
+ "Different dirs %s (%lld/%lld) != %s (%lld/%lld)",
+ priv->base_path, (long long)exportbuf.st_ino,
+ (long long)exportbuf.st_dev, rootstr,
+ (long long)rootbuf.st_ino, (long long)rootbuf.st_dev);
+ return -1;
- return 0;
+ break;
+ }
+
+ return 0;
}
gf_boolean_t
-posix_does_old_trash_exists (char *old_trash)
+posix_does_old_trash_exists(char *old_trash)
{
- uuid_t gfid = {0};
- gf_boolean_t exists = _gf_false;
- struct stat stbuf = {0};
- int ret = 0;
-
- ret = sys_lstat (old_trash, &stbuf);
- if ((ret == 0) && S_ISDIR (stbuf.st_mode)) {
- ret = sys_lgetxattr (old_trash, "trusted.gfid", gfid, 16);
- if ((ret < 0) && (errno == ENODATA || errno == ENOATTR) )
- exists = _gf_true;
- }
- return exists;
+ uuid_t gfid = {0};
+ gf_boolean_t exists = _gf_false;
+ struct stat stbuf = {0};
+ int ret = 0;
+
+ ret = sys_lstat(old_trash, &stbuf);
+ if ((ret == 0) && S_ISDIR(stbuf.st_mode)) {
+ ret = sys_lgetxattr(old_trash, "trusted.gfid", gfid, 16);
+ if ((ret < 0) && (errno == ENODATA || errno == ENOATTR))
+ exists = _gf_true;
+ }
+ return exists;
}
int
-posix_handle_new_trash_init (xlator_t *this, char *trash)
+posix_handle_new_trash_init(xlator_t *this, char *trash)
{
- int ret = 0;
- struct stat stbuf = {0};
+ int ret = 0;
+ struct stat stbuf = {0};
- ret = sys_lstat (trash, &stbuf);
- switch (ret) {
+ ret = sys_lstat(trash, &stbuf);
+ switch (ret) {
case -1:
- if (errno == ENOENT) {
- ret = sys_mkdir (trash, 0755);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_TRASH_CREATE,
- "Creating directory %s failed",
- trash);
- }
- } else {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_TRASH_CREATE,
- "Checking for %s failed", trash);
+ if (errno == ENOENT) {
+ ret = sys_mkdir(trash, 0755);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ P_MSG_HANDLE_TRASH_CREATE,
+ "Creating directory %s failed", trash);
}
- break;
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ P_MSG_HANDLE_TRASH_CREATE, "Checking for %s failed",
+ trash);
+ }
+ break;
case 0:
- if (!S_ISDIR (stbuf.st_mode)) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_TRASH_CREATE,
- "Not a directory: %s", trash);
- ret = -1;
- }
- break;
+ if (!S_ISDIR(stbuf.st_mode)) {
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ P_MSG_HANDLE_TRASH_CREATE, "Not a directory: %s", trash);
+ ret = -1;
+ }
+ break;
default:
- break;
- }
- return ret;
+ break;
+ }
+ return ret;
}
int
-posix_mv_old_trash_into_new_trash (xlator_t *this, char *old, char *new)
+posix_mv_old_trash_into_new_trash(xlator_t *this, char *old, char *new)
{
- char dest_old[PATH_MAX] = {0};
- int ret = 0;
- uuid_t dest_name = {0};
-
- if (!posix_does_old_trash_exists (old))
- goto out;
- gf_uuid_generate (dest_name);
- snprintf (dest_old, sizeof (dest_old), "%s/%s", new,
- uuid_utoa (dest_name));
- ret = sys_rename (old, dest_old);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_TRASH_CREATE,
- "Not able to move %s -> %s ", old, dest_old);
- }
+ char dest_old[PATH_MAX] = {0};
+ int ret = 0;
+ uuid_t dest_name = {0};
+
+ if (!posix_does_old_trash_exists(old))
+ goto out;
+ gf_uuid_generate(dest_name);
+ snprintf(dest_old, sizeof(dest_old), "%s/%s", new, uuid_utoa(dest_name));
+ ret = sys_rename(old, dest_old);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_TRASH_CREATE,
+ "Not able to move %s -> %s ", old, dest_old);
+ }
out:
- return ret;
+ return ret;
}
int
-posix_handle_trash_init (xlator_t *this)
+posix_handle_trash_init(xlator_t *this)
{
- int ret = -1;
- struct posix_private *priv = NULL;
- char old_trash[PATH_MAX] = {0};
-
- priv = this->private;
-
- priv->trash_path = GF_MALLOC (priv->base_path_length + SLEN ("/")
- + SLEN (GF_HIDDEN_PATH) + SLEN ("/")
- + SLEN (TRASH_DIR) + 1,
- gf_posix_mt_trash_path);
-
- if (!priv->trash_path)
- goto out;
-
- snprintf (priv->trash_path, priv->base_path_length
- + SLEN (GF_HIDDEN_PATH) + SLEN (TRASH_DIR) + 3,
- "%s/%s/%s", priv->base_path, GF_HIDDEN_PATH, TRASH_DIR);
-
- ret = posix_handle_new_trash_init (this, priv->trash_path);
- if (ret)
- goto out;
- snprintf (old_trash, sizeof (old_trash), "%s/.landfill",
- priv->base_path);
- ret = posix_mv_old_trash_into_new_trash (this, old_trash,
- priv->trash_path);
+ int ret = -1;
+ struct posix_private *priv = NULL;
+ char old_trash[PATH_MAX] = {0};
+
+ priv = this->private;
+
+ priv->trash_path = GF_MALLOC(priv->base_path_length + SLEN("/") +
+ SLEN(GF_HIDDEN_PATH) + SLEN("/") +
+ SLEN(TRASH_DIR) + 1,
+ gf_posix_mt_trash_path);
+
+ if (!priv->trash_path)
+ goto out;
+
+ snprintf(
+ priv->trash_path,
+ priv->base_path_length + SLEN(GF_HIDDEN_PATH) + SLEN(TRASH_DIR) + 3,
+ "%s/%s/%s", priv->base_path, GF_HIDDEN_PATH, TRASH_DIR);
+
+ ret = posix_handle_new_trash_init(this, priv->trash_path);
+ if (ret)
+ goto out;
+ snprintf(old_trash, sizeof(old_trash), "%s/.landfill", priv->base_path);
+ ret = posix_mv_old_trash_into_new_trash(this, old_trash, priv->trash_path);
out:
- return ret;
+ return ret;
}
int
-posix_handle_mkdir_hashes (xlator_t *this, const char *newpath)
+posix_handle_mkdir_hashes(xlator_t *this, const char *newpath)
{
- char *duppath = NULL;
- char *parpath = NULL;
- int ret = 0;
-
- duppath = strdupa (newpath);
- parpath = dirname (duppath);
- parpath = dirname (duppath);
-
- ret = sys_mkdir (parpath, 0700);
- if (ret == -1 && errno != EEXIST) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_CREATE,
- "error mkdir hash-1 %s ", parpath);
- return -1;
- }
+ char *duppath = NULL;
+ char *parpath = NULL;
+ int ret = 0;
+
+ duppath = strdupa(newpath);
+ parpath = dirname(duppath);
+ parpath = dirname(duppath);
+
+ ret = sys_mkdir(parpath, 0700);
+ if (ret == -1 && errno != EEXIST) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_CREATE,
+ "error mkdir hash-1 %s ", parpath);
+ return -1;
+ }
- strcpy (duppath, newpath);
- parpath = dirname (duppath);
+ strcpy(duppath, newpath);
+ parpath = dirname(duppath);
- ret = sys_mkdir (parpath, 0700);
- if (ret == -1 && errno != EEXIST) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_HANDLE_CREATE,
- "error mkdir hash-2 %s ", parpath);
- return -1;
- }
+ ret = sys_mkdir(parpath, 0700);
+ if (ret == -1 && errno != EEXIST) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_HANDLE_CREATE,
+ "error mkdir hash-2 %s ", parpath);
+ return -1;
+ }
- return 0;
+ return 0;
}
-
int
-posix_handle_hard (xlator_t *this, const char *oldpath, uuid_t gfid, struct stat *oldbuf)
+posix_handle_hard(xlator_t *this, const char *oldpath, uuid_t gfid,
+ struct stat *oldbuf)
{
- char *newpath = NULL;
- struct stat newbuf;
- int ret = -1;
+ char *newpath = NULL;
+ struct stat newbuf;
+ int ret = -1;
+ MAKE_HANDLE_ABSPATH(newpath, this, gfid);
- MAKE_HANDLE_ABSPATH (newpath, this, gfid);
+ ret = sys_lstat(newpath, &newbuf);
+ if (ret == -1 && errno != ENOENT) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE, "%s",
+ newpath);
+ return -1;
+ }
- ret = sys_lstat (newpath, &newbuf);
- if (ret == -1 && errno != ENOENT) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE,
- "%s", newpath);
- return -1;
+ if (ret == -1 && errno == ENOENT) {
+ ret = posix_handle_mkdir_hashes(this, newpath);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE,
+ "mkdir %s failed ", newpath);
+ return -1;
}
- if (ret == -1 && errno == ENOENT) {
- ret = posix_handle_mkdir_hashes (this, newpath);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE, "mkdir %s failed ",
- newpath);
- return -1;
- }
-
- ret = sys_link (oldpath, newpath);
-
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE, "link %s -> %s"
- "failed ", oldpath, newpath);
- return -1;
- }
+ ret = sys_link(oldpath, newpath);
- ret = sys_lstat (newpath, &newbuf);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE,
- "lstat on %s failed", newpath);
- return -1;
- }
- }
-
- if (newbuf.st_ino != oldbuf->st_ino ||
- newbuf.st_dev != oldbuf->st_dev) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_HANDLE_CREATE,
- "mismatching ino/dev between file %s (%lld/%lld) "
- "and handle %s (%lld/%lld)",
- oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->st_dev,
- newpath, (long long) newbuf.st_ino, (long long) newbuf.st_dev);
- ret = -1;
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE,
+ "link %s -> %s"
+ "failed ",
+ oldpath, newpath);
+ return -1;
}
- return ret;
+ ret = sys_lstat(newpath, &newbuf);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE,
+ "lstat on %s failed", newpath);
+ return -1;
+ }
+ }
+
+ if (newbuf.st_ino != oldbuf->st_ino || newbuf.st_dev != oldbuf->st_dev) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_HANDLE_CREATE,
+ "mismatching ino/dev between file %s (%lld/%lld) "
+ "and handle %s (%lld/%lld)",
+ oldpath, (long long)oldbuf->st_ino, (long long)oldbuf->st_dev,
+ newpath, (long long)newbuf.st_ino, (long long)newbuf.st_dev);
+ ret = -1;
+ }
+
+ return ret;
}
-
int
-posix_handle_soft (xlator_t *this, const char *real_path, loc_t *loc,
- uuid_t gfid, struct stat *oldbuf)
+posix_handle_soft(xlator_t *this, const char *real_path, loc_t *loc,
+ uuid_t gfid, struct stat *oldbuf)
{
- char *oldpath = NULL;
- char *newpath = NULL;
- struct stat newbuf;
- int ret = -1;
-
- MAKE_HANDLE_ABSPATH (newpath, this, gfid);
- MAKE_HANDLE_RELPATH (oldpath, this, loc->pargfid, loc->name);
-
- ret = sys_lstat (newpath, &newbuf);
- if (ret == -1 && errno != ENOENT) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE, "%s", newpath);
- return -1;
- }
-
- if (ret == -1 && errno == ENOENT) {
- if (posix_is_malformed_link (this, newpath, oldpath,
- strlen (oldpath))) {
- GF_ASSERT (!"Malformed link");
- errno = EINVAL;
- return -1;
- }
- ret = posix_handle_mkdir_hashes (this, newpath);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE,
- "mkdir %s failed ", newpath);
- return -1;
- }
-
- ret = sys_symlink (oldpath, newpath);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE,
- "symlink %s -> %s failed",
- oldpath, newpath);
- return -1;
- }
+ char *oldpath = NULL;
+ char *newpath = NULL;
+ struct stat newbuf;
+ int ret = -1;
+
+ MAKE_HANDLE_ABSPATH(newpath, this, gfid);
+ MAKE_HANDLE_RELPATH(oldpath, this, loc->pargfid, loc->name);
+
+ ret = sys_lstat(newpath, &newbuf);
+ if (ret == -1 && errno != ENOENT) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE, "%s",
+ newpath);
+ return -1;
+ }
- ret = sys_lstat (newpath, &newbuf);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE,
- "stat on %s failed ", newpath);
- return -1;
- }
+ if (ret == -1 && errno == ENOENT) {
+ if (posix_is_malformed_link(this, newpath, oldpath, strlen(oldpath))) {
+ GF_ASSERT(!"Malformed link");
+ errno = EINVAL;
+ return -1;
+ }
+ ret = posix_handle_mkdir_hashes(this, newpath);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE,
+ "mkdir %s failed ", newpath);
+ return -1;
}
- ret = sys_stat (real_path, &newbuf);
+ ret = sys_symlink(oldpath, newpath);
if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE,
- "stat on %s failed ", newpath);
- return -1;
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE,
+ "symlink %s -> %s failed", oldpath, newpath);
+ return -1;
}
- if (!oldbuf)
- return ret;
-
- if (newbuf.st_ino != oldbuf->st_ino ||
- newbuf.st_dev != oldbuf->st_dev) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_HANDLE_CREATE,
- "mismatching ino/dev between file %s (%lld/%lld) "
- "and handle %s (%lld/%lld)",
- oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->st_dev,
- newpath, (long long) newbuf.st_ino, (long long) newbuf.st_dev);
- ret = -1;
+ ret = sys_lstat(newpath, &newbuf);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE,
+ "stat on %s failed ", newpath);
+ return -1;
}
+ }
+ ret = sys_stat(real_path, &newbuf);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE,
+ "stat on %s failed ", newpath);
+ return -1;
+ }
+
+ if (!oldbuf)
return ret;
-}
+ if (newbuf.st_ino != oldbuf->st_ino || newbuf.st_dev != oldbuf->st_dev) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_HANDLE_CREATE,
+ "mismatching ino/dev between file %s (%lld/%lld) "
+ "and handle %s (%lld/%lld)",
+ oldpath, (long long)oldbuf->st_ino, (long long)oldbuf->st_dev,
+ newpath, (long long)newbuf.st_ino, (long long)newbuf.st_dev);
+ ret = -1;
+ }
+
+ return ret;
+}
int
-posix_handle_unset_gfid (xlator_t *this, uuid_t gfid)
+posix_handle_unset_gfid(xlator_t *this, uuid_t gfid)
{
- char *path = NULL;
- int ret = 0;
- struct stat stat;
+ char *path = NULL;
+ int ret = 0;
+ struct stat stat;
- MAKE_HANDLE_GFID_PATH (path, this, gfid, NULL);
+ MAKE_HANDLE_GFID_PATH(path, this, gfid, NULL);
- ret = sys_lstat (path, &stat);
+ ret = sys_lstat(path, &stat);
- if (ret == -1) {
- if (errno != ENOENT) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_DELETE, "%s", path);
- }
- goto out;
+ if (ret == -1) {
+ if (errno != ENOENT) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_DELETE, "%s",
+ path);
}
+ goto out;
+ }
- ret = sys_unlink (path);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_DELETE, "unlink %s failed ", path);
- }
+ ret = sys_unlink(path);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_DELETE,
+ "unlink %s failed ", path);
+ }
out:
- return ret;
+ return ret;
}
-
int
-posix_handle_unset (xlator_t *this, uuid_t gfid, const char *basename)
+posix_handle_unset(xlator_t *this, uuid_t gfid, const char *basename)
{
- int ret;
- struct iatt stat;
- char *path = NULL;
-
- if (!basename) {
- ret = posix_handle_unset_gfid (this, gfid);
- return ret;
- }
+ int ret;
+ struct iatt stat;
+ char *path = NULL;
- MAKE_HANDLE_PATH (path, this, gfid, basename);
- if (!path) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_HANDLE_DELETE,
- "Failed to create handle path for %s (%s)",
- basename, uuid_utoa(gfid));
- return -1;
- }
+ if (!basename) {
+ ret = posix_handle_unset_gfid(this, gfid);
+ return ret;
+ }
- /* stat is being used only for gfid, so passing a NULL inode
- * doesn't fetch time attributes which is fine
- */
- ret = posix_istat (this, NULL, gfid, basename, &stat);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_DELETE, "%s", path);
- return -1;
- }
+ MAKE_HANDLE_PATH(path, this, gfid, basename);
+ if (!path) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_HANDLE_DELETE,
+ "Failed to create handle path for %s (%s)", basename,
+ uuid_utoa(gfid));
+ return -1;
+ }
+
+ /* stat is being used only for gfid, so passing a NULL inode
+ * doesn't fetch time attributes which is fine
+ */
+ ret = posix_istat(this, NULL, gfid, basename, &stat);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_DELETE, "%s",
+ path);
+ return -1;
+ }
- ret = posix_handle_unset_gfid (this, stat.ia_gfid);
+ ret = posix_handle_unset_gfid(this, stat.ia_gfid);
- return ret;
+ return ret;
}
-
int
-posix_create_link_if_gfid_exists (xlator_t *this, uuid_t gfid, char *real_path,
- inode_table_t *itable)
+posix_create_link_if_gfid_exists(xlator_t *this, uuid_t gfid, char *real_path,
+ inode_table_t *itable)
{
- int ret = -1;
- char *newpath = NULL;
- char *unlink_path = NULL;
- uint64_t ctx_int = 0;
- inode_t *inode = NULL;
- struct stat stbuf = {0,};
- struct posix_private *priv = NULL;
- posix_inode_ctx_t *ctx = NULL;
-
- priv = this->private;
-
- MAKE_HANDLE_PATH (newpath, this, gfid, NULL);
- if (!newpath) {
- gf_msg (this->name, GF_LOG_WARNING, 0,
- P_MSG_HANDLE_CREATE,
- "Failed to create handle path (%s)", uuid_utoa(gfid));
- return ret;
- }
-
- ret = sys_lstat (newpath, &stbuf);
- if (!ret) {
- ret = sys_link (newpath, real_path);
- } else {
- inode = inode_find (itable, gfid);
- if (!inode)
- return -1;
-
- LOCK (&inode->lock);
- {
- ret = __posix_inode_ctx_get_all (inode, this, &ctx);
- if (ret)
- goto unlock;
-
- if (ctx->unlink_flag != GF_UNLINK_TRUE) {
- ret = -1;
- goto unlock;
- }
-
- POSIX_GET_FILE_UNLINK_PATH (priv->base_path, gfid,
- unlink_path);
- ret = sys_link (unlink_path, real_path);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE, "Failed to link "
- "%s with %s", real_path, unlink_path);
- goto unlock;
- }
- ret = sys_rename (unlink_path, newpath);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HANDLE_CREATE, "Failed to link "
- "%s with %s", real_path, unlink_path);
- goto unlock;
- }
- ctx_int = GF_UNLINK_FALSE;
- ret = __posix_inode_ctx_set_unlink_flag (inode, this,
- ctx_int);
- }
-unlock:
- UNLOCK (&inode->lock);
-
- inode_unref (inode);
- }
-
+ int ret = -1;
+ char *newpath = NULL;
+ char *unlink_path = NULL;
+ uint64_t ctx_int = 0;
+ inode_t *inode = NULL;
+ struct stat stbuf = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
+ posix_inode_ctx_t *ctx = NULL;
+
+ priv = this->private;
+
+ MAKE_HANDLE_PATH(newpath, this, gfid, NULL);
+ if (!newpath) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_HANDLE_CREATE,
+ "Failed to create handle path (%s)", uuid_utoa(gfid));
return ret;
+ }
+
+ ret = sys_lstat(newpath, &stbuf);
+ if (!ret) {
+ ret = sys_link(newpath, real_path);
+ } else {
+ inode = inode_find(itable, gfid);
+ if (!inode)
+ return -1;
+
+ LOCK(&inode->lock);
+ {
+ ret = __posix_inode_ctx_get_all(inode, this, &ctx);
+ if (ret)
+ goto unlock;
+
+ if (ctx->unlink_flag != GF_UNLINK_TRUE) {
+ ret = -1;
+ goto unlock;
+ }
+
+ POSIX_GET_FILE_UNLINK_PATH(priv->base_path, gfid, unlink_path);
+ ret = sys_link(unlink_path, real_path);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE,
+ "Failed to link "
+ "%s with %s",
+ real_path, unlink_path);
+ goto unlock;
+ }
+ ret = sys_rename(unlink_path, newpath);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE,
+ "Failed to link "
+ "%s with %s",
+ real_path, unlink_path);
+ goto unlock;
+ }
+ ctx_int = GF_UNLINK_FALSE;
+ ret = __posix_inode_ctx_set_unlink_flag(inode, this, ctx_int);
+ }
+ unlock:
+ UNLOCK(&inode->lock);
+
+ inode_unref(inode);
+ }
+
+ return ret;
}
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 8c0355e..99ee094 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -60,2218 +60,2173 @@
#include <sys/types.h>
char *marker_xattrs[] = {"trusted.glusterfs.quota.*",
- "trusted.glusterfs.*.xtime",
- NULL};
+ "trusted.glusterfs.*.xtime", NULL};
char *marker_contri_key = "trusted.*.*.contri";
-static char* posix_ignore_xattrs[] = {
- "gfid-req",
- GLUSTERFS_ENTRYLK_COUNT,
- GLUSTERFS_INODELK_COUNT,
- GLUSTERFS_POSIXLK_COUNT,
- GLUSTERFS_PARENT_ENTRYLK,
- GF_GFIDLESS_LOOKUP,
- GLUSTERFS_INODELK_DOM_COUNT,
- GLUSTERFS_INTERNAL_FOP_KEY,
- NULL
-};
-
-static char* list_xattr_ignore_xattrs[] = {
- GF_SELINUX_XATTR_KEY,
- GF_XATTR_VOL_ID_KEY,
- GFID_XATTR_KEY,
- NULL
-};
+static char *posix_ignore_xattrs[] = {"gfid-req",
+ GLUSTERFS_ENTRYLK_COUNT,
+ GLUSTERFS_INODELK_COUNT,
+ GLUSTERFS_POSIXLK_COUNT,
+ GLUSTERFS_PARENT_ENTRYLK,
+ GF_GFIDLESS_LOOKUP,
+ GLUSTERFS_INODELK_DOM_COUNT,
+ GLUSTERFS_INTERNAL_FOP_KEY,
+ NULL};
+
+static char *list_xattr_ignore_xattrs[] = {
+ GF_SELINUX_XATTR_KEY, GF_XATTR_VOL_ID_KEY, GFID_XATTR_KEY, NULL};
gf_boolean_t
-posix_special_xattr (char **pattern, char *key)
+posix_special_xattr(char **pattern, char *key)
{
- int i = 0;
- gf_boolean_t flag = _gf_false;
+ int i = 0;
+ gf_boolean_t flag = _gf_false;
- GF_VALIDATE_OR_GOTO ("posix", pattern, out);
- GF_VALIDATE_OR_GOTO ("posix", key, out);
+ GF_VALIDATE_OR_GOTO("posix", pattern, out);
+ GF_VALIDATE_OR_GOTO("posix", key, out);
- for (i = 0; pattern[i]; i++) {
- if (!fnmatch (pattern[i], key, 0)) {
- flag = _gf_true;
- break;
- }
+ for (i = 0; pattern[i]; i++) {
+ if (!fnmatch(pattern[i], key, 0)) {
+ flag = _gf_true;
+ break;
}
+ }
out:
- return flag;
+ return flag;
}
int
-posix_handle_mdata_xattr (call_frame_t *frame, const char *name, int *op_errno)
-{
- int i = 0;
- int ret = 0;
- int pid = 1;
- static const char * const internal_xattr[] = { GF_XATTR_MDATA_KEY,
- NULL
- };
- if (frame && frame->root) {
- pid = frame->root->pid;
- }
-
- if (!name || pid < GF_CLIENT_PID_MAX) {
- /* No need to do anything here */
- ret = 0;
- goto out;
- }
+posix_handle_mdata_xattr(call_frame_t *frame, const char *name, int *op_errno)
+{
+ int i = 0;
+ int ret = 0;
+ int pid = 1;
+ static const char *const internal_xattr[] = {GF_XATTR_MDATA_KEY, NULL};
+ if (frame && frame->root) {
+ pid = frame->root->pid;
+ }
+
+ if (!name || pid < GF_CLIENT_PID_MAX) {
+ /* No need to do anything here */
+ ret = 0;
+ goto out;
+ }
- for (i = 0; internal_xattr[i]; i++) {
- if (fnmatch (internal_xattr[i] , name, FNM_PERIOD) == 0) {
- ret = -1;
- if (op_errno) {
- *op_errno = ENOATTR;
- }
+ for (i = 0; internal_xattr[i]; i++) {
+ if (fnmatch(internal_xattr[i], name, FNM_PERIOD) == 0) {
+ ret = -1;
+ if (op_errno) {
+ *op_errno = ENOATTR;
+ }
- gf_msg_debug ("posix", ENOATTR,
- "Ignoring the key %s as an internal "
- "xattrs.", name);
- goto out;
- }
+ gf_msg_debug("posix", ENOATTR,
+ "Ignoring the key %s as an internal "
+ "xattrs.",
+ name);
+ goto out;
}
+ }
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
int
-posix_handle_georep_xattrs (call_frame_t *frame, const char *name,
- int *op_errno, gf_boolean_t is_getxattr)
-{
-
- int i = 0;
- int ret = 0;
- int pid = 1;
- gf_boolean_t filter_xattr = _gf_true;
- static const char *georep_xattr[] = { "*.glusterfs.*.stime",
- "*.glusterfs.*.xtime",
- "*.glusterfs.*.entry_stime",
- "*.glusterfs.volume-mark.*",
- NULL
- };
- if (frame && frame->root) {
- pid = frame->root->pid;
- }
-
- if (!name) {
- /* No need to do anything here */
- ret = 0;
- goto out;
- }
+posix_handle_georep_xattrs(call_frame_t *frame, const char *name, int *op_errno,
+ gf_boolean_t is_getxattr)
+{
+ int i = 0;
+ int ret = 0;
+ int pid = 1;
+ gf_boolean_t filter_xattr = _gf_true;
+ static const char *georep_xattr[] = {
+ "*.glusterfs.*.stime", "*.glusterfs.*.xtime",
+ "*.glusterfs.*.entry_stime", "*.glusterfs.volume-mark.*", NULL};
+ if (frame && frame->root) {
+ pid = frame->root->pid;
+ }
+
+ if (!name) {
+ /* No need to do anything here */
+ ret = 0;
+ goto out;
+ }
- if (pid == GF_CLIENT_PID_GSYNCD && is_getxattr) {
- filter_xattr = _gf_false;
+ if (pid == GF_CLIENT_PID_GSYNCD && is_getxattr) {
+ filter_xattr = _gf_false;
- /* getxattr from gsyncd process should return all the
- * internal xattr. In other cases ignore such xattrs
- */
- }
+ /* getxattr from gsyncd process should return all the
+ * internal xattr. In other cases ignore such xattrs
+ */
+ }
- for (i = 0; filter_xattr && georep_xattr[i]; i++) {
- if (fnmatch (georep_xattr[i] , name, FNM_PERIOD) == 0) {
- ret = -1;
- if (op_errno)
- *op_errno = ENOATTR;
+ for (i = 0; filter_xattr && georep_xattr[i]; i++) {
+ if (fnmatch(georep_xattr[i], name, FNM_PERIOD) == 0) {
+ ret = -1;
+ if (op_errno)
+ *op_errno = ENOATTR;
- gf_msg_debug ("posix", ENOATTR,
- "Ignoring the key %s as an internal "
- "xattrs.", name);
- goto out;
- }
+ gf_msg_debug("posix", ENOATTR,
+ "Ignoring the key %s as an internal "
+ "xattrs.",
+ name);
+ goto out;
}
+ }
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
int32_t
-posix_set_mode_in_dict (dict_t *in_dict, dict_t *out_dict,
- struct iatt *in_stbuf)
+posix_set_mode_in_dict(dict_t *in_dict, dict_t *out_dict, struct iatt *in_stbuf)
{
- int ret = -1;
- mode_t mode = 0;
+ int ret = -1;
+ mode_t mode = 0;
- if ((!in_dict) || (!in_stbuf) || (!out_dict)) {
- goto out;
- }
+ if ((!in_dict) || (!in_stbuf) || (!out_dict)) {
+ goto out;
+ }
- /* We need this only for files */
- if (!(IA_ISREG (in_stbuf->ia_type))) {
- ret = 0;
- goto out;
- }
+ /* We need this only for files */
+ if (!(IA_ISREG(in_stbuf->ia_type))) {
+ ret = 0;
+ goto out;
+ }
- /* Nobody asked for this */
- if (!dict_get (in_dict, DHT_MODE_IN_XDATA_KEY)) {
- ret = 0;
- goto out;
- }
- mode = st_mode_from_ia (in_stbuf->ia_prot, in_stbuf->ia_type);
+ /* Nobody asked for this */
+ if (!dict_get(in_dict, DHT_MODE_IN_XDATA_KEY)) {
+ ret = 0;
+ goto out;
+ }
+ mode = st_mode_from_ia(in_stbuf->ia_prot, in_stbuf->ia_type);
- ret = dict_set_int32 (out_dict, DHT_MODE_IN_XDATA_KEY, mode);
+ ret = dict_set_int32(out_dict, DHT_MODE_IN_XDATA_KEY, mode);
out:
- return ret;
+ return ret;
}
-
static gf_boolean_t
-posix_xattr_ignorable (char *key)
+posix_xattr_ignorable(char *key)
{
- return gf_get_index_by_elem (posix_ignore_xattrs, key) >= 0;
+ return gf_get_index_by_elem(posix_ignore_xattrs, key) >= 0;
}
static int
-_posix_xattr_get_set_from_backend (posix_xattr_filler_t *filler, char *key)
-{
- ssize_t xattr_size = -1;
- int ret = 0;
- char *value = NULL;
- char val_buf[256] = {0};
- gf_boolean_t have_val = _gf_false;
-
- if (!gf_is_valid_xattr_namespace (key)) {
- ret = -1;
- goto out;
- }
-
- /* Most of the gluster internal xattrs don't exceed 256 bytes. So try
- * getxattr with ~256 bytes. If it gives ERANGE then go the old way
- * of getxattr with NULL buf to find the length and then getxattr with
- * allocated buf to fill the data. This way we reduce lot of getxattrs.
- */
- if (filler->real_path)
- xattr_size = sys_lgetxattr (filler->real_path, key, val_buf,
- sizeof (val_buf) - 1);
- else
- xattr_size = sys_fgetxattr (filler->fdnum, key, val_buf,
- sizeof (val_buf) - 1);
+_posix_xattr_get_set_from_backend(posix_xattr_filler_t *filler, char *key)
+{
+ ssize_t xattr_size = -1;
+ int ret = 0;
+ char *value = NULL;
+ char val_buf[256] = {0};
+ gf_boolean_t have_val = _gf_false;
+
+ if (!gf_is_valid_xattr_namespace(key)) {
+ ret = -1;
+ goto out;
+ }
+
+ /* Most of the gluster internal xattrs don't exceed 256 bytes. So try
+ * getxattr with ~256 bytes. If it gives ERANGE then go the old way
+ * of getxattr with NULL buf to find the length and then getxattr with
+ * allocated buf to fill the data. This way we reduce lot of getxattrs.
+ */
+ if (filler->real_path)
+ xattr_size = sys_lgetxattr(filler->real_path, key, val_buf,
+ sizeof(val_buf) - 1);
+ else
+ xattr_size = sys_fgetxattr(filler->fdnum, key, val_buf,
+ sizeof(val_buf) - 1);
- if (xattr_size >= 0) {
- have_val = _gf_true;
- } else if (xattr_size == -1 && errno != ERANGE) {
- ret = -1;
- goto out;
- }
+ if (xattr_size >= 0) {
+ have_val = _gf_true;
+ } else if (xattr_size == -1 && errno != ERANGE) {
+ ret = -1;
+ goto out;
+ }
+
+ if (have_val) {
+ /*No need to do getxattr*/
+ } else if (filler->real_path) {
+ xattr_size = sys_lgetxattr(filler->real_path, key, NULL, 0);
+ } else {
+ xattr_size = sys_fgetxattr(filler->fdnum, key, NULL, 0);
+ }
+
+ if (xattr_size != -1) {
+ value = GF_MALLOC(xattr_size + 1, gf_posix_mt_char);
+ if (!value)
+ goto out;
if (have_val) {
- /*No need to do getxattr*/
- } else if (filler->real_path) {
- xattr_size = sys_lgetxattr (filler->real_path, key, NULL, 0);
+ memcpy(value, val_buf, xattr_size);
} else {
- xattr_size = sys_fgetxattr (filler->fdnum, key, NULL, 0);
- }
-
- if (xattr_size != -1) {
- value = GF_MALLOC (xattr_size + 1, gf_posix_mt_char);
- if (!value)
- goto out;
-
- if (have_val) {
- memcpy (value, val_buf, xattr_size);
- } else {
- bzero(value, xattr_size + 1);
- if (filler->real_path) {
- xattr_size = sys_lgetxattr (filler->real_path,
- key, value, xattr_size);
- } else {
- xattr_size = sys_fgetxattr (filler->fdnum, key,
- value, xattr_size);
- }
- }
- if (xattr_size == -1) {
- if (filler->real_path)
- gf_msg (filler->this->name, GF_LOG_WARNING, 0,
- P_MSG_XATTR_FAILED,
- "getxattr failed. path: %s, key: %s",
- filler->real_path, key);
- else
- gf_msg (filler->this->name, GF_LOG_WARNING, 0,
- P_MSG_XATTR_FAILED,
- "getxattr failed. gfid: %s, key: %s",
- uuid_utoa (filler->fd->inode->gfid),
- key);
- GF_FREE (value);
- goto out;
- }
-
- value[xattr_size] = '\0';
- ret = dict_set_bin (filler->xattr, key, value, xattr_size);
- if (ret < 0) {
- if (filler->real_path)
- gf_msg_debug (filler->this->name, 0,
- "dict set failed. path: %s, key: %s",
- filler->real_path, key);
- else
- gf_msg_debug (filler->this->name, 0,
- "dict set failed. gfid: %s, key: %s",
- uuid_utoa (filler->fd->inode->gfid),
- key);
- GF_FREE (value);
- goto out;
- }
- }
- ret = 0;
+ bzero(value, xattr_size + 1);
+ if (filler->real_path) {
+ xattr_size = sys_lgetxattr(filler->real_path, key, value,
+ xattr_size);
+ } else {
+ xattr_size = sys_fgetxattr(filler->fdnum, key, value,
+ xattr_size);
+ }
+ }
+ if (xattr_size == -1) {
+ if (filler->real_path)
+ gf_msg(filler->this->name, GF_LOG_WARNING, 0,
+ P_MSG_XATTR_FAILED, "getxattr failed. path: %s, key: %s",
+ filler->real_path, key);
+ else
+ gf_msg(filler->this->name, GF_LOG_WARNING, 0,
+ P_MSG_XATTR_FAILED, "getxattr failed. gfid: %s, key: %s",
+ uuid_utoa(filler->fd->inode->gfid), key);
+ GF_FREE(value);
+ goto out;
+ }
+
+ value[xattr_size] = '\0';
+ ret = dict_set_bin(filler->xattr, key, value, xattr_size);
+ if (ret < 0) {
+ if (filler->real_path)
+ gf_msg_debug(filler->this->name, 0,
+ "dict set failed. path: %s, key: %s",
+ filler->real_path, key);
+ else
+ gf_msg_debug(filler->this->name, 0,
+ "dict set failed. gfid: %s, key: %s",
+ uuid_utoa(filler->fd->inode->gfid), key);
+ GF_FREE(value);
+ goto out;
+ }
+ }
+ ret = 0;
out:
- return ret;
+ return ret;
}
static int gf_posix_xattr_enotsup_log;
static int
-_posix_get_marker_all_contributions (posix_xattr_filler_t *filler)
-{
- ssize_t size = -1, remaining_size = -1, list_offset = 0;
- int ret = -1;
- int len;
- char *list = NULL, key[4096] = {0, };
-
- if (filler->real_path)
- size = sys_llistxattr (filler->real_path, NULL, 0);
- else
- size = sys_flistxattr (filler->fdnum, NULL, 0);
- if (size == -1) {
- if ((errno == ENOTSUP) || (errno == ENOSYS)) {
- GF_LOG_OCCASIONALLY (gf_posix_xattr_enotsup_log,
- THIS->name, GF_LOG_WARNING,
- "Extended attributes not "
- "supported (try remounting brick"
- " with 'user_xattr' flag)");
- } else {
- if (filler->real_path)
- gf_msg (THIS->name, GF_LOG_WARNING, errno,
- P_MSG_XATTR_FAILED,
- "listxattr failed on %s",
- filler->real_path);
- else
- gf_msg (THIS->name, GF_LOG_WARNING, errno,
- P_MSG_XATTR_FAILED,
- "listxattr failed on %s",
- uuid_utoa (filler->fd->inode->gfid));
- }
- goto out;
- }
-
- if (size == 0) {
- ret = 0;
- goto out;
- }
-
- list = alloca (size);
- if (!list) {
- goto out;
- }
-
- if (filler->real_path)
- size = sys_llistxattr (filler->real_path, list, size);
- else
- size = sys_flistxattr (filler->fdnum, list, size);
- if (size <= 0) {
- ret = size;
- goto out;
- }
-
- remaining_size = size;
- list_offset = 0;
-
- while (remaining_size > 0) {
- strcpy (key, list + list_offset);
- if (fnmatch (marker_contri_key, key, 0) == 0) {
- ret = _posix_xattr_get_set_from_backend (filler, key);
- }
- len = strlen (key);
- remaining_size -= (len + 1);
- list_offset += (len + 1);
- }
-
+_posix_get_marker_all_contributions(posix_xattr_filler_t *filler)
+{
+ ssize_t size = -1, remaining_size = -1, list_offset = 0;
+ int ret = -1;
+ int len;
+ char *list = NULL, key[4096] = {
+ 0,
+ };
+
+ if (filler->real_path)
+ size = sys_llistxattr(filler->real_path, NULL, 0);
+ else
+ size = sys_flistxattr(filler->fdnum, NULL, 0);
+ if (size == -1) {
+ if ((errno == ENOTSUP) || (errno == ENOSYS)) {
+ GF_LOG_OCCASIONALLY(gf_posix_xattr_enotsup_log, THIS->name,
+ GF_LOG_WARNING,
+ "Extended attributes not "
+ "supported (try remounting brick"
+ " with 'user_xattr' flag)");
+ } else {
+ if (filler->real_path)
+ gf_msg(THIS->name, GF_LOG_WARNING, errno, P_MSG_XATTR_FAILED,
+ "listxattr failed on %s", filler->real_path);
+ else
+ gf_msg(THIS->name, GF_LOG_WARNING, errno, P_MSG_XATTR_FAILED,
+ "listxattr failed on %s",
+ uuid_utoa(filler->fd->inode->gfid));
+ }
+ goto out;
+ }
+
+ if (size == 0) {
ret = 0;
+ goto out;
+ }
+
+ list = alloca(size);
+ if (!list) {
+ goto out;
+ }
+
+ if (filler->real_path)
+ size = sys_llistxattr(filler->real_path, list, size);
+ else
+ size = sys_flistxattr(filler->fdnum, list, size);
+ if (size <= 0) {
+ ret = size;
+ goto out;
+ }
+
+ remaining_size = size;
+ list_offset = 0;
+
+ while (remaining_size > 0) {
+ strcpy(key, list + list_offset);
+ if (fnmatch(marker_contri_key, key, 0) == 0) {
+ ret = _posix_xattr_get_set_from_backend(filler, key);
+ }
+ len = strlen(key);
+ remaining_size -= (len + 1);
+ list_offset += (len + 1);
+ }
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
static int
-_posix_get_marker_quota_contributions (posix_xattr_filler_t *filler, char *key)
+_posix_get_marker_quota_contributions(posix_xattr_filler_t *filler, char *key)
{
- char *saveptr = NULL, *token = NULL, *tmp_key = NULL;
- char *ptr = NULL;
- int i = 0, ret = 0;
+ char *saveptr = NULL, *token = NULL, *tmp_key = NULL;
+ char *ptr = NULL;
+ int i = 0, ret = 0;
- tmp_key = ptr = gf_strdup (key);
- for (i = 0; i < 4; i++) {
- token = strtok_r (tmp_key, ".", &saveptr);
- tmp_key = NULL;
- }
+ tmp_key = ptr = gf_strdup(key);
+ for (i = 0; i < 4; i++) {
+ token = strtok_r(tmp_key, ".", &saveptr);
+ tmp_key = NULL;
+ }
- if (strncmp (token, "contri", SLEN ("contri")) == 0) {
- ret = _posix_get_marker_all_contributions (filler);
- } else {
- ret = _posix_xattr_get_set_from_backend (filler, key);
- }
+ if (strncmp(token, "contri", SLEN("contri")) == 0) {
+ ret = _posix_get_marker_all_contributions(filler);
+ } else {
+ ret = _posix_xattr_get_set_from_backend(filler, key);
+ }
- GF_FREE (ptr);
+ GF_FREE(ptr);
- return ret;
+ return ret;
}
static inode_t *
-_get_filler_inode (posix_xattr_filler_t *filler)
+_get_filler_inode(posix_xattr_filler_t *filler)
{
- if (filler->fd)
- return filler->fd->inode;
- else if (filler->loc && filler->loc->inode)
- return filler->loc->inode;
- else
- return NULL;
+ if (filler->fd)
+ return filler->fd->inode;
+ else if (filler->loc && filler->loc->inode)
+ return filler->loc->inode;
+ else
+ return NULL;
}
static int
-_posix_xattr_get_set (dict_t *xattr_req, char *key, data_t *data,
- void *xattrargs)
-{
- posix_xattr_filler_t *filler = xattrargs;
- int ret = -1;
- int len;
- char *databuf = NULL;
- int _fd = -1;
- ssize_t req_size = 0;
- int32_t list_offset = 0;
- ssize_t remaining_size = 0;
- char *xattr = NULL;
- inode_t *inode = NULL;
-
- if (posix_xattr_ignorable (key))
- goto out;
- /* should size be put into the data_t ? */
- if (!strcmp (key, GF_CONTENT_KEY)
- && IA_ISREG (filler->stbuf->ia_type)) {
- if (!filler->real_path)
- goto out;
-
- /* file content request */
- req_size = data_to_uint64 (data);
- if (req_size >= filler->stbuf->ia_size) {
- _fd = open (filler->real_path, O_RDONLY);
- if (_fd == -1) {
- gf_msg (filler->this->name, GF_LOG_ERROR, errno,
- P_MSG_XDATA_GETXATTR,
- "Opening file %s failed",
- filler->real_path);
- goto err;
- }
-
- /*
- * There could be a situation where the ia_size is
- * zero. GF_CALLOC will return a pointer to the
- * memory initialized by gf_mem_set_acct_info.
- * This function adds a header and a footer to
- * the allocated memory. The returned pointer
- * points to the memory just after the header, but
- * when size is zero, there is no space for user
- * data. The memory can be freed by calling GF_FREE.
- */
- databuf = GF_CALLOC (1, filler->stbuf->ia_size,
- gf_posix_mt_char);
- if (!databuf) {
- goto err;
- }
-
- ret = sys_read (_fd, databuf, filler->stbuf->ia_size);
- if (ret == -1) {
- gf_msg (filler->this->name, GF_LOG_ERROR, errno,
- P_MSG_XDATA_GETXATTR,
- "Read on file %s failed",
- filler->real_path);
- goto err;
- }
-
- ret = sys_close (_fd);
- _fd = -1;
- if (ret == -1) {
- gf_msg (filler->this->name, GF_LOG_ERROR, errno,
- P_MSG_XDATA_GETXATTR,
- "Close on file %s failed",
- filler->real_path);
- goto err;
- }
-
- ret = dict_set_bin (filler->xattr, key,
- databuf, filler->stbuf->ia_size);
- if (ret < 0) {
- gf_msg (filler->this->name, GF_LOG_ERROR, 0,
- P_MSG_XDATA_GETXATTR,
- "failed to set dict value. key: %s,"
- "path: %s",
- key, filler->real_path);
- goto err;
- }
-
- /* To avoid double free in cleanup below */
- databuf = NULL;
- err:
- if (_fd != -1)
- sys_close (_fd);
- GF_FREE (databuf);
- }
- } else if (!strcmp (key, GLUSTERFS_OPEN_FD_COUNT)) {
- inode = _get_filler_inode (filler);
- if (!inode || gf_uuid_is_null (inode->gfid))
- goto out;
- ret = dict_set_uint32 (filler->xattr, key, inode->fd_count);
- if (ret < 0) {
- gf_msg (filler->this->name, GF_LOG_WARNING, 0,
- P_MSG_DICT_SET_FAILED,
- "Failed to set dictionary value for %s", key);
- }
- } else if (!strcmp (key, GLUSTERFS_ACTIVE_FD_COUNT)) {
- inode = _get_filler_inode (filler);
- if (!inode || gf_uuid_is_null (inode->gfid))
- goto out;
- ret = dict_set_uint32 (filler->xattr, key,
- inode->active_fd_count);
- if (ret < 0) {
- gf_msg (filler->this->name, GF_LOG_WARNING, 0,
- P_MSG_DICT_SET_FAILED,
- "Failed to set dictionary value for %s", key);
- }
- } else if (!strcmp (key, GET_ANCESTRY_PATH_KEY)) {
- /* As of now, the only consumers of POSIX_ANCESTRY_PATH attempt
- * fetching it via path-based fops. Hence, leaving it as it is
- * for now.
- */
- if (!filler->real_path)
- goto out;
- char *path = NULL;
- ret = posix_get_ancestry (filler->this, filler->loc->inode,
- NULL, &path, POSIX_ANCESTRY_PATH,
- &filler->op_errno, xattr_req);
- if (ret < 0) {
- goto out;
- }
+_posix_xattr_get_set(dict_t *xattr_req, char *key, data_t *data,
+ void *xattrargs)
+{
+ posix_xattr_filler_t *filler = xattrargs;
+ int ret = -1;
+ int len;
+ char *databuf = NULL;
+ int _fd = -1;
+ ssize_t req_size = 0;
+ int32_t list_offset = 0;
+ ssize_t remaining_size = 0;
+ char *xattr = NULL;
+ inode_t *inode = NULL;
+
+ if (posix_xattr_ignorable(key))
+ goto out;
+ /* should size be put into the data_t ? */
+ if (!strcmp(key, GF_CONTENT_KEY) && IA_ISREG(filler->stbuf->ia_type)) {
+ if (!filler->real_path)
+ goto out;
+
+ /* file content request */
+ req_size = data_to_uint64(data);
+ if (req_size >= filler->stbuf->ia_size) {
+ _fd = open(filler->real_path, O_RDONLY);
+ if (_fd == -1) {
+ gf_msg(filler->this->name, GF_LOG_ERROR, errno,
+ P_MSG_XDATA_GETXATTR, "Opening file %s failed",
+ filler->real_path);
+ goto err;
+ }
+
+ /*
+ * There could be a situation where the ia_size is
+ * zero. GF_CALLOC will return a pointer to the
+ * memory initialized by gf_mem_set_acct_info.
+ * This function adds a header and a footer to
+ * the allocated memory. The returned pointer
+ * points to the memory just after the header, but
+ * when size is zero, there is no space for user
+ * data. The memory can be freed by calling GF_FREE.
+ */
+ databuf = GF_CALLOC(1, filler->stbuf->ia_size, gf_posix_mt_char);
+ if (!databuf) {
+ goto err;
+ }
+
+ ret = sys_read(_fd, databuf, filler->stbuf->ia_size);
+ if (ret == -1) {
+ gf_msg(filler->this->name, GF_LOG_ERROR, errno,
+ P_MSG_XDATA_GETXATTR, "Read on file %s failed",
+ filler->real_path);
+ goto err;
+ }
+
+ ret = sys_close(_fd);
+ _fd = -1;
+ if (ret == -1) {
+ gf_msg(filler->this->name, GF_LOG_ERROR, errno,
+ P_MSG_XDATA_GETXATTR, "Close on file %s failed",
+ filler->real_path);
+ goto err;
+ }
+
+ ret = dict_set_bin(filler->xattr, key, databuf,
+ filler->stbuf->ia_size);
+ if (ret < 0) {
+ gf_msg(filler->this->name, GF_LOG_ERROR, 0,
+ P_MSG_XDATA_GETXATTR,
+ "failed to set dict value. key: %s,"
+ "path: %s",
+ key, filler->real_path);
+ goto err;
+ }
+
+ /* To avoid double free in cleanup below */
+ databuf = NULL;
+ err:
+ if (_fd != -1)
+ sys_close(_fd);
+ GF_FREE(databuf);
+ }
+ } else if (!strcmp(key, GLUSTERFS_OPEN_FD_COUNT)) {
+ inode = _get_filler_inode(filler);
+ if (!inode || gf_uuid_is_null(inode->gfid))
+ goto out;
+ ret = dict_set_uint32(filler->xattr, key, inode->fd_count);
+ if (ret < 0) {
+ gf_msg(filler->this->name, GF_LOG_WARNING, 0, P_MSG_DICT_SET_FAILED,
+ "Failed to set dictionary value for %s", key);
+ }
+ } else if (!strcmp(key, GLUSTERFS_ACTIVE_FD_COUNT)) {
+ inode = _get_filler_inode(filler);
+ if (!inode || gf_uuid_is_null(inode->gfid))
+ goto out;
+ ret = dict_set_uint32(filler->xattr, key, inode->active_fd_count);
+ if (ret < 0) {
+ gf_msg(filler->this->name, GF_LOG_WARNING, 0, P_MSG_DICT_SET_FAILED,
+ "Failed to set dictionary value for %s", key);
+ }
+ } else if (!strcmp(key, GET_ANCESTRY_PATH_KEY)) {
+ /* As of now, the only consumers of POSIX_ANCESTRY_PATH attempt
+ * fetching it via path-based fops. Hence, leaving it as it is
+ * for now.
+ */
+ if (!filler->real_path)
+ goto out;
+ char *path = NULL;
+ ret = posix_get_ancestry(filler->this, filler->loc->inode, NULL, &path,
+ POSIX_ANCESTRY_PATH, &filler->op_errno,
+ xattr_req);
+ if (ret < 0) {
+ goto out;
+ }
- r