Project

General

Profile

Bug #4061 » leaks_rename.c

Marcel Telka, 2013-08-20 02:51 PM

 
1

    
2
#include <libzfs.h>
3

    
4
static void printerr(libzfs_handle_t *hlib, const char *msg)
5
{
6
    printf("%s: error=%d\n%s\n%s\n",
7
            msg,
8
            libzfs_errno(hlib),
9
            libzfs_error_description(hlib),
10
            libzfs_error_action(hlib));
11
}
12

    
13

    
14
int main(int argc, char *argv[])
15
{
16
    const char *old_name;
17
    const char *new_name;
18
    libzfs_handle_t *hlib;
19
    zfs_handle_t *hzfs;
20

    
21
    if (argc != 3) {
22
        printf("usage: leaks_rename old_name new_name\n");
23
        return 1;
24
    }
25

    
26
    old_name = argv[1];
27
    new_name = argv[2];
28

    
29
    hlib = libzfs_init();
30
    hzfs = zfs_open(hlib, old_name, ZFS_TYPE_FILESYSTEM);
31
    if (hzfs) {
32
        printf("renaming %s -> %s\n", old_name, new_name);
33
        if (zfs_rename(hzfs, new_name, 0, 0) != 0) {
34
            printerr(hlib, "zfs_rename()");
35
        }
36
        zfs_close(hzfs);
37
    } else {
38
        printerr(hlib, "zfs_open()");
39
    }
40
    libzfs_fini(hlib);
41

    
42
    printf("job done, sleeping...\n");
43
    sleep(10);
44

    
45
    return 0;
46
}
(2-2/2)