We need to pass a filehandle back for open(O_TRUNC) or else the app will
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 3 Feb 2014 01:39:04 +0000 (17:39 -0800)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 3 Feb 2014 01:39:04 +0000 (17:39 -0800)
be unhappy

lib/libnfs.c

index c2c20d4481b20945e8f30e3f8b2f28aef020a2bb..68e0d0343baa3a9fe0807a20f18ed19dead24be6 100644 (file)
@@ -1247,6 +1247,7 @@ static void nfs_open_trunc_cb(struct rpc_context *rpc, int status, void *command
 {
        struct nfs_cb_data *data = private_data;
        struct nfs_context *nfs = data->nfs;
+       struct nfsfh *nfsfh;
        SETATTR3res *res;
 
        assert(rpc->magic == RPC_CONTEXT_MAGIC);
@@ -1270,7 +1271,24 @@ static void nfs_open_trunc_cb(struct rpc_context *rpc, int status, void *command
                return;
        }
 
-       data->cb(0, nfs, NULL, data->private_data);
+       nfsfh = malloc(sizeof(struct nfsfh));
+       if (nfsfh == NULL) {
+               rpc_set_error(nfs->rpc, "NFS: Failed to allocate nfsfh structure");
+               data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
+               free_nfs_cb_data(data);
+               return;
+       }
+       memset(nfsfh, 0, sizeof(struct nfsfh));
+
+       if (data->continue_int & O_SYNC) {
+               nfsfh->is_sync = 1;
+       }
+
+       /* steal the filehandle */
+       nfsfh->fh = data->fh;
+       data->fh.data.data_val = NULL;
+
+       data->cb(0, nfs, nfsfh, data->private_data);
        free_nfs_cb_data(data);
 }
 
@@ -1327,30 +1345,13 @@ static void nfs_open_cb(struct rpc_context *rpc, int status, void *command_data,
                return;
        }
 
-       nfsfh = malloc(sizeof(struct nfsfh));
-       if (nfsfh == NULL) {
-               rpc_set_error(nfs->rpc, "NFS: Failed to allocate nfsfh structure");
-               data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
-               free_nfs_cb_data(data);
-               return;
-       }
-       memset(nfsfh, 0, sizeof(struct nfsfh));
-
-       if (data->continue_int & O_SYNC) {
-               nfsfh->is_sync = 1;
-       }
-
-       /* steal the filehandle */
-       nfsfh->fh = data->fh;
-       data->fh.data.data_val = NULL;
-
        /* Try to truncate it if we were requested to */
        if ((data->continue_int & O_TRUNC) &&
            (data->continue_int & (O_RDWR|O_WRONLY))) {
                SETATTR3args args;
 
                memset(&args, 0, sizeof(SETATTR3args));
-               args.object = nfsfh->fh;
+               args.object = data->fh;
                args.new_attributes.size.set_it = 1;
                args.new_attributes.size.set_size3_u.size = 0;
 
@@ -1366,6 +1367,23 @@ static void nfs_open_cb(struct rpc_context *rpc, int status, void *command_data,
                return;
        }
 
+       nfsfh = malloc(sizeof(struct nfsfh));
+       if (nfsfh == NULL) {
+               rpc_set_error(nfs->rpc, "NFS: Failed to allocate nfsfh structure");
+               data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
+               free_nfs_cb_data(data);
+               return;
+       }
+       memset(nfsfh, 0, sizeof(struct nfsfh));
+
+       if (data->continue_int & O_SYNC) {
+               nfsfh->is_sync = 1;
+       }
+
+       /* steal the filehandle */
+       nfsfh->fh = data->fh;
+       data->fh.data.data_val = NULL;
+
        data->cb(0, nfs, nfsfh, data->private_data);
        free_nfs_cb_data(data);
 }