summaryrefslogtreecommitdiffstats
path: root/xlators/features/trash
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/features/trash')
-rw-r--r--xlators/features/trash/src/Makefile.am7
-rw-r--r--xlators/features/trash/src/trash-mem-types.h23
-rw-r--r--xlators/features/trash/src/trash.c178
-rw-r--r--xlators/features/trash/src/trash.h30
4 files changed, 100 insertions, 138 deletions
diff --git a/xlators/features/trash/src/Makefile.am b/xlators/features/trash/src/Makefile.am
index 4671d06d3..5251eb082 100644
--- a/xlators/features/trash/src/Makefile.am
+++ b/xlators/features/trash/src/Makefile.am
@@ -1,15 +1,16 @@
xlator_LTLIBRARIES = trash.la
xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/testing/features
-trash_la_LDFLAGS = -module -avoidversion
+trash_la_LDFLAGS = -module -avoid-version
trash_la_SOURCES = trash.c
trash_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
noinst_HEADERS = trash.h trash-mem-types.h
-AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\
- -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS)
+AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src
+
+AM_CFLAGS = -Wall $(GF_CFLAGS)
CLEANFILES =
diff --git a/xlators/features/trash/src/trash-mem-types.h b/xlators/features/trash/src/trash-mem-types.h
index 48613d1e8..0e6ef572f 100644
--- a/xlators/features/trash/src/trash-mem-types.h
+++ b/xlators/features/trash/src/trash-mem-types.h
@@ -1,30 +1,19 @@
/*
- Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com>
+ Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.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/>.
+ 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 __TRASH_MEM_TYPES_H__
#define __TRASH_MEM_TYPES_H__
#include "mem-types.h"
enum gf_trash_mem_types_ {
- gf_trash_mt_trash_local_t = gf_common_mt_end + 1,
- gf_trash_mt_trash_private_t,
+ gf_trash_mt_trash_private_t = gf_common_mt_end + 1,
gf_trash_mt_char,
gf_trash_mt_trash_elim_pattern_t,
gf_trash_mt_end
diff --git a/xlators/features/trash/src/trash.c b/xlators/features/trash/src/trash.c
index c51d55a02..addeb66a0 100644
--- a/xlators/features/trash/src/trash.c
+++ b/xlators/features/trash/src/trash.c
@@ -1,22 +1,12 @@
/*
- 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"
@@ -63,7 +53,7 @@ trash_local_wipe (trash_local_t *local)
if (local->newfd)
fd_unref (local->newfd);
- GF_FREE (local);
+ mem_put (local);
out:
return;
}
@@ -73,7 +63,7 @@ trash_common_unwind_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
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;
}
@@ -96,7 +86,8 @@ trash_unlink_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
local = frame->local;
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,14 +148,15 @@ 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:
GF_FREE (cookie);
@@ -185,13 +178,11 @@ trash_unlink_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
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)) {
@@ -211,7 +202,7 @@ 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);
GF_FREE (tmp_str);
@@ -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;
@@ -256,7 +247,7 @@ trash_common_unwind_buf_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
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;
}
@@ -266,7 +257,7 @@ trash_common_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
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;
}
@@ -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;
@@ -356,7 +347,7 @@ 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);
GF_FREE (tmp_str);
return 0;
@@ -399,6 +390,7 @@ trash_rename_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
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;
@@ -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,11 +519,10 @@ trash_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
return 0;
}
- local = GF_CALLOC (1, sizeof (trash_local_t),
- gf_trash_mt_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;
}
@@ -550,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);
}
@@ -571,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;
@@ -606,11 +592,10 @@ trash_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc)
return 0;
}
- local = GF_CALLOC (1, sizeof (trash_local_t),
- gf_trash_mt_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;
@@ -623,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);
}
@@ -686,7 +670,7 @@ trash_truncate_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
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;
@@ -719,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;
}
@@ -759,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;
@@ -799,7 +783,7 @@ 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);
+ &tmp_loc, 0755, NULL);
GF_FREE (tmp_str);
goto out;
}
@@ -848,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 = 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)) {
@@ -876,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;
}
@@ -892,7 +877,7 @@ trash_truncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
FIRST_CHILD(this), FIRST_CHILD(this)->fops->create,
&local->newloc, flags,
st_mode_from_ia (prot, local->loc.inode->ia_type),
- local->newfd);
+ local->newfd, NULL);
goto out;
}
}
@@ -902,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;
@@ -922,7 +908,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);
out:
GF_FREE (cookie); /* strdup (dir_name) was sent here :) */
@@ -938,10 +924,8 @@ trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
{
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;
@@ -952,7 +936,7 @@ 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;
}
@@ -973,9 +957,8 @@ 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);
@@ -984,7 +967,6 @@ trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
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;
@@ -994,7 +976,7 @@ trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
FIRST_CHILD(this)->fops->create,
&local->newloc, flags,
st_mode_from_ia (buf->ia_prot, local->loc.inode->ia_type),
- local->newfd);
+ local->newfd, NULL);
return 0;
}
@@ -1038,11 +1020,10 @@ trash_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc,
LOCK_INIT (&frame->lock);
- local = GF_CALLOC (1, sizeof (trash_local_t),
- gf_trash_mt_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;
}
@@ -1104,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;
}
@@ -1136,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;
}
@@ -1173,7 +1154,7 @@ 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);
+ &tmp_loc, 0755, NULL);
GF_FREE (tmp_str);
return 0;
}
@@ -1188,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;
}
@@ -1213,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 = 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)) {
@@ -1241,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;
}
@@ -1258,7 +1240,7 @@ trash_ftruncate_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
FIRST_CHILD(this)->fops->create,
&local->newloc, flags,
st_mode_from_ia (prot, local->loc.inode->ia_type),
- local->newfd);
+ local->newfd, NULL);
goto out;
}
}
@@ -1288,7 +1270,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);
out:
GF_FREE (cookie); /* strdup (dir_name) was sent here :) */
@@ -1312,7 +1294,7 @@ 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->ia_size == 0) || (buf->ia_size > priv->max_trash_file_size))
@@ -1329,7 +1311,7 @@ trash_ftruncate_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
FIRST_CHILD(this)->fops->create, &local->newloc,
( O_CREAT | O_EXCL | O_WRONLY ),
st_mode_from_ia (buf->ia_prot, local->loc.inode->ia_type),
- local->newfd);
+ local->newfd, NULL);
return 0;
}
@@ -1341,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;
@@ -1377,18 +1357,14 @@ trash_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset)
return 0;
}
- local = GF_CALLOC (1, sizeof (trash_local_t),
- gf_trash_mt_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);
@@ -1402,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;
@@ -1420,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;
@@ -1450,7 +1424,7 @@ 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 = gf_strdup ("/.trashcan");
@@ -1484,6 +1458,7 @@ init (xlator_t *this)
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;
@@ -1502,7 +1477,7 @@ 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,
+ (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,
@@ -1515,6 +1490,14 @@ init (xlator_t *this)
_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;
}
@@ -1525,8 +1508,7 @@ fini (xlator_t *this)
trash_private_t *priv = NULL;
priv = this->private;
- if (priv)
- GF_FREE (priv);
+ GF_FREE (priv);
return;
}
diff --git a/xlators/features/trash/src/trash.h b/xlators/features/trash/src/trash.h
index e1a1c314d..9a7c03361 100644
--- a/xlators/features/trash/src/trash.h
+++ b/xlators/features/trash/src/trash.h
@@ -1,22 +1,12 @@
/*
- Copyright (c) 2006-2009 Gluster, Inc. <http://www.gluster.com>
- This file is part of GlusterFS.
+ Copyright (c) 2006-2012 Red Hat, Inc. <http://www.redhat.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/>.
+ 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 __TRASH_H__
#define __TRASH_H__
@@ -59,8 +49,8 @@ struct trash_struct {
char origpath[PATH_MAX];
char newpath[PATH_MAX];
int32_t loop_count;
- struct stat preparent;
- struct stat postparent;
+ struct iatt preparent;
+ struct iatt postparent;
};
typedef struct trash_struct trash_local_t;
@@ -77,11 +67,11 @@ struct trash_priv {
};
typedef struct trash_priv trash_private_t;
-#define TRASH_STACK_UNWIND(frame, params ...) do { \
+#define TRASH_STACK_UNWIND(op, frame, params ...) do { \
trash_local_t *__local = NULL; \
__local = frame->local; \
frame->local = NULL; \
- STACK_UNWIND (frame, params); \
+ STACK_UNWIND_STRICT (op, frame, params); \
trash_local_wipe (__local); \
} while (0)