diff mbox

[3/8] nfsref: Create junction object if none exists

Message ID 20121011190906.31447.10394.stgit@seurat.1015granger.net
State Accepted
Headers show

Commit Message

Chuck Lever Oct. 11, 2012, 7:09 p.m. UTC
At Connectathon 2012, it was requested that the Linux "nfsref add"
subcommand should create a junction object if one doesn't already
exist.

I had been told that the Solaris version of nfsref does not create
a junction object, it only adds junction metadata to an existing
object.  Experimentation with svn_134 shows this assumption is
incorrect.

rpc.fedfsd already creates a missing object during the
FEDFS_CREATE_JUNCTION operation (also to echo how Solaris is said
to operate).

Change the "nfsref add" subcommand to work the way Linux maintainers
prefer, and the way nfsref currently works on Solaris.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 src/nfsref/add.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/src/nfsref/add.c b/src/nfsref/add.c
index 9b292f5..1ce11a5 100644
--- a/src/nfsref/add.c
+++ b/src/nfsref/add.c
@@ -23,11 +23,15 @@ 
  *	http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
  */
 
+#include <sys/stat.h>
+#include <sys/types.h>
+
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <uuid/uuid.h>
 
@@ -607,6 +611,12 @@  out:
 int
 nfsref_add(enum nfsref_type type, const char *junct_path, char **argv, int optind)
 {
+	if (mkdir(junct_path, 0755) == -1)
+		if (errno != EEXIST) {
+			xlog(L_ERROR, "Failed to create junction object: %m");
+			return EXIT_FAILURE;
+		}
+
 	switch (type) {
 	case NFSREF_TYPE_UNSPECIFIED:
 	case NFSREF_TYPE_NFS_BASIC: