summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix
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/posix
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/posix')
-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
9 files changed, 11956 insertions, 12209 deletions
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;
+ }
- ret = dict_set_dynstr (filler->xattr, GET_ANCESTRY_PATH_KEY,
- path);
- if (ret < 0) {
- GF_FREE (path);
- goto out;
- }
+ ret = dict_set_dynstr(filler->xattr, GET_ANCESTRY_PATH_KEY, path);
+ if (ret < 0) {
+ GF_FREE(path);
+ goto out;
+ }
- } else if (fnmatch (marker_contri_key, key, 0) == 0) {
- ret = _posix_get_marker_quota_contributions (filler, key);
- } else if (strcmp(key, GF_REQUEST_LINK_COUNT_XDATA) == 0) {
- ret = dict_set (filler->xattr,
- GF_REQUEST_LINK_COUNT_XDATA, data);
- } else if (strcmp (key, GF_GET_SIZE) == 0) {
- if (filler->stbuf && IA_ISREG (filler->stbuf->ia_type)) {
- ret = dict_set_uint64 (filler->xattr, GF_GET_SIZE,
- filler->stbuf->ia_size);
- }
- } else {
- remaining_size = filler->list_size;
- while (remaining_size > 0) {
- xattr = filler->list + list_offset;
- if (fnmatch (key, xattr, 0) == 0)
- ret = _posix_xattr_get_set_from_backend (filler,
- xattr);
- len = strlen (xattr);
- remaining_size -= (len + 1);
- list_offset += (len + 1);
- }
+ } else if (fnmatch(marker_contri_key, key, 0) == 0) {
+ ret = _posix_get_marker_quota_contributions(filler, key);
+ } else if (strcmp(key, GF_REQUEST_LINK_COUNT_XDATA) == 0) {
+ ret = dict_set(filler->xattr, GF_REQUEST_LINK_COUNT_XDATA, data);
+ } else if (strcmp(key, GF_GET_SIZE) == 0) {
+ if (filler->stbuf && IA_ISREG(filler->stbuf->ia_type)) {
+ ret = dict_set_uint64(filler->xattr, GF_GET_SIZE,
+ filler->stbuf->ia_size);
}
+ } else {
+ remaining_size = filler->list_size;
+ while (remaining_size > 0) {
+ xattr = filler->list + list_offset;
+ if (fnmatch(key, xattr, 0) == 0)
+ ret = _posix_xattr_get_set_from_backend(filler, xattr);
+ len = strlen(xattr);
+ remaining_size -= (len + 1);
+ list_offset += (len + 1);
+ }
+ }
out:
- return 0;
+ return 0;
}
int
-posix_fill_gfid_path (xlator_t *this, const char *path, struct iatt *iatt)
+posix_fill_gfid_path(xlator_t *this, const char *path, struct iatt *iatt)
{
- int ret = 0;
- ssize_t size = 0;
+ int ret = 0;
+ ssize_t size = 0;
- if (!iatt)
- return 0;
+ if (!iatt)
+ return 0;
- size = sys_lgetxattr (path, GFID_XATTR_KEY, iatt->ia_gfid, 16);
- /* Return value of getxattr */
- if ((size == 16) || (size == -1))
- ret = 0;
- else
- ret = size;
+ size = sys_lgetxattr(path, GFID_XATTR_KEY, iatt->ia_gfid, 16);
+ /* Return value of getxattr */
+ if ((size == 16) || (size == -1))
+ ret = 0;
+ else
+ ret = size;
- return ret;
+ return ret;
}
-
int
-posix_fill_gfid_fd (xlator_t *this, int fd, struct iatt *iatt)
+posix_fill_gfid_fd(xlator_t *this, int fd, struct iatt *iatt)
{
- int ret = 0;
- ssize_t size = 0;
+ int ret = 0;
+ ssize_t size = 0;
- if (!iatt)
- return 0;
+ if (!iatt)
+ return 0;
- size = sys_fgetxattr (fd, GFID_XATTR_KEY, iatt->ia_gfid, 16);
- /* Return value of getxattr */
- if ((size == 16) || (size == -1))
- ret = 0;
- else
- ret = size;
+ size = sys_fgetxattr(fd, GFID_XATTR_KEY, iatt->ia_gfid, 16);
+ /* Return value of getxattr */
+ if ((size == 16) || (size == -1))
+ ret = 0;
+ else
+ ret = size;
- return ret;
+ return ret;
}
void
-posix_fill_ino_from_gfid (xlator_t *this, struct iatt *buf)
-{
- /* consider least significant 8 bytes of value out of gfid */
- if (gf_uuid_is_null (buf->ia_gfid)) {
- buf->ia_ino = -1;
- goto out;
- }
- buf->ia_ino = gfid_to_ino (buf->ia_gfid);
- buf->ia_flags |= IATT_INO;
+posix_fill_ino_from_gfid(xlator_t *this, struct iatt *buf)
+{
+ /* consider least significant 8 bytes of value out of gfid */
+ if (gf_uuid_is_null(buf->ia_gfid)) {
+ buf->ia_ino = -1;
+ goto out;
+ }
+ buf->ia_ino = gfid_to_ino(buf->ia_gfid);
+ buf->ia_flags |= IATT_INO;
out:
- return;
+ return;
}
int
-posix_fdstat (xlator_t *this, inode_t *inode, int fd, struct iatt *stbuf_p)
+posix_fdstat(xlator_t *this, inode_t *inode, int fd, struct iatt *stbuf_p)
{
- int ret = 0;
- struct stat fstatbuf = {0, };
- struct iatt stbuf = {0, };
- struct posix_private *priv = NULL;
+ int ret = 0;
+ struct stat fstatbuf = {
+ 0,
+ };
+ struct iatt stbuf = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
- priv = this->private;
+ priv = this->private;
- ret = sys_fstat (fd, &fstatbuf);
- if (ret == -1)
- goto out;
+ ret = sys_fstat(fd, &fstatbuf);
+ if (ret == -1)
+ goto out;
- if (fstatbuf.st_nlink && !S_ISDIR (fstatbuf.st_mode))
- fstatbuf.st_nlink--;
+ if (fstatbuf.st_nlink && !S_ISDIR(fstatbuf.st_mode))
+ fstatbuf.st_nlink--;
- iatt_from_stat (&stbuf, &fstatbuf);
+ iatt_from_stat(&stbuf, &fstatbuf);
- if (inode && priv->ctime) {
- ret = posix_get_mdata_xattr (this, NULL, fd, inode, &stbuf);
- 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;
- }
+ if (inode && priv->ctime) {
+ ret = posix_get_mdata_xattr(this, NULL, fd, inode, &stbuf);
+ 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;
}
- ret = posix_fill_gfid_fd (this, fd, &stbuf);
- stbuf.ia_flags |= IATT_GFID;
+ }
+ ret = posix_fill_gfid_fd(this, fd, &stbuf);
+ stbuf.ia_flags |= IATT_GFID;
- posix_fill_ino_from_gfid (this, &stbuf);
+ posix_fill_ino_from_gfid(this, &stbuf);
- if (stbuf_p)
- *stbuf_p = stbuf;
+ if (stbuf_p)
+ *stbuf_p = stbuf;
out:
- return ret;
+ return ret;
}
-
/* The inode here is expected to update posix_mdata stored on disk.
* Don't use it as a general purpose inode and don't expect it to
* be always exists
*/
int
-posix_istat (xlator_t *this, inode_t *inode, uuid_t gfid, const char *basename,
- struct iatt *buf_p)
-{
- char *real_path = NULL;
- struct stat lstatbuf = {0, };
- struct iatt stbuf = {0, };
- int ret = 0;
- struct posix_private *priv = NULL;
-
- priv = this->private;
-
- MAKE_HANDLE_PATH (real_path, this, gfid, basename);
- if (!real_path) {
- gf_msg (this->name, GF_LOG_ERROR, ESTALE,
- P_MSG_HANDLE_PATH_CREATE,
- "Failed to create handle path for %s/%s",
- uuid_utoa (gfid), basename ? basename : "");
- errno = ESTALE;
- ret = -1;
- goto out;
- }
-
- ret = sys_lstat (real_path, &lstatbuf);
-
- if (ret != 0) {
- if (ret == -1) {
- if (errno != ENOENT && errno != ELOOP)
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_LSTAT_FAILED,
- "lstat failed on %s",
- real_path);
- } else {
- // may be some backend filesystem issue
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_LSTAT_FAILED,
- "lstat failed on %s and return value is %d "
- "instead of -1. Please see dmesg output to "
- "check whether the failure is due to backend "
- "filesystem issue", real_path, ret);
- ret = -1;
- }
- goto out;
- }
-
- if ((lstatbuf.st_ino == priv->handledir.st_ino) &&
- (lstatbuf.st_dev == priv->handledir.st_dev)) {
- errno = ENOENT;
- return -1;
- }
+posix_istat(xlator_t *this, inode_t *inode, uuid_t gfid, const char *basename,
+ struct iatt *buf_p)
+{
+ char *real_path = NULL;
+ struct stat lstatbuf = {
+ 0,
+ };
+ struct iatt stbuf = {
+ 0,
+ };
+ int ret = 0;
+ struct posix_private *priv = NULL;
+
+ priv = this->private;
+
+ MAKE_HANDLE_PATH(real_path, this, gfid, basename);
+ if (!real_path) {
+ gf_msg(this->name, GF_LOG_ERROR, ESTALE, P_MSG_HANDLE_PATH_CREATE,
+ "Failed to create handle path for %s/%s", uuid_utoa(gfid),
+ basename ? basename : "");
+ errno = ESTALE;
+ ret = -1;
+ goto out;
+ }
+
+ ret = sys_lstat(real_path, &lstatbuf);
+
+ if (ret != 0) {
+ if (ret == -1) {
+ if (errno != ENOENT && errno != ELOOP)
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_LSTAT_FAILED,
+ "lstat failed on %s", real_path);
+ } else {
+ // may be some backend filesystem issue
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_LSTAT_FAILED,
+ "lstat failed on %s and return value is %d "
+ "instead of -1. Please see dmesg output to "
+ "check whether the failure is due to backend "
+ "filesystem issue",
+ real_path, ret);
+ ret = -1;
+ }
+ goto out;
+ }
+
+ if ((lstatbuf.st_ino == priv->handledir.st_ino) &&
+ (lstatbuf.st_dev == priv->handledir.st_dev)) {
+ errno = ENOENT;
+ return -1;
+ }
- if (!S_ISDIR (lstatbuf.st_mode))
- lstatbuf.st_nlink --;
+ if (!S_ISDIR(lstatbuf.st_mode))
+ lstatbuf.st_nlink--;
- iatt_from_stat (&stbuf, &lstatbuf);
+ iatt_from_stat(&stbuf, &lstatbuf);
- if (inode && priv->ctime) {
- ret = posix_get_mdata_xattr (this, real_path, -1, inode,
- &stbuf);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_GETMDATA_FAILED,
- "posix get mdata failed on %s", real_path);
- goto out;
- }
+ if (inode && priv->ctime) {
+ ret = posix_get_mdata_xattr(this, real_path, -1, inode, &stbuf);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_GETMDATA_FAILED,
+ "posix get mdata failed on %s", real_path);
+ goto out;
}
+ }
- if (basename)
- posix_fill_gfid_path (this, real_path, &stbuf);
- else
- gf_uuid_copy (stbuf.ia_gfid, gfid);
- stbuf.ia_flags |= IATT_GFID;
+ if (basename)
+ posix_fill_gfid_path(this, real_path, &stbuf);
+ else
+ gf_uuid_copy(stbuf.ia_gfid, gfid);
+ stbuf.ia_flags |= IATT_GFID;
- posix_fill_ino_from_gfid (this, &stbuf);
+ posix_fill_ino_from_gfid(this, &stbuf);
- if (buf_p)
- *buf_p = stbuf;
+ if (buf_p)
+ *buf_p = stbuf;
out:
- return ret;
+ return ret;
}
-
-
int
-posix_pstat (xlator_t *this, inode_t *inode, uuid_t gfid, const char *path,
- struct iatt *buf_p, gf_boolean_t inode_locked)
-{
- struct stat lstatbuf = {0, };
- struct iatt stbuf = {0, };
- int ret = 0;
- int op_errno = 0;
- struct posix_private *priv = NULL;
-
-
- priv = this->private;
+posix_pstat(xlator_t *this, inode_t *inode, uuid_t gfid, const char *path,
+ struct iatt *buf_p, gf_boolean_t inode_locked)
+{
+ struct stat lstatbuf = {
+ 0,
+ };
+ struct iatt stbuf = {
+ 0,
+ };
+ int ret = 0;
+ int op_errno = 0;
+ struct posix_private *priv = NULL;
+
+ priv = this->private;
+
+ if (gfid && !gf_uuid_is_null(gfid))
+ gf_uuid_copy(stbuf.ia_gfid, gfid);
+ else
+ posix_fill_gfid_path(this, path, &stbuf);
+ stbuf.ia_flags |= IATT_GFID;
+
+ ret = sys_lstat(path, &lstatbuf);
+ if (ret == -1) {
+ if (errno != ENOENT) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_LSTAT_FAILED,
+ "lstat failed on %s", path);
+ errno = op_errno; /*gf_msg could have changed errno*/
+ }
+ goto out;
+ }
+
+ if ((lstatbuf.st_ino == priv->handledir.st_ino) &&
+ (lstatbuf.st_dev == priv->handledir.st_dev)) {
+ errno = ENOENT;
+ return -1;
+ }
- if (gfid && !gf_uuid_is_null (gfid))
- gf_uuid_copy (stbuf.ia_gfid, gfid);
- else
- posix_fill_gfid_path (this, path, &stbuf);
- stbuf.ia_flags |= IATT_GFID;
+ if (!S_ISDIR(lstatbuf.st_mode))
+ lstatbuf.st_nlink--;
- ret = sys_lstat (path, &lstatbuf);
- if (ret == -1) {
- if (errno != ENOENT) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_LSTAT_FAILED, "lstat failed on %s", path);
- errno = op_errno;/*gf_msg could have changed errno*/
- }
- goto out;
- }
+ iatt_from_stat(&stbuf, &lstatbuf);
- if ((lstatbuf.st_ino == priv->handledir.st_ino) &&
- (lstatbuf.st_dev == priv->handledir.st_dev)) {
- errno = ENOENT;
- return -1;
+ if (inode && priv->ctime) {
+ if (!inode_locked) {
+ ret = posix_get_mdata_xattr(this, path, -1, inode, &stbuf);
+ } else {
+ ret = __posix_get_mdata_xattr(this, path, -1, inode, &stbuf);
}
-
- if (!S_ISDIR (lstatbuf.st_mode))
- lstatbuf.st_nlink --;
-
- iatt_from_stat (&stbuf, &lstatbuf);
-
- if (inode && priv->ctime) {
- if (!inode_locked) {
- ret = posix_get_mdata_xattr (this, path, -1, inode, &stbuf);
- } else {
- ret = __posix_get_mdata_xattr (this, path, -1, inode, &stbuf);
- }
- 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;
- }
+ 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;
}
+ }
- posix_fill_ino_from_gfid (this, &stbuf);
+ posix_fill_ino_from_gfid(this, &stbuf);
- if (buf_p)
- *buf_p = stbuf;
+ if (buf_p)
+ *buf_p = stbuf;
out:
- return ret;
+ return ret;
}
-
static void
-_get_list_xattr (posix_xattr_filler_t *filler)
+_get_list_xattr(posix_xattr_filler_t *filler)
{
- ssize_t size = 0;
+ ssize_t size = 0;
- if ((!filler) || ((!filler->real_path) && (filler->fdnum < 0)))
- goto out;
+ if ((!filler) || ((!filler->real_path) && (filler->fdnum < 0)))
+ goto out;
- if (filler->real_path)
- size = sys_llistxattr (filler->real_path, NULL, 0);
- else
- size = sys_flistxattr (filler->fdnum, NULL, 0);
+ if (filler->real_path)
+ size = sys_llistxattr(filler->real_path, NULL, 0);
+ else
+ size = sys_flistxattr(filler->fdnum, NULL, 0);
- if (size <= 0)
- goto out;
+ if (size <= 0)
+ goto out;
- filler->list = GF_CALLOC (1, size, gf_posix_mt_char);
- if (!filler->list)
- goto out;
+ filler->list = GF_CALLOC(1, size, gf_posix_mt_char);
+ if (!filler->list)
+ goto out;
- if (filler->real_path)
- size = sys_llistxattr (filler->real_path, filler->list, size);
- else
- size = sys_flistxattr (filler->fdnum, filler->list, size);
+ if (filler->real_path)
+ size = sys_llistxattr(filler->real_path, filler->list, size);
+ else
+ size = sys_flistxattr(filler->fdnum, filler->list, size);
- filler->list_size = size;
+ filler->list_size = size;
out:
- return;
+ return;
}
-
static void
-_handle_list_xattr (dict_t *xattr_req, const char *real_path, int fdnum,
- posix_xattr_filler_t *filler)
+_handle_list_xattr(dict_t *xattr_req, const char *real_path, int fdnum,
+ posix_xattr_filler_t *filler)
{
- int32_t list_offset = 0;
- ssize_t remaining_size = 0;
- char *key = NULL;
- int len;
+ int32_t list_offset = 0;
+ ssize_t remaining_size = 0;
+ char *key = NULL;
+ int len;
- list_offset = 0;
- remaining_size = filler->list_size;
- while (remaining_size > 0) {
- key = filler->list + list_offset;
+ list_offset = 0;
+ remaining_size = filler->list_size;
+ while (remaining_size > 0) {
+ key = filler->list + list_offset;
- if (gf_get_index_by_elem (list_xattr_ignore_xattrs, key) >= 0)
- goto next;
+ if (gf_get_index_by_elem(list_xattr_ignore_xattrs, key) >= 0)
+ goto next;
- if (posix_special_xattr (marker_xattrs, key))
- goto next;
+ if (posix_special_xattr(marker_xattrs, key))
+ goto next;
- if (posix_handle_georep_xattrs (NULL, key, NULL, _gf_false))
- goto next;
+ if (posix_handle_georep_xattrs(NULL, key, NULL, _gf_false))
+ goto next;
- if (posix_is_gfid2path_xattr (key))
- goto next;
+ if (posix_is_gfid2path_xattr(key))
+ goto next;
- if (dict_get (filler->xattr, key))
- goto next;
+ if (dict_get(filler->xattr, key))
+ goto next;
- (void) _posix_xattr_get_set_from_backend (filler, key);
-next:
- len = strlen (key);
- remaining_size -= (len + 1);
- list_offset += (len + 1);
+ (void)_posix_xattr_get_set_from_backend(filler, key);
+ next:
+ len = strlen(key);
+ remaining_size -= (len + 1);
+ list_offset += (len + 1);
- } /* while (remaining_size > 0) */
- return;
+ } /* while (remaining_size > 0) */
+ return;
}
dict_t *
-posix_xattr_fill (xlator_t *this, const char *real_path, loc_t *loc, fd_t *fd,
- int fdnum, dict_t *xattr_req, struct iatt *buf)
-{
- dict_t *xattr = NULL;
- posix_xattr_filler_t filler = {0, };
- gf_boolean_t list = _gf_false;
-
- if (dict_get (xattr_req, "list-xattr")) {
- dict_del (xattr_req, "list-xattr");
- list = _gf_true;
- }
-
- xattr = dict_new ();
- if (!xattr) {
- goto out;
- }
-
- filler.this = this;
- filler.real_path = real_path;
- filler.xattr = xattr;
- filler.stbuf = buf;
- filler.loc = loc;
- filler.fd = fd;
- filler.fdnum = fdnum;
-
- _get_list_xattr (&filler);
- dict_foreach (xattr_req, _posix_xattr_get_set, &filler);
- if (list)
- _handle_list_xattr (xattr_req, real_path, fdnum, &filler);
-
- GF_FREE (filler.list);
+posix_xattr_fill(xlator_t *this, const char *real_path, loc_t *loc, fd_t *fd,
+ int fdnum, dict_t *xattr_req, struct iatt *buf)
+{
+ dict_t *xattr = NULL;
+ posix_xattr_filler_t filler = {
+ 0,
+ };
+ gf_boolean_t list = _gf_false;
+
+ if (dict_get(xattr_req, "list-xattr")) {
+ dict_del(xattr_req, "list-xattr");
+ list = _gf_true;
+ }
+
+ xattr = dict_new();
+ if (!xattr) {
+ goto out;
+ }
+
+ filler.this = this;
+ filler.real_path = real_path;
+ filler.xattr = xattr;
+ filler.stbuf = buf;
+ filler.loc = loc;
+ filler.fd = fd;
+ filler.fdnum = fdnum;
+
+ _get_list_xattr(&filler);
+ dict_foreach(xattr_req, _posix_xattr_get_set, &filler);
+ if (list)
+ _handle_list_xattr(xattr_req, real_path, fdnum, &filler);
+
+ GF_FREE(filler.list);
out:
- return xattr;
+ return xattr;
}
void
-posix_gfid_unset (xlator_t *this, dict_t *xdata)
+posix_gfid_unset(xlator_t *this, dict_t *xdata)
{
- uuid_t uuid = {0, };
- int ret = 0;
+ uuid_t uuid = {
+ 0,
+ };
+ int ret = 0;
- if (xdata == NULL)
- goto out;
+ if (xdata == NULL)
+ goto out;
- ret = dict_get_gfuuid (xdata, "gfid-req", &uuid);
- if (ret) {
- goto out;
- }
+ ret = dict_get_gfuuid(xdata, "gfid-req", &uuid);
+ if (ret) {
+ goto out;
+ }
- posix_handle_unset (this, uuid, NULL);
+ posix_handle_unset(this, uuid, NULL);
out:
- return;
+ return;
}
int
-posix_gfid_set (xlator_t *this, const char *path, loc_t *loc,
- dict_t *xattr_req, pid_t pid, int *op_errno)
-{
- uuid_t uuid_req;
- uuid_t uuid_curr;
- int ret = 0;
- ssize_t size = 0;
- struct stat stat = {0, };
-
- *op_errno = 0;
-
- if (!xattr_req) {
- if (pid != GF_SERVER_PID_TRASH) {
- gf_msg (this->name, GF_LOG_ERROR, EINVAL,
- P_MSG_INVALID_ARGUMENT, "xattr_req is null");
- *op_errno = EINVAL;
- ret = -1;
- }
- goto out;
- }
-
- if (sys_lstat (path, &stat) != 0) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_LSTAT_FAILED, "lsatat on %s failed", path);
- goto out;
- }
-
- size = sys_lgetxattr (path, GFID_XATTR_KEY, uuid_curr, 16);
- if (size == 16) {
- ret = 0;
- goto verify_handle;
- }
-
- ret = dict_get_gfuuid (xattr_req, "gfid-req", &uuid_req);
- if (ret) {
- gf_msg_debug (this->name, 0,
- "failed to get the gfid from dict for %s",
- loc->path);
- *op_errno = -ret;
- ret = -1;
- goto out;
- }
- if (gf_uuid_is_null (uuid_req)) {
- gf_msg (this->name, GF_LOG_ERROR, EINVAL, P_MSG_NULL_GFID,
- "gfid is null for %s", loc ? loc->path : "");
- ret = -1;
- *op_errno = EINVAL;
- goto out;
- }
-
- ret = sys_lsetxattr (path, GFID_XATTR_KEY, uuid_req, 16, XATTR_CREATE);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_WARNING, errno, P_MSG_GFID_FAILED,
- "setting GFID on %s failed ", path);
- goto out;
- }
- gf_uuid_copy (uuid_curr, uuid_req);
+posix_gfid_set(xlator_t *this, const char *path, loc_t *loc, dict_t *xattr_req,
+ pid_t pid, int *op_errno)
+{
+ uuid_t uuid_req;
+ uuid_t uuid_curr;
+ int ret = 0;
+ ssize_t size = 0;
+ struct stat stat = {
+ 0,
+ };
+
+ *op_errno = 0;
+
+ if (!xattr_req) {
+ if (pid != GF_SERVER_PID_TRASH) {
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, P_MSG_INVALID_ARGUMENT,
+ "xattr_req is null");
+ *op_errno = EINVAL;
+ ret = -1;
+ }
+ goto out;
+ }
+
+ if (sys_lstat(path, &stat) != 0) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "lsatat on %s failed", path);
+ goto out;
+ }
+
+ size = sys_lgetxattr(path, GFID_XATTR_KEY, uuid_curr, 16);
+ if (size == 16) {
+ ret = 0;
+ goto verify_handle;
+ }
+
+ ret = dict_get_gfuuid(xattr_req, "gfid-req", &uuid_req);
+ if (ret) {
+ gf_msg_debug(this->name, 0, "failed to get the gfid from dict for %s",
+ loc->path);
+ *op_errno = -ret;
+ ret = -1;
+ goto out;
+ }
+ if (gf_uuid_is_null(uuid_req)) {
+ gf_msg(this->name, GF_LOG_ERROR, EINVAL, P_MSG_NULL_GFID,
+ "gfid is null for %s", loc ? loc->path : "");
+ ret = -1;
+ *op_errno = EINVAL;
+ goto out;
+ }
+
+ ret = sys_lsetxattr(path, GFID_XATTR_KEY, uuid_req, 16, XATTR_CREATE);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_GFID_FAILED,
+ "setting GFID on %s failed ", path);
+ goto out;
+ }
+ gf_uuid_copy(uuid_curr, uuid_req);
verify_handle:
- if (!S_ISDIR (stat.st_mode))
- ret = posix_handle_hard (this, path, uuid_curr, &stat);
- else
- ret = posix_handle_soft (this, path, loc, uuid_curr, &stat);
+ if (!S_ISDIR(stat.st_mode))
+ ret = posix_handle_hard(this, path, uuid_curr, &stat);
+ else
+ ret = posix_handle_soft(this, path, loc, uuid_curr, &stat);
out:
- if (!(*op_errno))
- *op_errno = errno;
- return ret;
+ if (!(*op_errno))
+ *op_errno = errno;
+ return ret;
}
-
#ifdef HAVE_SYS_ACL_H
int
-posix_pacl_set (const char *path, const char *key, const char *acl_s)
+posix_pacl_set(const char *path, const char *key, const char *acl_s)
{
- int ret = -1;
- acl_t acl = NULL;
- acl_type_t type = 0;
+ int ret = -1;
+ acl_t acl = NULL;
+ acl_type_t type = 0;
- type = gf_posix_acl_get_type (key);
+ type = gf_posix_acl_get_type(key);
- acl = acl_from_text (acl_s);
- ret = acl_set_file (path, type, acl);
- if (ret)
- /* posix_handle_pair expects ret to be the errno */
- ret = -errno;
+ acl = acl_from_text(acl_s);
+ ret = acl_set_file(path, type, acl);
+ if (ret)
+ /* posix_handle_pair expects ret to be the errno */
+ ret = -errno;
- acl_free (acl);
+ acl_free(acl);
- return ret;
+ return ret;
}
int
-posix_pacl_get (const char *path, const char *key, char **acl_s)
+posix_pacl_get(const char *path, const char *key, char **acl_s)
{
- int ret = -1;
- acl_t acl = NULL;
- acl_type_t type = 0;
- char *acl_tmp = NULL;
+ int ret = -1;
+ acl_t acl = NULL;
+ acl_type_t type = 0;
+ char *acl_tmp = NULL;
- type = gf_posix_acl_get_type (key);
- if (!type)
- return -1;
+ type = gf_posix_acl_get_type(key);
+ if (!type)
+ return -1;
- acl = acl_get_file (path, type);
- if (!acl)
- return -1;
+ acl = acl_get_file(path, type);
+ if (!acl)
+ return -1;
#ifdef HAVE_ACL_LIBACL_H
- acl_tmp = acl_to_any_text (acl, NULL, ',',
- TEXT_ABBREVIATE | TEXT_NUMERIC_IDS);
+ acl_tmp = acl_to_any_text(acl, NULL, ',',
+ TEXT_ABBREVIATE | TEXT_NUMERIC_IDS);
#else /* FreeBSD and the like */
- acl_tmp = acl_to_text_np (acl, NULL, ACL_TEXT_NUMERIC_IDS);
+ acl_tmp = acl_to_text_np(acl, NULL, ACL_TEXT_NUMERIC_IDS);
#endif
- if (!acl_tmp)
- goto free_acl;
+ if (!acl_tmp)
+ goto free_acl;
- *acl_s = gf_strdup (acl_tmp);
- if (*acl_s)
- ret = 0;
+ *acl_s = gf_strdup(acl_tmp);
+ if (*acl_s)
+ ret = 0;
- acl_free (acl_tmp);
+ acl_free(acl_tmp);
free_acl:
- acl_free (acl);
+ acl_free(acl);
- return ret;
+ return ret;
}
#else /* !HAVE_SYS_ACL_H (NetBSD) */
int
-posix_pacl_set (const char *path, const char *key, const char *acl_s)
+posix_pacl_set(const char *path, const char *key, const char *acl_s)
{
- errno = ENOTSUP;
- return -1;
+ errno = ENOTSUP;
+ return -1;
}
int
-posix_pacl_get (const char *path, const char *key, char **acl_s)
+posix_pacl_get(const char *path, const char *key, char **acl_s)
{
- errno = ENOTSUP;
- return -1;
+ errno = ENOTSUP;
+ return -1;
}
#endif
-
#ifdef GF_DARWIN_HOST_OS
-static
-void posix_dump_buffer (xlator_t *this, const char *real_path, const char *key,
- data_t *value, int flags)
-{
- char buffer[3*value->len+1];
- int index = 0;
- buffer[0] = 0;
- gf_loglevel_t log_level = gf_log_get_loglevel ();
- if (log_level == GF_LOG_TRACE) {
- char *data = (char *) value->data;
- for (index = 0; index < value->len; index++)
- sprintf(buffer+3*index, " %02x", data[index]);
- }
- gf_msg_debug (this->name, 0,
- "Dump %s: key:%s flags: %u length:%u data:%s ",
- real_path, key, flags, value->len,
- (log_level == GF_LOG_TRACE ? buffer : "<skipped in DEBUG>"));
+static void
+posix_dump_buffer(xlator_t *this, const char *real_path, const char *key,
+ data_t *value, int flags)
+{
+ char buffer[3 * value->len + 1];
+ int index = 0;
+ buffer[0] = 0;
+ gf_loglevel_t log_level = gf_log_get_loglevel();
+ if (log_level == GF_LOG_TRACE) {
+ char *data = (char *)value->data;
+ for (index = 0; index < value->len; index++)
+ sprintf(buffer + 3 * index, " %02x", data[index]);
+ }
+ gf_msg_debug(this->name, 0, "Dump %s: key:%s flags: %u length:%u data:%s ",
+ real_path, key, flags, value->len,
+ (log_level == GF_LOG_TRACE ? buffer : "<skipped in DEBUG>"));
}
#endif
int
-posix_handle_pair (xlator_t *this, const char *real_path,
- char *key, data_t *value, int flags, struct iatt *stbuf)
+posix_handle_pair(xlator_t *this, const char *real_path, char *key,
+ data_t *value, int flags, struct iatt *stbuf)
{
- int sys_ret = -1;
- int ret = 0;
+ int sys_ret = -1;
+ int ret = 0;
#ifdef GF_DARWIN_HOST_OS
- const int error_code = EINVAL;
+ const int error_code = EINVAL;
#else
- const int error_code = EEXIST;
+ const int error_code = EEXIST;
#endif
- if (XATTR_IS_PATHINFO (key)) {
- ret = -EACCES;
- goto out;
- } else if (posix_is_gfid2path_xattr (key)) {
- ret = -ENOTSUP;
- goto out;
- } else if (GF_POSIX_ACL_REQUEST (key)) {
- if (stbuf && IS_DHT_LINKFILE_MODE (stbuf))
- goto out;
- ret = posix_pacl_set (real_path, key, value->data);
- } else if (!strncmp(key, POSIX_ACL_ACCESS_XATTR, strlen(key))
- && stbuf && IS_DHT_LINKFILE_MODE (stbuf)) {
- goto out;
- } else if (!strncmp(key, GF_INTERNAL_CTX_KEY, strlen(key))) {
- /* ignore this key value pair */
- ret = 0;
- goto out;
- } else {
- sys_ret = sys_lsetxattr (real_path, key, value->data,
- value->len, flags);
+ if (XATTR_IS_PATHINFO(key)) {
+ ret = -EACCES;
+ goto out;
+ } else if (posix_is_gfid2path_xattr(key)) {
+ ret = -ENOTSUP;
+ goto out;
+ } else if (GF_POSIX_ACL_REQUEST(key)) {
+ if (stbuf && IS_DHT_LINKFILE_MODE(stbuf))
+ goto out;
+ ret = posix_pacl_set(real_path, key, value->data);
+ } else if (!strncmp(key, POSIX_ACL_ACCESS_XATTR, strlen(key)) && stbuf &&
+ IS_DHT_LINKFILE_MODE(stbuf)) {
+ goto out;
+ } else if (!strncmp(key, GF_INTERNAL_CTX_KEY, strlen(key))) {
+ /* ignore this key value pair */
+ ret = 0;
+ goto out;
+ } else {
+ sys_ret = sys_lsetxattr(real_path, key, value->data, value->len, flags);
#ifdef GF_DARWIN_HOST_OS
- posix_dump_buffer(this, real_path, key, value, flags);
+ posix_dump_buffer(this, real_path, key, value, flags);
#endif
- if (sys_ret < 0) {
- ret = -errno;
- if (errno == ENOENT) {
- if (!posix_special_xattr (marker_xattrs,
- key)) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_XATTR_FAILED,
- "setxattr on %s failed",
- real_path);
- }
- } else {
- if (errno == error_code) {
- gf_msg_debug (this->name, 0,
- "%s: key:%s"
- "flags: %u length:%d",
- real_path, key, flags,
- value->len);
- } else {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_XATTR_FAILED, "%s: key:%s"
- "flags: %u length:%d",
- real_path, key, flags,
- value->len);
- }
- }
-
- goto out;
+ if (sys_ret < 0) {
+ ret = -errno;
+ if (errno == ENOENT) {
+ if (!posix_special_xattr(marker_xattrs, key)) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "setxattr on %s failed", real_path);
+ }
+ } else {
+ if (errno == error_code) {
+ gf_msg_debug(this->name, 0,
+ "%s: key:%s"
+ "flags: %u length:%d",
+ real_path, key, flags, value->len);
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "%s: key:%s"
+ "flags: %u length:%d",
+ real_path, key, flags, value->len);
}
+ }
+
+ goto out;
}
+ }
out:
- return ret;
+ return ret;
}
int
-posix_fhandle_pair (call_frame_t *frame, xlator_t *this, int fd, char *key,
- data_t *value, int flags, struct iatt *stbuf, fd_t *_fd)
-{
- int sys_ret = -1;
- int ret = 0;
-
- if (XATTR_IS_PATHINFO (key)) {
- ret = -EACCES;
- goto out;
- } else if (posix_is_gfid2path_xattr (key)) {
- ret = -ENOTSUP;
- goto out;
- } else if (!strncmp(key, POSIX_ACL_ACCESS_XATTR, strlen(key))
- && stbuf && IS_DHT_LINKFILE_MODE (stbuf)) {
- goto out;
- }
-
- sys_ret = sys_fsetxattr (fd, key, value->data,
- value->len, flags);
-
- if (sys_ret < 0) {
- ret = -errno;
- if (errno == ENOENT) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_XATTR_FAILED, "fsetxattr on fd=%d"
- " failed", fd);
- } else {
-
+posix_fhandle_pair(call_frame_t *frame, xlator_t *this, int fd, char *key,
+ data_t *value, int flags, struct iatt *stbuf, fd_t *_fd)
+{
+ int sys_ret = -1;
+ int ret = 0;
+
+ if (XATTR_IS_PATHINFO(key)) {
+ ret = -EACCES;
+ goto out;
+ } else if (posix_is_gfid2path_xattr(key)) {
+ ret = -ENOTSUP;
+ goto out;
+ } else if (!strncmp(key, POSIX_ACL_ACCESS_XATTR, strlen(key)) && stbuf &&
+ IS_DHT_LINKFILE_MODE(stbuf)) {
+ goto out;
+ }
+
+ sys_ret = sys_fsetxattr(fd, key, value->data, value->len, flags);
+
+ if (sys_ret < 0) {
+ ret = -errno;
+ if (errno == ENOENT) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "fsetxattr on fd=%d"
+ " failed",
+ fd);
+ } else {
#ifdef GF_DARWIN_HOST_OS
- if (errno == EINVAL) {
- gf_msg_debug (this->name, 0, "fd=%d: key:%s "
- "error:%s", fd, key,
- strerror (errno));
- } else {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_XATTR_FAILED, "fd=%d: key:%s",
- fd, key);
- }
-
-#else /* ! DARWIN */
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_XATTR_FAILED, "fd=%d: key:%s",
- fd, key);
+ if (errno == EINVAL) {
+ gf_msg_debug(this->name, 0,
+ "fd=%d: key:%s "
+ "error:%s",
+ fd, key, strerror(errno));
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "fd=%d: key:%s", fd, key);
+ }
+
+#else /* ! DARWIN */
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_XATTR_FAILED,
+ "fd=%d: key:%s", fd, key);
#endif /* DARWIN */
- }
-
- goto out;
- } else if (_fd) {
- posix_set_ctime (frame, this, NULL, fd, _fd->inode, NULL);
}
+ goto out;
+ } else if (_fd) {
+ posix_set_ctime(frame, this, NULL, fd, _fd->inode, NULL);
+ }
+
out:
- return ret;
+ return ret;
}
static void
-del_stale_dir_handle (xlator_t *this, uuid_t gfid)
-{
- char newpath[PATH_MAX] = {0, };
- uuid_t gfid_curr = {0, };
- ssize_t size = -1;
- gf_boolean_t stale = _gf_false;
- char *hpath = NULL;
- struct stat stbuf = {0, };
- struct iatt iabuf = {0, };
-
- MAKE_HANDLE_GFID_PATH (hpath, this, gfid, NULL);
-
- /* check that it is valid directory handle */
- size = sys_lstat (hpath, &stbuf);
- if (size < 0) {
- gf_msg_debug (this->name, 0, "%s: Handle stat failed: "
- "%s", hpath, strerror (errno));
- goto out;
- }
-
- iatt_from_stat (&iabuf, &stbuf);
- if (iabuf.ia_nlink != 1 || !IA_ISLNK (iabuf.ia_type)) {
- gf_msg_debug (this->name, 0, "%s: Handle nlink %d %d",
- hpath, iabuf.ia_nlink, IA_ISLNK (iabuf.ia_type));
- goto out;
- }
-
- size = posix_handle_path (this, gfid, NULL, newpath, sizeof (newpath));
- if (size <= 0) {
- if (errno == ENOENT) {
- gf_msg_debug (this->name, 0, "%s: %s", newpath,
- strerror (ENOENT));
- stale = _gf_true;
- }
- goto out;
- }
-
- size = sys_lgetxattr (newpath, GFID_XATTR_KEY, gfid_curr, 16);
- if (size < 0 && errno == ENOENT) {
- gf_msg_debug (this->name, 0, "%s: %s", newpath,
- strerror (ENOENT));
- stale = _gf_true;
- } else if (size == 16 && gf_uuid_compare (gfid, gfid_curr)) {
- gf_msg_debug (this->name, 0, "%s: mismatching gfid: %s, "
- "at %s", hpath, uuid_utoa (gfid_curr), newpath);
- stale = _gf_true;
- }
+del_stale_dir_handle(xlator_t *this, uuid_t gfid)
+{
+ char newpath[PATH_MAX] = {
+ 0,
+ };
+ uuid_t gfid_curr = {
+ 0,
+ };
+ ssize_t size = -1;
+ gf_boolean_t stale = _gf_false;
+ char *hpath = NULL;
+ struct stat stbuf = {
+ 0,
+ };
+ struct iatt iabuf = {
+ 0,
+ };
+
+ MAKE_HANDLE_GFID_PATH(hpath, this, gfid, NULL);
+
+ /* check that it is valid directory handle */
+ size = sys_lstat(hpath, &stbuf);
+ if (size < 0) {
+ gf_msg_debug(this->name, 0,
+ "%s: Handle stat failed: "
+ "%s",
+ hpath, strerror(errno));
+ goto out;
+ }
+
+ iatt_from_stat(&iabuf, &stbuf);
+ if (iabuf.ia_nlink != 1 || !IA_ISLNK(iabuf.ia_type)) {
+ gf_msg_debug(this->name, 0, "%s: Handle nlink %d %d", hpath,
+ iabuf.ia_nlink, IA_ISLNK(iabuf.ia_type));
+ goto out;
+ }
+
+ size = posix_handle_path(this, gfid, NULL, newpath, sizeof(newpath));
+ if (size <= 0) {
+ if (errno == ENOENT) {
+ gf_msg_debug(this->name, 0, "%s: %s", newpath, strerror(ENOENT));
+ stale = _gf_true;
+ }
+ goto out;
+ }
+
+ size = sys_lgetxattr(newpath, GFID_XATTR_KEY, gfid_curr, 16);
+ if (size < 0 && errno == ENOENT) {
+ gf_msg_debug(this->name, 0, "%s: %s", newpath, strerror(ENOENT));
+ stale = _gf_true;
+ } else if (size == 16 && gf_uuid_compare(gfid, gfid_curr)) {
+ gf_msg_debug(this->name, 0,
+ "%s: mismatching gfid: %s, "
+ "at %s",
+ hpath, uuid_utoa(gfid_curr), newpath);
+ stale = _gf_true;
+ }
out:
- if (stale) {
- size = sys_unlink (hpath);
- if (size < 0 && errno != ENOENT)
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_STALE_HANDLE_REMOVE_FAILED, "%s: Failed"
- "to remove handle to %s", hpath, newpath);
- } else if (size == 16) {
- gf_msg_debug (this->name, 0, "%s: Fresh handle for "
- "%s with gfid %s", hpath, newpath,
- uuid_utoa (gfid_curr));
- }
- return;
+ if (stale) {
+ size = sys_unlink(hpath);
+ if (size < 0 && errno != ENOENT)
+ gf_msg(this->name, GF_LOG_ERROR, errno,
+ P_MSG_STALE_HANDLE_REMOVE_FAILED,
+ "%s: Failed"
+ "to remove handle to %s",
+ hpath, newpath);
+ } else if (size == 16) {
+ gf_msg_debug(this->name, 0,
+ "%s: Fresh handle for "
+ "%s with gfid %s",
+ hpath, newpath, uuid_utoa(gfid_curr));
+ }
+ return;
}
static int
-janitor_walker (const char *fpath, const struct stat *sb,
- int typeflag, struct FTW *ftwbuf)
-{
- struct iatt stbuf = {0, };
- xlator_t *this = NULL;
-
- this = THIS;
- /* posix_mdata_t is not filled, no time or size attributes
- * are being used, so fine.
- */
- posix_pstat (this, NULL, NULL, fpath, &stbuf, _gf_false);
- switch (sb->st_mode & S_IFMT) {
+janitor_walker(const char *fpath, const struct stat *sb, int typeflag,
+ struct FTW *ftwbuf)
+{
+ struct iatt stbuf = {
+ 0,
+ };
+ xlator_t *this = NULL;
+
+ this = THIS;
+ /* posix_mdata_t is not filled, no time or size attributes
+ * are being used, so fine.
+ */
+ posix_pstat(this, NULL, NULL, fpath, &stbuf, _gf_false);
+ switch (sb->st_mode & S_IFMT) {
case S_IFREG:
case S_IFBLK:
case S_IFLNK:
case S_IFCHR:
case S_IFIFO:
case S_IFSOCK:
- gf_msg_trace (THIS->name, 0,
- "unlinking %s", fpath);
- sys_unlink (fpath);
- if (stbuf.ia_nlink == 1)
- posix_handle_unset (this, stbuf.ia_gfid, NULL);
- break;
+ gf_msg_trace(THIS->name, 0, "unlinking %s", fpath);
+ sys_unlink(fpath);
+ if (stbuf.ia_nlink == 1)
+ posix_handle_unset(this, stbuf.ia_gfid, NULL);
+ break;
case S_IFDIR:
- if (ftwbuf->level) { /* don't remove top level dir */
- gf_msg_debug (THIS->name, 0,
- "removing directory %s", fpath);
+ if (ftwbuf->level) { /* don't remove top level dir */
+ gf_msg_debug(THIS->name, 0, "removing directory %s", fpath);
- sys_rmdir (fpath);
- del_stale_dir_handle (this, stbuf.ia_gfid);
- }
- break;
- }
+ sys_rmdir(fpath);
+ del_stale_dir_handle(this, stbuf.ia_gfid);
+ }
+ break;
+ }
- return 0; /* 0 = FTW_CONTINUE */
+ return 0; /* 0 = FTW_CONTINUE */
}
-
static struct posix_fd *
-janitor_get_next_fd (xlator_t *this)
+janitor_get_next_fd(xlator_t *this)
{
- struct posix_private *priv = NULL;
- struct posix_fd *pfd = NULL;
+ struct posix_private *priv = NULL;
+ struct posix_fd *pfd = NULL;
- struct timespec timeout;
+ struct timespec timeout;
- priv = this->private;
+ priv = this->private;
- pthread_mutex_lock (&priv->janitor_lock);
- {
- if (list_empty (&priv->janitor_fds)) {
- time (&timeout.tv_sec);
- timeout.tv_sec += priv->janitor_sleep_duration;
- timeout.tv_nsec = 0;
-
- pthread_cond_timedwait (&priv->janitor_cond,
- &priv->janitor_lock,
- &timeout);
- goto unlock;
- }
+ pthread_mutex_lock(&priv->janitor_lock);
+ {
+ if (list_empty(&priv->janitor_fds)) {
+ time(&timeout.tv_sec);
+ timeout.tv_sec += priv->janitor_sleep_duration;
+ timeout.tv_nsec = 0;
- pfd = list_entry (priv->janitor_fds.next, struct posix_fd,
- list);
-
- list_del (priv->janitor_fds.next);
+ pthread_cond_timedwait(&priv->janitor_cond, &priv->janitor_lock,
+ &timeout);
+ goto unlock;
}
+
+ pfd = list_entry(priv->janitor_fds.next, struct posix_fd, list);
+
+ list_del(priv->janitor_fds.next);
+ }
unlock:
- pthread_mutex_unlock (&priv->janitor_lock);
+ pthread_mutex_unlock(&priv->janitor_lock);
- return pfd;
+ return pfd;
}
-
static void *
-posix_janitor_thread_proc (void *data)
-{
- xlator_t * this = NULL;
- struct posix_private *priv = NULL;
- struct posix_fd *pfd;
-
- time_t now;
-
- this = data;
- priv = this->private;
-
- THIS = this;
-
- while (1) {
-
- time (&now);
- if ((now - priv->last_landfill_check) > priv->janitor_sleep_duration) {
- if (priv->disable_landfill_purge) {
- gf_msg_debug (this->name, 0,
- "Janitor would have "
- "cleaned out %s, but purge"
- "is disabled.",
- priv->trash_path);
- } else {
- gf_msg_trace (this->name, 0,
- "janitor cleaning out %s",
- priv->trash_path);
-
- nftw (priv->trash_path,
- janitor_walker,
- 32,
- FTW_DEPTH | FTW_PHYS);
- }
- priv->last_landfill_check = now;
- }
+posix_janitor_thread_proc(void *data)
+{
+ xlator_t *this = NULL;
+ struct posix_private *priv = NULL;
+ struct posix_fd *pfd;
- pfd = janitor_get_next_fd (this);
- if (pfd) {
- if (pfd->dir == NULL) {
- gf_msg_trace (this->name, 0,
- "janitor: closing file fd=%d", pfd->fd);
- sys_close (pfd->fd);
- } else {
- gf_msg_debug (this->name, 0, "janitor: closing"
- " dir fd=%p", pfd->dir);
- sys_closedir (pfd->dir);
- }
-
- GF_FREE (pfd);
- }
+ time_t now;
+
+ this = data;
+ priv = this->private;
+
+ THIS = this;
+
+ while (1) {
+ time(&now);
+ if ((now - priv->last_landfill_check) > priv->janitor_sleep_duration) {
+ if (priv->disable_landfill_purge) {
+ gf_msg_debug(this->name, 0,
+ "Janitor would have "
+ "cleaned out %s, but purge"
+ "is disabled.",
+ priv->trash_path);
+ } else {
+ gf_msg_trace(this->name, 0, "janitor cleaning out %s",
+ priv->trash_path);
+
+ nftw(priv->trash_path, janitor_walker, 32,
+ FTW_DEPTH | FTW_PHYS);
+ }
+ priv->last_landfill_check = now;
}
- return NULL;
-}
+ pfd = janitor_get_next_fd(this);
+ if (pfd) {
+ if (pfd->dir == NULL) {
+ gf_msg_trace(this->name, 0, "janitor: closing file fd=%d",
+ pfd->fd);
+ sys_close(pfd->fd);
+ } else {
+ gf_msg_debug(this->name, 0,
+ "janitor: closing"
+ " dir fd=%p",
+ pfd->dir);
+ sys_closedir(pfd->dir);
+ }
+ GF_FREE(pfd);
+ }
+ }
+
+ return NULL;
+}
void
-posix_spawn_janitor_thread (xlator_t *this)
+posix_spawn_janitor_thread(xlator_t *this)
{
- struct posix_private *priv = NULL;
- int ret = 0;
+ struct posix_private *priv = NULL;
+ int ret = 0;
- priv = this->private;
+ priv = this->private;
- LOCK (&priv->lock);
- {
- if (!priv->janitor_present) {
- ret = gf_thread_create (&priv->janitor, NULL,
- posix_janitor_thread_proc,
- this, "posixjan");
-
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_THREAD_FAILED, "spawning janitor "
- "thread failed");
- goto unlock;
- }
-
- priv->janitor_present = _gf_true;
- }
+ LOCK(&priv->lock);
+ {
+ if (!priv->janitor_present) {
+ ret = gf_thread_create(&priv->janitor, NULL,
+ posix_janitor_thread_proc, this, "posixjan");
+
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_THREAD_FAILED,
+ "spawning janitor "
+ "thread failed");
+ goto unlock;
+ }
+
+ priv->janitor_present = _gf_true;
}
+ }
unlock:
- UNLOCK (&priv->lock);
+ UNLOCK(&priv->lock);
}
static int
-is_fresh_file (int64_t ctime_sec)
+is_fresh_file(int64_t ctime_sec)
{
- struct timeval tv;
+ struct timeval tv;
- gettimeofday (&tv, NULL);
+ gettimeofday(&tv, NULL);
- if ((ctime_sec >= (tv.tv_sec - 1))
- && (ctime_sec <= tv.tv_sec))
- return 1;
+ if ((ctime_sec >= (tv.tv_sec - 1)) && (ctime_sec <= tv.tv_sec))
+ return 1;
- return 0;
+ return 0;
}
-
int
-posix_gfid_heal (xlator_t *this, const char *path, loc_t *loc, dict_t *xattr_req)
-{
- /* The purpose of this function is to prevent a race
- where an inode creation FOP (like mkdir/mknod/create etc)
- races with lookup in the following way:
-
- {create thread} | {lookup thread}
- |
- t0
- mkdir ("name") |
- t1
- | posix_gfid_set ("name", 2);
- t2
- posix_gfid_set ("name", 1); |
- t3
- lstat ("name"); | lstat ("name");
-
- In the above case mkdir FOP would have resulted with GFID 2 while
- it should have been GFID 1. It matters in the case where GFID would
- have gotten set to 1 on other subvolumes of replciate/distribute
-
- The "solution" here is that, if we detect lookup is attempting to
- set a GFID on a file which is created very recently, but does not
- yet have a GFID (i.e, between t1 and t2), then "fake" it as though
- posix_gfid_heal was called at t0 instead.
- */
-
- uuid_t uuid_curr;
- int ret = 0;
- struct stat stat = {0, };
- struct iatt stbuf = {0, };
- struct posix_private *priv = NULL;
-
- priv = this->private;
-
- if (!xattr_req)
- return 0;
+posix_gfid_heal(xlator_t *this, const char *path, loc_t *loc, dict_t *xattr_req)
+{
+ /* The purpose of this function is to prevent a race
+ where an inode creation FOP (like mkdir/mknod/create etc)
+ races with lookup in the following way:
+
+ {create thread} | {lookup thread}
+ |
+ t0
+ mkdir ("name") |
+ t1
+ | posix_gfid_set ("name", 2);
+ t2
+ posix_gfid_set ("name", 1); |
+ t3
+ lstat ("name"); | lstat ("name");
+
+ In the above case mkdir FOP would have resulted with GFID 2 while
+ it should have been GFID 1. It matters in the case where GFID would
+ have gotten set to 1 on other subvolumes of replciate/distribute
+
+ The "solution" here is that, if we detect lookup is attempting to
+ set a GFID on a file which is created very recently, but does not
+ yet have a GFID (i.e, between t1 and t2), then "fake" it as though
+ posix_gfid_heal was called at t0 instead.
+ */
+
+ uuid_t uuid_curr;
+ int ret = 0;
+ struct stat stat = {
+ 0,
+ };
+ struct iatt stbuf = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
+
+ priv = this->private;
+
+ if (!xattr_req)
+ return 0;
- if (loc->inode && priv->ctime) {
- if (sys_lstat (path, &stat) != 0) {
- return -errno;
- }
- /* stbuf is only to compare ctime, don't use it to access
- * other fields as they are zero. */
- ret = posix_get_mdata_xattr (this, path, -1, loc->inode,
- &stbuf);
- if (ret) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_GETMDATA_FAILED,
- "posix get mdata failed on gfid: %s",
- uuid_utoa(loc->inode->gfid));
- return -ENOENT;
- }
- ret = sys_lgetxattr (path, GFID_XATTR_KEY, uuid_curr, 16);
- if (ret != 16) {
- if (is_fresh_file (stbuf.ia_ctime)) {
- gf_msg (this->name, GF_LOG_ERROR, ENOENT,
- P_MSG_FRESHFILE,
- "Fresh file: %s", path);
- return -ENOENT;
- }
- }
- } else {
- if (sys_lstat (path, &stat) != 0) {
- return -errno;
- }
- ret = sys_lgetxattr (path, GFID_XATTR_KEY, uuid_curr, 16);
- if (ret != 16) {
- if (is_fresh_file (stat.st_ctime)) {
- gf_msg (this->name, GF_LOG_ERROR, ENOENT,
- P_MSG_FRESHFILE,
- "Fresh file: %s", path);
- return -ENOENT;
- }
- }
+ if (loc->inode && priv->ctime) {
+ if (sys_lstat(path, &stat) != 0) {
+ return -errno;
+ }
+ /* stbuf is only to compare ctime, don't use it to access
+ * other fields as they are zero. */
+ ret = posix_get_mdata_xattr(this, path, -1, loc->inode, &stbuf);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_GETMDATA_FAILED,
+ "posix get mdata failed on gfid: %s",
+ uuid_utoa(loc->inode->gfid));
+ return -ENOENT;
+ }
+ ret = sys_lgetxattr(path, GFID_XATTR_KEY, uuid_curr, 16);
+ if (ret != 16) {
+ if (is_fresh_file(stbuf.ia_ctime)) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOENT, P_MSG_FRESHFILE,
+ "Fresh file: %s", path);
+ return -ENOENT;
+ }
}
+ } else {
+ if (sys_lstat(path, &stat) != 0) {
+ return -errno;
+ }
+ ret = sys_lgetxattr(path, GFID_XATTR_KEY, uuid_curr, 16);
+ if (ret != 16) {
+ if (is_fresh_file(stat.st_ctime)) {
+ gf_msg(this->name, GF_LOG_ERROR, ENOENT, P_MSG_FRESHFILE,
+ "Fresh file: %s", path);
+ return -ENOENT;
+ }
+ }
+ }
- posix_gfid_set (this, path, loc, xattr_req, GF_CLIENT_PID_MAX, &ret);
- return 0;
+ posix_gfid_set(this, path, loc, xattr_req, GF_CLIENT_PID_MAX, &ret);
+ return 0;
}
-
int
-posix_acl_xattr_set (xlator_t *this, const char *path, dict_t *xattr_req)
+posix_acl_xattr_set(xlator_t *this, const char *path, dict_t *xattr_req)
{
- int ret = 0;
- data_t *data = NULL;
- struct stat stat = {0, };
+ int ret = 0;
+ data_t *data = NULL;
+ struct stat stat = {
+ 0,
+ };
- if (!xattr_req)
- goto out;
+ if (!xattr_req)
+ goto out;
- if (sys_lstat (path, &stat) != 0)
- goto out;
+ if (sys_lstat(path, &stat) != 0)
+ goto out;
- data = dict_get (xattr_req, POSIX_ACL_ACCESS_XATTR);
- if (data) {
- ret = sys_lsetxattr (path, POSIX_ACL_ACCESS_XATTR,
- data->data, data->len, 0);
+ data = dict_get(xattr_req, POSIX_ACL_ACCESS_XATTR);
+ if (data) {
+ ret = sys_lsetxattr(path, POSIX_ACL_ACCESS_XATTR, data->data, data->len,
+ 0);
#ifdef __FreeBSD__
- if (ret != -1) {
- ret = 0;
- }
-#endif /* __FreeBSD__ */
- if (ret != 0)
- goto out;
+ if (ret != -1) {
+ ret = 0;
}
-
- data = dict_get (xattr_req, POSIX_ACL_DEFAULT_XATTR);
- if (data) {
- ret = sys_lsetxattr (path, POSIX_ACL_DEFAULT_XATTR,
- data->data, data->len, 0);
-#ifdef __FreeBSD__
- if (ret != -1) {
- ret = 0;
- }
#endif /* __FreeBSD__ */
- if (ret != 0)
- goto out;
+ if (ret != 0)
+ goto out;
+ }
+
+ data = dict_get(xattr_req, POSIX_ACL_DEFAULT_XATTR);
+ if (data) {
+ ret = sys_lsetxattr(path, POSIX_ACL_DEFAULT_XATTR, data->data,
+ data->len, 0);
+#ifdef __FreeBSD__
+ if (ret != -1) {
+ ret = 0;
}
+#endif /* __FreeBSD__ */
+ if (ret != 0)
+ goto out;
+ }
out:
- return ret;
+ return ret;
}
static int
-_handle_entry_create_keyvalue_pair (dict_t *d, char *k, data_t *v,
- void *tmp)
+_handle_entry_create_keyvalue_pair(dict_t *d, char *k, data_t *v, void *tmp)
{
- int ret = -1;
- posix_xattr_filler_t *filler = NULL;
+ int ret = -1;
+ posix_xattr_filler_t *filler = NULL;
- filler = tmp;
+ filler = tmp;
- if (!strcmp (GFID_XATTR_KEY, k) ||
- !strcmp ("gfid-req", k) ||
- !strcmp (POSIX_ACL_DEFAULT_XATTR, k) ||
- !strcmp (POSIX_ACL_ACCESS_XATTR, k) ||
- posix_xattr_ignorable (k)) {
- return 0;
- }
-
- ret = posix_handle_pair (filler->this, filler->real_path, k, v,
- XATTR_CREATE, filler->stbuf);
- if (ret < 0) {
- errno = -ret;
- return -1;
- }
+ if (!strcmp(GFID_XATTR_KEY, k) || !strcmp("gfid-req", k) ||
+ !strcmp(POSIX_ACL_DEFAULT_XATTR, k) ||
+ !strcmp(POSIX_ACL_ACCESS_XATTR, k) || posix_xattr_ignorable(k)) {
return 0;
+ }
+
+ ret = posix_handle_pair(filler->this, filler->real_path, k, v, XATTR_CREATE,
+ filler->stbuf);
+ if (ret < 0) {
+ errno = -ret;
+ return -1;
+ }
+ return 0;
}
int
-posix_entry_create_xattr_set (xlator_t *this, const char *path,
- dict_t *dict)
+posix_entry_create_xattr_set(xlator_t *this, const char *path, dict_t *dict)
{
- int ret = -1;
+ int ret = -1;
- posix_xattr_filler_t filler = {0,};
+ posix_xattr_filler_t filler = {
+ 0,
+ };
- if (!dict)
- goto out;
+ if (!dict)
+ goto out;
- filler.this = this;
- filler.real_path = path;
- filler.stbuf = NULL;
+ filler.this = this;
+ filler.real_path = path;
+ filler.stbuf = NULL;
- ret = dict_foreach (dict, _handle_entry_create_keyvalue_pair, &filler);
+ ret = dict_foreach(dict, _handle_entry_create_keyvalue_pair, &filler);
out:
- return ret;
+ return ret;
}
static int
-__posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p,
- int *op_errno_p)
-{
- uint64_t tmp_pfd = 0;
- struct posix_fd *pfd = NULL;
- int ret = -1;
- char *real_path = NULL;
- char *unlink_path = NULL;
- int _fd = -1;
- int op_errno = 0;
- DIR *dir = NULL;
-
- struct posix_private *priv = NULL;
-
- priv = this->private;
-
- ret = __fd_ctx_get (fd, this, &tmp_pfd);
- if (ret == 0) {
- pfd = (void *)(long) tmp_pfd;
- goto out;
- }
- if (!fd_is_anonymous(fd)) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_READ_FAILED,
- "Failed to get fd context for a non-anonymous fd, "
- "file: %s, gfid: %s", real_path,
- uuid_utoa (fd->inode->gfid));
- op_errno = EINVAL;
- goto out;
- }
-
- MAKE_HANDLE_PATH (real_path, this, fd->inode->gfid, NULL);
- if (!real_path) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_READ_FAILED,
- "Failed to create handle path (%s)",
- uuid_utoa (fd->inode->gfid));
- ret = -1;
- op_errno = EINVAL;
- goto out;
- }
- pfd = GF_CALLOC (1, sizeof (*pfd), gf_posix_mt_posix_fd);
- if (!pfd) {
- op_errno = ENOMEM;
- goto out;
- }
- pfd->fd = -1;
-
- if (fd->inode->ia_type == IA_IFDIR) {
- dir = sys_opendir (real_path);
- if (!dir) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- P_MSG_READ_FAILED,
- "Failed to get anonymous fd for "
- "real_path: %s.", real_path);
- GF_FREE (pfd);
- pfd = NULL;
- goto out;
- }
- _fd = dirfd (dir);
- }
-
- /* Using fd->flags in case we choose to have anonymous
- * fds with different flags some day. As of today it
- * would be GF_ANON_FD_FLAGS and nothing else.
- */
- if (fd->inode->ia_type == IA_IFREG) {
- _fd = open (real_path, fd->flags);
- if ((_fd == -1) && (errno == ENOENT)) {
- POSIX_GET_FILE_UNLINK_PATH (priv->base_path,
- fd->inode->gfid,
- unlink_path);
- _fd = open (unlink_path, fd->flags);
- }
- if (_fd == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- P_MSG_READ_FAILED,
- "Failed to get anonymous fd for "
- "real_path: %s.", real_path);
- GF_FREE (pfd);
- pfd = NULL;
- goto out;
- }
- }
-
- pfd->fd = _fd;
- pfd->dir = dir;
- pfd->flags = fd->flags;
-
- ret = __fd_ctx_set (fd, this, (uint64_t) (long) pfd);
- if (ret != 0) {
- op_errno = ENOMEM;
- if (_fd != -1)
- sys_close (_fd);
- if (dir)
- sys_closedir (dir);
- GF_FREE (pfd);
- pfd = NULL;
- goto out;
- }
-
- ret = 0;
+__posix_fd_ctx_get(fd_t *fd, xlator_t *this, struct posix_fd **pfd_p,
+ int *op_errno_p)
+{
+ uint64_t tmp_pfd = 0;
+ struct posix_fd *pfd = NULL;
+ int ret = -1;
+ char *real_path = NULL;
+ char *unlink_path = NULL;
+ int _fd = -1;
+ int op_errno = 0;
+ DIR *dir = NULL;
+
+ struct posix_private *priv = NULL;
+
+ priv = this->private;
+
+ ret = __fd_ctx_get(fd, this, &tmp_pfd);
+ if (ret == 0) {
+ pfd = (void *)(long)tmp_pfd;
+ goto out;
+ }
+ if (!fd_is_anonymous(fd)) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_READ_FAILED,
+ "Failed to get fd context for a non-anonymous fd, "
+ "file: %s, gfid: %s",
+ real_path, uuid_utoa(fd->inode->gfid));
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ MAKE_HANDLE_PATH(real_path, this, fd->inode->gfid, NULL);
+ if (!real_path) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_READ_FAILED,
+ "Failed to create handle path (%s)", uuid_utoa(fd->inode->gfid));
+ ret = -1;
+ op_errno = EINVAL;
+ goto out;
+ }
+ pfd = GF_CALLOC(1, sizeof(*pfd), gf_posix_mt_posix_fd);
+ if (!pfd) {
+ op_errno = ENOMEM;
+ goto out;
+ }
+ pfd->fd = -1;
+
+ if (fd->inode->ia_type == IA_IFDIR) {
+ dir = sys_opendir(real_path);
+ if (!dir) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_READ_FAILED,
+ "Failed to get anonymous fd for "
+ "real_path: %s.",
+ real_path);
+ GF_FREE(pfd);
+ pfd = NULL;
+ goto out;
+ }
+ _fd = dirfd(dir);
+ }
+
+ /* Using fd->flags in case we choose to have anonymous
+ * fds with different flags some day. As of today it
+ * would be GF_ANON_FD_FLAGS and nothing else.
+ */
+ if (fd->inode->ia_type == IA_IFREG) {
+ _fd = open(real_path, fd->flags);
+ if ((_fd == -1) && (errno == ENOENT)) {
+ POSIX_GET_FILE_UNLINK_PATH(priv->base_path, fd->inode->gfid,
+ unlink_path);
+ _fd = open(unlink_path, fd->flags);
+ }
+ if (_fd == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_READ_FAILED,
+ "Failed to get anonymous fd for "
+ "real_path: %s.",
+ real_path);
+ GF_FREE(pfd);
+ pfd = NULL;
+ goto out;
+ }
+ }
+
+ pfd->fd = _fd;
+ pfd->dir = dir;
+ pfd->flags = fd->flags;
+
+ ret = __fd_ctx_set(fd, this, (uint64_t)(long)pfd);
+ if (ret != 0) {
+ op_errno = ENOMEM;
+ if (_fd != -1)
+ sys_close(_fd);
+ if (dir)
+ sys_closedir(dir);
+ GF_FREE(pfd);
+ pfd = NULL;
+ goto out;
+ }
+
+ ret = 0;
out:
- if (ret < 0 && op_errno_p)
- *op_errno_p = op_errno;
+ if (ret < 0 && op_errno_p)
+ *op_errno_p = op_errno;
- if (pfd_p)
- *pfd_p = pfd;
- return ret;
+ if (pfd_p)
+ *pfd_p = pfd;
+ return ret;
}
-
int
-posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd,
- int *op_errno)
+posix_fd_ctx_get(fd_t *fd, xlator_t *this, struct posix_fd **pfd, int *op_errno)
{
- int ret;
+ int ret;
- LOCK (&fd->inode->lock);
- {
- ret = __posix_fd_ctx_get (fd, this, pfd, op_errno);
- }
- UNLOCK (&fd->inode->lock);
+ LOCK(&fd->inode->lock);
+ {
+ ret = __posix_fd_ctx_get(fd, this, pfd, op_errno);
+ }
+ UNLOCK(&fd->inode->lock);
- return ret;
+ return ret;
}
int
-posix_fs_health_check (xlator_t *this)
-{
- struct posix_private *priv = NULL;
- int ret = -1;
- char *subvol_path = NULL;
- char timestamp[256] = {0,};
- int fd = -1;
- int timelen = -1;
- time_t time_sec = {0,};
- char buff[256] = {0};
- char file_path[PATH_MAX] = {0};
- char *op = NULL;
- int op_errno = 0;
- int cnt = 0;
- int timeout = 0;
- struct aiocb aiocb;
-
- GF_VALIDATE_OR_GOTO (this->name, this, out);
- priv = this->private;
- GF_VALIDATE_OR_GOTO ("posix-helpers", priv, out);
-
- subvol_path = priv->base_path;
- timeout = priv->health_check_timeout;
- snprintf (file_path, sizeof (file_path)-1, "%s/%s/health_check",
- subvol_path, GF_HIDDEN_PATH);
-
- time_sec = time (NULL);
- gf_time_fmt (timestamp, sizeof timestamp, time_sec, gf_timefmt_FT);
- timelen = strlen (timestamp);
-
- fd = open (file_path, O_CREAT|O_WRONLY|O_TRUNC, 0644);
- if (fd == -1) {
- op_errno = errno;
- op = "open_for_write";
- goto out;
- }
- memset(&aiocb, 0, sizeof(struct aiocb));
- aiocb.aio_fildes = fd;
- aiocb.aio_buf = timestamp;
- aiocb.aio_nbytes = timelen;
- aiocb.aio_sigevent.sigev_notify = SIGEV_NONE;
- if (aio_write(&aiocb) == -1) {
- op_errno = errno;
- op = "aio_write";
- goto out;
- }
-
- /* Wait until write completion */
- while ((aio_error (&aiocb) == EINPROGRESS) && (++cnt <= timeout))
- sleep (1);
-
- ret = aio_error (&aiocb);
- if (ret != 0) {
- op_errno = errno;
- op = "aio_write_error";
- ret = -1;
- goto out;
- }
-
- ret = aio_return (&aiocb);
- if (ret != timelen) {
- op_errno = errno;
- op = "aio_write_buf";
- ret = -1;
- goto out;
- }
-
- sys_close (fd);
-
- fd = open (file_path, O_RDONLY);
- if (fd == -1) {
- op_errno = errno;
- op = "open_for_read";
- goto out;
- }
-
- memset(&aiocb, 0, sizeof(struct aiocb));
- aiocb.aio_fildes = fd;
- aiocb.aio_buf = buff;
- aiocb.aio_nbytes = sizeof(buff);
- if (aio_read(&aiocb) == -1) {
- op_errno = errno;
- op = "aio_read";
- goto out;
- }
- cnt = 0;
- /* Wait until read completion */
- while ((aio_error (&aiocb) == EINPROGRESS) && (++cnt <= timeout))
- sleep (1);
-
- ret = aio_error (&aiocb);
- if (ret != 0) {
- op_errno = errno;
- op = "aio_read_error";
- ret = -1;
- goto out;
- }
-
- ret = aio_return (&aiocb);
- if (ret != timelen) {
- op_errno = errno;
- op = "aio_read_buf";
- ret = -1;
- goto out;
- }
-
- if (memcmp (timestamp, buff, ret)) {
- op_errno = EUCLEAN;
- op = "aio_read_cmp_buf";
- ret = -1;
- goto out;
- }
- ret = 0;
+posix_fs_health_check(xlator_t *this)
+{
+ struct posix_private *priv = NULL;
+ int ret = -1;
+ char *subvol_path = NULL;
+ char timestamp[256] = {
+ 0,
+ };
+ int fd = -1;
+ int timelen = -1;
+ time_t time_sec = {
+ 0,
+ };
+ char buff[256] = {0};
+ char file_path[PATH_MAX] = {0};
+ char *op = NULL;
+ int op_errno = 0;
+ int cnt = 0;
+ int timeout = 0;
+ struct aiocb aiocb;
+
+ GF_VALIDATE_OR_GOTO(this->name, this, out);
+ priv = this->private;
+ GF_VALIDATE_OR_GOTO("posix-helpers", priv, out);
+
+ subvol_path = priv->base_path;
+ timeout = priv->health_check_timeout;
+ snprintf(file_path, sizeof(file_path) - 1, "%s/%s/health_check",
+ subvol_path, GF_HIDDEN_PATH);
+
+ time_sec = time(NULL);
+ gf_time_fmt(timestamp, sizeof timestamp, time_sec, gf_timefmt_FT);
+ timelen = strlen(timestamp);
+
+ fd = open(file_path, O_CREAT | O_WRONLY | O_TRUNC, 0644);
+ if (fd == -1) {
+ op_errno = errno;
+ op = "open_for_write";
+ goto out;
+ }
+ memset(&aiocb, 0, sizeof(struct aiocb));
+ aiocb.aio_fildes = fd;
+ aiocb.aio_buf = timestamp;
+ aiocb.aio_nbytes = timelen;
+ aiocb.aio_sigevent.sigev_notify = SIGEV_NONE;
+ if (aio_write(&aiocb) == -1) {
+ op_errno = errno;
+ op = "aio_write";
+ goto out;
+ }
+
+ /* Wait until write completion */
+ while ((aio_error(&aiocb) == EINPROGRESS) && (++cnt <= timeout))
+ sleep(1);
+
+ ret = aio_error(&aiocb);
+ if (ret != 0) {
+ op_errno = errno;
+ op = "aio_write_error";
+ ret = -1;
+ goto out;
+ }
+
+ ret = aio_return(&aiocb);
+ if (ret != timelen) {
+ op_errno = errno;
+ op = "aio_write_buf";
+ ret = -1;
+ goto out;
+ }
+
+ sys_close(fd);
+
+ fd = open(file_path, O_RDONLY);
+ if (fd == -1) {
+ op_errno = errno;
+ op = "open_for_read";
+ goto out;
+ }
+
+ memset(&aiocb, 0, sizeof(struct aiocb));
+ aiocb.aio_fildes = fd;
+ aiocb.aio_buf = buff;
+ aiocb.aio_nbytes = sizeof(buff);
+ if (aio_read(&aiocb) == -1) {
+ op_errno = errno;
+ op = "aio_read";
+ goto out;
+ }
+ cnt = 0;
+ /* Wait until read completion */
+ while ((aio_error(&aiocb) == EINPROGRESS) && (++cnt <= timeout))
+ sleep(1);
+
+ ret = aio_error(&aiocb);
+ if (ret != 0) {
+ op_errno = errno;
+ op = "aio_read_error";
+ ret = -1;
+ goto out;
+ }
+
+ ret = aio_return(&aiocb);
+ if (ret != timelen) {
+ op_errno = errno;
+ op = "aio_read_buf";
+ ret = -1;
+ goto out;
+ }
+
+ if (memcmp(timestamp, buff, ret)) {
+ op_errno = EUCLEAN;
+ op = "aio_read_cmp_buf";
+ ret = -1;
+ goto out;
+ }
+ ret = 0;
out:
- if (fd != -1) {
- sys_close (fd);
- }
- if (ret && file_path[0]) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_HEALTHCHECK_FAILED,
- "%s() on %s returned", op, file_path);
- gf_event (EVENT_POSIX_HEALTH_CHECK_FAILED,
- "op=%s;path=%s;error=%s;brick=%s:%s timeout is %d",
- op, file_path, strerror (op_errno), priv->hostname,
- priv->base_path, timeout);
- }
- return ret;
-
+ if (fd != -1) {
+ sys_close(fd);
+ }
+ if (ret && file_path[0]) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HEALTHCHECK_FAILED,
+ "%s() on %s returned", op, file_path);
+ gf_event(EVENT_POSIX_HEALTH_CHECK_FAILED,
+ "op=%s;path=%s;error=%s;brick=%s:%s timeout is %d", op,
+ file_path, strerror(op_errno), priv->hostname, priv->base_path,
+ timeout);
+ }
+ return ret;
}
static void *
-posix_health_check_thread_proc (void *data)
-{
- xlator_t *this = NULL;
- struct posix_private *priv = NULL;
- uint32_t interval = 0;
- int ret = -1;
- xlator_t *top = NULL;
- xlator_t *victim = NULL;
- xlator_list_t **trav_p = NULL;
- int count = 0;
- gf_boolean_t victim_found = _gf_false;
- glusterfs_ctx_t *ctx = NULL;
-
- this = data;
- priv = this->private;
- ctx = THIS->ctx;
-
- /* prevent races when the interval is updated */
- interval = priv->health_check_interval;
- if (interval == 0)
- goto out;
-
- gf_msg_debug (this->name, 0, "health-check thread started, "
- "interval = %d seconds", interval);
- while (1) {
- /* aborting sleep() is a request to exit this thread, sleep()
- * will normally not return when cancelled */
- ret = sleep (interval);
- if (ret > 0)
- break;
- /* prevent thread errors while doing the health-check(s) */
- pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL);
-
- /* Do the health-check.*/
- ret = posix_fs_health_check (this);
- if (ret < 0 && priv->health_check_active)
- goto abort;
- if (!priv->health_check_active)
- goto out;
- pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
- }
+posix_health_check_thread_proc(void *data)
+{
+ xlator_t *this = NULL;
+ struct posix_private *priv = NULL;
+ uint32_t interval = 0;
+ int ret = -1;
+ xlator_t *top = NULL;
+ xlator_t *victim = NULL;
+ xlator_list_t **trav_p = NULL;
+ int count = 0;
+ gf_boolean_t victim_found = _gf_false;
+ glusterfs_ctx_t *ctx = NULL;
+
+ this = data;
+ priv = this->private;
+ ctx = THIS->ctx;
+
+ /* prevent races when the interval is updated */
+ interval = priv->health_check_interval;
+ if (interval == 0)
+ goto out;
+
+ gf_msg_debug(this->name, 0,
+ "health-check thread started, "
+ "interval = %d seconds",
+ interval);
+ while (1) {
+ /* aborting sleep() is a request to exit this thread, sleep()
+ * will normally not return when cancelled */
+ ret = sleep(interval);
+ if (ret > 0)
+ break;
+ /* prevent thread errors while doing the health-check(s) */
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
+
+ /* Do the health-check.*/
+ ret = posix_fs_health_check(this);
+ if (ret < 0 && priv->health_check_active)
+ goto abort;
+ if (!priv->health_check_active)
+ goto out;
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+ }
out:
- gf_msg_debug (this->name, 0, "health-check thread exiting");
+ gf_msg_debug(this->name, 0, "health-check thread exiting");
- LOCK (&priv->lock);
- {
- priv->health_check_active = _gf_false;
- }
- UNLOCK (&priv->lock);
+ LOCK(&priv->lock);
+ {
+ priv->health_check_active = _gf_false;
+ }
+ UNLOCK(&priv->lock);
- return NULL;
+ return NULL;
abort:
- LOCK (&priv->lock);
- {
- priv->health_check_active = _gf_false;
+ LOCK(&priv->lock);
+ {
+ priv->health_check_active = _gf_false;
+ }
+ UNLOCK(&priv->lock);
+
+ /* health-check failed */
+ gf_msg(this->name, GF_LOG_EMERG, 0, P_MSG_HEALTHCHECK_FAILED,
+ "health-check failed, going down");
+
+ xlator_notify(this->parents->xlator, GF_EVENT_CHILD_DOWN, this);
+
+ /* Below code is use to ensure if brick multiplexing is enabled if
+ count is more than 1 it means brick mux has enabled
+ */
+ if (this->ctx->active) {
+ top = this->ctx->active->first;
+ LOCK(&ctx->volfile_lock);
+ for (trav_p = &top->children; *trav_p; trav_p = &(*trav_p)->next) {
+ count++;
+ }
+ UNLOCK(&ctx->volfile_lock);
+ }
+
+ if (count == 1) {
+ gf_msg(this->name, GF_LOG_EMERG, 0, P_MSG_HEALTHCHECK_FAILED,
+ "still alive! -> SIGTERM");
+ ret = sleep(30);
+
+ /* Need to kill the process only while brick mux has not enabled
+ */
+ if (ret == 0)
+ kill(getpid(), SIGTERM);
+
+ ret = sleep(30);
+ gf_msg(this->name, GF_LOG_EMERG, 0, P_MSG_HEALTHCHECK_FAILED,
+ "still alive! -> SIGKILL");
+ if (ret == 0)
+ kill(getpid(), SIGKILL);
+
+ } else {
+ LOCK(&ctx->volfile_lock);
+ for (trav_p = &top->children; *trav_p; trav_p = &(*trav_p)->next) {
+ victim = (*trav_p)->xlator;
+ if (!victim->call_cleanup &&
+ strcmp(victim->name, priv->base_path) == 0) {
+ victim_found = _gf_true;
+ break;
+ }
}
- UNLOCK (&priv->lock);
-
- /* health-check failed */
- gf_msg (this->name, GF_LOG_EMERG, 0, P_MSG_HEALTHCHECK_FAILED,
- "health-check failed, going down");
-
- xlator_notify (this->parents->xlator, GF_EVENT_CHILD_DOWN, this);
-
- /* Below code is use to ensure if brick multiplexing is enabled if
- count is more than 1 it means brick mux has enabled
- */
- if (this->ctx->active) {
- top = this->ctx->active->first;
- LOCK (&ctx->volfile_lock);
- for (trav_p = &top->children; *trav_p;
- trav_p = &(*trav_p)->next) {
- count++;
- }
- UNLOCK (&ctx->volfile_lock);
- }
-
- if (count == 1) {
- gf_msg (this->name, GF_LOG_EMERG, 0, P_MSG_HEALTHCHECK_FAILED,
- "still alive! -> SIGTERM");
- ret = sleep (30);
-
- /* Need to kill the process only while brick mux has not enabled
- */
- if (ret == 0)
- kill (getpid(), SIGTERM);
-
- ret = sleep (30);
- gf_msg (this->name, GF_LOG_EMERG, 0, P_MSG_HEALTHCHECK_FAILED,
- "still alive! -> SIGKILL");
- if (ret == 0)
- kill (getpid(), SIGKILL);
-
- } else {
- LOCK (&ctx->volfile_lock);
- for (trav_p = &top->children; *trav_p;
- trav_p = &(*trav_p)->next) {
- victim = (*trav_p)->xlator;
- if (!victim->call_cleanup &&
- strcmp (victim->name, priv->base_path) == 0) {
- victim_found = _gf_true;
- break;
- }
- }
- UNLOCK (&ctx->volfile_lock);
- if (victim_found && !victim->cleanup_starting) {
- gf_log (THIS->name, GF_LOG_INFO, "detaching not-only "
- " child %s", priv->base_path);
- victim->cleanup_starting = 1;
- top->notify (top, GF_EVENT_CLEANUP, victim);
- }
+ UNLOCK(&ctx->volfile_lock);
+ if (victim_found && !victim->cleanup_starting) {
+ gf_log(THIS->name, GF_LOG_INFO,
+ "detaching not-only "
+ " child %s",
+ priv->base_path);
+ victim->cleanup_starting = 1;
+ top->notify(top, GF_EVENT_CLEANUP, victim);
}
+ }
- return NULL;
+ return NULL;
}
void
-posix_spawn_health_check_thread (xlator_t *xl)
+posix_spawn_health_check_thread(xlator_t *xl)
{
- struct posix_private *priv = NULL;
- int ret = -1;
+ struct posix_private *priv = NULL;
+ int ret = -1;
- priv = xl->private;
+ priv = xl->private;
- LOCK (&priv->lock);
- {
- /* cancel the running thread */
- if (priv->health_check_active == _gf_true) {
- pthread_cancel (priv->health_check);
- priv->health_check_active = _gf_false;
- }
+ LOCK(&priv->lock);
+ {
+ /* cancel the running thread */
+ if (priv->health_check_active == _gf_true) {
+ pthread_cancel(priv->health_check);
+ priv->health_check_active = _gf_false;
+ }
- /* prevent scheduling a check in a tight loop */
- if (priv->health_check_interval == 0)
- goto unlock;
-
- ret = gf_thread_create (&priv->health_check, NULL,
- posix_health_check_thread_proc,
- xl, "posixhc");
- if (ret < 0) {
- priv->health_check_interval = 0;
- priv->health_check_active = _gf_false;
- gf_msg (xl->name, GF_LOG_ERROR, errno,
- P_MSG_HEALTHCHECK_FAILED,
- "unable to setup health-check thread");
- goto unlock;
- }
+ /* prevent scheduling a check in a tight loop */
+ if (priv->health_check_interval == 0)
+ goto unlock;
- /* run the thread detached, resources will be freed on exit */
- pthread_detach (priv->health_check);
- priv->health_check_active = _gf_true;
+ ret = gf_thread_create(&priv->health_check, NULL,
+ posix_health_check_thread_proc, xl, "posixhc");
+ if (ret < 0) {
+ priv->health_check_interval = 0;
+ priv->health_check_active = _gf_false;
+ gf_msg(xl->name, GF_LOG_ERROR, errno, P_MSG_HEALTHCHECK_FAILED,
+ "unable to setup health-check thread");
+ goto unlock;
}
+
+ /* run the thread detached, resources will be freed on exit */
+ pthread_detach(priv->health_check);
+ priv->health_check_active = _gf_true;
+ }
unlock:
- UNLOCK (&priv->lock);
+ UNLOCK(&priv->lock);
}
void
-posix_disk_space_check (xlator_t *this)
-{
- struct posix_private *priv = NULL;
- char *subvol_path = NULL;
- int op_ret = 0;
- int percent = 0;
- struct statvfs buf = {0};
- uint64_t totsz = 0;
- uint64_t freesz = 0;
-
- GF_VALIDATE_OR_GOTO (this->name, this, out);
- priv = this->private;
- GF_VALIDATE_OR_GOTO (this->name, priv, out);
-
- subvol_path = priv->base_path;
- percent = priv->disk_reserve;
-
- op_ret = sys_statvfs (subvol_path, &buf);
-
- if (op_ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_STATVFS_FAILED,
- "statvfs failed on %s", subvol_path);
- goto out;
- }
- totsz = (buf.f_blocks * buf.f_bsize);
- freesz = (buf.f_bfree * buf.f_bsize);
-
- if (freesz <= ((totsz * percent) / 100)) {
- priv->disk_space_full = 1;
- } else {
- priv->disk_space_full = 0;
- }
+posix_disk_space_check(xlator_t *this)
+{
+ struct posix_private *priv = NULL;
+ char *subvol_path = NULL;
+ int op_ret = 0;
+ int percent = 0;
+ struct statvfs buf = {0};
+ uint64_t totsz = 0;
+ uint64_t freesz = 0;
+
+ GF_VALIDATE_OR_GOTO(this->name, this, out);
+ priv = this->private;
+ GF_VALIDATE_OR_GOTO(this->name, priv, out);
+
+ subvol_path = priv->base_path;
+ percent = priv->disk_reserve;
+
+ op_ret = sys_statvfs(subvol_path, &buf);
+
+ if (op_ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_STATVFS_FAILED,
+ "statvfs failed on %s", subvol_path);
+ goto out;
+ }
+ totsz = (buf.f_blocks * buf.f_bsize);
+ freesz = (buf.f_bfree * buf.f_bsize);
+
+ if (freesz <= ((totsz * percent) / 100)) {
+ priv->disk_space_full = 1;
+ } else {
+ priv->disk_space_full = 0;
+ }
out:
- return;
+ return;
}
-
static void *
-posix_disk_space_check_thread_proc (void *data)
-{
- xlator_t *this = NULL;
- struct posix_private *priv = NULL;
- uint32_t interval = 0;
- int ret = -1;
-
- this = data;
- priv = this->private;
-
- interval = 5;
- gf_msg_debug (this->name, 0, "disk-space thread started, "
- "interval = %d seconds", interval);
- while (1) {
- /* aborting sleep() is a request to exit this thread, sleep()
- * will normally not return when cancelled */
- ret = sleep (interval);
- if (ret > 0)
- break;
- /* prevent thread errors while doing the health-check(s) */
- pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL);
-
- /* Do the disk-check.*/
- posix_disk_space_check (this);
- if (!priv->disk_space_check_active)
- goto out;
- pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
- }
+posix_disk_space_check_thread_proc(void *data)
+{
+ xlator_t *this = NULL;
+ struct posix_private *priv = NULL;
+ uint32_t interval = 0;
+ int ret = -1;
+
+ this = data;
+ priv = this->private;
+
+ interval = 5;
+ gf_msg_debug(this->name, 0,
+ "disk-space thread started, "
+ "interval = %d seconds",
+ interval);
+ while (1) {
+ /* aborting sleep() is a request to exit this thread, sleep()
+ * will normally not return when cancelled */
+ ret = sleep(interval);
+ if (ret > 0)
+ break;
+ /* prevent thread errors while doing the health-check(s) */
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
+
+ /* Do the disk-check.*/
+ posix_disk_space_check(this);
+ if (!priv->disk_space_check_active)
+ goto out;
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+ }
out:
- gf_msg_debug (this->name, 0, "disk space check thread exiting");
- LOCK (&priv->lock);
- {
- priv->disk_space_check_active = _gf_false;
- }
- UNLOCK (&priv->lock);
+ gf_msg_debug(this->name, 0, "disk space check thread exiting");
+ LOCK(&priv->lock);
+ {
+ priv->disk_space_check_active = _gf_false;
+ }
+ UNLOCK(&priv->lock);
-
- return NULL;
+ return NULL;
}
void
-posix_spawn_disk_space_check_thread (xlator_t *xl)
+posix_spawn_disk_space_check_thread(xlator_t *xl)
{
- struct posix_private *priv = NULL;
- int ret = -1;
+ struct posix_private *priv = NULL;
+ int ret = -1;
- priv = xl->private;
+ priv = xl->private;
- LOCK (&priv->lock);
- {
- /* cancel the running thread */
- if (priv->disk_space_check_active == _gf_true) {
- pthread_cancel (priv->disk_space_check);
- priv->disk_space_check_active = _gf_false;
- }
-
- ret = gf_thread_create_detached (&priv->disk_space_check,
- posix_disk_space_check_thread_proc,
- xl, "posix_reserve");
- if (ret < 0) {
- priv->disk_space_check_active = _gf_false;
- gf_msg (xl->name, GF_LOG_ERROR, errno,
- P_MSG_DISK_SPACE_CHECK_FAILED,
- "unable to setup disk space check thread");
- goto unlock;
- }
+ LOCK(&priv->lock);
+ {
+ /* cancel the running thread */
+ if (priv->disk_space_check_active == _gf_true) {
+ pthread_cancel(priv->disk_space_check);
+ priv->disk_space_check_active = _gf_false;
+ }
- priv->disk_space_check_active = _gf_true;
+ ret = gf_thread_create_detached(&priv->disk_space_check,
+ posix_disk_space_check_thread_proc, xl,
+ "posix_reserve");
+ if (ret < 0) {
+ priv->disk_space_check_active = _gf_false;
+ gf_msg(xl->name, GF_LOG_ERROR, errno, P_MSG_DISK_SPACE_CHECK_FAILED,
+ "unable to setup disk space check thread");
+ goto unlock;
}
+
+ priv->disk_space_check_active = _gf_true;
+ }
unlock:
- UNLOCK (&priv->lock);
+ UNLOCK(&priv->lock);
}
int
-posix_fsyncer_pick (xlator_t *this, struct list_head *head)
+posix_fsyncer_pick(xlator_t *this, struct list_head *head)
{
- struct posix_private *priv = NULL;
- int count = 0;
+ struct posix_private *priv = NULL;
+ int count = 0;
- priv = this->private;
- pthread_mutex_lock (&priv->fsync_mutex);
- {
- while (list_empty (&priv->fsyncs))
- pthread_cond_wait (&priv->fsync_cond,
- &priv->fsync_mutex);
+ priv = this->private;
+ pthread_mutex_lock(&priv->fsync_mutex);
+ {
+ while (list_empty(&priv->fsyncs))
+ pthread_cond_wait(&priv->fsync_cond, &priv->fsync_mutex);
- count = priv->fsync_queue_count;
- priv->fsync_queue_count = 0;
- list_splice_init (&priv->fsyncs, head);
- }
- pthread_mutex_unlock (&priv->fsync_mutex);
+ count = priv->fsync_queue_count;
+ priv->fsync_queue_count = 0;
+ list_splice_init(&priv->fsyncs, head);
+ }
+ pthread_mutex_unlock(&priv->fsync_mutex);
- return count;
+ return count;
}
-
void
-posix_fsyncer_process (xlator_t *this, call_stub_t *stub, gf_boolean_t do_fsync)
-{
- struct posix_fd *pfd = NULL;
- int ret = -1;
- int op_errno = 0;
-
- ret = posix_fd_ctx_get (stub->args.fd, this, &pfd, &op_errno);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- P_MSG_GET_FDCTX_FAILED,
- "could not get fdctx for fd(%s)",
- uuid_utoa (stub->args.fd->inode->gfid));
- call_unwind_error (stub, -1, op_errno);
- return;
- }
+posix_fsyncer_process(xlator_t *this, call_stub_t *stub, gf_boolean_t do_fsync)
+{
+ struct posix_fd *pfd = NULL;
+ int ret = -1;
+ int op_errno = 0;
+
+ ret = posix_fd_ctx_get(stub->args.fd, this, &pfd, &op_errno);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_GET_FDCTX_FAILED,
+ "could not get fdctx for fd(%s)",
+ uuid_utoa(stub->args.fd->inode->gfid));
+ call_unwind_error(stub, -1, op_errno);
+ return;
+ }
- if (do_fsync) {
- if (stub->args.datasync)
- ret = sys_fdatasync (pfd->fd);
- else
- ret = sys_fsync (pfd->fd);
- } else {
- ret = 0;
- }
+ if (do_fsync) {
+ if (stub->args.datasync)
+ ret = sys_fdatasync(pfd->fd);
+ else
+ ret = sys_fsync(pfd->fd);
+ } else {
+ ret = 0;
+ }
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
- "could not fstat fd(%s)",
- uuid_utoa (stub->args.fd->inode->gfid));
- call_unwind_error (stub, -1, errno);
- return;
- }
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
+ "could not fstat fd(%s)", uuid_utoa(stub->args.fd->inode->gfid));
+ call_unwind_error(stub, -1, errno);
+ return;
+ }
- call_unwind_error (stub, 0, 0);
+ call_unwind_error(stub, 0, 0);
}
-
static void
-posix_fsyncer_syncfs (xlator_t *this, struct list_head *head)
+posix_fsyncer_syncfs(xlator_t *this, struct list_head *head)
{
- call_stub_t *stub = NULL;
- struct posix_fd *pfd = NULL;
- int ret = -1;
+ call_stub_t *stub = NULL;
+ struct posix_fd *pfd = NULL;
+ int ret = -1;
- stub = list_entry (head->prev, call_stub_t, list);
- ret = posix_fd_ctx_get (stub->args.fd, this, &pfd, NULL);
- if (ret)
- return;
+ stub = list_entry(head->prev, call_stub_t, list);
+ ret = posix_fd_ctx_get(stub->args.fd, this, &pfd, NULL);
+ if (ret)
+ return;
#ifdef GF_LINUX_HOST_OS
/* syncfs() is not "declared" in RHEL's glibc even though
@@ -2280,152 +2235,152 @@ posix_fsyncer_syncfs (xlator_t *this, struct list_head *head)
#include <sys/syscall.h>
#include <unistd.h>
#ifdef SYS_syncfs
- syscall (SYS_syncfs, pfd->fd);
+ syscall(SYS_syncfs, pfd->fd);
#else
- sync();
+ sync();
#endif
#else
- sync();
+ sync();
#endif
}
-
void *
-posix_fsyncer (void *d)
+posix_fsyncer(void *d)
{
- xlator_t *this = d;
- struct posix_private *priv = NULL;
- call_stub_t *stub = NULL;
- call_stub_t *tmp = NULL;
- struct list_head list;
- int count = 0;
- gf_boolean_t do_fsync = _gf_true;
+ xlator_t *this = d;
+ struct posix_private *priv = NULL;
+ call_stub_t *stub = NULL;
+ call_stub_t *tmp = NULL;
+ struct list_head list;
+ int count = 0;
+ gf_boolean_t do_fsync = _gf_true;
- priv = this->private;
+ priv = this->private;
- for (;;) {
- INIT_LIST_HEAD (&list);
+ for (;;) {
+ INIT_LIST_HEAD(&list);
- count = posix_fsyncer_pick (this, &list);
+ count = posix_fsyncer_pick(this, &list);
- usleep (priv->batch_fsync_delay_usec);
+ usleep(priv->batch_fsync_delay_usec);
- gf_msg_debug (this->name, 0,
- "picked %d fsyncs", count);
+ gf_msg_debug(this->name, 0, "picked %d fsyncs", count);
- switch (priv->batch_fsync_mode) {
- case BATCH_NONE:
- case BATCH_REVERSE_FSYNC:
- break;
- case BATCH_SYNCFS:
- case BATCH_SYNCFS_SINGLE_FSYNC:
- case BATCH_SYNCFS_REVERSE_FSYNC:
- posix_fsyncer_syncfs (this, &list);
- break;
- }
+ switch (priv->batch_fsync_mode) {
+ case BATCH_NONE:
+ case BATCH_REVERSE_FSYNC:
+ break;
+ case BATCH_SYNCFS:
+ case BATCH_SYNCFS_SINGLE_FSYNC:
+ case BATCH_SYNCFS_REVERSE_FSYNC:
+ posix_fsyncer_syncfs(this, &list);
+ break;
+ }
- if (priv->batch_fsync_mode == BATCH_SYNCFS)
- do_fsync = _gf_false;
- else
- do_fsync = _gf_true;
+ if (priv->batch_fsync_mode == BATCH_SYNCFS)
+ do_fsync = _gf_false;
+ else
+ do_fsync = _gf_true;
- list_for_each_entry_safe_reverse (stub, tmp, &list, list) {
- list_del_init (&stub->list);
+ list_for_each_entry_safe_reverse(stub, tmp, &list, list)
+ {
+ list_del_init(&stub->list);
- posix_fsyncer_process (this, stub, do_fsync);
+ posix_fsyncer_process(this, stub, do_fsync);
- if (priv->batch_fsync_mode == BATCH_SYNCFS_SINGLE_FSYNC)
- do_fsync = _gf_false;
- }
+ if (priv->batch_fsync_mode == BATCH_SYNCFS_SINGLE_FSYNC)
+ do_fsync = _gf_false;
}
+ }
}
/**
* TODO: move fd/inode interfaces into a single routine..
*/
static int32_t
-posix_fetch_signature_xattr (char *real_path,
- const char *key, dict_t *xattr, size_t *xsize)
-{
- int32_t ret = 0;
- char *memptr = NULL;
- ssize_t xattrsize = 0;
- char val_buf[2048] = {0,};
- gf_boolean_t have_val = _gf_false;
-
- xattrsize = sys_lgetxattr (real_path, key, val_buf,
- sizeof(val_buf) - 1);
- if (xattrsize >= 0) {
- have_val = _gf_true;
- } else {
- if (errno == ERANGE)
- xattrsize = sys_lgetxattr (real_path, key, NULL, 0);
- if ((errno == ENOATTR) || (errno == ENODATA))
- return 0;
- if (xattrsize == -1)
- goto error_return;
- }
- memptr = GF_MALLOC (xattrsize + 1, gf_posix_mt_char);
- if (!memptr)
- goto error_return;
- if (have_val) {
- memcpy (memptr, val_buf, xattrsize);
- memptr[xattrsize] = '\0';
- } else {
- bzero (memptr, xattrsize + 1);
- ret = sys_lgetxattr (real_path, key, memptr, xattrsize);
- if (ret == -1)
- goto freemem;
- }
- ret = dict_set_dynptr (xattr, (char *)key, memptr, xattrsize);
- if (ret)
- goto freemem;
+posix_fetch_signature_xattr(char *real_path, const char *key, dict_t *xattr,
+ size_t *xsize)
+{
+ int32_t ret = 0;
+ char *memptr = NULL;
+ ssize_t xattrsize = 0;
+ char val_buf[2048] = {
+ 0,
+ };
+ gf_boolean_t have_val = _gf_false;
+
+ xattrsize = sys_lgetxattr(real_path, key, val_buf, sizeof(val_buf) - 1);
+ if (xattrsize >= 0) {
+ have_val = _gf_true;
+ } else {
+ if (errno == ERANGE)
+ xattrsize = sys_lgetxattr(real_path, key, NULL, 0);
+ if ((errno == ENOATTR) || (errno == ENODATA))
+ return 0;
+ if (xattrsize == -1)
+ goto error_return;
+ }
+ memptr = GF_MALLOC(xattrsize + 1, gf_posix_mt_char);
+ if (!memptr)
+ goto error_return;
+ if (have_val) {
+ memcpy(memptr, val_buf, xattrsize);
+ memptr[xattrsize] = '\0';
+ } else {
+ bzero(memptr, xattrsize + 1);
+ ret = sys_lgetxattr(real_path, key, memptr, xattrsize);
+ if (ret == -1)
+ goto freemem;
+ }
+ ret = dict_set_dynptr(xattr, (char *)key, memptr, xattrsize);
+ if (ret)
+ goto freemem;
- if (xsize)
- *xsize = xattrsize;
+ if (xsize)
+ *xsize = xattrsize;
- return 0;
+ return 0;
- freemem:
- GF_FREE (memptr);
- error_return:
- return -1;
+freemem:
+ GF_FREE(memptr);
+error_return:
+ return -1;
}
static int32_t
-posix_fd_fetch_signature_xattr (int fd,
- const char *key, dict_t *xattr, size_t *xsize)
+posix_fd_fetch_signature_xattr(int fd, const char *key, dict_t *xattr,
+ size_t *xsize)
{
- int32_t ret = 0;
- char *memptr = NULL;
- ssize_t xattrsize = 0;
+ int32_t ret = 0;
+ char *memptr = NULL;
+ ssize_t xattrsize = 0;
- xattrsize = sys_fgetxattr (fd, key, NULL, 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA)))
- return 0;
- if (xattrsize == -1)
- goto error_return;
+ xattrsize = sys_fgetxattr(fd, key, NULL, 0);
+ if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA)))
+ return 0;
+ if (xattrsize == -1)
+ goto error_return;
- memptr = GF_CALLOC (xattrsize + 1, sizeof (char), gf_posix_mt_char);
- if (!memptr)
- goto error_return;
- ret = sys_fgetxattr (fd, key, memptr, xattrsize);
- if (ret == -1)
- goto freemem;
+ memptr = GF_CALLOC(xattrsize + 1, sizeof(char), gf_posix_mt_char);
+ if (!memptr)
+ goto error_return;
+ ret = sys_fgetxattr(fd, key, memptr, xattrsize);
+ if (ret == -1)
+ goto freemem;
- ret = dict_set_dynptr (xattr, (char *)key, memptr, xattrsize);
- if (ret)
- goto freemem;
+ ret = dict_set_dynptr(xattr, (char *)key, memptr, xattrsize);
+ if (ret)
+ goto freemem;
- if (xsize)
- *xsize = xattrsize;
+ if (xsize)
+ *xsize = xattrsize;
- return 0;
+ return 0;
- freemem:
- GF_FREE (memptr);
- error_return:
- return -1;
+freemem:
+ GF_FREE(memptr);
+error_return:
+ return -1;
}
/**
@@ -2435,65 +2390,65 @@ posix_fd_fetch_signature_xattr (int fd,
* interpreting the xattrs for anomalies.
*/
int32_t
-posix_get_objectsignature (char *real_path, dict_t *xattr)
+posix_get_objectsignature(char *real_path, dict_t *xattr)
{
- int32_t ret = 0;
- size_t signsize = 0;
+ int32_t ret = 0;
+ size_t signsize = 0;
- ret = posix_fetch_signature_xattr
- (real_path, BITROT_CURRENT_VERSION_KEY, xattr, NULL);
- if (ret)
- goto error_return;
+ ret = posix_fetch_signature_xattr(real_path, BITROT_CURRENT_VERSION_KEY,
+ xattr, NULL);
+ if (ret)
+ goto error_return;
- ret = posix_fetch_signature_xattr
- (real_path, BITROT_SIGNING_VERSION_KEY, xattr, &signsize);
- if (ret)
- goto delkey1;
+ ret = posix_fetch_signature_xattr(real_path, BITROT_SIGNING_VERSION_KEY,
+ xattr, &signsize);
+ if (ret)
+ goto delkey1;
- ret = dict_set_uint32
- (xattr, BITROT_SIGNING_XATTR_SIZE_KEY, (uint32_t) signsize);
- if (ret)
- goto delkey2;
+ ret = dict_set_uint32(xattr, BITROT_SIGNING_XATTR_SIZE_KEY,
+ (uint32_t)signsize);
+ if (ret)
+ goto delkey2;
- return 0;
+ return 0;
- delkey2:
- dict_del (xattr, BITROT_SIGNING_VERSION_KEY);
- delkey1:
- dict_del (xattr, BITROT_CURRENT_VERSION_KEY);
- error_return:
- return -EINVAL;
+delkey2:
+ dict_del(xattr, BITROT_SIGNING_VERSION_KEY);
+delkey1:
+ dict_del(xattr, BITROT_CURRENT_VERSION_KEY);
+error_return:
+ return -EINVAL;
}
int32_t
-posix_fdget_objectsignature (int fd, dict_t *xattr)
+posix_fdget_objectsignature(int fd, dict_t *xattr)
{
- int32_t ret = 0;
- size_t signsize = 0;
+ int32_t ret = 0;
+ size_t signsize = 0;
- ret = posix_fd_fetch_signature_xattr
- (fd, BITROT_CURRENT_VERSION_KEY, xattr, NULL);
- if (ret)
- goto error_return;
+ ret = posix_fd_fetch_signature_xattr(fd, BITROT_CURRENT_VERSION_KEY, xattr,
+ NULL);
+ if (ret)
+ goto error_return;
- ret = posix_fd_fetch_signature_xattr
- (fd, BITROT_SIGNING_VERSION_KEY, xattr, &signsize);
- if (ret)
- goto delkey1;
+ ret = posix_fd_fetch_signature_xattr(fd, BITROT_SIGNING_VERSION_KEY, xattr,
+ &signsize);
+ if (ret)
+ goto delkey1;
- ret = dict_set_uint32
- (xattr, BITROT_SIGNING_XATTR_SIZE_KEY, (uint32_t) signsize);
- if (ret)
- goto delkey2;
+ ret = dict_set_uint32(xattr, BITROT_SIGNING_XATTR_SIZE_KEY,
+ (uint32_t)signsize);
+ if (ret)
+ goto delkey2;
- return 0;
+ return 0;
- delkey2:
- dict_del (xattr, BITROT_SIGNING_VERSION_KEY);
- delkey1:
- dict_del (xattr, BITROT_CURRENT_VERSION_KEY);
- error_return:
- return -EINVAL;
+delkey2:
+ dict_del(xattr, BITROT_SIGNING_VERSION_KEY);
+delkey1:
+ dict_del(xattr, BITROT_CURRENT_VERSION_KEY);
+error_return:
+ return -EINVAL;
}
/*
@@ -2506,793 +2461,782 @@ posix_fdget_objectsignature (int fd, dict_t *xattr)
**/
int32_t
-posix_resolve_dirgfid_to_path (const uuid_t dirgfid, const char *brick_path,
- const char *bname, char **path)
-{
- char *linkname = NULL;
- char *dir_handle = NULL;
- char *pgfidstr = NULL;
- char *saveptr = NULL;
- ssize_t len = 0;
- int ret = 0;
- uuid_t tmp_gfid = {0, };
- uuid_t pargfid = {0, };
- char gpath[PATH_MAX] = {0,};
- char result[PATH_MAX] = {0,};
- char result1[PATH_MAX] = {0,};
- char *dir_name = NULL;
- char pre_dir_name[PATH_MAX] = {0,};
- xlator_t *this = NULL;
-
- this = THIS;
- GF_ASSERT (this);
-
- gf_uuid_copy (pargfid, dirgfid);
- if (!path || gf_uuid_is_null (pargfid)) {
- ret = -1;
- goto out;
- }
-
- if (__is_root_gfid (pargfid)) {
- if (bname) {
- snprintf (result, PATH_MAX, "/%s", bname);
- *path = gf_strdup (result);
- } else {
- *path = gf_strdup ("/");
- }
- return ret;
+posix_resolve_dirgfid_to_path(const uuid_t dirgfid, const char *brick_path,
+ const char *bname, char **path)
+{
+ char *linkname = NULL;
+ char *dir_handle = NULL;
+ char *pgfidstr = NULL;
+ char *saveptr = NULL;
+ ssize_t len = 0;
+ int ret = 0;
+ uuid_t tmp_gfid = {
+ 0,
+ };
+ uuid_t pargfid = {
+ 0,
+ };
+ char gpath[PATH_MAX] = {
+ 0,
+ };
+ char result[PATH_MAX] = {
+ 0,
+ };
+ char result1[PATH_MAX] = {
+ 0,
+ };
+ char *dir_name = NULL;
+ char pre_dir_name[PATH_MAX] = {
+ 0,
+ };
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT(this);
+
+ gf_uuid_copy(pargfid, dirgfid);
+ if (!path || gf_uuid_is_null(pargfid)) {
+ ret = -1;
+ goto out;
+ }
+
+ if (__is_root_gfid(pargfid)) {
+ if (bname) {
+ snprintf(result, PATH_MAX, "/%s", bname);
+ *path = gf_strdup(result);
+ } else {
+ *path = gf_strdup("/");
}
+ return ret;
+ }
- dir_handle = alloca (PATH_MAX);
- linkname = alloca (PATH_MAX);
- (void) snprintf (gpath, PATH_MAX, "%s/.glusterfs/", brick_path);
-
- while (!(__is_root_gfid (pargfid))) {
- len = snprintf (dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath,
- pargfid[0], pargfid[1], uuid_utoa (pargfid));
- if ((len < 0) || (len >= PATH_MAX)) {
- ret = -1;
- goto out;
- }
-
- len = sys_readlink (dir_handle, linkname, PATH_MAX);
- if (len < 0) {
- gf_msg (this->name, 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';
+ dir_handle = alloca(PATH_MAX);
+ linkname = alloca(PATH_MAX);
+ (void)snprintf(gpath, PATH_MAX, "%s/.glusterfs/", brick_path);
- pgfidstr = strtok_r (linkname + strlen("../../00/00/"), "/",
- &saveptr);
- dir_name = strtok_r (NULL, "/", &saveptr);
+ while (!(__is_root_gfid(pargfid))) {
+ len = snprintf(dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath,
+ pargfid[0], pargfid[1], uuid_utoa(pargfid));
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
- if (strlen(pre_dir_name) != 0) { /* Remove '/' at the end */
- len = snprintf (result, PATH_MAX, "%s/%s", dir_name,
- pre_dir_name);
- } else {
- len = snprintf (result, PATH_MAX, "%s", dir_name);
- }
- if ((len < 0) || (len >= PATH_MAX)) {
- ret = -1;
- goto out;
- }
+ len = sys_readlink(dir_handle, linkname, PATH_MAX);
+ if (len < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_READLINK_FAILED,
+ "could not read the "
+ "link from the gfid handle %s",
+ dir_handle);
+ ret = -1;
+ goto out;
+ }
- snprintf (pre_dir_name, sizeof (pre_dir_name), "%s", result);
+ linkname[len] = '\0';
- gf_uuid_parse (pgfidstr, tmp_gfid);
- gf_uuid_copy (pargfid, tmp_gfid);
- }
+ pgfidstr = strtok_r(linkname + strlen("../../00/00/"), "/", &saveptr);
+ dir_name = strtok_r(NULL, "/", &saveptr);
- if (bname) {
- len = snprintf (result1, PATH_MAX, "/%s/%s", result, bname);
+ if (strlen(pre_dir_name) != 0) { /* Remove '/' at the end */
+ len = snprintf(result, PATH_MAX, "%s/%s", dir_name, pre_dir_name);
} else {
- len = snprintf (result1, PATH_MAX, "/%s", result);
+ len = snprintf(result, PATH_MAX, "%s", dir_name);
}
if ((len < 0) || (len >= PATH_MAX)) {
- ret = -1;
- goto out;
+ ret = -1;
+ goto out;
}
- *path = gf_strdup (result1);
- if (*path == NULL) {
- ret = -1;
- goto out;
- }
+ snprintf(pre_dir_name, sizeof(pre_dir_name), "%s", result);
+
+ gf_uuid_parse(pgfidstr, tmp_gfid);
+ gf_uuid_copy(pargfid, tmp_gfid);
+ }
+
+ if (bname) {
+ len = snprintf(result1, PATH_MAX, "/%s/%s", result, bname);
+ } else {
+ len = snprintf(result1, PATH_MAX, "/%s", result);
+ }
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
+
+ *path = gf_strdup(result1);
+ if (*path == NULL) {
+ ret = -1;
+ goto out;
+ }
out:
- return ret;
+ return ret;
}
posix_inode_ctx_t *
-__posix_inode_ctx_get (inode_t *inode, xlator_t *this)
+__posix_inode_ctx_get(inode_t *inode, xlator_t *this)
{
- int ret = -1;
- uint64_t ctx_uint = 0;
- posix_inode_ctx_t *ctx_p = NULL;
+ int ret = -1;
+ uint64_t ctx_uint = 0;
+ posix_inode_ctx_t *ctx_p = NULL;
- ret = __inode_ctx_get (inode, this, &ctx_uint);
- if (ret == 0) {
- return (posix_inode_ctx_t *)ctx_uint;
- }
+ ret = __inode_ctx_get(inode, this, &ctx_uint);
+ if (ret == 0) {
+ return (posix_inode_ctx_t *)ctx_uint;
+ }
- ctx_p = GF_CALLOC (1, sizeof (*ctx_p), gf_posix_mt_inode_ctx_t);
- if (!ctx_p)
- return NULL;
+ ctx_p = GF_CALLOC(1, sizeof(*ctx_p), gf_posix_mt_inode_ctx_t);
+ if (!ctx_p)
+ return NULL;
- pthread_mutex_init (&ctx_p->xattrop_lock, NULL);
- pthread_mutex_init (&ctx_p->write_atomic_lock, NULL);
- pthread_mutex_init (&ctx_p->pgfid_lock, NULL);
+ pthread_mutex_init(&ctx_p->xattrop_lock, NULL);
+ pthread_mutex_init(&ctx_p->write_atomic_lock, NULL);
+ pthread_mutex_init(&ctx_p->pgfid_lock, NULL);
- ret = __inode_ctx_set (inode, this, (uint64_t *)&ctx_p);
- if (ret < 0) {
- pthread_mutex_destroy (&ctx_p->xattrop_lock);
- pthread_mutex_destroy (&ctx_p->write_atomic_lock);
- pthread_mutex_destroy (&ctx_p->pgfid_lock);
- GF_FREE (ctx_p);
- return NULL;
- }
+ ret = __inode_ctx_set(inode, this, (uint64_t *)&ctx_p);
+ if (ret < 0) {
+ pthread_mutex_destroy(&ctx_p->xattrop_lock);
+ pthread_mutex_destroy(&ctx_p->write_atomic_lock);
+ pthread_mutex_destroy(&ctx_p->pgfid_lock);
+ GF_FREE(ctx_p);
+ return NULL;
+ }
- return ctx_p;
+ return ctx_p;
}
int
-__posix_inode_ctx_set_unlink_flag (inode_t *inode, xlator_t *this, uint64_t ctx)
+__posix_inode_ctx_set_unlink_flag(inode_t *inode, xlator_t *this, uint64_t ctx)
{
- posix_inode_ctx_t *ctx_p = NULL;
+ posix_inode_ctx_t *ctx_p = NULL;
- ctx_p = __posix_inode_ctx_get (inode, this);
- if (ctx_p == NULL)
- return -1;
+ ctx_p = __posix_inode_ctx_get(inode, this);
+ if (ctx_p == NULL)
+ return -1;
- ctx_p->unlink_flag = ctx;
+ ctx_p->unlink_flag = ctx;
- return 0;
+ return 0;
}
int
-posix_inode_ctx_set_unlink_flag (inode_t *inode, xlator_t *this, uint64_t ctx)
+posix_inode_ctx_set_unlink_flag(inode_t *inode, xlator_t *this, uint64_t ctx)
{
- int ret = -1;
+ int ret = -1;
- LOCK(&inode->lock);
- {
- ret = __posix_inode_ctx_set_unlink_flag (inode, this, ctx);
- }
- UNLOCK(&inode->lock);
+ LOCK(&inode->lock);
+ {
+ ret = __posix_inode_ctx_set_unlink_flag(inode, this, ctx);
+ }
+ UNLOCK(&inode->lock);
- return ret;
+ return ret;
}
int
-__posix_inode_ctx_get_all (inode_t *inode, xlator_t *this,
- posix_inode_ctx_t **ctx)
+__posix_inode_ctx_get_all(inode_t *inode, xlator_t *this,
+ posix_inode_ctx_t **ctx)
{
- posix_inode_ctx_t *ctx_p = NULL;
+ posix_inode_ctx_t *ctx_p = NULL;
- ctx_p = __posix_inode_ctx_get (inode, this);
- if (ctx_p == NULL)
- return -1;
+ ctx_p = __posix_inode_ctx_get(inode, this);
+ if (ctx_p == NULL)
+ return -1;
- *ctx = ctx_p;
+ *ctx = ctx_p;
- return 0;
+ return 0;
}
int
-posix_inode_ctx_get_all (inode_t *inode, xlator_t *this,
- posix_inode_ctx_t **ctx)
+posix_inode_ctx_get_all(inode_t *inode, xlator_t *this, posix_inode_ctx_t **ctx)
{
- int ret = 0;
+ int ret = 0;
- LOCK(&inode->lock);
- {
- ret = __posix_inode_ctx_get_all (inode, this, ctx);
- }
- UNLOCK(&inode->lock);
+ LOCK(&inode->lock);
+ {
+ ret = __posix_inode_ctx_get_all(inode, this, ctx);
+ }
+ UNLOCK(&inode->lock);
- return ret;
+ return ret;
}
gf_boolean_t
-posix_is_bulk_removexattr (char *name, dict_t *xdata)
+posix_is_bulk_removexattr(char *name, dict_t *xdata)
{
- if (name && (strlen (name) == 0) && xdata)
- return _gf_true;
- return _gf_false;
+ if (name && (strlen(name) == 0) && xdata)
+ return _gf_true;
+ return _gf_false;
}
int32_t
-posix_set_iatt_in_dict (dict_t *dict, struct iatt *preop, struct iatt *postop)
-{
- int ret = -1;
- struct iatt *stbuf = NULL;
- int32_t len = sizeof(struct iatt);
- struct iatt *prebuf = NULL;
- struct iatt *postbuf = NULL;
-
- if (!dict)
- return ret;
-
- if (postop) {
- stbuf = GF_MALLOC (len, gf_common_mt_char);
- if (!stbuf)
- goto out;
- memcpy (stbuf, postop, len);
- ret = dict_set_iatt (dict, DHT_IATT_IN_XDATA_KEY, stbuf,
- false);
- if (ret < 0) {
- GF_FREE (stbuf);
- goto out;
- }
+posix_set_iatt_in_dict(dict_t *dict, struct iatt *preop, struct iatt *postop)
+{
+ int ret = -1;
+ struct iatt *stbuf = NULL;
+ int32_t len = sizeof(struct iatt);
+ struct iatt *prebuf = NULL;
+ struct iatt *postbuf = NULL;
+
+ if (!dict)
+ return ret;
+
+ if (postop) {
+ stbuf = GF_MALLOC(len, gf_common_mt_char);
+ if (!stbuf)
+ goto out;
+ memcpy(stbuf, postop, len);
+ ret = dict_set_iatt(dict, DHT_IATT_IN_XDATA_KEY, stbuf, false);
+ if (ret < 0) {
+ GF_FREE(stbuf);
+ goto out;
}
+ }
- if (preop) {
- prebuf = GF_MALLOC (len, gf_common_mt_char);
- if (!prebuf)
- goto out;
- memcpy (prebuf, preop, len);
- ret = dict_set_iatt (dict, GF_PRESTAT, prebuf, false);
- if (ret < 0) {
- GF_FREE (prebuf);
- goto out;
- }
+ if (preop) {
+ prebuf = GF_MALLOC(len, gf_common_mt_char);
+ if (!prebuf)
+ goto out;
+ memcpy(prebuf, preop, len);
+ ret = dict_set_iatt(dict, GF_PRESTAT, prebuf, false);
+ if (ret < 0) {
+ GF_FREE(prebuf);
+ goto out;
}
+ }
- if (postop) {
- postbuf = GF_MALLOC (len, gf_common_mt_char);
- if (!postbuf)
- goto out;
- memcpy (postbuf, postop, len);
- ret = dict_set_iatt (dict, GF_POSTSTAT, postbuf, false);
- if (ret < 0) {
- GF_FREE (postbuf);
- goto out;
- }
+ if (postop) {
+ postbuf = GF_MALLOC(len, gf_common_mt_char);
+ if (!postbuf)
+ goto out;
+ memcpy(postbuf, postop, len);
+ ret = dict_set_iatt(dict, GF_POSTSTAT, postbuf, false);
+ if (ret < 0) {
+ GF_FREE(postbuf);
+ goto out;
}
+ }
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
mode_t
-posix_override_umask (mode_t mode, mode_t mode_bit)
+posix_override_umask(mode_t mode, mode_t mode_bit)
{
- gf_msg_debug ("posix", 0, "The value of mode is %u", mode);
- mode = mode >> 9; /* 3x3 (bits for each octal digit)*/
- mode = (mode << 9) | mode_bit;
- gf_msg_debug ("posix", 0, "The value of mode is %u", mode);
- return mode;
+ gf_msg_debug("posix", 0, "The value of mode is %u", mode);
+ mode = mode >> 9; /* 3x3 (bits for each octal digit)*/
+ mode = (mode << 9) | mode_bit;
+ gf_msg_debug("posix", 0, "The value of mode is %u", mode);
+ return mode;
}
int
-posix_check_internal_writes (xlator_t *this, fd_t *fd, int sysfd,
- dict_t *xdata)
+posix_check_internal_writes(xlator_t *this, fd_t *fd, int sysfd, dict_t *xdata)
{
- int ret = 0;
- size_t xattrsize = 0;
- data_t *val = NULL;
-
- if (!xdata)
- return 0;
+ int ret = 0;
+ size_t xattrsize = 0;
+ data_t *val = NULL;
- LOCK (&fd->inode->lock);
- {
- val = dict_get (xdata, GF_PROTECT_FROM_EXTERNAL_WRITES);
- if (val) {
- ret = sys_fsetxattr (sysfd,
- GF_PROTECT_FROM_EXTERNAL_WRITES,
- val->data, val->len, 0);
- if (ret == -1) {
- gf_msg (this->name, GF_LOG_ERROR,
- P_MSG_XATTR_FAILED,
- errno, "setxattr failed key %s",
- GF_PROTECT_FROM_EXTERNAL_WRITES);
- }
-
- goto out;
- }
+ if (!xdata)
+ return 0;
- if (dict_get (xdata, GF_AVOID_OVERWRITE)) {
- xattrsize = sys_fgetxattr (sysfd,
- GF_PROTECT_FROM_EXTERNAL_WRITES,
- NULL, 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) ||
- (errno == ENODATA))) {
- ret = 0;
- } else {
- ret = -1;
- }
- }
+ LOCK(&fd->inode->lock);
+ {
+ val = dict_get(xdata, GF_PROTECT_FROM_EXTERNAL_WRITES);
+ if (val) {
+ ret = sys_fsetxattr(sysfd, GF_PROTECT_FROM_EXTERNAL_WRITES,
+ val->data, val->len, 0);
+ if (ret == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, P_MSG_XATTR_FAILED, errno,
+ "setxattr failed key %s",
+ GF_PROTECT_FROM_EXTERNAL_WRITES);
+ }
+
+ goto out;
+ }
+
+ if (dict_get(xdata, GF_AVOID_OVERWRITE)) {
+ xattrsize = sys_fgetxattr(sysfd, GF_PROTECT_FROM_EXTERNAL_WRITES,
+ NULL, 0);
+ if ((xattrsize == -1) &&
+ ((errno == ENOATTR) || (errno == ENODATA))) {
+ ret = 0;
+ } else {
+ ret = -1;
+ }
}
+ }
out:
- UNLOCK (&fd->inode->lock);
- return ret;
+ UNLOCK(&fd->inode->lock);
+ return ret;
}
gf_cs_obj_state
-posix_cs_heal_state (xlator_t *this, const char *realpath, int *fd,
- struct iatt *buf)
-{
- gf_boolean_t remote = _gf_false;
- gf_boolean_t downloading = _gf_false;
- int ret = 0;
- gf_cs_obj_state state = GF_CS_ERROR;
- size_t xattrsize = 0;
-
- if (!buf) {
- ret = -1;
- goto out;
+posix_cs_heal_state(xlator_t *this, const char *realpath, int *fd,
+ struct iatt *buf)
+{
+ gf_boolean_t remote = _gf_false;
+ gf_boolean_t downloading = _gf_false;
+ int ret = 0;
+ gf_cs_obj_state state = GF_CS_ERROR;
+ size_t xattrsize = 0;
+
+ if (!buf) {
+ ret = -1;
+ goto out;
+ }
+
+ if (fd) {
+ xattrsize = sys_fgetxattr(*fd, GF_CS_OBJECT_REMOTE, NULL, 0);
+ if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA))) {
+ remote = _gf_false;
+ } else if (xattrsize == -1) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ "fgetxattr"
+ " failed");
+ state = GF_CS_ERROR;
+ goto out;
+ } else {
+ remote = _gf_true;
+ }
+
+ xattrsize = sys_fgetxattr(*fd, GF_CS_OBJECT_DOWNLOADING, NULL, 0);
+ if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA))) {
+ downloading = _gf_false;
+ } else if (xattrsize == -1) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ "fgetxattr"
+ " failed");
+ state = GF_CS_ERROR;
+ goto out;
+ } else {
+ downloading = _gf_true;
+ }
+ } else {
+ xattrsize = sys_lgetxattr(realpath, GF_CS_OBJECT_REMOTE, NULL, 0);
+ if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA))) {
+ remote = _gf_false;
+ } else if (xattrsize == -1) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ "getxattr"
+ " failed");
+ state = GF_CS_ERROR;
+ goto out;
+ } else {
+ remote = _gf_true;
+ }
+
+ xattrsize = sys_lgetxattr(realpath, GF_CS_OBJECT_DOWNLOADING, NULL, 0);
+ if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA))) {
+ downloading = _gf_false;
+ } else if (xattrsize == -1) {
+ ret = -1;
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ "getxattr"
+ " failed");
+ state = GF_CS_ERROR;
+ goto out;
+ } else {
+ downloading = _gf_true;
}
+ }
+ if (remote && downloading) {
if (fd) {
- xattrsize = sys_fgetxattr (*fd, GF_CS_OBJECT_REMOTE, NULL, 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) ||
- (errno == ENODATA))) {
- remote = _gf_false;
- } else if (xattrsize == -1) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, 0, errno, "fgetxattr"
- " failed");
- state = GF_CS_ERROR;
- goto out;
- } else {
- remote = _gf_true;
- }
-
- xattrsize = sys_fgetxattr (*fd, GF_CS_OBJECT_DOWNLOADING, NULL,
- 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) ||
- (errno == ENODATA))) {
- downloading = _gf_false;
- } else if (xattrsize == -1) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, 0, errno, "fgetxattr"
- " failed");
- state = GF_CS_ERROR;
- goto out;
- } else {
- downloading = _gf_true;
- }
+ ret = sys_fremovexattr(*fd, GF_CS_OBJECT_DOWNLOADING);
} else {
- xattrsize = sys_lgetxattr (realpath, GF_CS_OBJECT_REMOTE, NULL,
- 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) ||
- (errno == ENODATA))) {
- remote = _gf_false;
- } else if (xattrsize == -1) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, 0, errno, "getxattr"
- " failed");
- state = GF_CS_ERROR;
- goto out;
- } else {
- remote = _gf_true;
- }
-
- xattrsize = sys_lgetxattr (realpath, GF_CS_OBJECT_DOWNLOADING,
- NULL, 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) ||
- (errno == ENODATA))) {
- downloading = _gf_false;
- } else if (xattrsize == -1) {
- ret = -1;
- gf_msg (this->name, GF_LOG_ERROR, 0, errno, "getxattr"
- " failed");
- state = GF_CS_ERROR;
- goto out;
- } else {
- downloading = _gf_true;
- }
+ ret = sys_lremovexattr(realpath, GF_CS_OBJECT_DOWNLOADING);
}
- if (remote && downloading) {
- if (fd) {
- ret = sys_fremovexattr (*fd, GF_CS_OBJECT_DOWNLOADING);
- } else {
- ret = sys_lremovexattr (realpath, GF_CS_OBJECT_DOWNLOADING);
- }
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ "failed to remove xattr, repair failed");
+ state = GF_CS_ERROR;
+ goto out;
+ }
+
+ if (buf->ia_size) {
+ if (fd) {
+ ret = sys_ftruncate(*fd, 0);
+ } else {
+ ret = sys_truncate(realpath, 0);
+ }
+
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ "truncate failed. File is in inconsistent"
+ " state");
+ state = GF_CS_ERROR;
+ goto out;
+ }
+ }
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, errno,
- "failed to remove xattr, repair failed");
- state = GF_CS_ERROR;
- goto out;
- }
+ state = GF_CS_REMOTE;
+ goto out;
- if (buf->ia_size) {
- if (fd) {
- ret = sys_ftruncate (*fd, 0);
- } else {
- ret = sys_truncate (realpath, 0);
- }
-
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, errno,
- "truncate failed. File is in inconsistent"
- " state");
- state = GF_CS_ERROR;
- goto out;
- }
- }
-
- state = GF_CS_REMOTE;
+ } else if (remote) {
+ if (buf->ia_size) {
+ if (fd) {
+ ret = sys_ftruncate(*fd, 0);
+ } else {
+ ret = sys_truncate(realpath, 0);
+ }
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ "truncate failed. File is in inconsistent"
+ " state");
+ state = GF_CS_ERROR;
goto out;
+ }
+ }
- } else if (remote) {
- if (buf->ia_size) {
- if (fd) {
- ret = sys_ftruncate (*fd, 0);
- } else {
- ret = sys_truncate (realpath, 0);
- }
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, errno,
- "truncate failed. File is in inconsistent"
- " state");
- state = GF_CS_ERROR;
- goto out;
- }
- }
+ state = GF_CS_REMOTE;
+ goto out;
+ } else if (downloading) {
+ if (buf->ia_size) {
+ if (fd) {
+ ret = sys_fremovexattr(*fd, GF_CS_OBJECT_DOWNLOADING);
+ } else {
+ ret = sys_lremovexattr(realpath, GF_CS_OBJECT_DOWNLOADING);
+ }
- state = GF_CS_REMOTE;
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ "failed to remove xattr, repair failed");
+ state = GF_CS_ERROR;
goto out;
- } else if (downloading) {
- if (buf->ia_size) {
- if (fd) {
- ret = sys_fremovexattr (*fd, GF_CS_OBJECT_DOWNLOADING);
- } else {
- ret = sys_lremovexattr (realpath, GF_CS_OBJECT_DOWNLOADING);
- }
-
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, errno,
- "failed to remove xattr, repair failed");
- state = GF_CS_ERROR;
- goto out;
- }
-
- state = GF_CS_LOCAL;
- goto out;
- }
+ }
+
+ state = GF_CS_LOCAL;
+ goto out;
}
+ }
- state = GF_CS_LOCAL;
+ state = GF_CS_LOCAL;
out:
- gf_msg_debug (this->name, 0, "heal state returned %d", state);
- return state;
+ gf_msg_debug(this->name, 0, "heal state returned %d", state);
+ return state;
}
gf_cs_obj_state
-posix_cs_check_status (xlator_t *this, const char *realpath, int *fd,
- struct iatt *buf)
-{
- gf_boolean_t remote = _gf_false;
- gf_boolean_t downloading = _gf_false;
- int ret = 0;
- gf_cs_obj_state state = GF_CS_LOCAL;
- size_t xattrsize = 0;
- int op_errno = 0;
-
- if (fd) {
- xattrsize = sys_fgetxattr (*fd, GF_CS_OBJECT_REMOTE, NULL, 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) ||
- (errno == ENODATA))) {
- remote = _gf_false;
- } else if (xattrsize == -1) {
- ret = -1;
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "getxattr "
- "failed err %d", errno);
- goto out;
- } else {
- remote = _gf_true;
- }
-
- xattrsize = sys_fgetxattr (*fd, GF_CS_OBJECT_DOWNLOADING, NULL,
- 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) ||
- (errno == ENODATA))) {
- downloading = _gf_false;
- } else if (xattrsize == -1) {
- ret = -1;
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "getxattr "
- "failed err : %d", errno);
-
- goto out;
- } else {
- downloading = _gf_true;
- }
-
+posix_cs_check_status(xlator_t *this, const char *realpath, int *fd,
+ struct iatt *buf)
+{
+ gf_boolean_t remote = _gf_false;
+ gf_boolean_t downloading = _gf_false;
+ int ret = 0;
+ gf_cs_obj_state state = GF_CS_LOCAL;
+ size_t xattrsize = 0;
+ int op_errno = 0;
+
+ if (fd) {
+ xattrsize = sys_fgetxattr(*fd, GF_CS_OBJECT_REMOTE, NULL, 0);
+ if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA))) {
+ remote = _gf_false;
+ } else if (xattrsize == -1) {
+ ret = -1;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "getxattr "
+ "failed err %d",
+ errno);
+ goto out;
+ } else {
+ remote = _gf_true;
}
- if (realpath) {
- xattrsize = sys_lgetxattr (realpath, GF_CS_OBJECT_REMOTE, NULL,
- 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) ||
- (errno == ENODATA))) {
- remote = _gf_false;
- } else if (xattrsize == -1) {
- ret = -1;
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "getxattr "
- "failed err : %d", errno);
- goto out;
- } else {
- remote = _gf_true;
- }
+ xattrsize = sys_fgetxattr(*fd, GF_CS_OBJECT_DOWNLOADING, NULL, 0);
+ if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA))) {
+ downloading = _gf_false;
+ } else if (xattrsize == -1) {
+ ret = -1;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "getxattr "
+ "failed err : %d",
+ errno);
- xattrsize = sys_lgetxattr (realpath, GF_CS_OBJECT_DOWNLOADING,
- NULL, 0);
- if ((xattrsize == -1) && ((errno == ENOATTR) ||
- (errno == ENODATA))) {
- downloading = _gf_false;
- } else if (xattrsize == -1) {
- ret = -1;
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "getxattr "
- "failed err : %d", errno);
- goto out;
- } else {
- downloading = _gf_true;
- }
+ goto out;
+ } else {
+ downloading = _gf_true;
+ }
+ }
+
+ if (realpath) {
+ xattrsize = sys_lgetxattr(realpath, GF_CS_OBJECT_REMOTE, NULL, 0);
+ if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA))) {
+ remote = _gf_false;
+ } else if (xattrsize == -1) {
+ ret = -1;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "getxattr "
+ "failed err : %d",
+ errno);
+ goto out;
+ } else {
+ remote = _gf_true;
+ }
+
+ xattrsize = sys_lgetxattr(realpath, GF_CS_OBJECT_DOWNLOADING, NULL, 0);
+ if ((xattrsize == -1) && ((errno == ENOATTR) || (errno == ENODATA))) {
+ downloading = _gf_false;
+ } else if (xattrsize == -1) {
+ ret = -1;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "getxattr "
+ "failed err : %d",
+ errno);
+ goto out;
+ } else {
+ downloading = _gf_true;
}
+ }
out:
- if (ret) {
- gf_msg ("POSIX", GF_LOG_ERROR, 0, op_errno, "getxattr failed "
- "with %d", op_errno);
- state = GF_CS_ERROR;
- return state;
- }
-
- if ((remote && downloading) || (remote && buf && buf->ia_size)) {
- state = GF_CS_REPAIR;
- gf_msg_debug (this->name, 0, "status is REPAIR");
- return state;
- }
-
- if (remote)
- state = GF_CS_REMOTE;
- else if (downloading)
- state = GF_CS_DOWNLOADING;
- else
- state = GF_CS_LOCAL;
+ if (ret) {
+ gf_msg("POSIX", GF_LOG_ERROR, 0, op_errno,
+ "getxattr failed "
+ "with %d",
+ op_errno);
+ state = GF_CS_ERROR;
+ return state;
+ }
- gf_msg_debug (this->name, 0, "state returned is %d", state);
+ if ((remote && downloading) || (remote && buf && buf->ia_size)) {
+ state = GF_CS_REPAIR;
+ gf_msg_debug(this->name, 0, "status is REPAIR");
return state;
+ }
+ if (remote)
+ state = GF_CS_REMOTE;
+ else if (downloading)
+ state = GF_CS_DOWNLOADING;
+ else
+ state = GF_CS_LOCAL;
+
+ gf_msg_debug(this->name, 0, "state returned is %d", state);
+ return state;
}
int
-posix_cs_set_state (xlator_t *this, dict_t **rsp, gf_cs_obj_state state,
- char const *path, int *fd)
+posix_cs_set_state(xlator_t *this, dict_t **rsp, gf_cs_obj_state state,
+ char const *path, int *fd)
{
- int ret = 0;
- char *value = NULL;
- size_t xattrsize = 0;
+ int ret = 0;
+ char *value = NULL;
+ size_t xattrsize = 0;
+ if (!(*rsp)) {
+ *rsp = dict_new();
if (!(*rsp)) {
- *rsp = dict_new ();
- if (!(*rsp)) {
- gf_msg (this->name, GF_LOG_ERROR, 0, ENOMEM, "failed to"
- " create dict");
- ret = -1;
- goto out;
- }
- }
-
- ret = dict_set_uint64 (*rsp, GF_CS_OBJECT_STATUS, state);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, ENOMEM, "failed to set "
- "dict");
+ gf_msg(this->name, GF_LOG_ERROR, 0, ENOMEM,
+ "failed to"
+ " create dict");
+ ret = -1;
+ goto out;
+ }
+ }
+
+ ret = dict_set_uint64(*rsp, GF_CS_OBJECT_STATUS, state);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, ENOMEM,
+ "failed to set "
+ "dict");
+ ret = -1;
+ goto out;
+ }
+
+ if (fd) {
+ xattrsize = sys_fgetxattr(*fd, GF_CS_OBJECT_REMOTE, NULL, 0);
+ if (xattrsize != -1) {
+ value = GF_CALLOC(1, xattrsize + 1, gf_posix_mt_char);
+ if (!value) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0, "no memory for value");
ret = -1;
goto out;
- }
+ }
+ /* TODO: Add check for ENODATA */
+ xattrsize = sys_fgetxattr(*fd, GF_CS_OBJECT_REMOTE, value,
+ xattrsize + 1);
+ if (xattrsize == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ " getxattr failed for key %s", GF_CS_OBJECT_REMOTE);
+ goto out;
+ } else {
+ value[xattrsize] = '\0';
+ }
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ " getxattr failed for key %s", GF_CS_OBJECT_REMOTE);
+ goto out;
+ }
+ } else {
+ xattrsize = sys_lgetxattr(path, GF_CS_OBJECT_REMOTE, NULL, 0);
+ if (xattrsize != -1) {
+ value = GF_CALLOC(1, xattrsize + 1, gf_posix_mt_char);
+ if (!value) {
+ ret = -1;
+ goto out;
+ }
- if (fd) {
- xattrsize = sys_fgetxattr (*fd, GF_CS_OBJECT_REMOTE, NULL, 0);
- if (xattrsize != -1) {
- value = GF_CALLOC (1, xattrsize + 1, gf_posix_mt_char);
- if (!value) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "no memory for value");
- ret = -1;
- goto out;
- }
- /* TODO: Add check for ENODATA */
- xattrsize = sys_fgetxattr (*fd, GF_CS_OBJECT_REMOTE,
- value, xattrsize + 1);
- if (xattrsize == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0, errno,
- " getxattr failed for key %s",
- GF_CS_OBJECT_REMOTE);
- goto out;
- } else {
- value[xattrsize] = '\0';
- }
- } else {
- gf_msg (this->name, GF_LOG_ERROR, 0, errno,
- " getxattr failed for key %s",
- GF_CS_OBJECT_REMOTE);
- goto out;
- }
+ xattrsize = sys_lgetxattr(path, GF_CS_OBJECT_REMOTE, value,
+ xattrsize + 1);
+ if (xattrsize == -1) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ " getxattr failed for key %s", GF_CS_OBJECT_REMOTE);
+ goto out;
+ } else {
+ value[xattrsize] = '\0';
+ }
} else {
- xattrsize = sys_lgetxattr (path, GF_CS_OBJECT_REMOTE, NULL, 0);
- if (xattrsize != -1) {
- value = GF_CALLOC (1, xattrsize + 1, gf_posix_mt_char);
- if (!value) {
- ret = -1;
- goto out;
- }
-
- xattrsize = sys_lgetxattr (path, GF_CS_OBJECT_REMOTE,
- value, xattrsize + 1);
- if (xattrsize == -1) {
- gf_msg (this->name, GF_LOG_ERROR, 0, errno,
- " getxattr failed for key %s",
- GF_CS_OBJECT_REMOTE);
- goto out;
- } else {
- value[xattrsize] = '\0';
- }
- } else {
- gf_msg (this->name, GF_LOG_ERROR, 0, errno,
- " getxattr failed for key %s",
- GF_CS_OBJECT_REMOTE);
- goto out;
- }
+ gf_msg(this->name, GF_LOG_ERROR, 0, errno,
+ " getxattr failed for key %s", GF_CS_OBJECT_REMOTE);
+ goto out;
}
+ }
- if (ret == 0) {
- ret = dict_set_str (*rsp, GF_CS_OBJECT_REMOTE, value);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "failed to set"
- "value");
- }
+ if (ret == 0) {
+ ret = dict_set_str(*rsp, GF_CS_OBJECT_REMOTE, value);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "failed to set"
+ "value");
}
+ }
out:
- return ret;
+ return ret;
}
-
/* This function checks the status of the file and updates the xattr response.
* Also it repairs the state of the file which could have been resulted from a
* crash or transient failures.
*/
int
-posix_cs_maintenance (xlator_t *this, fd_t *fd, loc_t *loc, int *pfd,
- struct iatt *buf, const char *realpath, dict_t *xattr_req,
- dict_t **xattr_rsp, gf_boolean_t ignore_failure)
+posix_cs_maintenance(xlator_t *this, fd_t *fd, loc_t *loc, int *pfd,
+ struct iatt *buf, const char *realpath, dict_t *xattr_req,
+ dict_t **xattr_rsp, gf_boolean_t ignore_failure)
{
- gf_cs_obj_state state = GF_CS_ERROR;
- int ret = 0;
-
- if (!(dict_get (xattr_req, GF_CS_OBJECT_STATUS) ||
- dict_get (xattr_req, GF_CS_OBJECT_REPAIR)))
- return 0;
+ gf_cs_obj_state state = GF_CS_ERROR;
+ int ret = 0;
+ if (!(dict_get(xattr_req, GF_CS_OBJECT_STATUS) ||
+ dict_get(xattr_req, GF_CS_OBJECT_REPAIR)))
+ return 0;
- if (fd) {
- LOCK (&fd->inode->lock);
- if (dict_get (xattr_req, GF_CS_OBJECT_STATUS)) {
- state = posix_cs_check_status (this, NULL, pfd, buf);
- gf_msg_debug (this->name, 0, "state : %d", state);
- ret = posix_cs_set_state (this, xattr_rsp,
- state, NULL, pfd);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "posix_cs_set_state failed");
- }
-
- if (ignore_failure) {
- ret = 0;
- goto unlock;
- } else {
- if (state != GF_CS_LOCAL || ret != 0) {
- ret = -1;
- goto unlock;
- }
- }
+ if (fd) {
+ LOCK(&fd->inode->lock);
+ if (dict_get(xattr_req, GF_CS_OBJECT_STATUS)) {
+ state = posix_cs_check_status(this, NULL, pfd, buf);
+ gf_msg_debug(this->name, 0, "state : %d", state);
+ ret = posix_cs_set_state(this, xattr_rsp, state, NULL, pfd);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "posix_cs_set_state failed");
+ }
+
+ if (ignore_failure) {
+ ret = 0;
+ goto unlock;
+ } else {
+ if (state != GF_CS_LOCAL || ret != 0) {
+ ret = -1;
+ goto unlock;
}
+ }
+ }
- if (dict_get (xattr_req, GF_CS_OBJECT_REPAIR)) {
- state = posix_cs_check_status (this, NULL, pfd,
- buf);
- gf_msg_debug (this->name, 0, "state : %d", state);
-
- if (state == GF_CS_REPAIR) {
- state = posix_cs_heal_state (this, NULL,
- pfd, buf);
-
- if (state == GF_CS_ERROR) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "repair check failed");
- }
- }
-
- ret = posix_cs_set_state (this, xattr_rsp,
- state, NULL, pfd);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "posix_cs_set_state failed");
- if (ignore_failure)
- ret = 0;
- else
- ret = -1;
- goto unlock;
- }
- }
- } else {
- if (!loc->inode) {
- ret = 0;
- goto out;
+ if (dict_get(xattr_req, GF_CS_OBJECT_REPAIR)) {
+ state = posix_cs_check_status(this, NULL, pfd, buf);
+ gf_msg_debug(this->name, 0, "state : %d", state);
+
+ if (state == GF_CS_REPAIR) {
+ state = posix_cs_heal_state(this, NULL, pfd, buf);
+
+ if (state == GF_CS_ERROR) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "repair check failed");
}
+ }
- LOCK (&loc->inode->lock);
- if (dict_get (xattr_req, GF_CS_OBJECT_STATUS)) {
- state = posix_cs_check_status (this, realpath, NULL,
- buf);
- gf_msg_debug (this->name, 0, "state : %d", state);
- ret = posix_cs_set_state (this, xattr_rsp, state,
- realpath, NULL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "posix_cs_set_state failed");
- }
-
- if (ignore_failure) {
- ret = 0;
- goto unlock;
- } else {
- if (state != GF_CS_LOCAL || ret != 0) {
- ret = -1;
- goto unlock;
- }
- }
+ ret = posix_cs_set_state(this, xattr_rsp, state, NULL, pfd);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "posix_cs_set_state failed");
+ if (ignore_failure)
+ ret = 0;
+ else
+ ret = -1;
+ goto unlock;
+ }
+ }
+ } else {
+ if (!loc->inode) {
+ ret = 0;
+ goto out;
+ }
+
+ LOCK(&loc->inode->lock);
+ if (dict_get(xattr_req, GF_CS_OBJECT_STATUS)) {
+ state = posix_cs_check_status(this, realpath, NULL, buf);
+ gf_msg_debug(this->name, 0, "state : %d", state);
+ ret = posix_cs_set_state(this, xattr_rsp, state, realpath, NULL);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "posix_cs_set_state failed");
+ }
+
+ if (ignore_failure) {
+ ret = 0;
+ goto unlock;
+ } else {
+ if (state != GF_CS_LOCAL || ret != 0) {
+ ret = -1;
+ goto unlock;
}
+ }
+ }
+
+ if (dict_get(xattr_req, GF_CS_OBJECT_REPAIR)) {
+ state = posix_cs_check_status(this, realpath, NULL, buf);
+ gf_msg_debug(this->name, 0, "state : %d", state);
- if (dict_get (xattr_req, GF_CS_OBJECT_REPAIR)) {
- state = posix_cs_check_status (this, realpath, NULL,
- buf);
- gf_msg_debug (this->name, 0, "state : %d", state);
-
- if (state == GF_CS_REPAIR) {
- state = posix_cs_heal_state (this, realpath,
- NULL, buf);
-
- if (state == GF_CS_ERROR) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "repair check failed");
- }
- }
-
- ret = posix_cs_set_state (this, xattr_rsp,
- state, realpath, NULL);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "posix_cs_set_state failed");
- if (ignore_failure)
- ret = 0;
- else
- ret = -1;
- goto unlock;
- }
+ if (state == GF_CS_REPAIR) {
+ state = posix_cs_heal_state(this, realpath, NULL, buf);
+
+ if (state == GF_CS_ERROR) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "repair check failed");
}
+ }
+
+ ret = posix_cs_set_state(this, xattr_rsp, state, realpath, NULL);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "posix_cs_set_state failed");
+ if (ignore_failure)
+ ret = 0;
+ else
+ ret = -1;
+ goto unlock;
+ }
}
+ }
unlock:
- if (fd)
- UNLOCK (&fd->inode->lock);
- else
- UNLOCK (&loc->inode->lock);
+ if (fd)
+ UNLOCK(&fd->inode->lock);
+ else
+ UNLOCK(&loc->inode->lock);
out:
- return ret;
+ return ret;
}
diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c
index e467706..2cb65d7 100644
--- a/xlators/storage/posix/src/posix-inode-fd-ops.c
+++ b/xlators/storage/posix/src/posix-inode-fd-ops.c
@@ -68,17 +68,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
@@ -95,3756 +99,3789 @@ 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
-static char *disallow_removexattrs[] = {
- GF_XATTR_VOL_ID_KEY,
- GFID_XATTR_KEY,
- NULL
-};
+static char *disallow_removexattrs[] = {GF_XATTR_VOL_ID_KEY, GFID_XATTR_KEY,
+ NULL};
int32_t
-posix_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
+posix_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
- struct iatt buf = {0,};
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- struct posix_private *priv = NULL;
- char *real_path = NULL;
- dict_t *xattr_rsp = NULL;
+ struct iatt buf = {
+ 0,
+ };
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ struct posix_private *priv = NULL;
+ char *real_path = NULL;
+ dict_t *xattr_rsp = NULL;
- DECLARE_OLD_FS_ID_VAR;
+ DECLARE_OLD_FS_ID_VAR;
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (loc, out);
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(loc, out);
- priv = this->private;
- VALIDATE_OR_GOTO (priv, out);
+ priv = this->private;
+ VALIDATE_OR_GOTO(priv, out);
- SET_FS_ID (frame->root->uid, frame->root->gid);
+ SET_FS_ID(frame->root->uid, frame->root->gid);
- MAKE_INODE_HANDLE (real_path, this, loc, &buf);
+ MAKE_INODE_HANDLE(real_path, this, loc, &buf);
- if (op_ret == -1) {
- op_errno = errno;
- if (op_errno == ENOENT) {
- gf_msg_debug(this->name, 0, "lstat on %s failed: %s",
- real_path ? real_path : "<null>",
- strerror (op_errno));
- } else {
- gf_msg (this->name, GF_LOG_ERROR, op_errno,
- P_MSG_LSTAT_FAILED, "lstat on %s failed",
- real_path ? real_path : "<null>");
- }
- goto out;
+ if (op_ret == -1) {
+ op_errno = errno;
+ if (op_errno == ENOENT) {
+ gf_msg_debug(this->name, 0, "lstat on %s failed: %s",
+ real_path ? real_path : "<null>", strerror(op_errno));
+ } else {
+ gf_msg(this->name, GF_LOG_ERROR, op_errno, P_MSG_LSTAT_FAILED,
+ "lstat on %s failed", real_path ? real_path : "<null>");
}
- if (xdata) {
- xattr_rsp = posix_xattr_fill (this, real_path, loc, NULL, -1,
- xdata, &buf);
+ goto out;
+ }
+ if (xdata) {
+ xattr_rsp = posix_xattr_fill(this, real_path, loc, NULL, -1, xdata,
+ &buf);
- posix_cs_maintenance (this, NULL, loc, NULL, &buf, real_path,
- xdata, &xattr_rsp, _gf_true);
- }
+ posix_cs_maintenance(this, NULL, loc, NULL, &buf, real_path, xdata,
+ &xattr_rsp, _gf_true);
+ }
- op_ret = 0;
+ op_ret = 0;
out:
- SET_TO_OLD_FS_ID();
- STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, &buf, xattr_rsp);
- if (xattr_rsp)
- dict_unref (xattr_rsp);
+ SET_TO_OLD_FS_ID();
+ STACK_UNWIND_STRICT(stat, frame, op_ret, op_errno, &buf, xattr_rsp);
+ if (xattr_rsp)
+ dict_unref(xattr_rsp);
- return 0;
+ return 0;
}
static int
-posix_do_chmod (xlator_t *this, const char *path, struct iatt *stbuf)
+posix_do_chmod(xlator_t *this, const char *path, struct iatt *stbuf)
{
- int32_t ret = -1;
- mode_t mode = 0;
- mode_t mode_bit = 0;
- struct posix_private *priv = NULL;
- struct stat stat;
- int is_symlink = 0;
-
- priv = this->private;
- VALIDATE_OR_GOTO (priv, out);
- ret = sys_lstat (path, &stat);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, 0, P_MSG_LSTAT_FAILED,
- "lstat failed: %s", path);
- goto out;
+ int32_t ret = -1;
+ mode_t mode = 0;
+ mode_t mode_bit = 0;
+ struct posix_private *priv = NULL;
+ struct stat stat;
+ int is_symlink = 0;
+
+ priv = this->private;
+ VALIDATE_OR_GOTO(priv, out);
+ ret = sys_lstat(path, &stat);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, 0, P_MSG_LSTAT_FAILED,
+ "lstat failed: %s", path);
+ goto out;
+ }
+
+ if (S_ISLNK(stat.st_mode))
+ is_symlink = 1;
+
+ if (S_ISDIR(stat.st_mode)) {
+ mode = st_mode_from_ia(stbuf->ia_prot, stbuf->ia_type);
+ mode_bit = (mode & priv->create_directory_mask) |
+ priv->force_directory_mode;
+ mode = posix_override_umask(mode, mode_bit);
+ } else {
+ mode = st_mode_from_ia(stbuf->ia_prot, stbuf->ia_type);
+ mode_bit = (mode & priv->create_mask) | priv->force_create_mode;
+ mode = posix_override_umask(mode, mode_bit);
+ }
+ ret = lchmod(path, mode);
+ if ((ret == -1) && (errno == ENOSYS)) {
+ /* in Linux symlinks are always in mode 0777 and no
+ such call as lchmod exists.
+ */
+ gf_msg_debug(this->name, 0, "%s (%s)", path, strerror(errno));
+ if (is_symlink) {
+ ret = 0;
+ goto out;
}
- if (S_ISLNK (stat.st_mode))
- is_symlink = 1;
-
- if (S_ISDIR (stat.st_mode)) {
- mode = st_mode_from_ia (stbuf->ia_prot, stbuf->ia_type);
- mode_bit = (mode & priv->create_directory_mask)
- | priv->force_directory_mode;
- mode = posix_override_umask(mode, mode_bit);
- } else {
- mode = st_mode_from_ia (stbuf->ia_prot, stbuf->ia_type);
- mode_bit = (mode & priv->create_mask)
- | priv->force_create_mode;
- mode = posix_override_umask(mode, mode_bit);
- }
- ret = lchmod (path, mode);
- if ((ret == -1) && (errno == ENOSYS)) {
- /* in Linux symlinks are always in mode 0777 and no
- such call as lchmod exists.
- */
- gf_msg_debug (this->name, 0, "%s (%s)", path, strerror (errno));
- if (is_symlink) {
- ret = 0;
- goto out;
- }
-
- ret = sys_chmod (path, mode);
- }
+ ret = sys_chmod(path, mode);
+ }
out:
- return ret;
+ return ret;
}
static int
-posix_do_chown (xlator_t *this,
- const char *path,
- struct iatt *stbuf,
- int32_t valid)
+posix_do_chown(xlator_t *this, const char *path, struct iatt *stbuf,
+ int32_t valid)
{
- int32_t ret = -1;
- uid_t uid = -1;
- gid_t gid = -1;
+ int32_t ret = -1;
+ uid_t uid = -1;
+ gid_t gid = -1;
- if (valid & GF_SET_ATTR_UID)
- uid = stbuf->ia_uid;
+ if (valid & GF_SET_ATTR_UID)
+ uid = stbuf->ia_uid;
- if (valid & GF_SET_ATTR_GID)
- gid = stbuf->ia_gid;
+ if (valid & GF_SET_ATTR_GID)
+ gid = stbuf->ia_gid;
- ret = sys_lchown (path, uid, gid);
+ ret = sys_lchown(path, uid, gid);
- return ret;
+ return ret;
}
static int
-posix_do_utimes (xlator_t *this,
- const char *path,
- struct iatt *stbuf,
- int valid)
+posix_do_utimes(xlator_t *this, const char *path, struct iatt *stbuf, int valid)
{
- int32_t ret = -1;
+ int32_t ret = -1;
#if defined(HAVE_UTIMENSAT)
- struct timespec tv[2] = { {0,}, {0,} };
+ struct timespec tv[2] = {{
+ 0,
+ },
+ {
+ 0,
+ }};
#else
- struct timeval tv[2] = { {0,}, {0,} };
+ struct timeval tv[2] = {{
+ 0,
+ },
+ {
+ 0,
+ }};
#endif
- struct stat stat;
- int is_symlink = 0;
-
- ret = sys_lstat (path, &stat);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_FILE_OP_FAILED, "%s", path);
- goto out;
- }
+ struct stat stat;
+ int is_symlink = 0;
- if (S_ISLNK (stat.st_mode))
- is_symlink = 1;
-
- if ((valid & GF_SET_ATTR_ATIME) == GF_SET_ATTR_ATIME) {
- tv[0].tv_sec = stbuf->ia_atime;
- SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv[0], stbuf->ia_atime_nsec);
- } else {
- /* atime is not given, use current values */
- tv[0].tv_sec = ST_ATIM_SEC (&stat);
- SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv[0], ST_ATIM_NSEC (&stat));
- }
-
- if ((valid & GF_SET_ATTR_MTIME) == GF_SET_ATTR_MTIME) {
- tv[1].tv_sec = stbuf->ia_mtime;
- SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv[1], stbuf->ia_mtime_nsec);
- } else {
- /* mtime is not given, use current values */
- tv[1].tv_sec = ST_MTIM_SEC (&stat);
- SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv[1], ST_MTIM_NSEC (&stat));
+ ret = sys_lstat(path, &stat);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_FILE_OP_FAILED, "%s",
+ path);
+ goto out;
+ }
+
+ if (S_ISLNK(stat.st_mode))
+ is_symlink = 1;
+
+ if ((valid & GF_SET_ATTR_ATIME) == GF_SET_ATTR_ATIME) {
+ tv[0].tv_sec = stbuf->ia_atime;
+ SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv[0], stbuf->ia_atime_nsec);
+ } else {
+ /* atime is not given, use current values */
+ tv[0].tv_sec = ST_ATIM_SEC(&stat);
+ SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv[0], ST_ATIM_NSEC(&stat));
+ }
+
+ if ((valid & GF_SET_ATTR_MTIME) == GF_SET_ATTR_MTIME) {
+ tv[1].tv_sec = stbuf->ia_mtime;
+ SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv[1], stbuf->ia_mtime_nsec);
+ } else {
+ /* mtime is not given, use current values */
+ tv[1].tv_sec = ST_MTIM_SEC(&stat);
+ SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv[1], ST_MTIM_NSEC(&stat));
+ }
+
+ ret = PATH_SET_TIMESPEC_OR_TIMEVAL(path, tv);
+ if ((ret == -1) && (errno == ENOSYS)) {
+ gf_msg_debug(this->name, 0, "%s (%s)", path, strerror(errno));
+ if (is_symlink) {
+ ret = 0;
+ goto out;
}
ret = PATH_SET_TIMESPEC_OR_TIMEVAL(path, tv);
- if ((ret == -1) && (errno == ENOSYS)) {
- gf_msg_debug (this->name, 0, "%s (%s)",
- path, strerror (errno));
- if (is_symlink) {
- ret = 0;
- goto out;
- }
-
- ret = PATH_SET_TIMESPEC_OR_TIMEVAL(path, tv);
- }
+ }
out:
- return ret;
+ return ret;
}
int
-posix_setattr (call_frame_t *frame, xlator_t *this,
- loc_t *loc, struct iatt *stbuf, int32_t valid, dict_t *xdata)
+posix_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- char * real_path = 0;
- struct iatt statpre = {0,};
- struct iatt statpost = {0,};
- dict_t *xattr_rsp = NULL;
- struct posix_private *priv = NULL;
-
- priv = this->private;
-
- 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);
- MAKE_INODE_HANDLE (real_path, this, loc, &statpre);
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ char *real_path = 0;
+ struct iatt statpre = {
+ 0,
+ };
+ struct iatt statpost = {
+ 0,
+ };
+ dict_t *xattr_rsp = NULL;
+ struct posix_private *priv = NULL;
+
+ priv = this->private;
+
+ 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);
+ MAKE_INODE_HANDLE(real_path, this, loc, &statpre);
+
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "setattr (lstat) on %s failed",
+ real_path ? real_path : "<null>");
+ goto out;
+ }
+ if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) {
+ op_ret = posix_do_chown(this, real_path, stbuf, valid);
if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "setattr (lstat) on %s failed",
- real_path ? real_path : "<null>");
- goto out;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_CHOWN_FAILED,
+ "setattr (chown) on %s "
+ "failed",
+ real_path);
+ goto out;
}
+ }
- if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)){
- op_ret = posix_do_chown (this, real_path, stbuf, valid);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_CHOWN_FAILED, "setattr (chown) on %s "
- "failed", real_path);
- goto out;
- }
- }
-
- if (valid & GF_SET_ATTR_MODE) {
- op_ret = posix_do_chmod (this, real_path, stbuf);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_CHMOD_FAILED, "setattr (chmod) on %s "
- "failed", real_path);
- goto out;
- }
+ if (valid & GF_SET_ATTR_MODE) {
+ op_ret = posix_do_chmod(this, real_path, stbuf);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_CHMOD_FAILED,
+ "setattr (chmod) on %s "
+ "failed",
+ real_path);
+ goto out;
}
+ }
- if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) {
- op_ret = posix_do_utimes (this, real_path, stbuf, valid);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_UTIMES_FAILED, "setattr (utimes) on %s "
- "failed", real_path);
- goto out;
- }
- posix_update_utime_in_mdata (this, real_path, -1, loc->inode,
- stbuf, valid);
- }
-
- if (valid & GF_SET_ATTR_CTIME && !priv->ctime) {
- /*
- * If ctime is not enabled, we have no means to associate an
- * arbitrary ctime with the file, so as a fallback, we ignore
- * the ctime payload and update the file ctime to current time
- * (which is possible directly with the POSIX API).
- */
- op_ret = PATH_SET_TIMESPEC_OR_TIMEVAL (real_path, NULL);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_UTIMES_FAILED, "setattr (utimes) on %s "
- "failed", real_path);
- goto out;
- }
+ if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) {
+ op_ret = posix_do_utimes(this, real_path, stbuf, valid);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_UTIMES_FAILED,
+ "setattr (utimes) on %s "
+ "failed",
+ real_path);
+ goto out;
+ }
+ posix_update_utime_in_mdata(this, real_path, -1, loc->inode, stbuf,
+ valid);
+ }
+
+ if (valid & GF_SET_ATTR_CTIME && !priv->ctime) {
+ /*
+ * If ctime is not enabled, we have no means to associate an
+ * arbitrary ctime with the file, so as a fallback, we ignore
+ * the ctime payload and update the file ctime to current time
+ * (which is possible directly with the POSIX API).
+ */
+ op_ret = PATH_SET_TIMESPEC_OR_TIMEVAL(real_path, NULL);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_UTIMES_FAILED,
+ "setattr (utimes) on %s "
+ "failed",
+ real_path);
+ goto out;
}
+ }
- if (!valid) {
- op_ret = sys_lchown (real_path, -1, -1);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_LCHOWN_FAILED, "lchown (%s, -1, -1) "
- "failed", real_path);
+ if (!valid) {
+ op_ret = sys_lchown(real_path, -1, -1);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LCHOWN_FAILED,
+ "lchown (%s, -1, -1) "
+ "failed",
+ real_path);
- goto out;
- }
+ goto out;
}
+ }
- op_ret = posix_pstat (this, loc->inode, loc->gfid, real_path,
- &statpost, _gf_false);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
- "setattr (lstat) on %s failed", real_path);
- goto out;
- }
+ op_ret = posix_pstat(this, loc->inode, loc->gfid, real_path, &statpost,
+ _gf_false);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_LSTAT_FAILED,
+ "setattr (lstat) on %s failed", real_path);
+ goto out;
+ }
- if (valid & GF_SET_ATTR_CTIME && priv->ctime) {
- /*
- * If we got ctime payload, we override
- * the ctime of statpost with that.
- */
- statpost.ia_ctime = stbuf->ia_ctime;
- statpost.ia_ctime_nsec = stbuf->ia_ctime_nsec;
- }
- posix_set_ctime (frame, this, real_path, -1, loc->inode, &statpost);
+ if (valid & GF_SET_ATTR_CTIME && priv->ctime) {
+ /*
+ * If we got ctime payload, we override
+ * the ctime of statpost with that.
+ */
+ statpost.ia_ctime = stbuf->ia_ctime;
+ statpost.ia_ctime_nsec = stbuf->ia_ctime_nsec;
+ }
+ posix_set_ctime(frame, this, real_path, -1, loc->inode, &statpost);
- if (xdata)
- xattr_rsp = posix_xattr_fill (this, real_path, loc, NULL, -1,
- xdata, &statpost);
- op_ret = 0;
+ if (xdata)
+ xattr_rsp = posix_xattr_fill(this, real_path, loc, NULL, -1, xdata,
+ &statpost);
+ op_ret = 0;
out:
- SET_TO_OLD_FS_ID ();
+ SET_TO_OLD_FS_ID();
- STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno,
- &statpre, &statpost, xattr_rsp);
- if (xattr_rsp)
- dict_unref (xattr_rsp);
+ STACK_UNWIND_STRICT(setattr, frame, op_ret, op_errno, &statpre, &statpost,
+ xattr_rsp);
+ if (xattr_rsp)
+ dict_unref(xattr_rsp);
- return 0;
+ return 0;
}
int32_t
-posix_do_fchown (xlator_t *this,
- int fd,
- struct iatt *stbuf,
- int32_t valid)
+posix_do_fchown(xlator_t *this, int fd, struct iatt *stbuf, int32_t valid)
{
- int ret = -1;
- uid_t uid = -1;
- gid_t gid = -1;
+ int ret = -1;
+ uid_t uid = -1;
+ gid_t gid = -1;
- if (valid & GF_SET_ATTR_UID)
- uid = stbuf->ia_uid;
+ if (valid & GF_SET_ATTR_UID)
+ uid = stbuf->ia_uid;
- if (valid & GF_SET_ATTR_GID)
- gid = stbuf->ia_gid;
+ if (valid & GF_SET_ATTR_GID)
+ gid = stbuf->ia_gid;
- ret = sys_fchown (fd, uid, gid);
+ ret = sys_fchown(fd, uid, gid);
- return ret;
+ return ret;
}
-
int32_t
-posix_do_fchmod (xlator_t *this,
- int fd, struct iatt *stbuf)
+posix_do_fchmod(xlator_t *this, int fd, struct iatt *stbuf)
{
- int32_t ret = -1;
- mode_t mode = 0;
- mode_t mode_bit = 0;
- struct posix_private *priv = NULL;
-
- priv = this->private;
- VALIDATE_OR_GOTO (priv, out);
- mode = st_mode_from_ia (stbuf->ia_prot, stbuf->ia_type);
- mode_bit = (mode & priv->create_mask)
- | priv->force_create_mode;
- mode = posix_override_umask (mode, mode_bit);
- ret = sys_fchmod (fd, mode);
+ int32_t ret = -1;
+ mode_t mode = 0;
+ mode_t mode_bit = 0;
+ struct posix_private *priv = NULL;
+
+ priv = this->private;
+ VALIDATE_OR_GOTO(priv, out);
+ mode = st_mode_from_ia(stbuf->ia_prot, stbuf->ia_type);
+ mode_bit = (mode & priv->create_mask) | priv->force_create_mode;
+ mode = posix_override_umask(mode, mode_bit);
+ ret = sys_fchmod(fd, mode);
out:
- return ret;
+ return ret;
}
static int
-posix_do_futimes (xlator_t *this, int fd, struct iatt *stbuf, int valid)
+posix_do_futimes(xlator_t *this, int fd, struct iatt *stbuf, int valid)
{
- int32_t ret = -1;
- struct timeval tv[2] = { {0,}, {0,} };
- struct stat stat = {0,};
-
- ret = sys_fstat (fd, &stat);
- if (ret != 0) {
- gf_msg (this->name, GF_LOG_WARNING, errno,
- P_MSG_FILE_OP_FAILED, "%d", fd);
- goto out;
- }
-
- if ((valid & GF_SET_ATTR_ATIME) == GF_SET_ATTR_ATIME) {
- tv[0].tv_sec = stbuf->ia_atime;
- tv[0].tv_usec = stbuf->ia_atime_nsec / 1000;
- } else {
- /* atime is not given, use current values */
- tv[0].tv_sec = ST_ATIM_SEC (&stat);
- tv[0].tv_usec = ST_ATIM_NSEC (&stat) / 1000;
- }
-
- if ((valid & GF_SET_ATTR_MTIME) == GF_SET_ATTR_MTIME) {
- tv[1].tv_sec = stbuf->ia_mtime;
- tv[1].tv_usec = stbuf->ia_mtime_nsec / 1000;
- } else {
- /* mtime is not given, use current values */
- tv[1].tv_sec = ST_MTIM_SEC (&stat);
- tv[1].tv_usec = ST_MTIM_NSEC (&stat) / 1000;
- }
-
- ret = sys_futimes (fd, tv);
- if (ret == -1)
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_FUTIMES_FAILED,
- "%d", fd);
+ int32_t ret = -1;
+ struct timeval tv[2] = {{
+ 0,
+ },
+ {
+ 0,
+ }};
+ struct stat stat = {
+ 0,
+ };
+
+ ret = sys_fstat(fd, &stat);
+ if (ret != 0) {
+ gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_FILE_OP_FAILED, "%d",
+ fd);
+ goto out;
+ }
+
+ if ((valid & GF_SET_ATTR_ATIME) == GF_SET_ATTR_ATIME) {
+ tv[0].tv_sec = stbuf->ia_atime;
+ tv[0].tv_usec = stbuf->ia_atime_nsec / 1000;
+ } else {
+ /* atime is not given, use current values */
+ tv[0].tv_sec = ST_ATIM_SEC(&stat);
+ tv[0].tv_usec = ST_ATIM_NSEC(&stat) / 1000;
+ }
+
+ if ((valid & GF_SET_ATTR_MTIME) == GF_SET_ATTR_MTIME) {
+ tv[1].tv_sec = stbuf->ia_mtime;
+ tv[1].tv_usec = stbuf->ia_mtime_nsec / 1000;
+ } else {
+ /* mtime is not given, use current values */
+ tv[1].tv_sec = ST_MTIM_SEC(&stat);
+ tv[1].tv_usec = ST_MTIM_NSEC(&stat) / 1000;
+ }
+
+ ret = sys_futimes(fd, tv);
+ if (ret == -1)
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FUTIMES_FAILED, "%d", fd);
out:
- return ret;
+ return ret;
}
int
-posix_fsetattr (call_frame_t *frame, xlator_t *this,
- fd_t *fd, struct iatt *stbuf, int32_t valid, dict_t *xdata)
+posix_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
- int32_t op_ret = -1;
- int32_t op_errno = 0;
- struct iatt statpre = {0,};
- struct iatt statpost = {0,};
- struct posix_fd *pfd = NULL;
- dict_t *xattr_rsp = NULL;
- int32_t ret = -1;
-
- DECLARE_OLD_FS_ID_VAR;
-
- SET_FS_ID (frame->root->uid, frame->root->gid);
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ struct iatt statpre = {
+ 0,
+ };
+ struct iatt statpost = {
+ 0,
+ };
+ struct posix_fd *pfd = NULL;
+ dict_t *xattr_rsp = NULL;
+ int32_t ret = -1;
+
+ DECLARE_OLD_FS_ID_VAR;
+
+ SET_FS_ID(frame->root->uid, frame->root->gid);
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
+
+ ret = posix_fd_ctx_get(fd, this, &pfd, &op_errno);
+ if (ret < 0) {
+ gf_msg_debug(this->name, 0, "pfd is NULL from fd=%p", fd);
+ goto out;
+ }
- ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
- if (ret < 0) {
- gf_msg_debug (this->name, 0, "pfd is NULL from fd=%p", fd);
- goto out;
- }
+ op_ret = posix_fdstat(this, fd->inode, pfd->fd, &statpre);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
+ "fsetattr (fstat) failed on fd=%p", fd);
+ goto out;
+ }
- op_ret = posix_fdstat (this, fd->inode, pfd->fd, &statpre);
+ if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) {
+ op_ret = posix_do_fchown(this, pfd->fd, stbuf, valid);
if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
- "fsetattr (fstat) failed on fd=%p", fd);
- goto out;
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FCHOWN_FAILED,
+ "fsetattr (fchown) failed"
+ " on fd=%p",
+ fd);
+ goto out;
}
+ }
- if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) {
- op_ret = posix_do_fchown (this, pfd->fd, stbuf, valid);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_FCHOWN_FAILED, "fsetattr (fchown) failed"
- " on fd=%p", fd);
- goto out;
- }
-
+ if (valid & GF_SET_ATTR_MODE) {
+ op_ret = posix_do_fchmod(this, pfd->fd, stbuf);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FCHMOD_FAILED,
+ "fsetattr (fchmod) failed"
+ " on fd=%p",
+ fd);
+ goto out;
}
+ }
- if (valid & GF_SET_ATTR_MODE) {
- op_ret = posix_do_fchmod (this, pfd->fd, stbuf);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_FCHMOD_FAILED, "fsetattr (fchmod) failed"
- " on fd=%p", fd);
- goto out;
- }
- }
+ if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) {
+ op_ret = posix_do_futimes(this, pfd->fd, stbuf, valid);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FUTIMES_FAILED,
+ "fsetattr (futimes) on "
+ "failed fd=%p",
+ fd);
+ goto out;
+ }
+ posix_update_utime_in_mdata(this, NULL, pfd->fd, fd->inode, stbuf,
+ valid);
+ }
+
+ if (!valid) {
+ op_ret = sys_fchown(pfd->fd, -1, -1);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FCHOWN_FAILED,
+ "fchown (%d, -1, -1) failed", pfd->fd);
- if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) {
- op_ret = posix_do_futimes (this, pfd->fd, stbuf, valid);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_FUTIMES_FAILED, "fsetattr (futimes) on "
- "failed fd=%p", fd);
- goto out;
- }
- posix_update_utime_in_mdata (this, NULL, pfd->fd, fd->inode,
- stbuf, valid);
+ goto out;
}
+ }
- if (!valid) {
- op_ret = sys_fchown (pfd->fd, -1, -1);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno,
- P_MSG_FCHOWN_FAILED,
- "fchown (%d, -1, -1) failed",
- pfd->fd);
-
- goto out;
- }
- }
-
- op_ret = posix_fdstat (this, fd->inode, pfd->fd, &statpost);
- if (op_ret == -1) {
- op_errno = errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
- "fsetattr (fstat) failed on fd=%p", fd);
- goto out;
- }
+ op_ret = posix_fdstat(this, fd->inode, pfd->fd, &statpost);
+ if (op_ret == -1) {
+ op_errno = errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
+ "fsetattr (fstat) failed on fd=%p", fd);
+ goto out;
+ }
- posix_set_ctime (frame, this, NULL, pfd->fd, fd->inode, &statpost);
+ posix_set_ctime(frame, this, NULL, pfd->fd, fd->inode, &statpost);
- if (xdata)
- xattr_rsp = posix_xattr_fill (this, NULL, NULL, fd, pfd->fd,
- xdata, &statpost);
- op_ret = 0;
+ if (xdata)
+ xattr_rsp = posix_xattr_fill(this, NULL, NULL, fd, pfd->fd, xdata,
+ &statpost);
+ op_ret = 0;
out:
- SET_TO_OLD_FS_ID ();
+ SET_TO_OLD_FS_ID();
- STACK_UNWIND_STRICT (fsetattr, frame, op_ret, op_errno,
- &statpre, &statpost, xattr_rsp);
- if (xattr_rsp)
- dict_unref (xattr_rsp);
+ STACK_UNWIND_STRICT(fsetattr, frame, op_ret, op_errno, &statpre, &statpost,
+ xattr_rsp);
+ if (xattr_rsp)
+ dict_unref(xattr_rsp);
- return 0;
+ return 0;
}
static int32_t
-posix_do_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd,
- int32_t flags, off_t offset, size_t len,
- struct iatt *statpre, struct iatt *statpost, dict_t *xdata,
- dict_t **rsp_xdata)
+posix_do_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags,
+ off_t offset, size_t len, struct iatt *statpre,
+ struct iatt *statpost, dict_t *xdata, dict_t **rsp_xdata)
{
- int32_t ret = -1;
- int32_t op_errno = 0;
- struct posix_fd *pfd = NULL;
- gf_boolean_t locked = _gf_false;
- posix_inode_ctx_t *ctx = NULL;
- struct posix_private *priv = NULL;
+ int32_t ret = -1;
+ int32_t op_errno = 0;
+ struct posix_fd *pfd = NULL;
+ gf_boolean_t locked = _gf_false;
+ posix_inode_ctx_t *ctx = NULL;
+ struct posix_private *priv = NULL;
- DECLARE_OLD_FS_ID_VAR;
+ DECLARE_OLD_FS_ID_VAR;
- SET_FS_ID (frame->root->uid, frame->root->gid);
+ SET_FS_ID(frame->root->uid, frame->root->gid);
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
- priv = this->private;
+ priv = this->private;
- /* fallocate case is special so call posix_disk_space_check separately
- for every fallocate fop instead of calling posix_disk_space with
- thread after every 5 sec sleep to working correctly storage.reserve
- option behaviour
- */
- if (priv->disk_reserve)
- posix_disk_space_check (this);
+ /* fallocate case is special so call posix_disk_space_check separately
+ for every fallocate fop instead of calling posix_disk_space with
+ thread after every 5 sec sleep to working correctly storage.reserve
+ option behaviour
+ */
+ if (priv->disk_reserve)
+ posix_disk_space_check(this);
- DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, ret, ret, out);
-
- ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
- if (ret < 0) {
- gf_msg_debug (this->name, 0, "pfd is NULL from fd=%p", fd);
- goto out;
- }
-
- ret = posix_inode_ctx_get_all (fd->inode, this, &ctx);
- if (ret < 0) {
- ret = -ENOMEM;
- goto out;
- }
-
- if (xdata && dict_get (xdata, GLUSTERFS_WRITE_UPDATE_ATOMIC)) {
- locked = _gf_true;
- pthread_mutex_lock (&ctx->write_atomic_lock);
- }
+ DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, ret, ret, out);
- ret = posix_fdstat (this, fd->inode, pfd->fd, statpre);
- if (ret == -1) {
- ret = -errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
- "fallocate (fstat) failed on fd=%p", fd);
- goto out;
- }
+ ret = posix_fd_ctx_get(fd, this, &pfd, &op_errno);
+ if (ret < 0) {
+ gf_msg_debug(this->name, 0, "pfd is NULL from fd=%p", fd);
+ goto out;
+ }
- if (xdata) {
- ret = posix_cs_maintenance (this, fd, NULL, &pfd->fd, statpre,
- NULL, xdata, rsp_xdata, _gf_false);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0,
- "file state check failed, fd %p", fd);
- ret = -EIO;
- goto out;
- }
- }
+ ret = posix_inode_ctx_get_all(fd->inode, this, &ctx);
+ if (ret < 0) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ if (xdata && dict_get(xdata, GLUSTERFS_WRITE_UPDATE_ATOMIC)) {
+ locked = _gf_true;
+ pthread_mutex_lock(&ctx->write_atomic_lock);
+ }
+
+ ret = posix_fdstat(this, fd->inode, pfd->fd, statpre);
+ if (ret == -1) {
+ ret = -errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
+ "fallocate (fstat) failed on fd=%p", fd);
+ goto out;
+ }
- ret = sys_fallocate (pfd->fd, flags, offset, len);
- if (ret == -1) {
- ret = -errno;
- gf_msg (this->name, GF_LOG_ERROR, -ret, P_MSG_FALLOCATE_FAILED,
- "fallocate failed on %s offset: %jd, "
- "len:%zu, flags: %d", uuid_utoa (fd->inode->gfid),
- offset, len, flags);
- goto out;
- }
+ if (xdata) {
+ ret = posix_cs_maintenance(this, fd, NULL, &pfd->fd, statpre, NULL,
+ xdata, rsp_xdata, _gf_false);
+ if (ret < 0) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "file state check failed, fd %p", fd);
+ ret = -EIO;
+ goto out;
+ }
+ }
+
+ ret = sys_fallocate(pfd->fd, flags, offset, len);
+ if (ret == -1) {
+ ret = -errno;
+ gf_msg(this->name, GF_LOG_ERROR, -ret, P_MSG_FALLOCATE_FAILED,
+ "fallocate failed on %s offset: %jd, "
+ "len:%zu, flags: %d",
+ uuid_utoa(fd->inode->gfid), offset, len, flags);
+ goto out;
+ }
- ret = posix_fdstat (this, fd->inode, pfd->fd, statpost);
- if (ret == -1) {
- ret = -errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
- "fallocate (fstat) failed on fd=%p", fd);
- goto out;
- }
+ ret = posix_fdstat(this, fd->inode, pfd->fd, statpost);
+ if (ret == -1) {
+ ret = -errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
+ "fallocate (fstat) failed on fd=%p", fd);
+ goto out;
+ }
- posix_set_ctime (frame, this, NULL, pfd->fd, fd->inode, statpost);
+ posix_set_ctime(frame, this, NULL, pfd->fd, fd->inode, statpost);
out:
- if (locked) {
- pthread_mutex_unlock (&ctx->write_atomic_lock);
- locked = _gf_false;
- }
- SET_TO_OLD_FS_ID ();
- if (ret == ENOSPC)
- ret = -ENOSPC;
-
- return ret;
+ if (locked) {
+ pthread_mutex_unlock(&ctx->write_atomic_lock);
+ locked = _gf_false;
+ }
+ SET_TO_OLD_FS_ID();
+ if (ret == ENOSPC)
+ ret = -ENOSPC;
+
+ return ret;
}
-char*
-_page_aligned_alloc (size_t size, char **aligned_buf)
+char *
+_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_posix_mt_char);
- if (!alloc_buf)
- goto out;
- /* page aligned buffer */
- buf = GF_ALIGN_BUF (alloc_buf, ALIGN_SIZE);
- *aligned_buf = buf;
+ alloc_buf = GF_CALLOC(1, (size + ALIGN_SIZE), gf_posix_mt_char);
+ if (!alloc_buf)
+ goto out;
+ /* page aligned buffer */
+ buf = GF_ALIGN_BUF(alloc_buf, ALIGN_SIZE);
+ *aligned_buf = buf;
out:
- return alloc_buf;
+ return alloc_buf;
}
static int32_t
_posix_do_zerofill(int fd, off_t offset, off_t len, int o_direct)
{
- off_t num_vect = 0;
- off_t num_loop = 1;
- off_t idx = 0;
- int32_t op_ret = -1;
- int32_t vect_size = VECTOR_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 < VECTOR_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_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;
+ off_t idx = 0;
+ int32_t op_ret = -1;
+ int32_t vect_size = VECTOR_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 < VECTOR_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_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;
+ }
- for (idx = 0; idx < num_loop; idx++) {
- op_ret = sys_writev (fd, vector, num_vect);
- if (op_ret < 0)
- goto err;
- if (op_ret != (vect_size * num_vect)) {
- op_ret = -1;
- errno = ENOSPC;
- goto err;
- }
- }
- if (extra) {
- op_ret = sys_writev (fd, vector, extra);
- if (op_ret < 0)
- goto err;
- if (op_ret != (vect_size * extra)) {
- op_ret = -1;
- errno = ENOSPC;
- goto err;
- }
- }
- if (remain) {
- vector[0].iov_len = remain;
- op_ret = sys_writev (fd, vector , 1);
- if (op_ret < 0)
- goto err;
- if (op_ret != remain) {
- op_ret = -1;
- errno = ENOSPC;
- goto err;
- }
+ for (idx = 0; idx < num_loop; idx++) {
+ op_ret = sys_writev(fd, vector, num_vect);
+ if (op_ret < 0)
+ goto err;
+ if (op_ret != (vect_size * num_vect)) {
+ op_ret = -1;
+ errno = ENOSPC;
+ goto err;
+ }
+ }
+ if (extra) {
+ op_ret = sys_writev(fd, vector, extra);
+ if (op_ret < 0)
+ goto err;
+ if (op_ret != (vect_size * extra)) {
+ op_ret = -1;
+ errno = ENOSPC;
+ goto err;
+ }
+ }
+ if (remain) {
+ vector[0].iov_len = remain;
+ op_ret = sys_writev(fd, vector, 1);
+ if (op_ret < 0)
+ goto err;
+ if (op_ret != remain) {
+ op_ret = -1;
+ errno = ENOSPC;
+ goto err;
}
+ }
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;
}
static int32_t
-posix_do_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
- off_t len, struct iatt *statpre, struct iatt *statpost,
- dict_t *xdata, dict_t **rsp_xdata)
+posix_do_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ off_t len, struct iatt *statpre, struct iatt *statpost,
+ dict_t *xdata, dict_t **rsp_xdata)
{
- int32_t ret = -1;
- int32_t op_errno = 0;
- int32_t flags = 0;
- struct posix_fd *pfd = NULL;
- gf_boolean_t locked = _gf_false;
- posix_inode_ctx_t *ctx = NULL;
-
- DECLARE_OLD_FS_ID_VAR;
-
- SET_FS_ID (frame->root->uid, frame->root->gid);
+ int32_t ret = -1;
+ int32_t op_errno = 0;
+ int32_t flags = 0;
+ struct posix_fd *pfd = NULL;
+ gf_boolean_t locked = _gf_false;
+ posix_inode_ctx_t *ctx = NULL;
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
- VALIDATE_OR_GOTO (fd, out);
+ DECLARE_OLD_FS_ID_VAR;
- ret = posix_fd_ctx_get (fd, this, &pfd, &op_errno);
- if (ret < 0) {
- gf_msg_debug (this->name, 0, "pfd is NULL from fd=%p", fd);
- goto out;
- }
+ SET_FS_ID(frame->root->uid, frame->root->gid);
- ret = posix_inode_ctx_get_all (fd->inode, this, &ctx);
- if (ret < 0) {
- ret = -ENOMEM;
- goto out;
- }
-
- if (dict_get (xdata, GLUSTERFS_WRITE_UPDATE_ATOMIC)) {
- locked = _gf_true;
- pthread_mutex_lock (&ctx->write_atomic_lock);
- }
-
- ret = posix_fdstat (this, fd->inode, pfd->fd, statpre);
- if (ret == -1) {
- ret = -errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
- "pre-operation fstat failed on fd = %p", fd);
- goto out;
- }
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+ VALIDATE_OR_GOTO(fd, out);
- if (xdata) {
- ret = posix_cs_maintenance (this, fd, NULL, &pfd->fd, statpre,
- NULL, xdata, rsp_xdata, _gf_false);
- if (ret < 0) {
- gf_msg (this->name, GF_LOG_ERROR, 0, 0, "file state "
- "check failed, fd %p", fd);
- ret = -EIO;
- goto out;
- }
- }
+ ret = posix_fd_ctx_get(fd, this, &pfd, &op_errno);
+ if (ret < 0) {
+ gf_msg_debug(this->name, 0, "pfd is NULL from fd=%p", fd);
+ goto out;
+ }
- /* See if we can use FALLOC_FL_ZERO_RANGE to perform the zero fill.
- * If it fails, fall back to _posix_do_zerofill() and an optional fsync.
- */
- flags = FALLOC_FL_ZERO_RANGE;
- ret = sys_fallocate (pfd->fd, flags, offset, len);
- if (ret == 0) {
- goto fsync;
- } else {
- ret = -errno;
- if ((ret != -ENOSYS) && (ret != -EOPNOTSUPP)) {
- goto out;
- }
- }
+ ret = posix_inode_ctx_get_all(fd->inode, this, &ctx);
+ if (ret < 0) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ if (dict_get(xdata, GLUSTERFS_WRITE_UPDATE_ATOMIC)) {
+ locked = _gf_true;
+ pthread_mutex_lock(&ctx->write_atomic_lock);
+ }
+
+ ret = posix_fdstat(this, fd->inode, pfd->fd, statpre);
+ if (ret == -1) {
+ ret = -errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
+ "pre-operation fstat failed on fd = %p", fd);
+ goto out;
+ }
- ret = _posix_do_zerofill (pfd->fd, offset, len, pfd->flags & O_DIRECT);
+ if (xdata) {
+ ret = posix_cs_maintenance(this, fd, NULL, &pfd->fd, statpre, NULL,
+ xdata, rsp_xdata, _gf_false);
if (ret < 0) {
- ret = -errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_ZEROFILL_FAILED,
- "zerofill failed on fd %d length %" PRId64 ,
- pfd->fd, len);
- goto out;
+ gf_msg(this->name, GF_LOG_ERROR, 0, 0,
+ "file state "
+ "check failed, fd %p",
+ fd);
+ ret = -EIO;
+ goto out;
}
+ }
-fsync:
- if (pfd->flags & (O_SYNC|O_DSYNC)) {
- ret = sys_fsync (pfd->fd);
- if (ret) {
- gf_msg (this->name, GF_LOG_ERROR, 0,
- P_MSG_WRITEV_FAILED, "fsync() in writev on fd"
- "%d failed", pfd->fd);
- ret = -errno;
- goto out;
- }
- }
+ /* See if we can use FALLOC_FL_ZERO_RANGE to perform the zero fill.
+ * If it fails, fall back to _posix_do_zerofill() and an optional fsync.
+ */
+ flags = FALLOC_FL_ZERO_RANGE;
+ ret = sys_fallocate(pfd->fd, flags, offset, len);
+ if (ret == 0) {
+ goto fsync;
+ } else {
+ ret = -errno;
+ if ((ret != -ENOSYS) && (ret != -EOPNOTSUPP)) {
+ goto out;
+ }
+ }
+
+ ret = _posix_do_zerofill(pfd->fd, offset, len, pfd->flags & O_DIRECT);
+ if (ret < 0) {
+ ret = -errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_ZEROFILL_FAILED,
+ "zerofill failed on fd %d length %" PRId64, pfd->fd, len);
+ goto out;
+ }
- ret = posix_fdstat (this, fd->inode, pfd->fd, statpost);
- if (ret == -1) {
- ret = -errno;
- gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
- "post operation fstat failed on fd=%p", fd);
- goto out;
- }
+fsync:
+ if (pfd->flags & (O_SYNC | O_DSYNC)) {
+ ret = sys_fsync(pfd->fd);
+ if (ret) {
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_WRITEV_FAILED,
+ "fsync() in writev on fd"
+ "%d failed",
+ pfd->fd);
+ ret = -errno;
+ goto out;
+ }
+ }
+
+ ret = posix_fdstat(this, fd->inode, pfd->fd, statpost);
+ if (ret == -1) {
+ ret = -errno;
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_FSTAT_FAILED,
+ "post operation fstat failed on fd=%p", fd);
+ goto out;
+ }
- posix_set_ctime (frame, this, NULL, pfd->fd, fd->inode, statpost);
+ posix_set_ctime(frame, this, NULL, pfd->fd, fd->inode, statpost);
out:
- if (locked) {
- pthread_mutex_unlock (&ctx->write_atomic_lock);
- locked = _gf_false;
- }
- SET_TO_OLD_FS_ID ();
+ if (locked) {
+ pthread_mutex_unlock(&ctx->write_atomic_lock);
+ locked = _gf_false;
+ }
+ SET_TO_OLD_FS_ID();
- return ret;
+ return ret;
}
int32_t
-posix_glfallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t keep_size,
- off_t offset, size_t len, dict_t *xdata)
+posix_glfallocate(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ int32_t keep_size, off_t offset, size_t len, dict_t *xdata)
{
- int32_t ret;
- int32_t flags = 0;
- struct iatt statpre = {0,};
- struct iatt statpost = {0,};
+ int32_t ret;
+ int32_t flags = 0;
+ struct iatt statpre = {
+ 0,
+ };
+ struct iatt statpost = {
+ 0,
+ };
#ifdef FALLOC_FL_KEEP_SIZE
- if (keep_size)
- flags = FALLOC_FL_KEEP_SIZE;
+ if (keep_size)
+ flags = FALLOC_FL_KEEP_SIZE;
#endif /* FALLOC_FL_KEEP_SIZE */
- ret = posix_do_fallocate (frame, this, fd, flags, offset, len,
- &statpre, &statpost, xdata, NULL);
- if (ret < 0)
- goto err;
+ ret = posix_do_fallocate(frame, this, fd, flags, offset, len, &statpre,
+ &statpost, xdata, NULL);
+ if (ret < 0)
+ goto err;
- STACK_UNWIND_STRICT(fallocate, frame, 0, 0, &statpre, &statpost, NULL);
- return 0;
+ STACK_UNWIND_STRICT(fallocate, frame, 0, 0, &statpre, &statpost, NULL);
+ return 0;
err:
- STACK_UNWIND_STRICT(fallocate, frame, -1, -ret, NULL, NULL, NULL);
- return 0;
+ STACK_UNWIND_STRICT(fallocate, frame, -1, -ret, NULL, NULL, NULL);
+ return 0;
}
int32_t
posix_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
size_t len, dict_t *xdata)
{
- int32_t ret;
- dict_t *rsp_xdata = NULL;
+ int32_t ret;
+ dict_t *rsp_xdata = NULL;
#ifndef FALLOC_FL_KEEP_SIZE
- ret = EOPNOTSUPP;
+ ret = EOPNOTSUPP;
-#else /* FALLOC_FL_KEEP_SIZE */
- int32_t flags = FALLOC_FL_KEEP_SIZE|FALLOC_FL_PUNCH_HOLE;
- struct iatt statpre = {0,};
- struct iatt statpost = {0,};
+#else /* FALLOC_FL_KEEP_SIZE */
+ int32_t flags = FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE;
+ struct iatt statpre = {
+ 0,
+ };
+ struct iatt statpost = {
+ 0,
+ };
- ret = posix_do_fallocate (frame, this, fd, flags, offset, len,
- &statpre, &statpost, xdata, &rsp_xdata);
- if (ret < 0)
- goto err;
+ ret = posix_do_fallocate(frame, this, fd, flags, offset, len, &statpre,
+ &statpost, xdata, &rsp_xdata);
+ if (ret < 0)
+ goto err;
- STACK_UNWIND_STRICT(discard, frame, 0, 0, &statpre, &statpost,
- rsp_xdata);
- return 0;
+ STACK_UNWIND_STRICT(discard, frame, 0, 0, &statpre, &statpost, rsp_xdata);
+ return 0;
err:
#endif /* FALLOC_FL_KEEP_SIZE */
- STACK_UNWIND_STRICT(discard, frame, -1, -ret, NULL, NULL, rsp_xdata);
- return 0;
+ STACK_UNWIND_STRICT(discard, frame, -1, -ret, NULL, NULL, rsp_xdata);
+ return 0;
}
int32_t
posix_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
- off_t len, dict_t *xdata)
+ off_t len, dict_t *xdata)
{
- int32_t ret = 0;
- struct iatt statpre = {0,};
- struct iatt statpost = {0,};
- struct posix_private *priv = NULL;
- int op_ret = -1;
- int op_errno = -EINVAL;
- dict_t *rsp_xdata = NULL;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (this, out);
-
- priv = this->private;
- DISK_SPACE_CHECK_AND_GOTO (frame, priv, xdata, op_ret, op_errno, out);
-
- ret = posix_do_zerofill (frame, this, fd, offset, len,
- &statpre, &statpost, xdata, &rsp_xdata);
- if (ret < 0) {
- op_ret = -1;
- op_errno = -ret;
- goto out;
- }
+ int32_t ret = 0;
+ struct iatt statpre = {
+ 0,
+ };
+ struct iatt statpost = {
+ 0,
+ };
+ struct posix_private *priv = NULL;
+ int op_ret = -1;
+ int op_errno = -EINVAL;
+ dict_t *rsp_xdata = NULL;
+
+ VALIDATE_OR_GOTO(frame, out);
+ VALIDATE_OR_GOTO(this, out);
+
+ priv = this->private;
+ DISK_SPACE_CHECK_AND_GOTO(frame, priv, xdata, op_ret, op_errno, out);
+
+ ret = posix_do_zerofill(frame, this, fd, offset, len, &statpre, &statpost,
+ xdata, &rsp_xdata);
+ if (ret < 0) {
+ op_ret = -1;
+ op_errno = -ret;
+ goto out;
+ }
- STACK_UNWIND_STRICT(zerofill, frame, 0, 0, &statpre, &statpost,
- rsp_xdata);
- return 0;
+ STACK_UNWIND_STRICT(zerofill, frame, 0, 0, &statpre, &statpost, rsp_xdata);
+ return 0;
out:
- STACK_UNWIND_STRICT(zerofill, frame, op_ret, op_errno, NULL, NULL,
- rsp_xdata);
- return 0;
+ STACK_UNWIND_STRICT(zerofill, frame, op_ret, op_errno, NULL, NULL,
+ rsp_xdata);
+ return 0;
}
int32_t
-posix_ipc (call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata)
+posix_ipc(call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata)
{
- /*
- * IPC is for inter-translator communication. If one gets here, it
- * means somebody sent one that nobody else recognized, which is an
- * error much like an uncaught exception.
- */
- gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_IPC_NOT_HANDLE,
- "GF_LOG_IPC(%d) not handled", op);
- STACK_UNWIND_STRICT (ipc, frame, -1, -EOPNOTSUPP, NULL);
- return 0;
-
+ /*
+ * IPC is for inter-translator communication. If one gets here, it
+ * means somebody sent one that nobody else recognized, which is an
+ * error much like an uncaught exception.
+ */
+ gf_msg(this->name, GF_LOG_ERROR, 0, P_MSG_IPC_NOT_HANDLE,
+ "GF_LOG_IPC(%d) not handled", op);
+ STACK_UNWIND_STRICT(ipc, frame, -1, -EOPNOTSUPP, NULL);
+ return 0;
}
int32_t
-posix_seek (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
- gf_seek_what_t what, dict_t *xdata)
+posix_seek(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ gf_seek_what_t what, dict_t *xdata)
{
#ifdef HAVE_SEEK_HOLE
- struct posix_fd *pfd = NULL;
- off_t ret = -1;
- int err = 0;
- int whence = 0;
- struct iatt preop = {0,};
- dict_t *rsp_xdata = NULL;
+ struct posix_fd *pfd = NULL;
+ off_t ret = -1;
+ int err = 0;
+ int whence = 0;
+ struct iatt preop = {
+ 0,
+ };<