summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiffin Tony Thottan <jthottan@redhat.com>2017-07-21 12:14:25 +0530
committersoumya k <skoduri@redhat.com>2017-08-02 12:09:54 +0000
commit5c433f8f5834a4cae62d0375bfdb273242630f01 (patch)
treeb66101c9bd8775a0c0bacb1e3c65fd952dfdc6a8
parent0cc24da2fd79dd8680b771475d2192db0b63e7de (diff)
tests/gfapi : add test case for nameless lookups in glfs_resolve_component()
Plus address pending comment to add check for entry "" in glfs_resolve_component() Change-Id: I6063f776ce1cd76cb4c1b1f621b064f3dcc91e5c BUG: 1460514 Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com> Reviewed-on: https://review.gluster.org/17844 Smoke: Gluster Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Niels de Vos <ndevos@redhat.com> Reviewed-by: soumya k <skoduri@redhat.com>
-rw-r--r--api/src/glfs-resolve.c3
-rw-r--r--tests/bugs/gfapi/bug-1447266/1460514.c143
-rw-r--r--tests/bugs/gfapi/bug-1447266/1460514.t26
3 files changed, 171 insertions, 1 deletions
diff --git a/api/src/glfs-resolve.c b/api/src/glfs-resolve.c
index 8e91cd71c20..76835cbaebd 100644
--- a/api/src/glfs-resolve.c
+++ b/api/src/glfs-resolve.c
@@ -282,7 +282,8 @@ glfs_resolve_component (struct glfs *fs, xlator_t *subvol, inode_t *parent,
if (__is_root_gfid (parent->gfid) &&
((strcmp (component, ".") == 0) ||
- (strcmp (component, "..") == 0))) {
+ (strcmp (component, "..") == 0) ||
+ (strcmp (component, "") == 0))) {
if (!force_lookup) {
inode = inode_ref (parent);
} else {
diff --git a/tests/bugs/gfapi/bug-1447266/1460514.c b/tests/bugs/gfapi/bug-1447266/1460514.c
new file mode 100644
index 00000000000..f04d2d1463f
--- /dev/null
+++ b/tests/bugs/gfapi/bug-1447266/1460514.c
@@ -0,0 +1,143 @@
+#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;