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>
This commit is contained in:
Jiffin Tony Thottan 2017-07-21 12:14:25 +05:30 committed by soumya k
parent 0cc24da2fd
commit 5c433f8f58
3 changed files with 171 additions and 1 deletions

View File

@ -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 {

View File

@ -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);
}

View File

@ -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;