diff options
Diffstat (limited to 'xlators/features/trash/src/trash.c')
| -rw-r--r-- | xlators/features/trash/src/trash.c | 378 |
1 files changed, 185 insertions, 193 deletions
diff --git a/xlators/features/trash/src/trash.c b/xlators/features/trash/src/trash.c index aa5cea0d1..addeb66a0 100644 --- a/xlators/features/trash/src/trash.c +++ b/xlators/features/trash/src/trash.c @@ -1,52 +1,42 @@ /* - Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ + Copyright (c) 2006-2012 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 _CONFIG_H #define _CONFIG_H #include "config.h" #endif #include "trash.h" - +#include "trash-mem-types.h" int32_t trash_ftruncate_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iovec *vector, int32_t count, - struct stat *stbuf, struct iobref *iobuf); + struct iatt *stbuf, struct iobref *iobuf); int32_t trash_truncate_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct stat *prebuf, struct stat *postbuf); + struct iatt *prebuf, struct iatt *postbuf); int32_t trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, - struct stat *stbuf, struct stat *preparent, - struct stat *postparent); + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent); int32_t trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf, - struct stat *preoldparent, struct stat *postoldparent, - struct stat *prenewparent, struct stat *postnewparent); + int32_t op_ret, int32_t op_errno, struct iatt *buf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent); void trash_local_wipe (trash_local_t *local) @@ -63,7 +53,7 @@ trash_local_wipe (trash_local_t *local) if (local->newfd) fd_unref (local->newfd); - FREE (local); + mem_put (local); out: return; } @@ -71,17 +61,17 @@ out: int32_t trash_common_unwind_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct stat *preparent, struct stat *postparent) + struct iatt *preparent, struct iatt *postparent) { - TRASH_STACK_UNWIND (frame, op_ret, op_errno, preparent, postparent); + TRASH_STACK_UNWIND (unlink, frame, op_ret, op_errno, preparent, postparent); return 0; } int32_t trash_unlink_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, - struct stat *stbuf, struct stat *preparent, - struct stat *postparent) + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent) { trash_local_t *local = NULL; char *tmp_str = NULL; @@ -94,9 +84,10 @@ trash_unlink_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, loc_t tmp_loc = {0,}; local = frame->local; - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { - gf_log (this->name, GF_LOG_DEBUG, "out of memory"); + gf_log (this->name, GF_LOG_ERROR, "out of memory"); + goto out; } loop_count = local->loop_count; @@ -113,7 +104,8 @@ trash_unlink_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } tmp_path = memdup (local->newpath, count); if (!tmp_path) { - gf_log (this->name, GF_LOG_DEBUG, "out of memory"); + gf_log (this->name, GF_LOG_ERROR, "out of memory"); + goto out; } tmp_loc.path = tmp_path; @@ -122,7 +114,7 @@ trash_unlink_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND_COOKIE (frame, trash_unlink_mkdir_cbk, tmp_path, this->children->xlator, this->children->xlator->fops->mkdir, - &tmp_loc, 0755); + &tmp_loc, 0755, NULL); goto out; } @@ -156,18 +148,19 @@ trash_unlink_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } tmp_path = memdup (local->newpath, count); if (!tmp_path) { - gf_log (this->name, GF_LOG_DEBUG, "out of memory"); + gf_log (this->name, GF_LOG_ERROR, "out of memory"); + goto out; } tmp_loc.path = tmp_path; STACK_WIND_COOKIE (frame, trash_unlink_mkdir_cbk, tmp_path, this->children->xlator, this->children->xlator->fops->mkdir, - &tmp_loc, 0755); + &tmp_loc, 0755, NULL); out: - free (cookie); - free (tmp_str); + GF_FREE (cookie); + GF_FREE (tmp_str); return 0; } @@ -175,27 +168,25 @@ out: int32_t trash_rename_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, - struct stat *stbuf, struct stat *preparent, - struct stat *postparent); + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent); int32_t trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf, - struct stat *preoldparent, struct stat *postoldparent, - struct stat *prenewparent, struct stat *postnewparent) + int32_t op_ret, int32_t op_errno, struct iatt *buf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent) { trash_local_t *local = NULL; - trash_private_t *priv = NULL; char *tmp_str = NULL; char *dir_name = NULL; char *tmp_cookie = NULL; loc_t tmp_loc = {0,}; - priv = this->private; local = frame->local; if ((op_ret == -1) && (op_errno == ENOENT)) { - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -203,7 +194,7 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, tmp_loc.path = dir_name; - tmp_cookie = strdup (dir_name); + tmp_cookie = gf_strdup (dir_name); if (!tmp_cookie) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -211,9 +202,9 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND_COOKIE (frame, trash_unlink_mkdir_cbk, tmp_cookie, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mkdir, - &tmp_loc, 0755); + &tmp_loc, 0755, NULL); - free (tmp_str); + GF_FREE (tmp_str); return 0; } @@ -243,7 +234,7 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } /* All other cases, unlink should return success */ - TRASH_STACK_UNWIND (frame, 0, op_errno, &local->preparent, + TRASH_STACK_UNWIND (unlink, frame, 0, op_errno, &local->preparent, &local->postparent); return 0; @@ -254,19 +245,19 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t trash_common_unwind_buf_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct stat *prebuf, struct stat *postbuf) + struct iatt *prebuf, struct iatt *postbuf) { - TRASH_STACK_UNWIND (frame, op_ret, op_errno, prebuf, postbuf); + TRASH_STACK_UNWIND (truncate, frame, op_ret, op_errno, prebuf, postbuf); return 0; } int trash_common_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *stbuf, - struct stat *preoldparent, struct stat *postoldparent, - struct stat *prenewparent, struct stat *postnewparent) + int32_t op_ret, int32_t op_errno, struct iatt *stbuf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent) { - TRASH_STACK_UNWIND (frame, op_ret, op_errno, stbuf, preoldparent, + TRASH_STACK_UNWIND (rename, frame, op_ret, op_errno, stbuf, preoldparent, postoldparent, prenewparent, postnewparent); return 0; } @@ -274,7 +265,7 @@ trash_common_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t trash_unlink_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) + int32_t op_ret, int32_t op_errno, struct iatt *buf) { trash_private_t *priv = NULL; trash_local_t *local = NULL; @@ -289,15 +280,15 @@ trash_unlink_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto fail; } - if ((buf->st_size == 0) || - (buf->st_size > priv->max_trash_file_size)) { + if ((buf->ia_size == 0) || + (buf->ia_size > priv->max_trash_file_size)) { /* if the file is too big or zero, just unlink it */ - if (buf->st_size > priv->max_trash_file_size) { + if (buf->ia_size > priv->max_trash_file_size) { gf_log (this->name, GF_LOG_DEBUG, - "%s: file size too big (%"GF_PRI_SIZET") to " + "%s: file size too big (%"PRId64") to " "move into trash directory", - local->loc.path, buf->st_size); + local->loc.path, buf->ia_size); } STACK_WIND (frame, trash_common_unwind_cbk, @@ -316,8 +307,8 @@ trash_unlink_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, return 0; fail: - TRASH_STACK_UNWIND (frame, op_ret, op_errno, buf, - NULL, NULL, NULL, NULL); + TRASH_STACK_UNWIND (unlink, frame, op_ret, op_errno, buf, + NULL); return 0; @@ -325,9 +316,9 @@ fail: int32_t trash_rename_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf, - struct stat *preoldparent, struct stat *postoldparent, - struct stat *prenewparent, struct stat *postnewparent) + int32_t op_ret, int32_t op_errno, struct iatt *buf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent) { trash_local_t *local = NULL; char *tmp_str = NULL; @@ -337,7 +328,7 @@ trash_rename_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, local = frame->local; if ((op_ret == -1) && (op_errno == ENOENT)) { - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -346,7 +337,7 @@ trash_rename_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, /* check for the errno, if its ENOENT create directory and call * rename later */ - tmp_path = strdup (dir_name); + tmp_path = gf_strdup (dir_name); if (!tmp_path) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -356,9 +347,9 @@ trash_rename_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND_COOKIE (frame, trash_rename_mkdir_cbk, tmp_path, this->children->xlator, this->children->xlator->fops->mkdir, - &tmp_loc, 0755); + &tmp_loc, 0755, NULL); - free (tmp_str); + GF_FREE (tmp_str); return 0; } @@ -384,8 +375,8 @@ trash_rename_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t trash_rename_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, - struct stat *stbuf, struct stat *preparent, - struct stat *postparent) + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent) { trash_local_t *local = NULL; char *tmp_str = NULL; @@ -396,9 +387,10 @@ trash_rename_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, loc_t tmp_loc = {0,}; local = frame->local; - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); + goto out; } if ((op_ret == -1) && (op_errno == ENOENT)) { @@ -421,7 +413,7 @@ trash_rename_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND_COOKIE (frame, trash_rename_mkdir_cbk, tmp_path, this->children->xlator, this->children->xlator->fops->mkdir, - &tmp_loc, 0755); + &tmp_loc, 0755, NULL); } goto out; @@ -438,8 +430,8 @@ trash_rename_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } out: - free (cookie); /* strdup (dir_name) was sent here :) */ - free (tmp_str); + GF_FREE (cookie); /* strdup (dir_name) was sent here :) */ + GF_FREE (tmp_str); return 0; } @@ -447,8 +439,8 @@ out: int32_t trash_rename_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, - struct stat *buf, dict_t *xattr, - struct stat *postparent) + struct iatt *buf, dict_t *xattr, + struct iatt *postparent) { trash_private_t *priv = NULL; trash_local_t *local = NULL; @@ -464,15 +456,15 @@ trash_rename_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, &local->loc, &local->newloc); return 0; } - if ((buf->st_size == 0) || - (buf->st_size > priv->max_trash_file_size)) { + if ((buf->ia_size == 0) || + (buf->ia_size > priv->max_trash_file_size)) { /* if the file is too big or zero, just unlink it */ - if (buf->st_size > priv->max_trash_file_size) { + if (buf->ia_size > priv->max_trash_file_size) { gf_log (this->name, GF_LOG_DEBUG, - "%s: file size too big (%"GF_PRI_SIZET") to " + "%s: file size too big (%"PRId64") to " "move into trash directory", - local->newloc.path, buf->st_size); + local->newloc.path, buf->ia_size); } STACK_WIND (frame, trash_common_rename_cbk, @@ -500,9 +492,7 @@ trash_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, trash_elim_pattern_t *trav = NULL; trash_private_t *priv = NULL; trash_local_t *local = NULL; - struct tm *tm = NULL; - char timestr[256] = {0,}; - time_t utime = 0; + char timestr[64] = {0,}; int32_t match = 0; priv = this->private; @@ -529,10 +519,10 @@ trash_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, return 0; } - local = CALLOC (1, sizeof (trash_local_t)); + local = mem_get0 (this->local_pool); if (!local) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); - TRASH_STACK_UNWIND (frame, -1, ENOMEM, + TRASH_STACK_UNWIND (rename, frame, -1, ENOMEM, NULL, NULL, NULL, NULL, NULL); return 0; } @@ -549,9 +539,8 @@ trash_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, { /* append timestamp to file name */ /* TODO: can we make it optional? */ - utime = time (NULL); - tm = localtime (&utime); - strftime (timestr, 256, ".%Y-%m-%d-%H%M%S", tm); + gf_time_ftm (timestr, sizeof timestr, time (NULL), + gf_timefmt_F_HMS); strcat (local->newpath, timestr); } @@ -570,9 +559,7 @@ trash_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) trash_elim_pattern_t *trav = NULL; trash_private_t *priv = NULL; trash_local_t *local = NULL; - struct tm *tm = NULL; - char timestr[256] = {0,}; - time_t utime = 0; + char timestr[64] = {0,}; int32_t match = 0; priv = this->private; @@ -605,10 +592,10 @@ trash_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) return 0; } - local = CALLOC (1, sizeof (trash_local_t)); + local = mem_get0 (this->local_pool); if (!local) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); - TRASH_STACK_UNWIND (frame, -1, ENOMEM, NULL, NULL); + TRASH_STACK_UNWIND (unlink, frame, -1, ENOMEM, NULL, NULL); return 0; } frame->local = local; @@ -621,9 +608,8 @@ trash_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) { /* append timestamp to file name */ /* TODO: can we make it optional? */ - utime = time (NULL); - tm = localtime (&utime); - strftime (timestr, 256, ".%Y-%m-%d-%H%M%S", tm); + gf_time_fmt (timestr, sizeof timestr, time (NULL), + gf_timefmt_F_HMS); strcat (local->newpath, timestr); } @@ -639,7 +625,7 @@ trash_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) int32_t trash_truncate_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct stat *preparent, struct stat *postparent) + struct iatt *preparent, struct iatt *postparent) { /* use this Function when a failure occurs, and delete the newly created file. */ @@ -664,7 +650,7 @@ int32_t trash_truncate_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iovec *vector, int32_t count, - struct stat *stbuf, struct iobref *iobuf) + struct iatt *stbuf, struct iobref *iobuf) { trash_local_t *local = NULL; @@ -681,10 +667,10 @@ trash_truncate_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } - local->fsize = stbuf->st_size; + local->fsize = stbuf->ia_size; STACK_WIND (frame, trash_truncate_writev_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->writev, - local->newfd, vector, count, local->cur_offset, iobuf); + local->newfd, vector, count, local->cur_offset, 0, iobuf); out: return 0; @@ -694,7 +680,7 @@ out: int32_t trash_truncate_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct stat *prebuf, struct stat *postbuf) + struct iatt *prebuf, struct iatt *postbuf) { trash_local_t *local = NULL; @@ -717,7 +703,7 @@ trash_truncate_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND (frame, trash_truncate_readv_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readv, local->fd, (size_t)GF_BLOCK_READV_SIZE, - local->cur_offset); + local->cur_offset, 0); goto out; } @@ -757,7 +743,7 @@ trash_truncate_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND (frame, trash_truncate_readv_cbk, FIRST_CHILD (this), FIRST_CHILD (this)->fops->readv, - local->fd, (size_t)GF_BLOCK_READV_SIZE, local->cur_offset); + local->fd, (size_t)GF_BLOCK_READV_SIZE, local->cur_offset, 0); out: return 0; @@ -767,8 +753,8 @@ out: int32_t trash_truncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, fd_t *fd, - inode_t *inode, struct stat *buf, - struct stat *preparent, struct stat *postparent) + inode_t *inode, struct iatt *buf, + struct iatt *preparent, struct iatt *postparent) { trash_local_t *local = NULL; char *tmp_str = NULL; @@ -781,13 +767,13 @@ trash_truncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if ((op_ret == -1) && (op_errno == ENOENT)) { //Creating the directory structure here. - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } dir_name = dirname (tmp_str); - tmp_path = strdup (dir_name); + tmp_path = gf_strdup (dir_name); if (!tmp_path) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -797,8 +783,8 @@ trash_truncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND_COOKIE (frame, trash_truncate_mkdir_cbk, tmp_path, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mkdir, - &tmp_loc, 0755); - free (tmp_str); + &tmp_loc, 0755, NULL); + GF_FREE (tmp_str); goto out; } @@ -830,8 +816,8 @@ out: int32_t trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, - struct stat *stbuf, struct stat *preparent, - struct stat *postparent) + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent) { trash_local_t *local = NULL; char *tmp_str = NULL; @@ -846,13 +832,14 @@ trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, local = frame->local; if (!local) - return 0; + goto out; loop_count = local->loop_count; - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); + goto out; } if ((op_ret == -1) && (op_errno == ENOENT)) { @@ -874,7 +861,7 @@ trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND_COOKIE (frame, trash_truncate_mkdir_cbk, tmp_path, this->children->xlator, this->children->xlator->fops->mkdir, - &tmp_loc, 0755); + &tmp_loc, 0755, NULL); goto out; } @@ -883,12 +870,14 @@ trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, dir_name = dirname (tmp_str); if (strcmp ((char*)cookie, dir_name) == 0) { flags = O_CREAT|O_EXCL|O_WRONLY; + ia_prot_t prot = {0, }; //Call create again once directory structure is created. STACK_WIND (frame, trash_truncate_create_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->create, - &local->newloc, flags, local->loc.inode->st_mode, - local->newfd); + &local->newloc, flags, + st_mode_from_ia (prot, local->loc.inode->ia_type), + local->newfd, NULL); goto out; } } @@ -898,6 +887,7 @@ trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, loop_count = ++local->loop_count; } UNLOCK (&frame->lock); + tmp_dirname = strchr (tmp_str, '/'); while (tmp_dirname) { count = tmp_dirname - tmp_str; @@ -918,11 +908,11 @@ trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND_COOKIE (frame, trash_truncate_mkdir_cbk, tmp_path, this->children->xlator, this->children->xlator->fops->mkdir, - &tmp_loc, 0755); + &tmp_loc, 0755, NULL); out: - free (cookie); /* strdup (dir_name) was sent here :) */ - free (tmp_str); + GF_FREE (cookie); /* strdup (dir_name) was sent here :) */ + GF_FREE (tmp_str); return 0; } @@ -930,14 +920,12 @@ out: int32_t trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) + int32_t op_ret, int32_t op_errno, struct iatt *buf) { trash_private_t *priv = NULL; trash_local_t *local = NULL; - struct tm *tm = NULL; - char timestr[256] = {0,}; + char timestr[64] = {0,}; char loc_newname[PATH_MAX] = {0,}; - time_t utime = 0; int32_t flags = 0; priv = this->private; @@ -948,13 +936,13 @@ trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, "fstat on the file failed: %s", strerror (op_errno)); - TRASH_STACK_UNWIND (frame, op_ret, op_errno, buf); + TRASH_STACK_UNWIND (truncate, frame, op_ret, op_errno, buf, NULL); return 0; } - if ((buf->st_size == 0) || (buf->st_size > priv->max_trash_file_size)) { + if ((buf->ia_size == 0) || (buf->ia_size > priv->max_trash_file_size)) { // If the file is too big, just unlink it. - if (buf->st_size > priv->max_trash_file_size) + if (buf->ia_size > priv->max_trash_file_size) gf_log (this->name, GF_LOG_DEBUG, "%s: file too big, " "not moving to trash", local->loc.path); @@ -969,18 +957,16 @@ trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, strcat (local->newpath, local->loc.path); { - utime = time (NULL); - tm = localtime (&utime); - strftime (timestr, 256, ".%Y-%m-%d-%H%M%S", tm); + gf_time_fmt (timestr, sizeof timestr, time (NULL), + gf_timefmt_F_HMS); strcat (local->newpath, timestr); } strcpy (loc_newname,local->loc.name); strcat (loc_newname,timestr); - local->newloc.name = strdup (loc_newname); - local->newloc.path = strdup (local->newpath); + local->newloc.name = gf_strdup (loc_newname); + local->newloc.path = gf_strdup (local->newpath); local->newloc.inode = inode_new (local->loc.inode->table); - local->newloc.ino = local->newloc.inode->ino; local->newfd = fd_create (local->newloc.inode, frame->root->pid); flags = O_CREAT|O_EXCL|O_WRONLY; @@ -988,8 +974,9 @@ trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND (frame, trash_truncate_create_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->create, - &local->newloc, flags, local->loc.inode->st_mode, - local->newfd); + &local->newloc, flags, + st_mode_from_ia (buf->ia_prot, local->loc.inode->ia_type), + local->newfd, NULL); return 0; } @@ -1033,10 +1020,10 @@ trash_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, LOCK_INIT (&frame->lock); - local = CALLOC (1, sizeof (trash_local_t)); + local = mem_get0 (this->local_pool); if (!local) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); - TRASH_STACK_UNWIND (frame, -1, ENOMEM, NULL); + TRASH_STACK_UNWIND (truncate, frame, -1, ENOMEM, NULL, NULL); return 0; } @@ -1057,7 +1044,7 @@ out: int32_t trash_ftruncate_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct stat *preparent, struct stat *postparent) + struct iatt *preparent, struct iatt *postparent) { trash_local_t *local = NULL; @@ -1080,7 +1067,7 @@ trash_ftruncate_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t trash_ftruncate_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct stat *prebuf, struct stat *postbuf) + struct iatt *prebuf, struct iatt *postbuf) { trash_local_t *local = NULL; @@ -1098,7 +1085,7 @@ trash_ftruncate_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND (frame, trash_ftruncate_readv_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readv, local->fd, (size_t)GF_BLOCK_READV_SIZE, - local->cur_offset); + local->cur_offset, 0); return 0; } @@ -1114,12 +1101,12 @@ int32_t trash_ftruncate_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iovec *vector, int32_t count, - struct stat *stbuf, struct iobref *iobuf) + struct iatt *stbuf, struct iobref *iobuf) { trash_local_t *local = NULL; local = frame->local; - local->fsize = stbuf->st_size; + local->fsize = stbuf->ia_size; if (op_ret == -1) { STACK_WIND (frame, trash_ftruncate_unlink_cbk, @@ -1130,7 +1117,7 @@ trash_ftruncate_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND (frame, trash_ftruncate_writev_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->writev, - local->newfd, vector, count, local->cur_offset, NULL); + local->newfd, vector, count, local->cur_offset, 0, NULL); return 0; } @@ -1139,8 +1126,8 @@ trash_ftruncate_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t trash_ftruncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, fd_t *fd, - inode_t *inode, struct stat *buf, - struct stat *preparent, struct stat *postparent) + inode_t *inode, struct iatt *buf, + struct iatt *preparent, struct iatt *postparent) { trash_local_t *local = NULL; char *tmp_str = NULL; @@ -1151,13 +1138,13 @@ trash_ftruncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, local = frame->local; if ((op_ret == -1) && (op_errno == ENOENT)) { - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } dir_name = dirname (tmp_str); - tmp_path = strdup (dir_name); + tmp_path = gf_strdup (dir_name); if (!tmp_path) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -1167,8 +1154,8 @@ trash_ftruncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND_COOKIE (frame, trash_truncate_mkdir_cbk, tmp_path, FIRST_CHILD(this), FIRST_CHILD(this)->fops->mkdir, - &tmp_loc, 0755); - free (tmp_str); + &tmp_loc, 0755, NULL); + GF_FREE (tmp_str); return 0; } @@ -1182,7 +1169,7 @@ trash_ftruncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND (frame, trash_ftruncate_readv_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->readv, local->fd, - (size_t)GF_BLOCK_READV_SIZE, local->cur_offset); + (size_t)GF_BLOCK_READV_SIZE, local->cur_offset, 0); return 0; } @@ -1191,8 +1178,8 @@ trash_ftruncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t trash_ftruncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, - struct stat *stbuf, struct stat *preparent, - struct stat *postparent) + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent) { trash_local_t *local = NULL; char *tmp_str = NULL; @@ -1207,13 +1194,14 @@ trash_ftruncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, local = frame->local; if (!local) - return 0; + goto out; loop_count = local->loop_count; - tmp_str = strdup (local->newpath); + tmp_str = gf_strdup (local->newpath); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); + goto out; } if ((op_ret == -1) && (op_errno == ENOENT)) { @@ -1235,7 +1223,7 @@ trash_ftruncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND_COOKIE (frame, trash_ftruncate_mkdir_cbk, tmp_path, this->children->xlator, this->children->xlator->fops->mkdir, - &tmp_loc, 0755); + &tmp_loc, 0755, NULL); goto out; } @@ -1243,6 +1231,7 @@ trash_ftruncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (op_ret == 0) { dir_name = dirname (tmp_str); if (strcmp ((char*)cookie, dir_name) == 0) { + ia_prot_t prot = {0, }; flags = O_CREAT|O_EXCL|O_WRONLY; //Call create again once directory structure is created. @@ -1250,7 +1239,8 @@ trash_ftruncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, FIRST_CHILD(this), FIRST_CHILD(this)->fops->create, &local->newloc, flags, - local->loc.inode->st_mode, local->newfd); + st_mode_from_ia (prot, local->loc.inode->ia_type), + local->newfd, NULL); goto out; } } @@ -1280,11 +1270,11 @@ trash_ftruncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND_COOKIE (frame, trash_ftruncate_mkdir_cbk, tmp_path, this->children->xlator, this->children->xlator->fops->mkdir, - &tmp_loc, 0755); + &tmp_loc, 0755, NULL); out: - free (cookie); /* strdup (dir_name) was sent here :) */ - free (tmp_str); + GF_FREE (cookie); /* strdup (dir_name) was sent here :) */ + GF_FREE (tmp_str); return 0; } @@ -1292,7 +1282,7 @@ out: int32_t trash_ftruncate_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct stat *buf) + int32_t op_ret, int32_t op_errno, struct iatt *buf) { trash_private_t *priv = NULL; trash_local_t *local = NULL; @@ -1304,10 +1294,10 @@ trash_ftruncate_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, gf_log (this->name, GF_LOG_DEBUG, "%s: %s",local->newloc.path, strerror(op_errno)); - TRASH_STACK_UNWIND (frame, -1, op_errno, buf, NULL); + TRASH_STACK_UNWIND (ftruncate, frame, -1, op_errno, buf, NULL); return 0; } - if ((buf->st_size == 0) || (buf->st_size > priv->max_trash_file_size)) + if ((buf->ia_size == 0) || (buf->ia_size > priv->max_trash_file_size)) { STACK_WIND (frame, trash_common_unwind_buf_cbk, this->children->xlator, @@ -1320,7 +1310,8 @@ trash_ftruncate_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, STACK_WIND (frame, trash_ftruncate_create_cbk, FIRST_CHILD(this), FIRST_CHILD(this)->fops->create, &local->newloc, ( O_CREAT | O_EXCL | O_WRONLY ), - local->loc.inode->st_mode, local->newfd); + st_mode_from_ia (buf->ia_prot, local->loc.inode->ia_type), + local->newfd, NULL); return 0; } @@ -1332,11 +1323,9 @@ trash_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) trash_private_t *priv = NULL; trash_local_t *local = NULL; dentry_t *dir_entry = NULL; - struct tm *tm = NULL; char *pathbuf = NULL; inode_t *newinode = NULL; - time_t utime = 0; - char timestr[256]; + char timestr[64]; int32_t retval = 0; int32_t match = 0; @@ -1368,17 +1357,14 @@ trash_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) return 0; } - local = CALLOC (1, sizeof (trash_local_t)); + local = mem_get0 (this->local_pool); if (!local) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); - TRASH_STACK_UNWIND (frame, -1, ENOMEM, NULL, NULL); + TRASH_STACK_UNWIND (ftruncate, frame, -1, ENOMEM, NULL, NULL); return 0; } - utime = time (NULL); - tm = localtime (&utime); - strftime (timestr, 256, ".%Y-%m-%d-%H%M%S", tm); - + gf_time_fmt (timestr, sizeof timestr, time (NULL), gf_timefmt_F_HMS); strcpy (local->newpath, priv->trash_dir); strcat (local->newpath, pathbuf); strcat (local->newpath, timestr); @@ -1392,7 +1378,6 @@ trash_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) local->newloc.path = local->newpath; local->loc.inode = inode_ref (fd->inode); - local->loc.ino = fd->inode->ino; local->loc.path = pathbuf; local->fop_offset = offset; @@ -1410,7 +1395,6 @@ trash_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) int32_t init (xlator_t *this) { - int32_t ret = 0; data_t *data = NULL; trash_private_t *_priv = NULL; trash_elim_pattern_t *trav = NULL; @@ -1418,6 +1402,7 @@ init (xlator_t *this) char *strtokptr = NULL; char *component = NULL; char trash_dir[PATH_MAX] = {0,}; + uint64_t max_trash_file_size64 = 0; /* Create .trashcan directory in init */ if (!this->children || this->children->next) { @@ -1431,7 +1416,7 @@ init (xlator_t *this) "dangling volume. check volfile "); } - _priv = CALLOC (1, sizeof (*_priv)); + _priv = GF_CALLOC (1, sizeof (*_priv), gf_trash_mt_trash_private_t); if (!_priv) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); return -1; @@ -1439,20 +1424,20 @@ init (xlator_t *this) data = dict_get (this->options, "trash-dir"); if (!data) { - gf_log (this->name, GF_LOG_NORMAL, + gf_log (this->name, GF_LOG_INFO, "no option specified for 'trash-dir', " "using \"/.trashcan/\""); - _priv->trash_dir = strdup ("/.trashcan"); + _priv->trash_dir = gf_strdup ("/.trashcan"); } else { /* Need a path with '/' as the first char, if not given, append it */ if (data->data[0] == '/') { - _priv->trash_dir = strdup (data->data); + _priv->trash_dir = gf_strdup (data->data); } else { /* TODO: Make sure there is no ".." in the path */ strcpy (trash_dir, "/"); strcat (trash_dir, data->data); - _priv->trash_dir = strdup (trash_dir); + _priv->trash_dir = gf_strdup (trash_dir); } } @@ -1461,7 +1446,7 @@ init (xlator_t *this) gf_log (this->name, GF_LOG_TRACE, "no option specified for 'eliminate', using NULL"); } else { - tmp_str = strdup (data->data); + tmp_str = gf_strdup (data->data); if (!tmp_str) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); } @@ -1469,9 +1454,11 @@ init (xlator_t *this) /* Match Filename to option specified in eliminate. */ component = strtok_r (tmp_str, "|", &strtokptr); while (component) { - trav = CALLOC (1, sizeof (*trav)); + trav = GF_CALLOC (1, sizeof (*trav), + gf_trash_mt_trash_elim_pattern_t); if (!trav) { gf_log (this->name, GF_LOG_DEBUG, "out of memory"); + break; } trav->pattern = component; trav->next = _priv->eliminate; @@ -1490,18 +1477,27 @@ init (xlator_t *this) GF_DEFAULT_MAX_FILE_SIZE / GF_UNIT_MB); _priv->max_trash_file_size = GF_DEFAULT_MAX_FILE_SIZE; } else { - ret = gf_string2bytesize (data->data, - &_priv->max_trash_file_size); - if( _priv->max_trash_file_size > GF_ALLOWED_MAX_FILE_SIZE ) { + (void)gf_string2bytesize (data->data, + &max_trash_file_size64); + if( max_trash_file_size64 > GF_ALLOWED_MAX_FILE_SIZE ) { gf_log (this->name, GF_LOG_DEBUG, "Size specified for max-size(in MB) is too " "large so using 1GB as max-size (NOT IDEAL)"); _priv->max_trash_file_size = GF_ALLOWED_MAX_FILE_SIZE; - } + } else + _priv->max_trash_file_size = max_trash_file_size64; gf_log (this->name, GF_LOG_DEBUG, "%"GF_PRI_SIZET" max-size", _priv->max_trash_file_size); } + this->local_pool = mem_pool_new (trash_local_t, 64); + if (!this->local_pool) { + gf_log (this->name, GF_LOG_ERROR, + "failed to create local_t's memory pool"); + return -1; + } + + this->private = (void *)_priv; return 0; } @@ -1512,8 +1508,7 @@ fini (xlator_t *this) trash_private_t *priv = NULL; priv = this->private; - if (priv) - FREE (priv); + GF_FREE (priv); return; } @@ -1525,9 +1520,6 @@ struct xlator_fops fops = { .ftruncate = trash_ftruncate, }; -struct xlator_mops mops = { -}; - struct xlator_cbks cbks = { }; |
