Skip to content

Commit

Permalink
one by one lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshbabu murugesan committed Aug 26, 2020
1 parent d897e6d commit a665bfd
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 28 deletions.
1 change: 0 additions & 1 deletion include/nfsc/libnfs-raw.h
Original file line number Diff line number Diff line change
Expand Up @@ -2297,7 +2297,6 @@ EXTERN int rpc_nfs4_compound_async2(struct rpc_context *rpc, rpc_cb cb,
struct COMPOUND4args *args,
void *private_data,
size_t alloc_hint,
void *private_data,
sessionid4 sessionid,
uint32_t* seqid);

Expand Down
4 changes: 2 additions & 2 deletions include/nfsc/libnfs-zdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ struct ZDR {
typedef struct ZDR ZDR;


typedef uint32_t enum_t;
typedef uint32_t bool_t;
typedef int enum_t;
typedef int bool_t;

typedef uint32_t (*zdrproc_t) (ZDR *, void *,...);

Expand Down
150 changes: 125 additions & 25 deletions lib/nfs_v4.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ struct nfs4_cb_data {

/* Data we need for updating offset in read/write */
struct rw_data rw_data;

char **lookup_path_components;

int lookup_curr_component_idx;

int lookup_total_components;

struct nfs_fh lookup_last_fh;
};

static uint32_t standard_attributes[2] = {
Expand Down Expand Up @@ -1128,7 +1136,7 @@ nfs4_op_getattr(struct nfs_context *nfs, nfs_argop4 *op,
*/
static int
nfs4_allocate_op(struct nfs_context *nfs, nfs_argop4 **op,
char *path, int num_extra)
char *path, int num_extra, struct nfs_fh *nfs_fh)
{
char *ptr;
int i, count;
Expand All @@ -1144,7 +1152,13 @@ nfs4_allocate_op(struct nfs_context *nfs, nfs_argop4 **op,
}

i = 0;
if (nfs->rootfh.len) {
if (nfs_fh != NULL && nfs_fh->len) {
struct nfsfh fh;

fh.fh.len = nfs_fh->len;
fh.fh.val = nfs_fh->val;
i += nfs4_op_putfh(nfs, &(*op)[i], &fh);
} else if (nfs->rootfh.len) {
struct nfsfh fh;

fh.fh.len = nfs->rootfh.len;
Expand Down Expand Up @@ -1389,7 +1403,7 @@ nfs4_lookup_path_1_cb(struct rpc_context *rpc, int status, void *command_data,
}

/* We need to resolve the symlink */
if ((i = nfs4_allocate_op(nfs, &op, path, 1)) < 0) {
if ((i = nfs4_allocate_op(nfs, &op, path, 1, NULL)) < 0) {
data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data);
free_nfs4_cb_data(data);
free(path);
Expand Down Expand Up @@ -1417,7 +1431,61 @@ nfs4_lookup_path_1_cb(struct rpc_context *rpc, int status, void *command_data,
}

static int
nfs4_lookup_path_async(struct nfs_context *nfs,
nfs4_lookup_path_async_helper(struct nfs_context *nfs,
struct nfs4_cb_data *data,
rpc_cb cb);

static void nfs4_lookup_path_async_helper_cb(struct rpc_context *rpc,
int status, void *command_data,
void *private_data) {
struct nfs4_cb_data *data = private_data;
struct nfs_context *nfs = data->nfs;
GETFH4resok *gfhresok;
COMPOUND4res *res = command_data;
assert(rpc->magic == RPC_CONTEXT_MAGIC);
int i = 0;

if (check_nfs4_error(nfs, status, data, res, "GETFH")) {
data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data);
free_nfs4_cb_data(data);
return;
}

if ((i = nfs4_find_op(nfs, data, res, OP_GETFH, "GETFH")) < 0) {
data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data);
free_nfs4_cb_data(data);
return;
}

gfhresok =
&res->resarray.resarray_val[i].nfs_resop4_u.opgetfh.GETFH4res_u.resok4;

if (data->lookup_last_fh.len != 0) {
free(data->lookup_last_fh.val);
data->lookup_last_fh.val = NULL;
}
data->lookup_last_fh.len = gfhresok->object.nfs_fh4_len;
data->lookup_last_fh.val = malloc(data->lookup_last_fh.len);
if (data->lookup_last_fh.val == NULL) {
nfs_set_error(nfs, "%s: %s", __FUNCTION__, nfs_get_error(nfs));
data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data);
free_nfs4_cb_data(data);
return;
}
memcpy(data->lookup_last_fh.val, gfhresok->object.nfs_fh4_val,
data->lookup_last_fh.len);
data->lookup_curr_component_idx++;
if (data->lookup_curr_component_idx == data->lookup_total_components) {
data->cb(0, nfs, NULL, data->private_data);
free_nfs4_cb_data(data);
return;
}
nfs4_lookup_path_async_helper(nfs, data, nfs4_lookup_path_async_helper_cb);

}

static int
nfs4_lookup_path_async_helper(struct nfs_context *nfs,
struct nfs4_cb_data *data,
rpc_cb cb)
{
Expand All @@ -1426,23 +1494,14 @@ nfs4_lookup_path_async(struct nfs_context *nfs,
char *path;
int i, num_op;

path = nfs4_resolve_path(nfs, data->path);
if (path == NULL) {
return -1;
}
free(data->path);
data->path = path;

path = strdup(path);
if (path == NULL) {
return -1;
}

fprintf(stderr, "path %s\n", path);
if ((i = nfs4_allocate_op(nfs, &op, path, data->filler.max_op)) < 0) {
path = data->lookup_path_components[data->lookup_curr_component_idx];
fprintf(stderr, "nfs4_allocate %s\n", path);
if ((i = nfs4_allocate_op(nfs, &op, path, data->filler.max_op, &data->lookup_last_fh)) < 0) {
free(path);
return -1;
}
fprintf(stderr, "done nfs4_allocate %s\n", path);



num_op = data->filler.func(data, &op[i]);
Expand All @@ -1457,16 +1516,57 @@ nfs4_lookup_path_async(struct nfs_context *nfs,
data, nfs->sessionid, &nfs->seqid) != 0) {
nfs_set_error(nfs, "Failed to queue LOOKUP command. %s",
nfs_get_error(nfs));
free(path);
free(op);
return -1;
}

free(path);
free(op);
return 0;
}

static int nfs4_lookup_path_async(struct nfs_context *nfs,
struct nfs4_cb_data *data, rpc_cb cb) {
char *path;
char *token;
int i;

fprintf(stderr, "lookup path %s\n", data->path);
path = nfs4_resolve_path(nfs, data->path);
if (path == NULL) {
return -1;
}
free(data->path);

path = strdup(path);
if (path == NULL) {
return -1;
}

data->lookup_total_components = nfs4_num_path_components(nfs, path);
data->lookup_path_components =
malloc(data->lookup_total_components * sizeof(char *));
data->lookup_curr_component_idx = 0;
data->lookup_last_fh.len = 0;
data->lookup_last_fh.val = NULL;

i = 0;
while ((token = strtok_r(path, "/", &path))) {
data->lookup_path_components[i] = malloc(strlen(token) + 2);
data->lookup_path_components[i][0] = '/';
strcpy(&data->lookup_path_components[i][1], token);
fprintf(stderr, "path components %s\n", data->lookup_path_components[i]);
i++;
}

if (i == 0) {
data->lookup_path_components[i] = malloc(2);
strcpy(&data->lookup_path_components[i][0], "/");
}

return nfs4_lookup_path_async_helper(nfs, data,
nfs4_lookup_path_async_helper_cb);
}

static int
nfs4_populate_getfh(struct nfs4_cb_data *data, nfs_argop4 *op)
{
Expand Down Expand Up @@ -1739,10 +1839,10 @@ nfs4_mount_async(struct nfs_context *nfs, const char *server,

new_export = strdup(export);
if (nfs_normalize_path(nfs, new_export)) {
nfs_set_error(nfs, "Bad export path. %s",
nfs_get_error(nfs));
free(new_export);
return -1;
nfs_set_error(nfs, "Bad export path. %s :%s", new_export,
nfs_get_error(nfs));
free(new_export);
return -1;
}
free(nfs->export);
nfs->export = new_export;
Expand Down Expand Up @@ -2492,7 +2592,6 @@ nfs4_open_readlink(struct rpc_context *rpc, COMPOUND4res *res,
if (ores->status != NFS4ERR_SYMLINK) {
continue;
}

if (data->filler.flags & O_NOFOLLOW) {
nfs_set_error(nfs, "Symlink encountered during "
"open(O_NOFOLLOW)");
Expand Down Expand Up @@ -3142,6 +3241,7 @@ int
nfs4_create_async(struct nfs_context *nfs, const char *path, int flags,
int mode, nfs_cb cb, void *private_data)
{

return nfs4_open_async(nfs, path, O_CREAT | flags, mode,
cb, private_data);
}
Expand Down

0 comments on commit a665bfd

Please sign in to comment.