multithreading: make nfs_get_error() work for multithreaded applications
This mostly consists of creating one slave nfs_context for each nfs thread to track the error-string. Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>master
parent
f85c21755e
commit
29b4cea00f
|
@ -37,3 +37,18 @@ stamp-h1
|
|||
libnfs.pc
|
||||
!libnfs.pc.in
|
||||
build
|
||||
/win32/libnfs/x64/Debug/libnfs.tlog/CL.command.1.tlog
|
||||
/win32/libnfs/x64/Debug/libnfs.tlog/libnfs.lastbuildstate
|
||||
/win32/libnfs/x64/Debug/libnfs.tlog/unsuccessfulbuild
|
||||
/win32/libnfs/x64/Debug/libnfs.log
|
||||
/win32/libnfs/x64/Debug/vc143.idb
|
||||
/win32/nfs-cp/x64/Debug/nfs-cp.tlog/CL.command.1.tlog
|
||||
*.tlog
|
||||
/win32/nfs-cp/x64/Debug/nfs-cp.exe.recipe
|
||||
/win32/nfs-cp/x64/Debug/nfs-cp.log
|
||||
/win32/nfs-cp/x64/Debug/vc143.idb
|
||||
/win32/nfs-ls/x64/Debug/nfs-ls.exe.recipe
|
||||
/win32/nfs-ls/x64/Debug/nfs-ls.log
|
||||
/win32/nfs-ls/x64/Debug/vc143.idb
|
||||
/win32/libnfs/x64/Debug/libnfs.vcxproj.FileListAbsolute.txt
|
||||
/win32/libnfs/x64/Debug/version.res
|
||||
|
|
|
@ -208,7 +208,7 @@ int main(int argc, char *argv[])
|
|||
} else if (!strncmp(argv[1], "acl", 3)) {
|
||||
ret = nfs_open(nfs, url->file, 0600, &nfsfh);
|
||||
if (ret != 0) {
|
||||
printf("failed to open %s\n", url->file);
|
||||
printf("failed to open %s. %s\n", url->file, nfs_get_error(nfs));
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ static void *nfs_stat_thread(void *arg)
|
|||
while(!sd->is_finished) {
|
||||
ret = nfs_open(sd->nfs, sd->path, 0600, &nfsfh);
|
||||
if (ret != 0) {
|
||||
printf("failed to open %s\n", sd->path);
|
||||
printf("failed to open %s. %s\n", sd->path, nfs_get_error(sd->nfs));
|
||||
exit(10);
|
||||
}
|
||||
if (nfsfh == NULL) {
|
||||
|
|
|
@ -35,14 +35,17 @@ extern "C" {
|
|||
typedef pthread_t libnfs_thread_t;
|
||||
typedef pthread_mutex_t libnfs_mutex_t;
|
||||
typedef sem_t libnfs_sem_t;
|
||||
typedef pid_t nfs_tid_t;
|
||||
#endif /* HAVE_PTHREAD */
|
||||
|
||||
#ifdef WIN32
|
||||
typedef HANDLE libnfs_thread_t;
|
||||
typedef HANDLE libnfs_mutex_t;
|
||||
typedef HANDLE libnfs_sem_t;
|
||||
typedef DWORD nfs_tid_t;
|
||||
#endif
|
||||
|
||||
nfs_tid_t nfs_mt_get_tid(void);
|
||||
int nfs_mt_mutex_init(libnfs_mutex_t *mutex);
|
||||
int nfs_mt_mutex_destroy(libnfs_mutex_t *mutex);
|
||||
int nfs_mt_mutex_lock(libnfs_mutex_t *mutex);
|
||||
|
|
|
@ -287,22 +287,19 @@ struct nfs_fh {
|
|||
char *val;
|
||||
};
|
||||
|
||||
struct nfs_context {
|
||||
struct rpc_context *rpc;
|
||||
struct nfs_context_internal {
|
||||
char *server;
|
||||
char *export;
|
||||
char *cwd;
|
||||
struct nfs_fh rootfh;
|
||||
uint64_t readmax;
|
||||
uint64_t writemax;
|
||||
char *cwd;
|
||||
int dircache_enabled;
|
||||
int auto_reconnect;
|
||||
int dircache_enabled;
|
||||
struct nfsdir *dircache;
|
||||
uint16_t mask;
|
||||
|
||||
int auto_traverse_mounts;
|
||||
struct nested_mounts *nested_mounts;
|
||||
|
||||
int version;
|
||||
int nfsport;
|
||||
int mountport;
|
||||
|
@ -317,10 +314,30 @@ struct nfs_context {
|
|||
#ifdef HAVE_MULTITHREADING
|
||||
int multithreading_enabled;
|
||||
libnfs_thread_t service_thread;
|
||||
libnfs_mutex_t nfs_mutex;
|
||||
libnfs_mutex_t nfs4_open_mutex;
|
||||
struct nfs_thread_context *thread_ctx;
|
||||
#endif /* HAVE_MULTITHREADING */
|
||||
};
|
||||
|
||||
struct nfs_context {
|
||||
struct rpc_context *rpc;
|
||||
struct nfs_context_internal *nfsi;
|
||||
char *error_string;
|
||||
|
||||
#ifdef HAVE_MULTITHREADING
|
||||
struct nfs_context *master_ctx;
|
||||
#endif /* HAVE_MULTITHREADING */
|
||||
};
|
||||
|
||||
#ifdef HAVE_MULTITHREADING
|
||||
struct nfs_thread_context {
|
||||
struct nfs_thread_context *next;
|
||||
nfs_tid_t tid;
|
||||
struct nfs_context nfs;
|
||||
};
|
||||
#endif /* HAVE_MULTITHREADING */
|
||||
|
||||
typedef int (*continue_func)(struct nfs_context *nfs, struct nfs_attr *attr,
|
||||
struct nfs_cb_data *data);
|
||||
|
||||
|
|
|
@ -121,18 +121,46 @@ struct sync_cb_data {
|
|||
};
|
||||
|
||||
static inline int
|
||||
nfs_init_cb_data(struct nfs_context *nfs, struct sync_cb_data *cb_data)
|
||||
nfs_init_cb_data(struct nfs_context **nfs, struct sync_cb_data *cb_data)
|
||||
{
|
||||
cb_data->is_finished = 0;
|
||||
#ifdef HAVE_MULTITHREADING
|
||||
if (nfs && (*nfs)->nfsi->multithreading_enabled && (*nfs)->master_ctx == NULL) {
|
||||
struct nfs_thread_context *ntc;
|
||||
|
||||
for(ntc = (*nfs)->nfsi->thread_ctx; ntc; ntc = ntc->next) {
|
||||
if (nfs_mt_get_tid() == ntc->tid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ntc) {
|
||||
*nfs = &ntc->nfs;
|
||||
} else {
|
||||
ntc = calloc(1, sizeof(struct nfs_thread_context));
|
||||
if (ntc == NULL) {
|
||||
return -1;
|
||||
}
|
||||
nfs_mt_mutex_lock(&(*nfs)->rpc->rpc_mutex);
|
||||
ntc->next = (*nfs)->nfsi->thread_ctx;
|
||||
ntc->tid = nfs_mt_get_tid();
|
||||
(*nfs)->nfsi->thread_ctx = ntc;
|
||||
nfs_mt_mutex_unlock(&(*nfs)->rpc->rpc_mutex);
|
||||
memcpy(&ntc->nfs, *nfs, sizeof(struct nfs_context));
|
||||
ntc->nfs.error_string = NULL;
|
||||
ntc->nfs.master_ctx = *nfs;
|
||||
|
||||
*nfs = &ntc->nfs;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a semaphore and initialize it to zero. So that we
|
||||
* can wait for it and immetiately block until the service thread
|
||||
* has received the reply.
|
||||
*/
|
||||
if (nfs_mt_sem_init(&cb_data->wait_sem, 0)) {
|
||||
if (nfs) {
|
||||
nfs_set_error(nfs, "Failed to initialize semaphore");
|
||||
if (nfs && *nfs) {
|
||||
nfs_set_error(*nfs, "Failed to initialize semaphore");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -232,7 +260,7 @@ wait_for_nfs_reply(struct nfs_context *nfs, struct sync_cb_data *cb_data)
|
|||
int ret;
|
||||
|
||||
#ifdef HAVE_MULTITHREADING
|
||||
if(nfs->multithreading_enabled) {
|
||||
if(nfs->nfsi->multithreading_enabled) {
|
||||
nfs_mt_sem_wait(&cb_data->wait_sem);
|
||||
return;
|
||||
}
|
||||
|
@ -288,7 +316,7 @@ nfs_mount(struct nfs_context *nfs, const char *server, const char *export)
|
|||
|
||||
assert(rpc->magic == RPC_CONTEXT_MAGIC);
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -343,7 +371,7 @@ nfs_umount(struct nfs_context *nfs)
|
|||
|
||||
assert(rpc->magic == RPC_CONTEXT_MAGIC);
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -405,7 +433,7 @@ nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st)
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = st;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -443,7 +471,7 @@ nfs_stat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st)
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = st;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -466,7 +494,7 @@ nfs_lstat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st)
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = st;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -513,7 +541,7 @@ nfs_open(struct nfs_context *nfs, const char *path, int flags,
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = nfsfh;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -537,7 +565,7 @@ nfs_open2(struct nfs_context *nfs, const char *path, int flags,
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = nfsfh;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -577,7 +605,7 @@ nfs_chdir(struct nfs_context *nfs, const char *path)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -625,7 +653,7 @@ nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset,
|
|||
|
||||
cb_data.return_data = buffer;
|
||||
cb_data.call = "pread";
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -654,7 +682,7 @@ nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count,
|
|||
|
||||
cb_data.return_data = buffer;
|
||||
cb_data.call = "read";
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -694,7 +722,7 @@ nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -725,7 +753,7 @@ nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st)
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = st;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -751,7 +779,7 @@ nfs_fstat64(struct nfs_context *nfs, struct nfsfh *nfsfh,
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = st;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -794,7 +822,7 @@ nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset,
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.call = "pwrite";
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -822,7 +850,7 @@ nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count,
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.call = "write";
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -863,7 +891,7 @@ nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -905,7 +933,7 @@ nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -947,7 +975,7 @@ int nfs_truncate(struct nfs_context *nfs, const char *path, uint64_t length)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -988,7 +1016,7 @@ nfs_mkdir(struct nfs_context *nfs, const char *path)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1010,7 +1038,7 @@ nfs_mkdir2(struct nfs_context *nfs, const char *path, int mode)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1051,7 +1079,7 @@ int nfs_rmdir(struct nfs_context *nfs, const char *path)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1100,7 +1128,7 @@ nfs_create(struct nfs_context *nfs, const char *path, int flags, int mode,
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = nfsfh;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1147,7 +1175,7 @@ nfs_mknod(struct nfs_context *nfs, const char *path, int mode, int dev)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1188,7 +1216,7 @@ nfs_unlink(struct nfs_context *nfs, const char *path)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1236,7 +1264,7 @@ nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir)
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = nfsdir;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1282,7 +1310,7 @@ nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int when
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = current_offset;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1325,7 +1353,7 @@ nfs_lockf(struct nfs_context *nfs, struct nfsfh *nfsfh,
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1367,7 +1395,7 @@ nfs_fcntl(struct nfs_context *nfs, struct nfsfh *nfsfh,
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1411,7 +1439,7 @@ nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs)
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = svfs;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1456,7 +1484,7 @@ nfs_statvfs64(struct nfs_context *nfs, const char *path,
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = svfs;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1506,7 +1534,7 @@ nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize)
|
|||
|
||||
cb_data.return_data = buf;
|
||||
cb_data.return_int = bufsize;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1557,7 +1585,7 @@ nfs_readlink2(struct nfs_context *nfs, const char *path, char **bufptr)
|
|||
|
||||
*bufptr = NULL;
|
||||
cb_data.return_data = bufptr;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1598,7 +1626,7 @@ nfs_chmod(struct nfs_context *nfs, const char *path, int mode)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1620,7 +1648,7 @@ nfs_lchmod(struct nfs_context *nfs, const char *path, int mode)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1663,7 +1691,7 @@ nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1706,7 +1734,7 @@ nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1731,7 +1759,7 @@ nfs_lchown(struct nfs_context *nfs, const char *path, int uid, int gid)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1771,7 +1799,7 @@ nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1813,7 +1841,7 @@ nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1835,7 +1863,7 @@ nfs_lutimes(struct nfs_context *nfs, const char *path, struct timeval *times)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1877,7 +1905,7 @@ nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1917,7 +1945,7 @@ nfs_access(struct nfs_context *nfs, const char *path, int mode)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1959,7 +1987,7 @@ nfs_access2(struct nfs_context *nfs, const char *path)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2001,7 +2029,7 @@ nfs_symlink(struct nfs_context *nfs, const char *target, const char *linkname)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2043,7 +2071,7 @@ nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2085,7 +2113,7 @@ nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath)
|
|||
{
|
||||
struct sync_cb_data cb_data;
|
||||
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2146,7 +2174,7 @@ nfs3_getacl(struct nfs_context *nfs, struct nfsfh *nfsfh,
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = acl;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2225,7 +2253,7 @@ nfs4_getacl(struct nfs_context *nfs, struct nfsfh *nfsfh,
|
|||
struct sync_cb_data cb_data;
|
||||
|
||||
cb_data.return_data = acl;
|
||||
if (nfs_init_cb_data(nfs, &cb_data)) {
|
||||
if (nfs_init_cb_data(&nfs, &cb_data)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
323
lib/libnfs.c
323
lib/libnfs.c
File diff suppressed because it is too large
Load Diff
|
@ -54,6 +54,13 @@
|
|||
#ifdef HAVE_MULTITHREADING
|
||||
|
||||
#ifdef HAVE_PTHREAD
|
||||
pid_t gettid(void);
|
||||
|
||||
nfs_tid_t nfs_mt_get_tid(void)
|
||||
{
|
||||
return gettid();
|
||||
}
|
||||
|
||||
static void *nfs_mt_service_thread(void *arg)
|
||||
{
|
||||
struct nfs_context *nfs = (struct nfs_context *)arg;
|
||||
|
@ -61,9 +68,9 @@ static void *nfs_mt_service_thread(void *arg)
|
|||
int revents;
|
||||
int ret;
|
||||
|
||||
nfs->multithreading_enabled = 1;
|
||||
nfs->nfsi->multithreading_enabled = 1;
|
||||
|
||||
while (nfs->multithreading_enabled) {
|
||||
while (nfs->nfsi->multithreading_enabled) {
|
||||
pfd.fd = nfs_get_fd(nfs);
|
||||
pfd.events = nfs_which_events(nfs);
|
||||
pfd.revents = 0;
|
||||
|
@ -85,12 +92,12 @@ static void *nfs_mt_service_thread(void *arg)
|
|||
|
||||
int nfs_mt_service_thread_start(struct nfs_context *nfs)
|
||||
{
|
||||
if (pthread_create(&nfs->service_thread, NULL,
|
||||
if (pthread_create(&nfs->nfsi->service_thread, NULL,
|
||||
&nfs_mt_service_thread, nfs)) {
|
||||
nfs_set_error(nfs, "Failed to start service thread");
|
||||
return -1;
|
||||
}
|
||||
while (nfs->multithreading_enabled == 0) {
|
||||
while (nfs->nfsi->multithreading_enabled == 0) {
|
||||
struct timespec ts = {0, 1000000};
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
|
@ -99,8 +106,8 @@ int nfs_mt_service_thread_start(struct nfs_context *nfs)
|
|||
|
||||
void nfs_mt_service_thread_stop(struct nfs_context *nfs)
|
||||
{
|
||||
nfs->multithreading_enabled = 0;
|
||||
pthread_join(nfs->service_thread, NULL);
|
||||
nfs->nfsi->multithreading_enabled = 0;
|
||||
pthread_join(nfs->nfsi->service_thread, NULL);
|
||||
}
|
||||
|
||||
int nfs_mt_mutex_init(libnfs_mutex_t *mutex)
|
||||
|
@ -146,6 +153,10 @@ int nfs_mt_sem_wait(libnfs_sem_t *sem)
|
|||
}
|
||||
|
||||
#elif WIN32
|
||||
nfs_tid_t nfs_mt_get_tid(void)
|
||||
{
|
||||
return GetCurrentThreadId();
|
||||
}
|
||||
static void* nfs_mt_service_thread(void* arg)
|
||||
{
|
||||
struct nfs_context* nfs = (struct nfs_context*)arg;
|
||||
|
@ -153,9 +164,9 @@ static void* nfs_mt_service_thread(void* arg)
|
|||
int revents;
|
||||
int ret;
|
||||
|
||||
nfs->multithreading_enabled = 1;
|
||||
nfs->nfsi->multithreading_enabled = 1;
|
||||
|
||||
while (nfs->multithreading_enabled) {
|
||||
while (nfs->nfsi->multithreading_enabled) {
|
||||
pfd.fd = nfs_get_fd(nfs);
|
||||
pfd.events = nfs_which_events(nfs);
|
||||
pfd.revents = 0;
|
||||
|
@ -193,12 +204,12 @@ static DWORD WINAPI service_thread_init(LPVOID lpParam)
|
|||
|
||||
int nfs_mt_service_thread_start(struct nfs_context* nfs)
|
||||
{
|
||||
nfs->service_thread = CreateThread(NULL, 1024*1024, service_thread_init, nfs, 0, NULL);
|
||||
if (nfs->service_thread == NULL) {
|
||||
nfs->nfsi->service_thread = CreateThread(NULL, 1024*1024, service_thread_init, nfs, 0, NULL);
|
||||
if (nfs->nfsi->service_thread == NULL) {
|
||||
nfs_set_error(nfs, "Failed to start service thread");
|
||||
return -1;
|
||||
}
|
||||
while (nfs->multithreading_enabled == 0) {
|
||||
while (nfs->nfsi->multithreading_enabled == 0) {
|
||||
Sleep(100);
|
||||
}
|
||||
return 0;
|
||||
|
@ -206,8 +217,8 @@ int nfs_mt_service_thread_start(struct nfs_context* nfs)
|
|||
|
||||
void nfs_mt_service_thread_stop(struct nfs_context* nfs)
|
||||
{
|
||||
nfs->multithreading_enabled = 0;
|
||||
while (WaitForSingleObject(nfs->service_thread, INFINITE) != WAIT_OBJECT_0);
|
||||
nfs->nfsi->multithreading_enabled = 0;
|
||||
while (WaitForSingleObject(nfs->nfsi->service_thread, INFINITE) != WAIT_OBJECT_0);
|
||||
}
|
||||
|
||||
int nfs_mt_mutex_init(libnfs_mutex_t* mutex)
|
||||
|
|
133
lib/nfs_v3.c
133
lib/nfs_v3.c
|
@ -192,8 +192,8 @@ nfs3_lookup_path_2_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
/* Handle absolute paths, ensuring that the path lies within the
|
||||
* export. */
|
||||
if (path[0] == '/') {
|
||||
if (strstr(path, nfs->export) == path) {
|
||||
char *ptr = path + strlen(nfs->export);
|
||||
if (strstr(path, nfs_get_export(nfs)) == path) {
|
||||
char *ptr = path + strlen(nfs_get_export(nfs));
|
||||
if (*ptr == '/') {
|
||||
newpath = strdup(ptr);
|
||||
} else if (*ptr == '\0') {
|
||||
|
@ -248,7 +248,7 @@ nfs3_lookup_path_2_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
}
|
||||
|
||||
data->path = data->saved_path;
|
||||
nfs3_lookup_path_async_internal(nfs, NULL, data, &nfs->rootfh);
|
||||
nfs3_lookup_path_async_internal(nfs, NULL, data, &nfs->nfsi->rootfh);
|
||||
return;
|
||||
|
||||
nomem:
|
||||
|
@ -459,7 +459,7 @@ nfs3_lookup_path_getattr_cb(struct rpc_context *rpc, int status,
|
|||
/* This function will always invoke the callback and cleanup
|
||||
* for failures. So no need to check the return value.
|
||||
*/
|
||||
nfs3_lookup_path_async_internal(nfs, &attr, data, &nfs->rootfh);
|
||||
nfs3_lookup_path_async_internal(nfs, &attr, data, &nfs->nfsi->rootfh);
|
||||
}
|
||||
|
||||
/* This function will free continue_data on error */
|
||||
|
@ -498,14 +498,14 @@ nfs3_lookuppath_async(struct nfs_context *nfs, const char *path, int no_follow,
|
|||
if (path[0] == '/') {
|
||||
data->saved_path = strdup(path);
|
||||
} else {
|
||||
data->saved_path = malloc(strlen(path) + strlen(nfs->cwd) + 2);
|
||||
data->saved_path = malloc(strlen(path) + strlen(nfs->nfsi->cwd) + 2);
|
||||
if (data->saved_path == NULL) {
|
||||
nfs_set_error(nfs, "Out of memory: failed to "
|
||||
"allocate path string");
|
||||
free_nfs_cb_data(data);
|
||||
return -1;
|
||||
}
|
||||
sprintf(data->saved_path, "%s/%s", nfs->cwd, path);
|
||||
sprintf(data->saved_path, "%s/%s", nfs->nfsi->cwd, path);
|
||||
}
|
||||
|
||||
if (data->saved_path == NULL) {
|
||||
|
@ -520,7 +520,7 @@ nfs3_lookuppath_async(struct nfs_context *nfs, const char *path, int no_follow,
|
|||
}
|
||||
|
||||
data->path = data->saved_path;
|
||||
fh = &nfs->rootfh;
|
||||
fh = &nfs->nfsi->rootfh;
|
||||
|
||||
if (data->path[0]) {
|
||||
struct nested_mounts *mnt;
|
||||
|
@ -531,7 +531,7 @@ nfs3_lookuppath_async(struct nfs_context *nfs, const char *path, int no_follow,
|
|||
size_t max_match_len = 0;
|
||||
|
||||
/* Do we need to switch to a different nested export ? */
|
||||
for (mnt = nfs->nested_mounts; mnt; mnt = mnt->next) {
|
||||
for (mnt = nfs->nfsi->nested_mounts; mnt; mnt = mnt->next) {
|
||||
if (strlen(mnt->path) < max_match_len)
|
||||
continue;
|
||||
if (strncmp(mnt->path, data->saved_path,
|
||||
|
@ -620,7 +620,7 @@ nfs3_mount_7_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
return;
|
||||
}
|
||||
|
||||
if (!nfs->nested_mounts)
|
||||
if (!nfs->nfsi->nested_mounts)
|
||||
goto finished;
|
||||
|
||||
/* nested mount traversals are best-effort only, so any
|
||||
|
@ -633,7 +633,7 @@ nfs3_mount_7_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
memset(ma, 0, sizeof(struct mount_attr_cb));
|
||||
ma->data = data;
|
||||
|
||||
for(mnt = nfs->nested_mounts; mnt; mnt = mnt->next) {
|
||||
for(mnt = nfs->nfsi->nested_mounts; mnt; mnt = mnt->next) {
|
||||
struct mount_attr_item_cb *ma_item;
|
||||
struct GETATTR3args args;
|
||||
|
||||
|
@ -685,7 +685,7 @@ nfs3_mount_6_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
|
||||
if (res->status != NFS3_OK) {
|
||||
nfs_set_error(nfs, "NFS: FSINFO of %s failed with %s(%d)",
|
||||
nfs->export, nfsstat3_to_str(res->status),
|
||||
nfs_get_export(nfs), nfsstat3_to_str(res->status),
|
||||
nfsstat3_to_errno(res->status));
|
||||
data->cb(nfsstat3_to_errno(res->status), nfs,
|
||||
nfs_get_error(nfs), data->private_data);
|
||||
|
@ -693,35 +693,35 @@ nfs3_mount_6_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
return;
|
||||
}
|
||||
|
||||
nfs->readmax = res->FSINFO3res_u.resok.rtmax;
|
||||
nfs->writemax = res->FSINFO3res_u.resok.wtmax;
|
||||
nfs->nfsi->readmax = res->FSINFO3res_u.resok.rtmax;
|
||||
nfs->nfsi->writemax = res->FSINFO3res_u.resok.wtmax;
|
||||
|
||||
/* The server supports sizes up to rtmax and wtmax, so it is legal
|
||||
* to use smaller transfers sizes.
|
||||
*/
|
||||
if (nfs->readmax > NFS_MAX_XFER_SIZE)
|
||||
nfs->readmax = NFS_MAX_XFER_SIZE;
|
||||
else if (nfs->readmax < NFSMAXDATA2) {
|
||||
if (nfs->nfsi->readmax > NFS_MAX_XFER_SIZE)
|
||||
nfs->nfsi->readmax = NFS_MAX_XFER_SIZE;
|
||||
else if (nfs->nfsi->readmax < NFSMAXDATA2) {
|
||||
nfs_set_error(nfs, "server max rsize of %" PRIu64,
|
||||
nfs->readmax);
|
||||
nfs->nfsi->readmax);
|
||||
data->cb(-EINVAL, nfs, nfs_get_error(nfs), data->private_data);
|
||||
free_nfs_cb_data(data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nfs->writemax > NFS_MAX_XFER_SIZE)
|
||||
nfs->writemax = NFS_MAX_XFER_SIZE;
|
||||
else if (nfs->writemax < NFSMAXDATA2) {
|
||||
if (nfs->nfsi->writemax > NFS_MAX_XFER_SIZE)
|
||||
nfs->nfsi->writemax = NFS_MAX_XFER_SIZE;
|
||||
else if (nfs->nfsi->writemax < NFSMAXDATA2) {
|
||||
nfs_set_error(nfs, "server max wsize of %" PRIu64,
|
||||
nfs->writemax);
|
||||
nfs->nfsi->writemax);
|
||||
data->cb(-EINVAL, nfs, nfs_get_error(nfs), data->private_data);
|
||||
free_nfs_cb_data(data);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&args, 0, sizeof(GETATTR3args));
|
||||
args.object.data.data_len = nfs->rootfh.len;
|
||||
args.object.data.data_val = nfs->rootfh.val;
|
||||
args.object.data.data_len = nfs->nfsi->rootfh.len;
|
||||
args.object.data.data_val = nfs->nfsi->rootfh.val;
|
||||
|
||||
if (rpc_nfs3_getattr_async(rpc, nfs3_mount_7_cb, &args, data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s", __FUNCTION__, nfs_get_error(nfs));
|
||||
|
@ -749,10 +749,10 @@ nfs3_mount_5_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
/* NFS TCP: As we are connected now we can pass on the auto-reconnect
|
||||
* settings to the RPC layer.
|
||||
*/
|
||||
rpc_set_autoreconnect(rpc, nfs->auto_reconnect);
|
||||
rpc_set_autoreconnect(rpc, nfs->nfsi->auto_reconnect);
|
||||
|
||||
args.fsroot.data.data_len = nfs->rootfh.len;
|
||||
args.fsroot.data.data_val = nfs->rootfh.val;
|
||||
args.fsroot.data.data_len = nfs->nfsi->rootfh.len;
|
||||
args.fsroot.data.data_val = nfs->nfsi->rootfh.val;
|
||||
if (rpc_nfs3_fsinfo_async(rpc, nfs3_mount_6_cb, &args, data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s", __FUNCTION__, nfs_get_error(nfs));
|
||||
data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data);
|
||||
|
@ -836,7 +836,7 @@ nfs3_mount_4_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
mnt->path = md_item_cb->path;
|
||||
md_item_cb->path = NULL;
|
||||
|
||||
LIBNFS_LIST_ADD(&nfs->nested_mounts, mnt);
|
||||
LIBNFS_LIST_ADD(&nfs->nfsi->nested_mounts, mnt);
|
||||
|
||||
finished:
|
||||
free(md_item_cb->path);
|
||||
|
@ -861,8 +861,9 @@ finished:
|
|||
return;
|
||||
}
|
||||
|
||||
if (nfs->nfsport) {
|
||||
if (rpc_connect_port_async(nfs->rpc, nfs->server, nfs->nfsport,
|
||||
if (nfs->nfsi->nfsport) {
|
||||
if (rpc_connect_port_async(nfs->rpc, nfs_get_server(nfs),
|
||||
nfs->nfsi->nfsport,
|
||||
NFS_PROGRAM, NFS_V3,
|
||||
nfs3_mount_5_cb, data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s", __FUNCTION__,
|
||||
|
@ -876,7 +877,8 @@ finished:
|
|||
return;
|
||||
}
|
||||
|
||||
if (rpc_connect_program_async(nfs->rpc, nfs->server, NFS_PROGRAM,
|
||||
if (rpc_connect_program_async(nfs->rpc, nfs_get_server(nfs),
|
||||
NFS_PROGRAM,
|
||||
NFS_V3, nfs3_mount_5_cb, data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s", __FUNCTION__, nfs_get_error(nfs));
|
||||
data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data);
|
||||
|
@ -907,7 +909,7 @@ nfs3_mount_3_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
/* Iterate over all exports and check if there are any mounts nested
|
||||
* below the current mount.
|
||||
*/
|
||||
len = strlen(nfs->export);
|
||||
len = strlen(nfs_get_export(nfs));
|
||||
if (!len) {
|
||||
data->cb(-EFAULT, nfs, "Export is empty", data->private_data);
|
||||
free_nfs_cb_data(data);
|
||||
|
@ -917,7 +919,7 @@ nfs3_mount_3_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
while (res) {
|
||||
struct mount_discovery_item_cb *md_item_cb;
|
||||
|
||||
if (strncmp(nfs->export, res->ex_dir, len)) {
|
||||
if (strncmp(nfs_get_export(nfs), res->ex_dir, len)) {
|
||||
res = res->ex_next;
|
||||
continue;
|
||||
}
|
||||
|
@ -938,7 +940,7 @@ nfs3_mount_3_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
memset(md_item_cb, 0, sizeof(*md_item_cb));
|
||||
|
||||
md_item_cb->path = strdup(res->ex_dir + len
|
||||
- (nfs->export[len -1] == '/'));
|
||||
- (nfs_get_export(nfs)[len -1] == '/'));
|
||||
if (md_item_cb->path == NULL) {
|
||||
free(md_item_cb);
|
||||
continue;
|
||||
|
@ -983,8 +985,9 @@ nfs3_mount_3_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
*/
|
||||
rpc_disconnect(rpc, "normal disconnect");
|
||||
|
||||
if (nfs->nfsport) {
|
||||
if (rpc_connect_port_async(nfs->rpc, nfs->server, nfs->nfsport,
|
||||
if (nfs->nfsi->nfsport) {
|
||||
if (rpc_connect_port_async(nfs->rpc, nfs_get_server(nfs),
|
||||
nfs->nfsi->nfsport,
|
||||
NFS_PROGRAM, NFS_V3,
|
||||
nfs3_mount_5_cb, data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s", __FUNCTION__,
|
||||
|
@ -997,7 +1000,8 @@ nfs3_mount_3_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
return;
|
||||
}
|
||||
|
||||
if (rpc_connect_program_async(nfs->rpc, nfs->server, NFS_PROGRAM,
|
||||
if (rpc_connect_program_async(nfs->rpc, nfs_get_server(nfs),
|
||||
NFS_PROGRAM,
|
||||
NFS_V3, nfs3_mount_5_cb, data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s", __FUNCTION__, nfs_get_error(nfs));
|
||||
data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data);
|
||||
|
@ -1035,19 +1039,19 @@ nfs3_mount_2_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
return;
|
||||
}
|
||||
|
||||
nfs->rootfh.len = res->mountres3_u.mountinfo.fhandle.fhandle3_len;
|
||||
nfs->rootfh.val = malloc(nfs->rootfh.len);
|
||||
if (nfs->rootfh.val == NULL) {
|
||||
nfs->nfsi->rootfh.len = res->mountres3_u.mountinfo.fhandle.fhandle3_len;
|
||||
nfs->nfsi->rootfh.val = malloc(nfs->nfsi->rootfh.len);
|
||||
if (nfs->nfsi->rootfh.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_nfs_cb_data(data);
|
||||
return;
|
||||
}
|
||||
memcpy(nfs->rootfh.val,
|
||||
memcpy(nfs->nfsi->rootfh.val,
|
||||
res->mountres3_u.mountinfo.fhandle.fhandle3_val,
|
||||
nfs->rootfh.len);
|
||||
nfs->nfsi->rootfh.len);
|
||||
|
||||
if (nfs->auto_traverse_mounts) {
|
||||
if (nfs->nfsi->auto_traverse_mounts) {
|
||||
if (rpc_mount3_export_async(rpc, nfs3_mount_3_cb, data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s", __FUNCTION__,
|
||||
nfs_get_error(nfs));
|
||||
|
@ -1060,8 +1064,9 @@ nfs3_mount_2_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
}
|
||||
|
||||
rpc_disconnect(rpc, "normal disconnect");
|
||||
if (nfs->nfsport) {
|
||||
if (rpc_connect_port_async(nfs->rpc, nfs->server, nfs->nfsport,
|
||||
if (nfs->nfsi->nfsport) {
|
||||
if (rpc_connect_port_async(nfs->rpc, nfs_get_server(nfs),
|
||||
nfs->nfsi->nfsport,
|
||||
NFS_PROGRAM, NFS_V3,
|
||||
nfs3_mount_5_cb, data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s", __FUNCTION__,
|
||||
|
@ -1074,7 +1079,8 @@ nfs3_mount_2_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
return;
|
||||
}
|
||||
|
||||
if (rpc_connect_program_async(nfs->rpc, nfs->server, NFS_PROGRAM,
|
||||
if (rpc_connect_program_async(nfs->rpc, nfs_get_server(nfs),
|
||||
NFS_PROGRAM,
|
||||
NFS_V3, nfs3_mount_5_cb, data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s", __FUNCTION__, nfs_get_error(nfs));
|
||||
data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data);
|
||||
|
@ -1098,7 +1104,7 @@ nfs3_mount_1_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
return;
|
||||
}
|
||||
|
||||
if (rpc_mount3_mnt_async(rpc, nfs3_mount_2_cb, nfs->export,
|
||||
if (rpc_mount3_mnt_async(rpc, nfs3_mount_2_cb, nfs->nfsi->export,
|
||||
data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s.", __FUNCTION__, nfs_get_error(nfs));
|
||||
data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data);
|
||||
|
@ -1123,20 +1129,20 @@ nfs3_mount_async(struct nfs_context *nfs, const char *server,
|
|||
memset(data, 0, sizeof(struct nfs_cb_data));
|
||||
new_server = strdup(server);
|
||||
new_export = strdup(export);
|
||||
if (nfs->server != NULL) {
|
||||
free(nfs->server);
|
||||
if (nfs->nfsi->server != NULL) {
|
||||
free(nfs->nfsi->server);
|
||||
}
|
||||
nfs->server = new_server;
|
||||
if (nfs->export != NULL) {
|
||||
free(nfs->export);
|
||||
nfs->nfsi->server = new_server;
|
||||
if (nfs->nfsi->export != NULL) {
|
||||
free(nfs->nfsi->export);
|
||||
}
|
||||
nfs->export = new_export;
|
||||
nfs->nfsi->export = new_export;
|
||||
data->nfs = nfs;
|
||||
data->cb = cb;
|
||||
data->private_data = private_data;
|
||||
|
||||
if (nfs->mountport) {
|
||||
if (rpc_connect_port_async(nfs->rpc, server, nfs->mountport,
|
||||
if (nfs->nfsi->mountport) {
|
||||
if (rpc_connect_port_async(nfs->rpc, server, nfs->nfsi->mountport,
|
||||
MOUNT_PROGRAM, MOUNT_V3,
|
||||
nfs3_mount_1_cb, data) != 0) {
|
||||
nfs_set_error(nfs, "Failed to start connection. %s",
|
||||
|
@ -1192,7 +1198,7 @@ nfs3_umount_1_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
return;
|
||||
}
|
||||
|
||||
if (rpc_mount3_umnt_async(rpc, nfs3_umount_2_cb, nfs->export,
|
||||
if (rpc_mount3_umnt_async(rpc, nfs3_umount_2_cb, nfs->nfsi->export,
|
||||
data) != 0) {
|
||||
nfs_set_error(nfs, "%s: %s.", __FUNCTION__, nfs_get_error(nfs));
|
||||
data->cb(-ENOMEM, nfs, nfs_get_error(nfs), data->private_data);
|
||||
|
@ -1220,9 +1226,9 @@ nfs3_umount_async(struct nfs_context *nfs, nfs_cb cb, void *private_data)
|
|||
|
||||
rpc_disconnect(nfs->rpc, "umount");
|
||||
|
||||
if (nfs->mountport) {
|
||||
if (rpc_connect_port_async(nfs->rpc, nfs->server,
|
||||
nfs->mountport,
|
||||
if (nfs->nfsi->mountport) {
|
||||
if (rpc_connect_port_async(nfs->rpc, nfs_get_server(nfs),
|
||||
nfs->nfsi->mountport,
|
||||
MOUNT_PROGRAM, MOUNT_V3,
|
||||
nfs3_umount_1_cb, data) != 0) {
|
||||
nfs_set_error(nfs, "Failed to start connection. %s",
|
||||
|
@ -1233,7 +1239,7 @@ nfs3_umount_async(struct nfs_context *nfs, nfs_cb cb, void *private_data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (rpc_connect_program_async(nfs->rpc, nfs->server,
|
||||
if (rpc_connect_program_async(nfs->rpc, nfs_get_server(nfs),
|
||||
MOUNT_PROGRAM, MOUNT_V3,
|
||||
nfs3_umount_1_cb, data) != 0) {
|
||||
nfs_set_error(nfs, "Failed to start connection. %s",
|
||||
|
@ -2927,7 +2933,7 @@ nfs3_opendir_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
splen = 0;
|
||||
|
||||
/* No name attributes. Is it a nested mount then?*/
|
||||
for(mnt = nfs->nested_mounts; mnt; mnt = mnt->next) {
|
||||
for(mnt = nfs->nfsi->nested_mounts; mnt; mnt = mnt->next) {
|
||||
if (strncmp(data->saved_path, mnt->path, splen))
|
||||
continue;
|
||||
if (mnt->path[splen] != '/')
|
||||
|
@ -4977,8 +4983,11 @@ nfs3_chdir_continue_internal(struct nfs_context *nfs,
|
|||
struct nfs_cb_data *data)
|
||||
{
|
||||
/* steal saved_path */
|
||||
free(nfs->cwd);
|
||||
nfs->cwd = data->saved_path;
|
||||
nfs_mt_mutex_lock(&nfs->rpc->rpc_mutex);
|
||||
free(nfs->nfsi->cwd);
|
||||
nfs->nfsi->cwd = data->saved_path;
|
||||
nfs_mt_mutex_unlock(&nfs->rpc->rpc_mutex);
|
||||
|
||||
data->saved_path = NULL;
|
||||
|
||||
data->cb(0, nfs, NULL, data->private_data);
|
||||
|
|
90
lib/nfs_v4.c
90
lib/nfs_v4.c
|
@ -223,9 +223,9 @@ nfs4_resolve_path(struct nfs_context *nfs, const char *path)
|
|||
if (path[0] == '/') {
|
||||
new_path = strdup(path);
|
||||
} else {
|
||||
new_path = malloc(strlen(path) + strlen(nfs->cwd) + 2);
|
||||
new_path = malloc(strlen(path) + strlen(nfs->nfsi->cwd) + 2);
|
||||
if (new_path != NULL) {
|
||||
sprintf(new_path, "%s/%s", nfs->cwd, path);
|
||||
sprintf(new_path, "%s/%s", nfs->nfsi->cwd, path);
|
||||
}
|
||||
}
|
||||
if (new_path == NULL) {
|
||||
|
@ -651,7 +651,7 @@ nfs4_op_release_lockowner(struct nfs_context *nfs, nfs_argop4 *op, struct nfsfh
|
|||
op->argop = OP_RELEASE_LOCKOWNER;
|
||||
rlargs = &op->nfs_argop4_u.oprelease_lockowner;
|
||||
|
||||
rlargs->lock_owner.clientid = nfs->clientid;
|
||||
rlargs->lock_owner.clientid = nfs->nfsi->clientid;
|
||||
rlargs->lock_owner.owner.owner_len = 4;
|
||||
rlargs->lock_owner.owner.owner_val = (char *)&fh->lock_owner;
|
||||
|
||||
|
@ -963,7 +963,7 @@ nfs4_op_lock(struct nfs_context *nfs, nfs_argop4 *op, struct nfsfh *fh,
|
|||
largs->offset = offset;
|
||||
largs->length = length;
|
||||
|
||||
if (nfs->has_lock_owner) {
|
||||
if (nfs->nfsi->has_lock_owner) {
|
||||
largs->locker.new_lock_owner = 0;
|
||||
largs->locker.locker4_u.lock_owner.lock_stateid.seqid =
|
||||
fh->lock_stateid.seqid;
|
||||
|
@ -980,11 +980,11 @@ nfs4_op_lock(struct nfs_context *nfs, nfs_argop4 *op, struct nfsfh *fh,
|
|||
memcpy(largs->locker.locker4_u.open_owner.open_stateid.other,
|
||||
fh->stateid.other, 12);
|
||||
largs->locker.locker4_u.open_owner.lock_owner.clientid =
|
||||
nfs->clientid;
|
||||
nfs->nfsi->clientid;
|
||||
largs->locker.locker4_u.open_owner.lock_owner.owner.owner_len =
|
||||
strlen(nfs->client_name);
|
||||
strlen(nfs->nfsi->client_name);
|
||||
largs->locker.locker4_u.open_owner.lock_owner.owner.owner_val =
|
||||
nfs->client_name;
|
||||
nfs->nfsi->client_name;
|
||||
largs->locker.locker4_u.open_owner.lock_seqid =
|
||||
fh->lock_seqid;
|
||||
}
|
||||
|
@ -1026,9 +1026,9 @@ nfs4_op_lockt(struct nfs_context *nfs, nfs_argop4 *op, struct nfsfh *fh,
|
|||
ltargs->offset = offset;
|
||||
ltargs->length = length;
|
||||
|
||||
ltargs->owner.clientid = nfs->clientid;
|
||||
ltargs->owner.owner.owner_len = strlen(nfs->client_name);
|
||||
ltargs->owner.owner.owner_val = nfs->client_name;
|
||||
ltargs->owner.clientid = nfs->nfsi->clientid;
|
||||
ltargs->owner.owner.owner_len = strlen(nfs->nfsi->client_name);
|
||||
ltargs->owner.owner.owner_val = nfs->nfsi->client_name;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1133,11 +1133,11 @@ nfs4_allocate_op(struct nfs_context *nfs, nfs_argop4 **op,
|
|||
}
|
||||
|
||||
i = 0;
|
||||
if (nfs->rootfh.len) {
|
||||
if (nfs->nfsi->rootfh.len) {
|
||||
struct nfsfh fh;
|
||||
|
||||
fh.fh.len = nfs->rootfh.len;
|
||||
fh.fh.val = nfs->rootfh.val;
|
||||
fh.fh.len = nfs->nfsi->rootfh.len;
|
||||
fh.fh.val = nfs->nfsi->rootfh.val;
|
||||
i += nfs4_op_putfh(nfs, &(*op)[i], &fh);
|
||||
} else {
|
||||
i += nfs4_op_putrootfh(nfs, &(*op)[i]);
|
||||
|
@ -1497,17 +1497,17 @@ nfs4_mount_4_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
}
|
||||
gfhresok = &res->resarray.resarray_val[i].nfs_resop4_u.opgetfh.GETFH4res_u.resok4;
|
||||
|
||||
nfs->rootfh.len = gfhresok->object.nfs_fh4_len;
|
||||
nfs->rootfh.val = malloc(nfs->rootfh.len);
|
||||
if (nfs->rootfh.val == NULL) {
|
||||
nfs->nfsi->rootfh.len = gfhresok->object.nfs_fh4_len;
|
||||
nfs->nfsi->rootfh.val = malloc(nfs->nfsi->rootfh.len);
|
||||
if (nfs->nfsi->rootfh.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(nfs->rootfh.val,
|
||||
memcpy(nfs->nfsi->rootfh.val,
|
||||
gfhresok->object.nfs_fh4_val,
|
||||
nfs->rootfh.len);
|
||||
nfs->nfsi->rootfh.len);
|
||||
|
||||
|
||||
data->cb(0, nfs, NULL, data->private_data);
|
||||
|
@ -1567,15 +1567,15 @@ nfs4_mount_2_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
}
|
||||
|
||||
scidresok = &res->resarray.resarray_val[0].nfs_resop4_u.opsetclientid.SETCLIENTID4res_u.resok4;
|
||||
nfs->clientid = scidresok->clientid;
|
||||
memcpy(nfs->setclientid_confirm,
|
||||
nfs->nfsi->clientid = scidresok->clientid;
|
||||
memcpy(nfs->nfsi->setclientid_confirm,
|
||||
scidresok->setclientid_confirm,
|
||||
NFS4_VERIFIER_SIZE);
|
||||
|
||||
memset(op, 0, sizeof(op));
|
||||
|
||||
i = nfs4_op_setclientid_confirm(nfs, &op[0], nfs->clientid,
|
||||
nfs->setclientid_confirm);
|
||||
i = nfs4_op_setclientid_confirm(nfs, &op[0], nfs->nfsi->clientid,
|
||||
nfs->nfsi->setclientid_confirm);
|
||||
|
||||
memset(&args, 0, sizeof(args));
|
||||
args.argarray.argarray_len = i;
|
||||
|
@ -1609,7 +1609,7 @@ nfs4_mount_1_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
|
||||
memset(op, 0, sizeof(op));
|
||||
|
||||
i = nfs4_op_setclientid(nfs, &op[0], nfs->verifier, nfs->client_name);
|
||||
i = nfs4_op_setclientid(nfs, &op[0], nfs->nfsi->verifier, nfs->nfsi->client_name);
|
||||
|
||||
memset(&args, 0, sizeof(args));
|
||||
args.argarray.argarray_len = i;
|
||||
|
@ -1633,8 +1633,8 @@ nfs4_mount_async(struct nfs_context *nfs, const char *server,
|
|||
int port;
|
||||
|
||||
new_server = strdup(server);
|
||||
free(nfs->server);
|
||||
nfs->server = new_server;
|
||||
free(nfs->nfsi->server);
|
||||
nfs->nfsi->server = new_server;
|
||||
|
||||
new_export = strdup(export);
|
||||
if (nfs_normalize_path(nfs, new_export)) {
|
||||
|
@ -1643,8 +1643,8 @@ nfs4_mount_async(struct nfs_context *nfs, const char *server,
|
|||
free(new_export);
|
||||
return -1;
|
||||
}
|
||||
free(nfs->export);
|
||||
nfs->export = new_export;
|
||||
free(nfs->nfsi->export);
|
||||
nfs->nfsi->export = new_export;
|
||||
|
||||
|
||||
data = malloc(sizeof(*data));
|
||||
|
@ -1660,7 +1660,7 @@ nfs4_mount_async(struct nfs_context *nfs, const char *server,
|
|||
data->private_data = private_data;
|
||||
data->path = strdup(new_export);
|
||||
|
||||
port = nfs->nfsport ? nfs->nfsport : 2049;
|
||||
port = nfs->nfsi->nfsport ? nfs->nfsi->nfsport : 2049;
|
||||
if (rpc_connect_port_async(nfs->rpc, server, port,
|
||||
NFS4_PROGRAM, NFS_V4,
|
||||
nfs4_mount_1_cb, data) != 0) {
|
||||
|
@ -1687,8 +1687,11 @@ nfs4_chdir_1_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
}
|
||||
|
||||
/* Ok, all good. Lets steal the path string. */
|
||||
free(nfs->cwd);
|
||||
nfs->cwd = data->path;
|
||||
nfs_mt_mutex_lock(&nfs->rpc->rpc_mutex);
|
||||
free(nfs->nfsi->cwd);
|
||||
nfs->nfsi->cwd = data->path;
|
||||
nfs_mt_mutex_unlock(&nfs->rpc->rpc_mutex);
|
||||
|
||||
data->path = NULL;
|
||||
|
||||
data->cb(0, nfs, NULL, data->private_data);
|
||||
|
@ -2248,7 +2251,7 @@ nfs4_populate_open(struct nfs4_cb_data *data, nfs_argop4 *op)
|
|||
oargs->share_access |= OPEN4_SHARE_ACCESS_WRITE;
|
||||
}
|
||||
oargs->share_deny = OPEN4_SHARE_DENY_NONE;
|
||||
oargs->owner.clientid = nfs->clientid;
|
||||
oargs->owner.clientid = nfs->nfsi->clientid;
|
||||
oargs->owner.owner.owner_len = 4;
|
||||
oargs->owner.owner.owner_val = (char *)&data->lock_owner;
|
||||
oargs->seqid = 0;
|
||||
|
@ -2343,12 +2346,13 @@ nfs4_open_readlink_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
data_split_path(data);
|
||||
|
||||
#ifdef HAVE_MULTITHREADING
|
||||
nfs_mt_mutex_lock(&data->nfs->nfs4_open_mutex);
|
||||
#endif
|
||||
data->lock_owner = nfs->open_counter++;
|
||||
#ifdef HAVE_MULTITHREADING
|
||||
nfs_mt_mutex_unlock(&data->nfs->nfs4_open_mutex);
|
||||
nfs_mt_mutex_lock(&data->nfs->nfsi->nfs4_open_mutex);
|
||||
data->lock_owner = nfs->nfsi->open_counter++;
|
||||
nfs_mt_mutex_unlock(&data->nfs->nfsi->nfs4_open_mutex);
|
||||
#else
|
||||
data->lock_owner = nfs->nfsi->open_counter++;
|
||||
#endif
|
||||
|
||||
data->filler.func = nfs4_populate_open;
|
||||
data->filler.max_op = 3;
|
||||
|
||||
|
@ -2466,11 +2470,11 @@ nfs4_open_async_internal(struct nfs_context *nfs, struct nfs4_cb_data *data,
|
|||
}
|
||||
|
||||
#ifdef HAVE_MULTITHREADING
|
||||
nfs_mt_mutex_lock(&data->nfs->nfs4_open_mutex);
|
||||
nfs_mt_mutex_lock(&data->nfs->nfsi->nfs4_open_mutex);
|
||||
#endif
|
||||
data->lock_owner = nfs->open_counter++;
|
||||
data->lock_owner = nfs->nfsi->open_counter++;
|
||||
#ifdef HAVE_MULTITHREADING
|
||||
nfs_mt_mutex_unlock(&data->nfs->nfs4_open_mutex);
|
||||
nfs_mt_mutex_unlock(&data->nfs->nfsi->nfs4_open_mutex);
|
||||
#endif
|
||||
data->filler.func = nfs4_populate_open;
|
||||
data->filler.max_op = 3;
|
||||
|
@ -4156,7 +4160,7 @@ nfs4_lockf_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
}
|
||||
|
||||
lresok = &res->resarray.resarray_val[i].nfs_resop4_u.oplock.LOCK4res_u.resok4;
|
||||
nfs->has_lock_owner = 1;
|
||||
nfs->nfsi->has_lock_owner = 1;
|
||||
fh->lock_stateid.seqid = lresok->lock_stateid.seqid;
|
||||
memcpy(fh->lock_stateid.other, lresok->lock_stateid.other, 12);
|
||||
break;
|
||||
|
@ -4275,7 +4279,7 @@ nfs4_fcntl_cb(struct rpc_context *rpc, int status, void *command_data,
|
|||
}
|
||||
|
||||
lresok = &res->resarray.resarray_val[i].nfs_resop4_u.oplock.LOCK4res_u.resok4;
|
||||
nfs->has_lock_owner = 1;
|
||||
nfs->nfsi->has_lock_owner = 1;
|
||||
fh->lock_stateid.seqid = lresok->lock_stateid.seqid;
|
||||
memcpy(fh->lock_stateid.other,
|
||||
lresok->lock_stateid.other, 12);
|
||||
|
@ -4700,8 +4704,8 @@ nfs4_statvfs_async_internal(struct nfs_context *nfs, const char *path,
|
|||
data->flags |= LOOKUP_FLAG_IS_STATVFS64;
|
||||
}
|
||||
|
||||
fh.fh.len = nfs->rootfh.len;
|
||||
fh.fh.val = nfs->rootfh.val;
|
||||
fh.fh.len = nfs->nfsi->rootfh.len;
|
||||
fh.fh.val = nfs->nfsi->rootfh.val;
|
||||
|
||||
i = nfs4_op_putfh(nfs, &op[0], &fh);
|
||||
i += nfs4_op_getattr(nfs, &op[i], statvfs_attributes, 2);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<ProjectOutputs>
|
||||
<ProjectOutput>
|
||||
<FullPath>C:\Users\User\source\repos\sahlberg\libnfs\win32\libnfs\x64\Debug\libnfs.dll</FullPath>
|
||||
</ProjectOutput>
|
||||
</ProjectOutputs>
|
||||
<ContentFiles />
|
||||
<SatelliteDlls />
|
||||
<NonRecipeFileRefs />
|
||||
</Project>
|
Loading…
Reference in New Issue