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 /xlators/storage/bdb/src/bdb.c | |
parent | 8fea700263bd356e6ecacd3dabc9a9c00043a804 (diff) |
link() & rename() on storage/bdb will always return EXDEV.
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'xlators/storage/bdb/src/bdb.c')
-rw-r--r-- | xlators/storage/bdb/src/bdb.c | 274 |
1 files changed, 2 insertions, 272 deletions
diff --git a/xlators/storage/bdb/src/bdb.c b/xlators/storage/bdb/src/bdb.c index 6355855ce3c..a3c6c44ea7e 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; } |