Add MKNOD command support
[deb_libnfs.git] / lib / libnfs-sync.c
index 97d5a611247d585c8c596cc9e275ad8a4e3d39e4..701cd0678a747716d514227a590f8d786ca2975a 100644 (file)
@@ -105,19 +105,6 @@ static void wait_for_nfs_reply(struct nfs_context *nfs, struct sync_cb_data *cb_
                        cb_data->status = -EIO;
                        break;
                }
-               if (nfs_get_fd(nfs) == -1) {
-                       char *server = strdup(nfs_get_server(nfs));
-                       char *export = strdup(nfs_get_export(nfs));
-
-                       if (nfs_mount(nfs, server, export) != 0) {
-                               nfs_set_error(nfs, "Failed to reconnect to nfs server %s", nfs_get_error(nfs));
-                               free(server);
-                               free(export);
-                               break;
-                       }
-                       free(server);
-                       free(export);
-               }
        }
 }
 
@@ -145,6 +132,7 @@ static void mount_cb(int status, struct nfs_context *nfs, void *data, void *priv
 int nfs_mount(struct nfs_context *nfs, const char *server, const char *export)
 {
        struct sync_cb_data cb_data;
+       struct rpc_context *rpc = nfs_get_rpc_context(nfs);
 
        cb_data.is_finished = 0;
 
@@ -155,6 +143,9 @@ int nfs_mount(struct nfs_context *nfs, const char *server, const char *export)
 
        wait_for_nfs_reply(nfs, &cb_data);
 
+       /* Dont want any more callbacks even if the socket is closed */
+       rpc->connect_cb = NULL;
+
        return cb_data.status;
 }
 
@@ -585,7 +576,37 @@ int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh
        return cb_data.status;
 }
 
+/*
+ * mknod()
+ */
+static void mknod_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
+{
+       struct sync_cb_data *cb_data = private_data;
 
+       cb_data->is_finished = 1;
+       cb_data->status = status;
+
+       if (status < 0) {
+               nfs_set_error(nfs, "mknod call failed with \"%s\"", (char *)data);
+               return;
+       }
+}
+
+int nfs_mknod(struct nfs_context *nfs, const char *path, int mode, int dev)
+{
+       struct sync_cb_data cb_data;
+
+       cb_data.is_finished = 0;
+
+       if (nfs_mknod_async(nfs, path, mode, dev, mknod_cb, &cb_data) != 0) {
+               nfs_set_error(nfs, "nfs_creat_async failed");
+               return -1;
+       }
+
+       wait_for_nfs_reply(nfs, &cb_data);
+
+       return cb_data.status;
+}
 
 
 /*