diff options
Diffstat (limited to 'xlators/features/utime/src')
| -rw-r--r-- | xlators/features/utime/src/Makefile.am | 2 | ||||
| -rw-r--r-- | xlators/features/utime/src/utime-autogen-fops-tmpl.c | 10 | ||||
| -rw-r--r-- | xlators/features/utime/src/utime-autogen-fops-tmpl.h | 2 | ||||
| -rwxr-xr-x[-rw-r--r--] | xlators/features/utime/src/utime-gen-fops-c.py | 36 | ||||
| -rwxr-xr-x[-rw-r--r--] | xlators/features/utime/src/utime-gen-fops-h.py | 4 | ||||
| -rw-r--r-- | xlators/features/utime/src/utime-helpers.c | 101 | ||||
| -rw-r--r-- | xlators/features/utime/src/utime-helpers.h | 11 | ||||
| -rw-r--r-- | xlators/features/utime/src/utime-mem-types.h | 21 | ||||
| -rw-r--r-- | xlators/features/utime/src/utime-messages.h | 29 | ||||
| -rw-r--r-- | xlators/features/utime/src/utime.c | 398 | ||||
| -rw-r--r-- | xlators/features/utime/src/utime.h | 10 |
11 files changed, 444 insertions, 180 deletions
diff --git a/xlators/features/utime/src/Makefile.am b/xlators/features/utime/src/Makefile.am index e94a00a8326..7c3adbc2195 100644 --- a/xlators/features/utime/src/Makefile.am +++ b/xlators/features/utime/src/Makefile.am @@ -15,6 +15,8 @@ utime_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la noinst_HEADERS_utime = $(UTIME_SRC)/utime-helpers.h noinst_HEADERS_utime += $(UTIME_SRC)/utime.h +noinst_HEADERS_utime += $(UTIME_SRC)/utime-messages.h +noinst_HEADERS_utime += $(UTIME_SRC)/utime-mem-types.h noinst_HEADERS = $(top_srcdir)/xlators/lib/src/libxlator.h noinst_HEADERS += $(noinst_HEADERS_utime) diff --git a/xlators/features/utime/src/utime-autogen-fops-tmpl.c b/xlators/features/utime/src/utime-autogen-fops-tmpl.c index b4be66eebd1..f2f35322926 100644 --- a/xlators/features/utime/src/utime-autogen-fops-tmpl.c +++ b/xlators/features/utime/src/utime-autogen-fops-tmpl.c @@ -18,11 +18,11 @@ #include "config.h" #endif -#include "glusterfs.h" -#include "xlator.h" -#include "logging.h" -#include "statedump.h" +#include <glusterfs/glusterfs.h> +#include <glusterfs/xlator.h> +#include <glusterfs/logging.h> +#include <glusterfs/statedump.h> #include "utime-helpers.h" -#include "timespec.h" +#include <glusterfs/timespec.h> #pragma generate diff --git a/xlators/features/utime/src/utime-autogen-fops-tmpl.h b/xlators/features/utime/src/utime-autogen-fops-tmpl.h index e2e807cdf64..4e102ffed6c 100644 --- a/xlators/features/utime/src/utime-autogen-fops-tmpl.h +++ b/xlators/features/utime/src/utime-autogen-fops-tmpl.h @@ -15,7 +15,7 @@ #ifndef _UTIME_AUTOGEN_FOPS_H #define _UTIME_AUTOGEN_FOPS_H -#include "xlator.h" +#include <glusterfs/xlator.h> #pragma generate diff --git a/xlators/features/utime/src/utime-gen-fops-c.py b/xlators/features/utime/src/utime-gen-fops-c.py index 6ebd1afe9cd..9fb3e1b8b1a 100644..100755 --- a/xlators/features/utime/src/utime-gen-fops-c.py +++ b/xlators/features/utime/src/utime-gen-fops-c.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 from __future__ import print_function import os @@ -16,7 +16,7 @@ gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this, { gl_timespec_get(&frame->root->ctime); - (void) utime_update_attribute_flags(frame, GF_FOP_@UPNAME@); + (void) utime_update_attribute_flags(frame, this, GF_FOP_@UPNAME@); STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@); return 0; @@ -41,7 +41,7 @@ gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this, { gl_timespec_get(&frame->root->ctime); - (void) utime_update_attribute_flags(frame, GF_FOP_READ); + (void) utime_update_attribute_flags(frame, this, GF_FOP_READ); STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@); return 0; @@ -55,7 +55,21 @@ gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this, { gl_timespec_get(&frame->root->ctime); - (void) utime_update_attribute_flags(frame, GF_FOP_WRITE); + (void) utime_update_attribute_flags(frame, this, GF_FOP_WRITE); + STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@); + return 0; +} +""" + +FOPS_COPY_FILE_RANGE_TEMPLATE = """ +int32_t +gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this, + @LONG_ARGS@) +{ + gl_timespec_get(&frame->root->ctime); + + (void) utime_update_attribute_flags(frame, this, GF_FOP_COPY_FILE_RANGE); STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@); return 0; @@ -81,6 +95,16 @@ gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this, frame->root->flags |= MDATA_CTIME; } + if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { + if (valid & GF_ATTR_ATIME_NOW) { + frame->root->ctime.tv_sec = stbuf->ia_atime; + frame->root->ctime.tv_nsec = stbuf->ia_atime_nsec; + } else if (valid & GF_ATTR_MTIME_NOW) { + frame->root->ctime.tv_sec = stbuf->ia_mtime; + frame->root->ctime.tv_nsec = stbuf->ia_mtime_nsec; + } + } + STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@); return 0; @@ -94,6 +118,7 @@ utime_ops = ['fallocate', 'zerofill', 'opendir', 'mknod', 'mkdir', utime_read_op = ['readv'] utime_write_op = ['writev'] utime_setattr_ops = ['setattr', 'fsetattr'] +utime_copy_file_range_ops = ['copy_file_range'] def gen_defaults(): for name in ops: @@ -109,6 +134,9 @@ def gen_defaults(): if name in utime_setattr_ops: print(generate(FOPS_CBK_COMMON_TEMPLATE, name, cbk_subs)) print(generate(FOPS_SETATTR_TEMPLATE, name, fop_subs)) + if name in utime_copy_file_range_ops: + print(generate(FOPS_CBK_COMMON_TEMPLATE, name, cbk_subs)) + print(generate(FOPS_COPY_FILE_RANGE_TEMPLATE, name, fop_subs)) for l in open(sys.argv[1], 'r').readlines(): if l.find('#pragma generate') != -1: diff --git a/xlators/features/utime/src/utime-gen-fops-h.py b/xlators/features/utime/src/utime-gen-fops-h.py index e04cbd41293..e96274c229a 100644..100755 --- a/xlators/features/utime/src/utime-gen-fops-h.py +++ b/xlators/features/utime/src/utime-gen-fops-h.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 from __future__ import print_function import os @@ -18,7 +18,7 @@ gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this, utime_ops = ['fallocate', 'zerofill', 'opendir', 'mknod', 'mkdir', 'unlink', 'rmdir', 'symlink', 'rename', 'link', 'truncate', 'ftruncate', 'create', 'open', 'removexattr', 'fremovexattr', - 'readv', 'writev', 'setattr', 'fsetattr'] + 'readv', 'writev', 'setattr', 'fsetattr', 'copy_file_range'] def gen_defaults(): for name, value in ops.items(): diff --git a/xlators/features/utime/src/utime-helpers.c b/xlators/features/utime/src/utime-helpers.c index 6cac9651190..29d9ad93561 100644 --- a/xlators/features/utime/src/utime-helpers.c +++ b/xlators/features/utime/src/utime-helpers.c @@ -9,87 +9,102 @@ */ #include "utime-helpers.h" +#include "utime.h" void -gl_timespec_get (struct timespec *ts) +gl_timespec_get(struct timespec *ts) { - #ifdef TIME_UTC - timespec_get (ts, TIME_UTC); - #else - timespec_now (ts); - #endif +#ifdef TIME_UTC + timespec_get(ts, TIME_UTC); +#else + timespec_now_realtime(ts); +#endif } void -utime_update_attribute_flags(call_frame_t *frame, glusterfs_fop_t fop) +utime_update_attribute_flags(call_frame_t *frame, xlator_t *this, + glusterfs_fop_t fop) { + utime_priv_t *utime_priv = NULL; - if (!frame) { - goto out; - } + if (!frame || !this) { + goto out; + } - switch (fop) { + utime_priv = this->private; + + switch (fop) { case GF_FOP_SETXATTR: case GF_FOP_FSETXATTR: - frame->root->flags |= MDATA_CTIME; - break; + frame->root->flags |= MDATA_CTIME; + break; case GF_FOP_FALLOCATE: case GF_FOP_ZEROFILL: - frame->root->flags |= MDATA_MTIME; - frame->root->flags |= MDATA_ATIME; - break; + frame->root->flags |= MDATA_MTIME; + frame->root->flags |= MDATA_ATIME; + break; case GF_FOP_OPENDIR: case GF_FOP_OPEN: case GF_FOP_READ: + if (!utime_priv->noatime) { frame->root->flags |= MDATA_ATIME; - break; - + } + break; case GF_FOP_MKNOD: case GF_FOP_MKDIR: case GF_FOP_SYMLINK: case GF_FOP_CREATE: - frame->root->flags |= MDATA_ATIME; - frame->root->flags |= MDATA_CTIME; - frame->root->flags |= MDATA_MTIME; - frame->root->flags |= MDATA_PAR_CTIME; - frame->root->flags |= MDATA_PAR_MTIME; - break; + frame->root->flags |= MDATA_ATIME; + frame->root->flags |= MDATA_CTIME; + frame->root->flags |= MDATA_MTIME; + frame->root->flags |= MDATA_PAR_CTIME; + frame->root->flags |= MDATA_PAR_MTIME; + break; case GF_FOP_UNLINK: case GF_FOP_RMDIR: - frame->root->flags |= MDATA_CTIME; - frame->root->flags |= MDATA_PAR_CTIME; - frame->root->flags |= MDATA_PAR_MTIME; - break; + frame->root->flags |= MDATA_CTIME; + frame->root->flags |= MDATA_PAR_CTIME; + frame->root->flags |= MDATA_PAR_MTIME; + break; case GF_FOP_WRITE: - frame->root->flags |= MDATA_MTIME; - frame->root->flags |= MDATA_CTIME; - break; + frame->root->flags |= MDATA_MTIME; + frame->root->flags |= MDATA_CTIME; + break; case GF_FOP_LINK: case GF_FOP_RENAME: - frame->root->flags |= MDATA_CTIME; - frame->root->flags |= MDATA_PAR_CTIME; - frame->root->flags |= MDATA_PAR_MTIME; - break; + frame->root->flags |= MDATA_CTIME; + frame->root->flags |= MDATA_PAR_CTIME; + frame->root->flags |= MDATA_PAR_MTIME; + break; case GF_FOP_TRUNCATE: case GF_FOP_FTRUNCATE: - frame->root->flags |= MDATA_CTIME; - frame->root->flags |= MDATA_MTIME; - break; + frame->root->flags |= MDATA_CTIME; + frame->root->flags |= MDATA_MTIME; + break; case GF_FOP_REMOVEXATTR: case GF_FOP_FREMOVEXATTR: - frame->root->flags |= MDATA_CTIME; - break; + frame->root->flags |= MDATA_CTIME; + break; + case GF_FOP_COPY_FILE_RANGE: + /* Below 2 are for destination fd */ + frame->root->flags |= MDATA_CTIME; + frame->root->flags |= MDATA_MTIME; + /* Below flag is for the source fd */ + if (!utime_priv->noatime) { + frame->root->flags |= MDATA_ATIME; + } + break; default: - frame->root->flags = 0; - } + frame->root->flags = 0; + } out: - return; + return; } diff --git a/xlators/features/utime/src/utime-helpers.h b/xlators/features/utime/src/utime-helpers.h index f526aecb063..2e32d4bece6 100644 --- a/xlators/features/utime/src/utime-helpers.h +++ b/xlators/features/utime/src/utime-helpers.h @@ -11,14 +11,15 @@ #ifndef _UTIME_HELPERS_H #define _UTIME_HELPERS_H -#include "glusterfs-fops.h" -#include "stack.h" -#include "timespec.h" +#include <glusterfs/stack.h> +#include <glusterfs/xlator.h> +#include <glusterfs/timespec.h> #include <time.h> void -gl_timespec_get (struct timespec *ts); +gl_timespec_get(struct timespec *ts); void -utime_update_attribute_flags(call_frame_t *frame, glusterfs_fop_t fop); +utime_update_attribute_flags(call_frame_t *frame, xlator_t *this, + glusterfs_fop_t fop); #endif /* _UTIME_HELPERS_H */ diff --git a/xlators/features/utime/src/utime-mem-types.h b/xlators/features/utime/src/utime-mem-types.h new file mode 100644 index 00000000000..ad1255f85f3 --- /dev/null +++ b/xlators/features/utime/src/utime-mem-types.h @@ -0,0 +1,21 @@ +/* + Copyright (c) 2018 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef __UTIME_MEM_TYPES_H__ +#define __UTIME_MEM_TYPES_H__ + +#include <glusterfs/mem-types.h> + +enum gf_utime_mem_types_ { + utime_mt_utime_t = gf_common_mt_end + 1, + utime_mt_end +}; + +#endif /* __UTIME_MEM_TYPES_H__ */ diff --git a/xlators/features/utime/src/utime-messages.h b/xlators/features/utime/src/utime-messages.h new file mode 100644 index 00000000000..bd40265abaf --- /dev/null +++ b/xlators/features/utime/src/utime-messages.h @@ -0,0 +1,29 @@ +/* + Copyright (c) 2018 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef __UTIME_MESSAGES_H__ +#define __UTIME_MESSAGES_H__ + +#include <glusterfs/glfs-message-id.h> + +/* To add new message IDs, append new identifiers at the end of the list. + * + * Never remove a message ID. If it's not used anymore, you can rename it or + * leave it as it is, but not delete it. This is to prevent reutilization of + * IDs by other messages. + * + * The component name must match one of the entries defined in + * glfs-message-id.h. + */ + +GLFS_MSGID(UTIME, UTIME_MSG_NO_MEMORY, UTIME_MSG_SET_MDATA_FAILED, + UTIME_MSG_DICT_SET_FAILED); + +#endif /* __UTIME_MESSAGES_H__ */ diff --git a/xlators/features/utime/src/utime.c b/xlators/features/utime/src/utime.c index a8d74d9cb5c..2acc63e6a05 100644 --- a/xlators/features/utime/src/utime.c +++ b/xlators/features/utime/src/utime.c @@ -9,220 +9,384 @@ */ #include "utime.h" +#include "utime-helpers.h" +#include "utime-messages.h" +#include "utime-mem-types.h" +#include <glusterfs/call-stub.h> int32_t -gf_utime_invalidate (xlator_t *this, - inode_t *inode) +gf_utime_invalidate(xlator_t *this, inode_t *inode) { - return 0; + return 0; } - int32_t -gf_utime_forget (xlator_t *this, - inode_t *inode) +gf_utime_forget(xlator_t *this, inode_t *inode) { - return 0; + return 0; } - int32_t -gf_utime_client_destroy (xlator_t *this, - client_t *client) +gf_utime_client_destroy(xlator_t *this, client_t *client) { - return 0; + return 0; } - void -gf_utime_ictxmerge (xlator_t *this, - fd_t *fd, - inode_t *inode, - inode_t *linked_inode) +gf_utime_ictxmerge(xlator_t *this, fd_t *fd, inode_t *inode, + inode_t *linked_inode) { - return; + return; } - int32_t -gf_utime_release (xlator_t *this, - fd_t *fd) +gf_utime_release(xlator_t *this, fd_t *fd) { - return 0; + return 0; } - int32_t -gf_utime_releasedir (xlator_t *this, - fd_t *fd) +gf_utime_releasedir(xlator_t *this, fd_t *fd) { - return 0; + return 0; } - int32_t -gf_utime_client_disconnect (xlator_t *this, - client_t *client) +gf_utime_client_disconnect(xlator_t *this, client_t *client) { - return 0; + return 0; } - int32_t -gf_utime_fdctx_to_dict (xlator_t *this, - fd_t *fd, - dict_t *dict) +gf_utime_fdctx_to_dict(xlator_t *this, fd_t *fd, dict_t *dict) { - return 0; + return 0; } - int32_t -gf_utime_inode (xlator_t *this) +gf_utime_inode(xlator_t *this) { - return 0; + return 0; } - int32_t -gf_utime_inode_to_dict (xlator_t *this, - dict_t *dict) +gf_utime_inode_to_dict(xlator_t *this, dict_t *dict) { - return 0; + return 0; } - int32_t -gf_utime_history (xlator_t *this) +gf_utime_history(xlator_t *this) { - return 0; + return 0; } - int32_t -gf_utime_fd (xlator_t *this) +gf_utime_fd(xlator_t *this) { - return 0; + return 0; } - int32_t -gf_utime_fd_to_dict (xlator_t *this, - dict_t *dict) +gf_utime_fd_to_dict(xlator_t *this, dict_t *dict) { - return 0; + return 0; } - int32_t -gf_utime_fdctx (xlator_t *this, - fd_t *fd) +gf_utime_fdctx(xlator_t *this, fd_t *fd) { - return 0; + return 0; } - int32_t -gf_utime_inodectx (xlator_t *this, - inode_t *ino) +gf_utime_inodectx(xlator_t *this, inode_t *ino) { - return 0; + return 0; } +int32_t +gf_utime_inodectx_to_dict(xlator_t *this, inode_t *ino, dict_t *dict) +{ + return 0; +} int32_t -gf_utime_inodectx_to_dict (xlator_t *this, - inode_t *ino, - dict_t *dict) +gf_utime_priv_to_dict(xlator_t *this, dict_t *dict, char *brickname) { - return 0; + return 0; } +int32_t +gf_utime_priv(xlator_t *this) +{ + return 0; +} int32_t -gf_utime_priv_to_dict (xlator_t *this, - dict_t *dict, char *brickname) +mem_acct_init(xlator_t *this) { - return 0; + if (xlator_mem_acct_init(this, utime_mt_end + 1) != 0) { + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, UTIME_MSG_NO_MEMORY, + "Memory accounting initialization failed."); + return -1; + } + return 0; } +int32_t +gf_utime_set_mdata_setxattr_cbk(call_frame_t *frame, void *cookie, + xlator_t *this, int op_ret, int op_errno, + dict_t *xdata) +{ + call_stub_t *stub = frame->local; + /* Don't fail lookup if mdata setxattr fails */ + if (op_ret) { + gf_msg(this->name, GF_LOG_ERROR, op_errno, UTIME_MSG_SET_MDATA_FAILED, + "dict set of key for set-ctime-mdata failed"); + } + frame->local = NULL; + call_resume(stub); + STACK_DESTROY(frame->root); + return 0; +} int32_t -gf_utime_priv (xlator_t *this) +gf_utime_set_mdata_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *stbuf, dict_t *xdata, + struct iatt *postparent) { + dict_t *dict = NULL; + struct mdata_iatt *mdata = NULL; + int ret = 0; + loc_t loc = { + 0, + }; + call_frame_t *new_frame = NULL; + + if (!op_ret && dict_get(xdata, GF_XATTR_MDATA_KEY) == NULL) { + dict = dict_new(); + if (!dict) { + op_errno = ENOMEM; + goto err; + } + mdata = GF_MALLOC(sizeof(struct mdata_iatt), gf_common_mt_char); + if (mdata == NULL) { + op_errno = ENOMEM; + goto err; + } + iatt_to_mdata(mdata, stbuf); + ret = dict_set_mdata(dict, CTIME_MDATA_XDATA_KEY, mdata, _gf_false); + if (ret < 0) { + gf_msg(this->name, GF_LOG_WARNING, ENOMEM, UTIME_MSG_NO_MEMORY, + "dict set of key for set-ctime-mdata failed"); + goto err; + } + new_frame = copy_frame(frame); + if (!new_frame) { + op_errno = ENOMEM; + goto stub_err; + } + + new_frame->local = fop_lookup_cbk_stub(frame, default_lookup_cbk, + op_ret, op_errno, inode, stbuf, + xdata, postparent); + if (!new_frame->local) { + gf_msg(this->name, GF_LOG_WARNING, ENOMEM, UTIME_MSG_NO_MEMORY, + "lookup_cbk stub allocation failed"); + op_errno = ENOMEM; + STACK_DESTROY(new_frame->root); + goto stub_err; + } + + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, stbuf->ia_gfid); + + new_frame->root->uid = 0; + new_frame->root->gid = 0; + new_frame->root->pid = GF_CLIENT_PID_SET_UTIME; + STACK_WIND(new_frame, gf_utime_set_mdata_setxattr_cbk, + FIRST_CHILD(this), FIRST_CHILD(this)->fops->setxattr, &loc, + dict, 0, NULL); + + dict_unref(dict); + inode_unref(loc.inode); return 0; + } + + STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, stbuf, xdata, + postparent); + return 0; + +err: + if (mdata) { + GF_FREE(mdata); + } +stub_err: + if (dict) { + dict_unref(dict); + } + STACK_UNWIND_STRICT(lookup, frame, -1, op_errno, NULL, NULL, NULL, NULL); + return 0; } +int +gf_utime_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) +{ + int op_errno = EINVAL; + int ret = -1; + + VALIDATE_OR_GOTO(frame, err); + VALIDATE_OR_GOTO(this, err); + VALIDATE_OR_GOTO(loc, err); + VALIDATE_OR_GOTO(loc->inode, err); + + xdata = xdata ? dict_ref(xdata) : dict_new(); + if (!xdata) { + op_errno = ENOMEM; + goto err; + } + + ret = dict_set_int8(xdata, GF_XATTR_MDATA_KEY, 1); + if (ret < 0) { + gf_msg(this->name, GF_LOG_WARNING, -ret, UTIME_MSG_DICT_SET_FAILED, + "%s: Unable to set dict value for %s", loc->path, + GF_XATTR_MDATA_KEY); + op_errno = -ret; + goto free_dict; + } + + STACK_WIND(frame, gf_utime_set_mdata_lookup_cbk, FIRST_CHILD(this), + FIRST_CHILD(this)->fops->lookup, loc, xdata); + dict_unref(xdata); + return 0; + +free_dict: + dict_unref(xdata); +err: + STACK_UNWIND_STRICT(lookup, frame, ret, op_errno, NULL, NULL, NULL, NULL); + return 0; +} int32_t -init (xlator_t *this) +init(xlator_t *this) { - return 0; + utime_priv_t *utime = NULL; + + utime = GF_MALLOC(sizeof(*utime), utime_mt_utime_t); + if (utime == NULL) { + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, UTIME_MSG_NO_MEMORY, + "Failed to allocate private memory."); + return -1; + } + memset(utime, 0, sizeof(*utime)); + + this->private = utime; + GF_OPTION_INIT("noatime", utime->noatime, bool, err); + + return 0; +err: + return -1; } void -fini (xlator_t *this) +fini(xlator_t *this) { - return; + utime_priv_t *utime = NULL; + + utime = this->private; + GF_FREE(utime); + return; } int32_t -reconfigure (xlator_t *this, dict_t *dict) +reconfigure(xlator_t *this, dict_t *options) { - return 0; + utime_priv_t *utime = this->private; + + GF_OPTION_RECONF("noatime", utime->noatime, options, bool, err); + + return 0; +err: + return -1; } int -notify (xlator_t *this, int event, void *data, ...) +notify(xlator_t *this, int event, void *data, ...) { - return default_notify (this, event, data); + return default_notify(this, event, data); } - struct xlator_fops fops = { - /* TODO: Need to go through other fops and - * check if they modify time attributes - */ - .rename = gf_utime_rename, - .mknod = gf_utime_mknod, - .readv = gf_utime_readv, - .fremovexattr = gf_utime_fremovexattr, - .open = gf_utime_open, - .create = gf_utime_create, - .mkdir = gf_utime_mkdir, - .writev = gf_utime_writev, - .rmdir = gf_utime_rmdir, - .fallocate = gf_utime_fallocate, - .truncate = gf_utime_truncate, - .symlink = gf_utime_symlink, - .zerofill = gf_utime_zerofill, - .link = gf_utime_link, - .ftruncate = gf_utime_ftruncate, - .unlink = gf_utime_unlink, - .setattr = gf_utime_setattr, - .fsetattr = gf_utime_fsetattr, - .opendir = gf_utime_opendir, - .removexattr = gf_utime_removexattr, + .rename = gf_utime_rename, + .mknod = gf_utime_mknod, + .readv = gf_utime_readv, + .fremovexattr = gf_utime_fremovexattr, + .open = gf_utime_open, + .create = gf_utime_create, + .mkdir = gf_utime_mkdir, + .writev = gf_utime_writev, + .rmdir = gf_utime_rmdir, + .fallocate = gf_utime_fallocate, + .truncate = gf_utime_truncate, + .symlink = gf_utime_symlink, + .zerofill = gf_utime_zerofill, + .link = gf_utime_link, + .ftruncate = gf_utime_ftruncate, + .unlink = gf_utime_unlink, + .setattr = gf_utime_setattr, + .fsetattr = gf_utime_fsetattr, + .opendir = gf_utime_opendir, + .removexattr = gf_utime_removexattr, + .lookup = gf_utime_lookup, }; struct xlator_cbks cbks = { - .invalidate = gf_utime_invalidate, - .forget = gf_utime_forget, - .client_destroy = gf_utime_client_destroy, - .ictxmerge = gf_utime_ictxmerge, - .release = gf_utime_release, - .releasedir = gf_utime_releasedir, - .client_disconnect = gf_utime_client_disconnect, + .invalidate = gf_utime_invalidate, + .forget = gf_utime_forget, + .client_destroy = gf_utime_client_destroy, + .ictxmerge = gf_utime_ictxmerge, + .release = gf_utime_release, + .releasedir = gf_utime_releasedir, + .client_disconnect = gf_utime_client_disconnect, }; struct xlator_dumpops dumpops = { - .fdctx_to_dict = gf_utime_fdctx_to_dict, - .inode = gf_utime_inode, - .inode_to_dict = gf_utime_inode_to_dict, - .history = gf_utime_history, - .fd = gf_utime_fd, - .fd_to_dict = gf_utime_fd_to_dict, - .fdctx = gf_utime_fdctx, - .inodectx = gf_utime_inodectx, - .inodectx_to_dict = gf_utime_inodectx_to_dict, - .priv_to_dict = gf_utime_priv_to_dict, - .priv = gf_utime_priv, + .fdctx_to_dict = gf_utime_fdctx_to_dict, + .inode = gf_utime_inode, + .inode_to_dict = gf_utime_inode_to_dict, + .history = gf_utime_history, + .fd = gf_utime_fd, + .fd_to_dict = gf_utime_fd_to_dict, + .fdctx = gf_utime_fdctx, + .inodectx = gf_utime_inodectx, + .inodectx_to_dict = gf_utime_inodectx_to_dict, + .priv_to_dict = gf_utime_priv_to_dict, + .priv = gf_utime_priv, +}; + +struct volume_options options[] = { + {.key = {"noatime"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "on", + .op_version = {GD_OP_VERSION_5_0}, + .flags = OPT_FLAG_SETTABLE | OPT_FLAG_CLIENT_OPT | OPT_FLAG_DOC, + .tags = {"ctime"}, + .description = "Enable/Disable atime updation when ctime feature is " + "enabled. When noatime is on, atime is not updated with " + "ctime feature enabled and vice versa."}, + {.key = {NULL}}}; + +xlator_api_t xlator_api = { + .init = init, + .fini = fini, + .notify = notify, + .reconfigure = reconfigure, + .mem_acct_init = mem_acct_init, + .op_version = {GD_OP_VERSION_5_0}, + .dumpops = &dumpops, + .fops = &fops, + .cbks = &cbks, + .options = options, + .identifier = "utime", + .category = GF_MAINTAINED, }; diff --git a/xlators/features/utime/src/utime.h b/xlators/features/utime/src/utime.h index f8d5eca082e..ba55eec00de 100644 --- a/xlators/features/utime/src/utime.h +++ b/xlators/features/utime/src/utime.h @@ -11,9 +11,13 @@ #ifndef __UTIME_H__ #define __UTIME_H__ -#include "glusterfs.h" -#include "xlator.h" -#include "defaults.h" +#include <glusterfs/glusterfs.h> +#include <glusterfs/xlator.h> +#include <glusterfs/defaults.h> #include "utime-autogen-fops.h" +typedef struct utime_priv { + gf_boolean_t noatime; +} utime_priv_t; + #endif /* __UTIME_H__ */ |
