diff options
Diffstat (limited to 'tests/bugs/gfapi/bug-1447266')
| -rw-r--r-- | tests/bugs/gfapi/bug-1447266/1460514.c | 150 | ||||
| -rw-r--r-- | tests/bugs/gfapi/bug-1447266/1460514.t | 26 | ||||
| -rw-r--r-- | tests/bugs/gfapi/bug-1447266/bug-1447266.c | 107 | ||||
| -rw-r--r-- | tests/bugs/gfapi/bug-1447266/bug-1447266.t | 60 |
4 files changed, 343 insertions, 0 deletions
diff --git a/tests/bugs/gfapi/bug-1447266/1460514.c b/tests/bugs/gfapi/bug-1447266/1460514.c new file mode 100644 index 00000000000..c721559a668 --- /dev/null +++ b/tests/bugs/gfapi/bug-1447266/1460514.c @@ -0,0 +1,150 @@ +#include <fcntl.h> +#include <unistd.h> +#include <time.h> +#include <limits.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <glusterfs/api/glfs.h> +#include <glusterfs/api/glfs-handles.h> + +#define LOG_ERR(func, ret) \ + do { \ + if (ret != 0) { \ + fprintf(stderr, "%s : returned error %d (%s)\n", func, ret, \ + strerror(errno)); \ + goto out; \ + } else { \ + fprintf(stderr, "%s : returned %d\n", func, ret); \ + } \ + } while (0) + +int +main(int argc, char *argv[]) +{ + int ret = 0; + glfs_t *fs = NULL; + struct glfs_object *root = NULL, *dir = NULL, *subdir = NULL; + struct stat sb = { + 0, + }; + char *dirname = "dir"; + char *subdirname = "subdir"; + char *logfile = NULL; + char *volname = NULL; + char *hostname = NULL; + unsigned char subdir_handle[GFAPI_HANDLE_LENGTH] = {'\0'}; + + if (argc != 4) { + fprintf(stderr, "Invalid argument\n"); + exit(1); + } + + hostname = argv[1]; + volname = argv[2]; + logfile = argv[3]; + + fs = glfs_new(volname); + if (!fs) { + fprintf(stderr, "glfs_new: returned NULL\n"); + ret = -1; + goto out; + } + + ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007); + LOG_ERR("glfs_set_volfile_server", ret); + + ret = glfs_set_logging(fs, logfile, 7); + LOG_ERR("glfs_set_logging", ret); + + ret = glfs_init(fs); + LOG_ERR("first attempt glfs_init", ret); + + root = glfs_h_lookupat(fs, NULL, "/", &sb, 0); + if (root == NULL) { + fprintf(stderr, "glfs_h_lookupat: error on lookup of / ,%s\n", + strerror(errno)); + goto out; + } + dir = glfs_h_mkdir(fs, root, dirname, 0644, &sb); + if (dir == NULL) { + fprintf(stderr, "glfs_h_mkdir: error on directory creation dir ,%s\n", + strerror(errno)); + goto out; + } + subdir = glfs_h_mkdir(fs, root, subdirname, 0644, &sb); + if (subdir == NULL) { + fprintf(stderr, + "glfs_h_mkdir: error on directory creation subdir ,%s\n", + strerror(errno)); + goto out; + } + ret = glfs_h_extract_handle(subdir, subdir_handle, GFAPI_HANDLE_LENGTH); + if (ret < 0) { + fprintf(stderr, + "glfs_h_extract_handle: error extracting handle of %s: %s\n", + subdirname, strerror(errno)); + goto out; + } + + glfs_h_close(subdir); + subdir = NULL; + glfs_h_close(dir); + dir = NULL; + + if (fs) { + ret = glfs_fini(fs); + fprintf(stderr, "glfs_fini(fs) returned %d \n", ret); + } + + fs = NULL; + + fs = glfs_new(volname); + if (!fs) { + fprintf(stderr, "glfs_new: returned NULL\n"); + ret = -1; + goto out; + } + + ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007); + LOG_ERR("glfs_set_volfile_server", ret); + + ret = glfs_set_logging(fs, logfile, 7); + LOG_ERR("glfs_set_logging", ret); + + ret = glfs_init(fs); + LOG_ERR("second attempt glfs_init", ret); + + subdir = glfs_h_create_from_handle(fs, subdir_handle, GFAPI_HANDLE_LENGTH, + &sb); + if (subdir == NULL) { + fprintf( + stderr, + "glfs_h_create_from_handle: error on create of %s: from (%p),%s\n", + subdirname, subdir_handle, strerror(errno)); + goto out; + } + dir = glfs_h_lookupat(fs, subdir, "..", &sb, 0); + if (dir == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on directory lookup dir using .. ,%s\n", + strerror(errno)); + goto out; + } + +out: + if (subdir) + glfs_h_close(subdir); + if (dir) + glfs_h_close(dir); + + if (fs) { + ret = glfs_fini(fs); + fprintf(stderr, "glfs_fini(fs) returned %d \n", ret); + } + + if (ret) + exit(1); + exit(0); +} diff --git a/tests/bugs/gfapi/bug-1447266/1460514.t b/tests/bugs/gfapi/bug-1447266/1460514.t new file mode 100644 index 00000000000..594af75cae2 --- /dev/null +++ b/tests/bugs/gfapi/bug-1447266/1460514.t @@ -0,0 +1,26 @@ +#!/bin/bash + +. $(dirname $0)/../../../include.rc +. $(dirname $0)/../../../volume.rc + +cleanup; + +TEST glusterd + +TEST $CLI volume create $V0 $H0:$B0/brick1; +EXPECT 'Created' volinfo_field $V0 'Status'; + +TEST $CLI volume start $V0; +EXPECT 'Started' volinfo_field $V0 'Status'; + +logdir=`gluster --print-logdir` + +TEST build_tester $(dirname $0)/1460514.c -lgfapi -o $(dirname $0)/1460514 +TEST ./$(dirname $0)/1460514 $H0 $V0 $logdir/1460514.log + +cleanup_tester $(dirname $0)/1460514 + +TEST $CLI volume stop $V0 +TEST $CLI volume delete $V0 + +cleanup; diff --git a/tests/bugs/gfapi/bug-1447266/bug-1447266.c b/tests/bugs/gfapi/bug-1447266/bug-1447266.c new file mode 100644 index 00000000000..2b7e2d627fe --- /dev/null +++ b/tests/bugs/gfapi/bug-1447266/bug-1447266.c @@ -0,0 +1,107 @@ +#include <glusterfs/api/glfs.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#define TOTAL_ARGS 4 +int +main(int argc, char *argv[]) +{ + char *cwd = (char *)malloc(PATH_MAX * sizeof(char *)); + char *resolved = NULL; + char *result = NULL; + char *buf = NULL; + struct stat st; + char *path = NULL; + int ret; + + if (argc != TOTAL_ARGS) { + printf( + "Please give all required command line args.\n" + "Format : <volname> <server_ip> <path_name>\n"); + goto out; + } + + glfs_t *fs = glfs_new(argv[1]); + + if (fs == NULL) { + printf("glfs_new: %s\n", strerror(errno)); + /* No need to fail the test for this error */ + ret = 0; + goto out; + } + + ret = glfs_set_volfile_server(fs, "tcp", argv[2], 24007); + if (ret) { + printf("glfs_set_volfile_server: %s\n", strerror(errno)); + /* No need to fail the test for this error */ + ret = 0; + goto out; + } + + path = argv[3]; + + ret = glfs_set_logging(fs, "/tmp/gfapi.log", 7); + if (ret) { + printf("glfs_set_logging: %s\n", strerror(errno)); + /* No need to fail the test for this error */ + ret = 0; + goto out; + } + + ret = glfs_init(fs); + if (ret) { + printf("glfs_init: %s\n", strerror(errno)); + /* No need to fail the test for this error */ + ret = 0; + goto out; + } + + sleep(1); + + ret = glfs_chdir(fs, path); + if (ret) { + printf("glfs_chdir: %s\n", strerror(errno)); + goto out; + } + + buf = glfs_getcwd(fs, cwd, PATH_MAX); + if (cwd == NULL) { + printf("glfs_getcwd: %s\n", strerror(errno)); + goto out; + } + + printf("\ncwd = %s\n\n", cwd); + + result = glfs_realpath(fs, path, resolved); + if (result == NULL) { + printf("glfs_realpath: %s\n", strerror(errno)); + goto out; + } + + ret = glfs_stat(fs, path, &st); + if (ret) { + printf("glfs_stat: %s\n", strerror(errno)); + goto out; + } + if (cwd) + free(cwd); + + result = glfs_realpath(fs, path, resolved); + if (result == NULL) { + printf("glfs_realpath: %s\n", strerror(errno)); + goto out; + } + + ret = glfs_fini(fs); + if (ret) { + printf("glfs_fini: %s\n", strerror(errno)); + /* No need to fail the test for this error */ + ret = 0; + goto out; + } + + printf("\n"); +out: + return ret; +} diff --git a/tests/bugs/gfapi/bug-1447266/bug-1447266.t b/tests/bugs/gfapi/bug-1447266/bug-1447266.t new file mode 100644 index 00000000000..45547f4f0e7 --- /dev/null +++ b/tests/bugs/gfapi/bug-1447266/bug-1447266.t @@ -0,0 +1,60 @@ +#!/bin/bash + +. $(dirname $0)/../../../include.rc +. $(dirname $0)/../../../volume.rc +. $(dirname $0)/../../../snapshot.rc + +cleanup; + +TEST init_n_bricks 3; +TEST setup_lvm 3; + +TEST glusterd; + +TEST pidof glusterd; + +TEST $CLI volume create $V0 $H0:$L1 $H0:$L2 $H0:$L3; +TEST $CLI volume set $V0 nfs.disable false + + +TEST $CLI volume start $V0; + +TEST $GFS --volfile-server=$H0 --volfile-id=$V0 $M0; + +for i in {1..10} ; do echo "file" > $M0/file$i ; done + +# Create file and hard-links +TEST touch $M0/f1 +TEST mkdir $M0/dir +TEST ln $M0/f1 $M0/f2 +TEST ln $M0/f1 $M0/dir/f3 + +TEST $CLI snapshot config activate-on-create enable +TEST $CLI volume set $V0 features.uss enable; + +TEST $CLI snapshot create snap1 $V0 no-timestamp; + +for i in {11..20} ; do echo "file" > $M0/file$i ; done + +TEST $CLI snapshot create snap2 $V0 no-timestamp; +TEST build_tester $(dirname $0)/bug-1447266.c -lgfapi + +#Testing strts from here--> + +TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.." +TEST $(dirname $0)/bug-1447266 $V0 $H0 "/." +TEST $(dirname $0)/bug-1447266 $V0 $H0 "/../." +TEST $(dirname $0)/bug-1447266 $V0 $H0 "/../.." +TEST $(dirname $0)/bug-1447266 $V0 $H0 "/dir/../." +#Since dir1 is not present, this test should fail +TEST ! $(dirname $0)/bug-1447266 $V0 $H0 "/dir/../dir1" +TEST $(dirname $0)/bug-1447266 $V0 $H0 "/dir/.." +TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps" +TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/." +#Since snap3 is not present, this test should fail +TEST ! $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/.././snap3" +TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/../." +TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/./snap1/./../snap1/dir/." + +cleanup_tester $(dirname $0)/bug-1447266 +cleanup; |
