Closed GoogleCodeExporter closed 9 years ago
bug总述 ======== hlfs_rm_snapshot设计的目的是删除一个snapshot, 但是如果这个snapshot根本就没有 take,我们再去删除这个snapshot,这时我们应该给出用户一个提� ��,你要删除的snapshot 不存在。存在以下场景,可能会出现问题, 用户删除snapshot时,名字给错了,但是咱们系统没给出提示, 那么他还以为自己删除了。 测试环境 ========= Distributor ID: Ubuntu Description: Ubuntu 10.04.3 LTS Release: 10.04 Codename: lucid Linux jiawei-laptop 2.6.32-37-generic #81-Ubuntu SMP Fri Dec 2 20:35:14 UTC 2011 i686 GNU/Linux 测试用例 ========= #include <glib.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include "api/hlfs.h" #include "hlfs_log.h" #define REQ_SIZE 4096 #define TOTAL_SIZE 40960 typedef struct { struct hlfs_ctrl *ctrl; } Fixture; static void do_snapshot(Fixture *fixture, int i) { g_message("enter func %s", __func__); char buffer[128]; memset(buffer, 0, 128); if (0 == i) { sprintf(buffer, "%s%d", "snapshot", i); g_message("%d buffer is [%s]", i, buffer); int ret = hlfs_take_snapshot(fixture->ctrl, buffer); g_assert(ret == 0); } else if (1 == i) { sprintf(buffer, "%s", " "); g_message("%d buffer is [%s]", i, buffer); int ret = hlfs_take_snapshot(fixture->ctrl, buffer); g_assert(ret == 0); } else if (2 == i) { sprintf(buffer, "%s", "+"); g_message("%d buffer is [%s]", i, buffer); int ret = hlfs_take_snapshot(fixture->ctrl, buffer); g_assert(ret == 0); } else if (3 == i) { sprintf(buffer, "%s", "##@"); g_message("%d buffer is [%s]", i, buffer); int ret = hlfs_take_snapshot(fixture->ctrl, buffer); g_assert(ret == 0); } else if (4 == i) { sprintf(buffer, "%s", ".."); g_message("%d buffer is [%s]", i, buffer); int ret = hlfs_take_snapshot(fixture->ctrl, buffer); g_assert(ret == 0); } else if (5 == i) { sprintf(buffer, "%s", " **"); g_message("%d buffer is [%s]", i, buffer); int ret = hlfs_take_snapshot(fixture->ctrl, buffer); g_assert(ret == 0); } else if (6 == i) { sprintf(buffer, "%s", "1234"); g_message("%d buffer is [%s]", i, buffer); int ret = hlfs_take_snapshot(fixture->ctrl, buffer); g_assert(ret == 0); } g_message("leave func %s", __func__); return ; } static void take_snapshot(Fixture *fixture, const void *data) { g_message("enter func %s", __func__); char content[REQ_SIZE]; int offset = 0; int i = 0; memset(content, 0, REQ_SIZE); while (offset < TOTAL_SIZE) { int ret1 = hlfs_write(fixture->ctrl, content, REQ_SIZE, offset); g_assert_cmpint(ret1, ==, REQ_SIZE); do_snapshot(fixture, i); offset += REQ_SIZE; i += 1; } g_message("leave func %s", __func__); return; } static void hlfs_rm_snapshot_setup(Fixture *fixture, const void *data) { g_message("enter func %s", __func__); const char *uri = (const char *)data; fixture->ctrl = init_hlfs(uri); int ret = hlfs_open(fixture->ctrl, 1); g_assert_cmpint(ret, == , 0); g_assert(fixture->ctrl != NULL); take_snapshot(fixture, data); g_message("leave func %s", __func__); return ; } static void test_hlfs_rm_snapshot(Fixture *fixture, const void *data) { g_message("enter func %s", __func__); const char *uri = (const char *) data; int ret = 0; ret = hlfs_rm_snapshot(uri, "snapshot0"); g_assert(ret == 0); ret = hlfs_rm_snapshot(uri, "bug here"); g_assert(ret == 0); g_message("leave func %s", __func__); return ; } static void hlfs_rm_snapshot_tear_down(Fixture *fixture, const void *data) { g_message("enter func %s", __func__); hlfs_close(fixture->ctrl); deinit_hlfs(fixture->ctrl); g_message("leave func %s", __func__); return; } int main(int argc, char **argv) { g_message("enter func %s", __func__); if (log4c_init()) { g_message("log4c init error!"); } g_test_init(&argc, &argv, NULL); g_test_add("/misc/hlfs_rm_snapshot", Fixture, "local:///tmp/testenv/testfs", hlfs_rm_snapshot_setup, test_hlfs_rm_snapshot, hlfs_rm_snapshot_tear_down); g_message("leave func %s", __func__); return g_test_run(); } 用例分析 =========== 调用hlfs_take_snapshot创建了以下snapshot "snapshot0" " " "+" "##@" ".." " **" "1234" 调用hlfs_rm_snapshot删除以下snapshot "snapshot0" "bug here" 期望输出 ========= +snapshot0#1325165574277#8240# + #1325165574333#16660# ++#1325165574401#25080# +##@#1325165574445#33500# +..#1325165574490#41920# + **#1325165574535#50340# +1234#1325165574579#58760# -snapshot0### 实际输出 ======== +snapshot0#1325165574277#8240# + #1325165574333#16660# ++#1325165574401#25080# +##@#1325165574445#33500# +..#1325165574490#41920# + **#1325165574535#50340# +1234#1325165574579#58760# -snapshot0### -bug here### bug分析 ======= 我们在删除“bug here”快照之前,根本没有take 它,也就是说删除这个bug的记录 不应该放到snapshot.txt文件中,至少应该给用户一个提示,“�� �所删除的快照不存在” 或者其他形式。 出现bug的原因 ============== 在删除某个快照之前,没有判断此刻这个快照是否存在 这个bug的目前状态 ================= 目前这个bug还没解决,我会尽快进行处理。
Original issue reported on code.google.com by harryxi...@gmail.com on 29 Dec 2011 at 1:58
harryxi...@gmail.com
已经修复了
Original comment by harryxi...@gmail.com on 2 Jan 2012 at 12:47
Original issue reported on code.google.com by
harryxi...@gmail.com
on 29 Dec 2011 at 1:58