LINUX: Turn on AFS_NEW_BKG 84/13284/7
authorAndrew Deason <adeason@sinenomine.net>
Tue, 14 Aug 2018 20:54:29 +0000 (15:54 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Sun, 18 Aug 2019 18:08:14 +0000 (14:08 -0400)
AFS_NEW_BKG allows libafs to request the afsd background daemon
processes to do certain userspace operations. This is currently only
used on DARWIN for handling EXDEV file moves, but this framework can
be useful on LINUX, as well. So, turn it on for LINUX.

This commit does not introduce any new background operations for LINUX
to actually use; we're just turning on the new framework. Future
commits will introduce new background operations.

Change-Id: I5d371f85b87899ce6ab2d5e520954a893679d37e
Reviewed-on: https://gerrit.openafs.org/13284
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

src/afs/afs_call.c
src/afsd/afsd.c
src/config/afs_args.h
src/config/param.linux26.h

index 6c961d2..1c83865 100644 (file)
@@ -706,6 +706,7 @@ afs_syscall_call(long parm, long parm2, long parm3,
        if (!code) {
            mvParam->retval = 0;
            /* for reqs where pointers are strings: */
+#  ifdef AFS_DARWIN_ENV
            if (mvParam->reqtype == AFS_USPC_UMV) {
                /* don't copy out random kernel memory */
                AFS_COPYOUT(param2, AFSKPTR(parm4),
@@ -713,6 +714,7 @@ afs_syscall_call(long parm, long parm2, long parm3,
                AFS_COPYOUT(param1, AFSKPTR(parm3),
                            MIN(namebufsz, strlen((char *)param1)+1), code);
            }
+#  endif /* AFS_DARWIN_ENV */
            AFS_COPYOUT((caddr_t)mvParam, AFSKPTR(parm2),
                       sizeof(struct afs_uspc_param), code);
        }
index 2bc6649..345f1c8 100644 (file)
@@ -1543,11 +1543,6 @@ BkgHandler(void)
     uspc->ts = -1;
 
     while (1) {
-       pid_t child = 0;
-       int status;
-       char srcpath[BUFSIZ];
-       char dstpath[BUFSIZ];
-
        /* pushing in a buffer this large */
        uspc->bufSz = 256;
 
@@ -1573,72 +1568,80 @@ BkgHandler(void)
            /* Client is shutting down */
            return;
 
+# ifdef AFS_DARWIN_ENV
        case AFS_USPC_UMV:
-           snprintf(srcpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
-                    uspc->req.umv.sCell, uspc->req.umv.sVolume,
-                    uspc->req.umv.sVnode, uspc->req.umv.sUnique, srcName);
-           snprintf(dstpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
-                    uspc->req.umv.dCell, uspc->req.umv.dVolume,
-                    uspc->req.umv.dVnode, uspc->req.umv.dUnique, dstName);
-           if ((child = fork()) == 0) {
-               /* first child does cp; second, rm. mv would re-enter. */
-
-               switch (uspc->req.umv.idtype) {
-               case IDTYPE_UID:
-                   if (setuid(uspc->req.umv.id) != 0) {
-                       exit(-1);
-                   }
-                   break;
-               default:
-                   exit(-1);
-                   break; /* notreached */
-               }
-               execl("/bin/cp", "(afsd EXDEV helper)", "-PRp", "--", srcpath,
-                     dstpath, (char *) NULL);
-           }
-           if (child == (pid_t) -1) {
-               uspc->retval = -1;
-               continue;
-           }
-
-           if (waitpid(child, &status, 0) == -1)
-               uspc->retval = EIO;
-           else if (WIFEXITED(status) != 0 && WEXITSTATUS(status) == 0) {
-               if ((child = fork()) == 0) {
-                   switch (uspc->req.umv.idtype) {
-                   case IDTYPE_UID:
-                       if (setuid(uspc->req.umv.id) != 0) {
-                           exit(-1);
-                       }
-                       break;
-                   default:
-                       exit(-1);
-                       break; /* notreached */
-                   }
-                   execl("/bin/rm", "(afsd EXDEV helper)", "-rf", "--",
-                         srcpath, (char *) NULL);
-               }
-               if (child == (pid_t) -1) {
-                   uspc->retval = -1;
-                   continue;
-               }
-               if (waitpid(child, &status, 0) == -1)
-                   uspc->retval = EIO;
-               else if (WIFEXITED(status) != 0) {
-                   /* rm exit status */
-                   uspc->retval = WEXITSTATUS(status);
-               } else {
-                   /* rm signal status */
-                   uspc->retval = -(WTERMSIG(status));
-               }
-           } else {
-               /* error from cp: exit or signal status */
-               uspc->retval = (WIFEXITED(status) != 0) ?
-                   WEXITSTATUS(status) : -(WTERMSIG(status));
-           }
+            {
+                pid_t child = 0;
+                int status;
+                char srcpath[BUFSIZ];
+                char dstpath[BUFSIZ];
+                snprintf(srcpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
+                         uspc->req.umv.sCell, uspc->req.umv.sVolume,
+                         uspc->req.umv.sVnode, uspc->req.umv.sUnique, srcName);
+                snprintf(dstpath, BUFSIZ, "/afs/.:mount/%d:%d:%d:%d/%s",
+                         uspc->req.umv.dCell, uspc->req.umv.dVolume,
+                         uspc->req.umv.dVnode, uspc->req.umv.dUnique, dstName);
+                if ((child = fork()) == 0) {
+                    /* first child does cp; second, rm. mv would re-enter. */
+
+                    switch (uspc->req.umv.idtype) {
+                    case IDTYPE_UID:
+                        if (setuid(uspc->req.umv.id) != 0) {
+                            exit(-1);
+                        }
+                        break;
+                    default:
+                        exit(-1);
+                        break; /* notreached */
+                    }
+                    execl("/bin/cp", "(afsd EXDEV helper)", "-PRp", "--", srcpath,
+                          dstpath, (char *) NULL);
+                }
+                if (child == (pid_t) -1) {
+                    uspc->retval = -1;
+                    continue;
+                }
+
+                if (waitpid(child, &status, 0) == -1)
+                    uspc->retval = EIO;
+                else if (WIFEXITED(status) != 0 && WEXITSTATUS(status) == 0) {
+                    if ((child = fork()) == 0) {
+                        switch (uspc->req.umv.idtype) {
+                        case IDTYPE_UID:
+                            if (setuid(uspc->req.umv.id) != 0) {
+                                exit(-1);
+                            }
+                            break;
+                        default:
+                            exit(-1);
+                            break; /* notreached */
+                        }
+                        execl("/bin/rm", "(afsd EXDEV helper)", "-rf", "--",
+                              srcpath, (char *) NULL);
+                    }
+                    if (child == (pid_t) -1) {
+                        uspc->retval = -1;
+                        continue;
+                    }
+                    if (waitpid(child, &status, 0) == -1)
+                        uspc->retval = EIO;
+                    else if (WIFEXITED(status) != 0) {
+                        /* rm exit status */
+                        uspc->retval = WEXITSTATUS(status);
+                    } else {
+                        /* rm signal status */
+                        uspc->retval = -(WTERMSIG(status));
+                    }
+                } else {
+                    /* error from cp: exit or signal status */
+                    uspc->retval = (WIFEXITED(status) != 0) ?
+                        WEXITSTATUS(status) : -(WTERMSIG(status));
+                }
+            }
            memset(srcName, 0, sizeof(srcName));
            memset(dstName, 0, sizeof(dstName));
            break;
+# endif /* AFS_DARWIN_ENV */
 
        default:
            /* unknown req type */
index 611f857..3ea8af3 100644 (file)
@@ -145,7 +145,9 @@ struct afs_umv_param {
     afs_int32 dUnique;
 };
 
-#define AFS_USPC_UMV 1
+#ifdef AFS_DARWIN_ENV
+# define AFS_USPC_UMV 1
+#endif
 #define AFS_USPC_SHUTDOWN 2
 
 struct afs_uspc_param {
index 37de8d6..3ea6a39 100644 (file)
@@ -37,6 +37,7 @@
 #define AFS_VM_RDWR_ENV                1       /* read/write implemented via VM */
 #define AFS_USE_GETTIMEOFDAY   1       /* use gettimeofday to implement rx clock */
 #define AFS_MAXVCOUNT_ENV       1
+#define AFS_NEW_BKG             1
 
 #define AFS_PRIVATE_OSI_ALLOCSPACES    1