NFSv4 Add support for nfs_rmdir()
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>libnfs-4.0.0-vitalif
parent
8a9fceb725
commit
93fbecd7c1
|
@ -468,6 +468,8 @@ int nfs4_mkdir2_async(struct nfs_context *nfs, const char *path, int mode,
|
|||
nfs_cb cb, void *private_data);
|
||||
int nfs4_mount_async(struct nfs_context *nfs, const char *server,
|
||||
const char *export, nfs_cb cb, void *private_data);
|
||||
int nfs4_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb,
|
||||
void *private_data);
|
||||
int nfs4_stat64_async(struct nfs_context *nfs, const char *path,
|
||||
int no_follow, nfs_cb cb, void *private_data);
|
||||
|
||||
|
|
|
@ -1159,9 +1159,11 @@ nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb,
|
|||
switch (nfs->version) {
|
||||
case NFS_V3:
|
||||
return nfs3_rmdir_async(nfs, path, cb, private_data);
|
||||
case NFS_V4:
|
||||
return nfs4_rmdir_async(nfs, path, cb, private_data);
|
||||
default:
|
||||
nfs_set_error(nfs, "%s does not support NFSv4",
|
||||
__FUNCTION__);
|
||||
nfs_set_error(nfs, "%s does not support NFSv%d",
|
||||
__FUNCTION__, nfs->version);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
84
lib/nfs_v4.c
84
lib/nfs_v4.c
|
@ -1248,3 +1248,87 @@ nfs4_mkdir2_async(struct nfs_context *nfs, const char *orig_path, int mode,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Takes object name as filler.data
|
||||
*/
|
||||
static void
|
||||
nfs4_populate_rmdir(struct nfs4_cb_data *data, nfs_argop4 *op)
|
||||
{
|
||||
REMOVE4args *rmargs;
|
||||
|
||||
rmargs = &op[0].nfs_argop4_u.opremove;
|
||||
memset(rmargs, 0, sizeof(*rmargs));
|
||||
rmargs->target.utf8string_val = data->filler.data;
|
||||
rmargs->target.utf8string_len = strlen(rmargs->target.utf8string_val);
|
||||
op[0].argop = OP_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
nfs4_rmdir_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;
|
||||
COMPOUND4res *res = command_data;
|
||||
|
||||
assert(rpc->magic == RPC_CONTEXT_MAGIC);
|
||||
|
||||
if (check_nfs4_error(nfs, status, data, res, "RMDIR")) {
|
||||
free_nfs4_cb_data(data);
|
||||
return;
|
||||
}
|
||||
|
||||
data->cb(0, nfs, NULL, data->private_data);
|
||||
free_nfs4_cb_data(data);
|
||||
}
|
||||
|
||||
int
|
||||
nfs4_rmdir_async(struct nfs_context *nfs, const char *orig_path,
|
||||
nfs_cb cb, void *private_data)
|
||||
{
|
||||
struct nfs4_cb_data *data;
|
||||
char *path;
|
||||
|
||||
data = malloc(sizeof(*data));
|
||||
if (data == NULL) {
|
||||
nfs_set_error(nfs, "Out of memory. Failed to allocate "
|
||||
"cb data");
|
||||
return -1;
|
||||
}
|
||||
memset(data, 0, sizeof(*data));
|
||||
|
||||
data->nfs = nfs;
|
||||
data->cb = cb;
|
||||
data->private_data = private_data;
|
||||
|
||||
data->path = nfs4_resolve_path(nfs, orig_path);
|
||||
if (data->path == NULL) {
|
||||
nfs_set_error(nfs, "Out of memory resolving path");
|
||||
free_nfs4_cb_data(data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
path = strrchr(data->path, '/');
|
||||
if (path == data->path) {
|
||||
char *ptr;
|
||||
|
||||
for (ptr = data->path; *ptr; ptr++) {
|
||||
*ptr = *(ptr + 1);
|
||||
}
|
||||
/* No path to lookup */
|
||||
data->filler.data = data->path;
|
||||
data->path = strdup("/");
|
||||
} else {
|
||||
*path++ = 0;
|
||||
data->filler.data = strdup(path);
|
||||
}
|
||||
data->filler.func = nfs4_populate_rmdir;
|
||||
data->filler.num_op = 1;
|
||||
|
||||
if (nfs4_lookup_path_async(nfs, data, nfs4_rmdir_cb) < 0) {
|
||||
free_nfs4_cb_data(data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,56 +21,56 @@ echo -n "Verifying it is a directory ... "
|
|||
grep "nfs_mode:40" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Remove a root directory (abs) (2) ... "
|
||||
./prog_rmdir "${TESTURL}/" "." /testdir 2>/dev/null || failure
|
||||
echo -n "test nfs_rmdir() for a root directory (abs) (2) ... "
|
||||
./prog_rmdir "${TESTURL}/?version=${VERS}" "." /testdir || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir2() for a root directory (rel) (3) ... "
|
||||
./prog_mkdir "${TESTURL}/?version=${VERS}" "." testdir 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Remove a root directory (rel) (4) ... "
|
||||
./prog_rmdir "${TESTURL}/" "." testdir 2>/dev/null || failure
|
||||
echo -n "test nfs_rmdir() for a root directory (rel) (4) ... "
|
||||
./prog_rmdir "${TESTURL}/?version=${VERS}" "." testdir 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir2() in a subdirectory (abs) (5) ... "
|
||||
./prog_mkdir "${TESTURL}/?version=${VERS}" "." /subdir/testdir 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Remove a directory from a subdirectory (abs) (6) ... "
|
||||
./prog_rmdir "${TESTURL}/" "." /subdir/testdir 2>/dev/null || failure
|
||||
echo -n "test nfs_rmdir() for a subdirectory (abs) (6) ... "
|
||||
./prog_rmdir "${TESTURL}/?version=${VERS}" "." /subdir/testdir 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir2() in a subdirectory (rel) (7) ... "
|
||||
./prog_mkdir "${TESTURL}/?version=${VERS}" "." subdir/testdir 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Remove a directory from a subdirectory (rel) (8) ... "
|
||||
./prog_rmdir "${TESTURL}/" "." subdir/testdir 2>/dev/null || failure
|
||||
echo -n "test nfs_rmdir() for a subdirectory (rel) (8) ... "
|
||||
./prog_rmdir "${TESTURL}/?version=${VERS}" "." subdir/testdir 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir2() from a different cwd (rel) (9) ... "
|
||||
./prog_mkdir "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/testdir 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Remove a directory from a subdirectory (rel) (10) ... "
|
||||
./prog_rmdir "${TESTURL}/" "." subdir2/testdir 2>/dev/null || failure
|
||||
echo -n "test nfs_rmdir() for a subdirectory (rel) (10) ... "
|
||||
./prog_rmdir "${TESTURL}/?version=${VERS}" "." subdir2/testdir 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir2() outside of the share (rel) (11) ... "
|
||||
./prog_mkdir "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/../../testdir 2>/dev/null && failure
|
||||
success
|
||||
|
||||
echo -n "Remove a directory outside of the share (rel) (12) ... "
|
||||
./prog_rmdir "${TESTURL}/" "subdir" ../subdir2/../../testdir 2>/dev/null && failure
|
||||
echo -n "test nfs_rmdir() outside of the share (rel) (12) ... "
|
||||
./prog_rmdir "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/../../testdir 2>/dev/null && failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir2() on an existing dir (rel) (13) ... "
|
||||
./prog_mkdir "${TESTURL}/?version=${VERS}" "subdir" 2>/dev/null ../subdir2 && failure
|
||||
success
|
||||
|
||||
echo -n "Remove a directory that does not exist (rel) (14) ... "
|
||||
./prog_rmdir "${TESTURL}/" "subdir" ../subdir3 2>/dev/null && failure
|
||||
echo -n "test nfs_rmdir() that does not exist (rel) (14) ... "
|
||||
./prog_rmdir "${TESTURL}/?version=${VERS}" "subdir" ../subdir3 2>/dev/null && failure
|
||||
success
|
||||
|
||||
stop_share
|
||||
|
|
|
@ -13,48 +13,48 @@ echo -n "test nfs_mkdir() (1) ... "
|
|||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_mkdir "${TESTURL}/?version=${VERS}" "." /mkdir1 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_rmdir() (2) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/" "." /mkdir1 2>/dev/null || failure
|
||||
echo -n "test nfs_rmdir() (2) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/?version=${VERS}" "." /mkdir1 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir() (3) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_mkdir "${TESTURL}/?version=${VERS}" "." mkdir3 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_rmdir() (4) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/" "." mkdir3 2>/dev/null || failure
|
||||
echo -n "test nfs_rmdir() (4) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/?version=${VERS}" "." mkdir3 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir() (5) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_mkdir "${TESTURL}/?version=${VERS}" "." /subdir/mkdir5 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_rmdir() (6) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/" "." /subdir/mkdir5 2>/dev/null || failure
|
||||
echo -n "test nfs_rmdir() (6) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/?version=${VERS}" "." /subdir/mkdir5 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir() (7) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_mkdir "${TESTURL}/?version=${VERS}" "." subdir/mkdir7 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_rmdir() (8) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/" "." subdir/mkdir7 2>/dev/null || failure
|
||||
echo -n "test nfs_rmdir() (8) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/?version=${VERS}" "." subdir/mkdir7 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir() (9) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_mkdir "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/mkdir9 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_rmdir() (10) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/" "subdir" ../subdir2/mkdir9 2>/dev/null || failure
|
||||
echo -n "test nfs_rmdir() (10) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/?version=${VERS}" "subdir" ../subdir2/mkdir9 2>/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mkdir() (11) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_mkdir "${TESTURL}/?version=${VERS}" "subdir" ../../subdir2/mkdir9 2>/dev/null || expr $? != 99 >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_rmdir() (12) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/" "subdir" ../../subdir2/mkdir12 2>/dev/null || expr $? != 99 >/dev/null || failure
|
||||
echo -n "test nfs_rmdir() (12) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_rmdir "${TESTURL}/?version=${VERS}" "subdir" ../../subdir2/mkdir12 2>/dev/null || expr $? != 99 >/dev/null || failure
|
||||
success
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue