diff options
author | Basavanagowda Kanur <gowda@gluster.com> | 2009-04-08 04:24:00 +0530 |
---|---|---|
committer | Anand V. Avati <avati@amp.gluster.com> | 2009-04-08 15:04:02 +0530 |
commit | abf35ff6c7a2cc94d9e1e738fb76f711bd2abc16 (patch) | |
tree | ca60920681094b2fa10ee04570df174a17afe1dc | |
parent | 8fea700263bd356e6ecacd3dabc9a9c00043a804 (diff) |
link() & rename() on storage/bdb will always return EXDEV.
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
-rw-r--r-- | xlators/storage/bdb/src/bctx.c | 73 | ||||
-rw-r--r-- | xlators/storage/bdb/src/bdb.c | 274 | ||||
-rw-r--r-- | xlators/storage/bdb/src/bdb.h | 8 |
3 files changed, 2 insertions, 353 deletions
diff --git a/xlators/storage/bdb/src/bctx.c b/xlators/storage/bdb/src/bctx.c index 7fc47cd7b..fce78e95f 100644 --- a/xlators/storage/bdb/src/bctx.c +++ b/xlators/storage/bdb/src/bctx.c @@ -324,76 +324,3 @@ out: free (pathname); return bctx; } - -inline int32_t -bdb_db_rename (bctx_table_t *table, - const char *oldpath, - const char *newpath) -{ - DB_ENV *dbenv = NULL; - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO ("bctx", table, out); - GF_VALIDATE_OR_GOTO ("bctx", oldpath, out); - GF_VALIDATE_OR_GOTO ("bctx", newpath, out); - - dbenv = table->dbenv; - GF_VALIDATE_OR_GOTO ("bctx", dbenv, out); - - LOCK (&table->lock); - { - ret = dbenv->dbrename (dbenv, NULL, oldpath, NULL, newpath, 0); - - if (ret != 0) { - gf_log ("bctx", GF_LOG_ERROR, - "failed to rename %s to %s: %s", - oldpath, newpath, db_strerror (ret)); - } else { - gf_log ("bctx", GF_LOG_DEBUG, - "successfully renamed %s to %s: %s", - oldpath, newpath, db_strerror (ret)); - } - } - UNLOCK (&table->lock); - -out: - return ret; -} - -bctx_t * -bctx_rename (bctx_t *bctx, - const char *db_newpath) -{ - bctx_table_t *table = NULL; - int32_t ret = -1; - - table = bctx->table; - - LOCK (&table->lock); - { - __unhash_bctx (bctx); - list_del_init (&bctx->list); - if (bctx->dbp) { - ret = bctx->dbp->close (bctx->dbp, 0); - if (ret != 0) { - gf_log ("bdb-ll", GF_LOG_ERROR, - "failed to close db for " - "directory %s (%s)", - bctx->directory, db_strerror (ret)); - } - bctx->dbp = NULL; - } - } - UNLOCK (&table->lock); - - ret = bdb_db_rename (table, bctx->db_path, db_newpath); - - if (ret != 0) { - gf_log ("bctx", GF_LOG_ERROR, - "bdb_db_rename failed for directory %s", - bctx->directory); - bctx = NULL; - } - - return bctx; -} diff --git a/xlators/storage/bdb/src/bdb.c b/xlators/storage/bdb/src/bdb.c index 6355855ce..a3c6c44ea 100644 --- a/xlators/storage/bdb/src/bdb.c +++ b/xlators/storage/bdb/src/bdb.c @@ -228,278 +228,8 @@ bdb_rename (call_frame_t *frame, loc_t *oldloc, loc_t *newloc) { - struct bdb_private *private = NULL; - bctx_table_t *table = NULL; - bctx_t *oldbctx = NULL; - bctx_t *newbctx = NULL; - bctx_t *tmpbctx = NULL; - int32_t op_ret = -1; - int32_t op_errno = ENOENT; - int32_t read_size = 0; - struct stat stbuf = {0,}; - struct stat old_stbuf = {0,}; - DB_TXN *txnid = NULL; - char *real_newpath = NULL; - char *real_oldpath = NULL; - char *oldkey = NULL; - char *newkey = NULL; - - /* pointer to temporary buffer, where the contents of a file are read, - * if file being renamed is a regular file */ - char *buf = NULL; - char *real_db_newpath = NULL; - char *tmp_db_newpath = NULL; - - GF_VALIDATE_OR_GOTO ("bdb", frame, out); - GF_VALIDATE_OR_GOTO ("bdb", this, out); - GF_VALIDATE_OR_GOTO (this->name, newloc, out); - GF_VALIDATE_OR_GOTO (this->name, oldloc, out); - - private = this->private; - table = private->b_table; - - MAKE_REAL_PATH (real_oldpath, this, oldloc->path); - - if (S_ISREG (oldloc->inode->st_mode)) { - oldbctx = bctx_parent (B_TABLE(this), oldloc->path); - MAKE_REAL_PATH (real_newpath, this, newloc->path); - - op_ret = lstat (real_newpath, &stbuf); - - if ((op_ret == 0) && (S_ISDIR (stbuf.st_mode))) { - op_ret = -1; - op_errno = EISDIR; - goto out; - } - if (op_ret == 0) { - /* destination is a symlink */ - MAKE_KEY_FROM_PATH (oldkey, oldloc->path); - MAKE_KEY_FROM_PATH (newkey, newloc->path); - - op_ret = unlink (real_newpath); - op_errno = errno; - if (op_ret != 0) { - gf_log (this->name, - GF_LOG_ERROR, - "failed to unlink %s (%s)", - newloc->path, strerror (op_errno)); - goto out; - } - newbctx = bctx_parent (B_TABLE (this), newloc->path); - GF_VALIDATE_OR_GOTO (this->name, newbctx, out); - - op_ret = bdb_txn_begin (BDB_ENV(this), &txnid); - - if ((read_size = - bdb_db_get (oldbctx, txnid, oldkey, &buf, 0, 0)) < 0) { - bdb_txn_abort (txnid); - } else if ((op_ret = - bdb_db_del (oldbctx, txnid, oldkey)) != 0) { - bdb_txn_abort (txnid); - } else if ((op_ret = bdb_db_put (newbctx, txnid, - newkey, buf, - read_size, 0, 0)) != 0) { - bdb_txn_abort (txnid); - } else { - bdb_txn_commit (txnid); - } - - /* NOTE: bctx_unref always returns success, - * see description of bctx_unref for more details */ - bctx_unref (newbctx); - } else { - /* destination doesn't exist or a regular file */ - MAKE_KEY_FROM_PATH (oldkey, oldloc->path); - MAKE_KEY_FROM_PATH (newkey, newloc->path); - - newbctx = bctx_parent (B_TABLE (this), newloc->path); - GF_VALIDATE_OR_GOTO (this->name, newbctx, out); - - op_ret = bdb_txn_begin (BDB_ENV(this), &txnid); - - if ((read_size = bdb_db_get (oldbctx, txnid, - oldkey, &buf, - 0, 0)) < 0) { - bdb_txn_abort (txnid); - } else if ((op_ret = bdb_db_del (oldbctx, - txnid, oldkey)) != 0) { - bdb_txn_abort (txnid); - } else if ((op_ret = bdb_db_put (newbctx, txnid, - newkey, buf, - read_size, 0, 0)) != 0) { - bdb_txn_abort (txnid); - } else { - bdb_txn_commit (txnid); - } - - /* NOTE: bctx_unref always returns success, - * see description of bctx_unref for more details */ - bctx_unref (newbctx); - } - /* NOTE: bctx_unref always returns success, - * see description of bctx_unref for more details */ - bctx_unref (oldbctx); - } else if (S_ISLNK (oldloc->inode->st_mode)) { - MAKE_REAL_PATH (real_newpath, this, newloc->path); - op_ret = lstat (real_newpath, &stbuf); - if ((op_ret == 0) && (S_ISDIR (stbuf.st_mode))) { - op_ret = -1; - op_errno = EISDIR; - goto out; - } - - if (op_ret == 0){ - /* destination exists and is also a symlink */ - MAKE_REAL_PATH (real_oldpath, this, oldloc->path); - op_ret = rename (real_oldpath, real_newpath); - op_errno = errno; - - if (op_ret != 0) { - gf_log (this->name, - GF_LOG_ERROR, - "failed to rename symlink %s (%s)", - oldloc->path, strerror (op_errno)); - } - goto out; - } - - /* destination doesn't exist */ - MAKE_REAL_PATH (real_oldpath, this, oldloc->path); - MAKE_KEY_FROM_PATH (newkey, newloc->path); - newbctx = bctx_parent (B_TABLE (this), newloc->path); - GF_VALIDATE_OR_GOTO (this->name, newbctx, out); - - op_ret = bdb_db_del (newbctx, txnid, newkey); - if (op_ret != 0) { - /* no problem */ - } - op_ret = rename (real_oldpath, real_newpath); - op_errno = errno; - if (op_ret != 0) { - gf_log (this->name, - GF_LOG_ERROR, - "failed to rename %s to %s (%s)", - oldloc->path, newloc->path, strerror (op_errno)); - goto out; - } - /* NOTE: bctx_unref always returns success, - * see description of bctx_unref for more details */ - bctx_unref (newbctx); - } else if (S_ISDIR (oldloc->inode->st_mode) && - (old_stbuf.st_nlink == 2)) { - - tmp_db_newpath = tempnam (private->export_path, "rename_temp"); - GF_VALIDATE_OR_GOTO (this->name, tmp_db_newpath, out); - - MAKE_REAL_PATH (real_newpath, this, newloc->path); - - MAKE_REAL_PATH_TO_STORAGE_DB (real_db_newpath, this, newloc->path); - - oldbctx = bctx_lookup (B_TABLE(this), oldloc->path); - op_ret = -1; - op_errno = EINVAL; - GF_VALIDATE_OR_GOTO (this->name, oldbctx, out); - - op_ret = lstat (real_newpath, &stbuf); - if ((op_ret == 0) && - S_ISDIR (stbuf.st_mode) && - is_dir_empty (this, newloc)) { - - tmpbctx = bctx_rename (oldbctx, tmp_db_newpath); - op_ret = -1; - op_errno = ENOENT; - GF_VALIDATE_OR_GOTO (this->name, tmpbctx, out); - - op_ret = rename (real_oldpath, real_newpath); - op_errno = errno; - if (op_ret != 0) { - gf_log (this->name, - GF_LOG_ERROR, - "rename directory %s to %s failed: %s", - oldloc->path, newloc->path, - strerror (errno)); - op_ret = bdb_db_rename (table, - tmp_db_newpath, - oldbctx->db_path); - if (op_ret != 0) { - gf_log (this->name, - GF_LOG_ERROR, - "renaming temp database back to old db failed" - " for directory %s", oldloc->path); - goto out; - } else { - /* this is a error case, set op_errno & op_ret */ - op_ret = -1; - op_errno = ENOENT; /* TODO: errno */ - } - } - op_ret = bdb_db_rename (table, tmp_db_newpath, real_db_newpath); - if (op_ret != 0) { - gf_log (this->name, - GF_LOG_ERROR, - "renaming temp database to new db failed" - " for directory %s", oldloc->path); - goto out; - } - } else if ((op_ret != 0) && (errno == ENOENT)) { - tmp_db_newpath = tempnam (private->export_path, "rename_temp"); - GF_VALIDATE_OR_GOTO (this->name, tmp_db_newpath, out); - - tmpbctx = bctx_rename (oldbctx, tmp_db_newpath); - op_ret = -1; - op_errno = ENOENT; - GF_VALIDATE_OR_GOTO (this->name, tmpbctx, out); - - op_ret = rename (real_oldpath, real_newpath); - op_errno = errno; - if (op_ret != 0) { - gf_log (this->name, - GF_LOG_ERROR, - "rename directory %s to %s failed: %s", - oldloc->path, newloc->path, - strerror (errno)); - op_ret = bdb_db_rename (table, - tmp_db_newpath, - oldbctx->db_path); - if (op_ret != 0) { - gf_log (this->name, - GF_LOG_ERROR, - "renaming temp database back to old db failed" - " for directory %s", oldloc->path); - goto out; - } else { - /* this is a error case, set op_errno & op_ret */ - op_ret = -1; - op_errno = ENOENT; /* TODO: errno */ - } - } else { - op_ret = bdb_db_rename (table, - tmp_db_newpath, - real_db_newpath); - if (op_ret != 0) { - gf_log (this->name, - GF_LOG_ERROR, - "renaming temp database to new db failed" - " for directory %s", oldloc->path); - goto out; - } else { - /* this is a error case, set op_errno & op_ret */ - op_ret = -1; - op_errno = ENOENT; /* TODO: errno */ - } - } - } - } else { - gf_log (this->name, - GF_LOG_CRITICAL, - "rename called on non-existent file type"); - op_ret = -1; - op_errno = EPERM; - } - -out: frame->root->rsp_refs = NULL; - STACK_UNWIND (frame, op_ret, op_errno, &stbuf); + STACK_UNWIND (frame, -1, EXDEV, NULL); return 0; } @@ -510,7 +240,7 @@ bdb_link (call_frame_t *frame, loc_t *newloc) { frame->root->rsp_refs = NULL; - STACK_UNWIND (frame, -1, EPERM, NULL, NULL); + STACK_UNWIND (frame, -1, EXDEV, NULL, NULL); return 0; } diff --git a/xlators/storage/bdb/src/bdb.h b/xlators/storage/bdb/src/bdb.h index a041d942d..c9db02c10 100644 --- a/xlators/storage/bdb/src/bdb.h +++ b/xlators/storage/bdb/src/bdb.h @@ -521,12 +521,4 @@ bctx_unref (bctx_t *ctx); bctx_t * bctx_ref (bctx_t *ctx); -bctx_t * -bctx_rename (bctx_t *bctx, - const char *db_newpath); - -int32_t -bdb_db_rename (bctx_table_t *table, - const char *tmp_db_newpath, - const char *real_db_newpath); #endif /* _BDB_H */ |