]> andersk Git - moira.git/blobdiff - incremental/afs.c
New database and column names for Moira2.
[moira.git] / incremental / afs.c
index 5f930fbc1c059e5f7bdfb118521a5247797ed611..4171c2a76c5cac4c1a0e7c9004fecdb9b48857b6 100644 (file)
@@ -7,6 +7,7 @@
  * <mit-copyright.h>.
  */
 
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/file.h>
 #include <strings.h>
 #define STOP_FILE "/moira/afs/noafs"
 #define file_exists(file) (access((file), F_OK) == 0)
 
+#if defined(vax) && !defined(__STDC__)
+#define volatile
+#endif
+
 char *whoami;
 
 /* Main stub routines */
@@ -165,7 +170,7 @@ int afterc;
            return;
        }
 
-       if (beforec) {
+       if (bstate != 0) {
            /* Reactivating a user; get his group list */
            gethostname(hostname, sizeof(hostname));
            code = mr_connect(hostname);
@@ -180,7 +185,7 @@ int afterc;
            av[1] = after[U_NAME];
            code = mr_query("get_lists_of_member", 2, av,
                            add_user_lists, after[U_NAME]);
-           if (code)
+           if (code && code != MR_NO_MATCH)
                critical_alert("incremental",
                               "Couldn't retrieve membership of user %s: %s",
                               after[U_NAME], error_message(code));
@@ -325,11 +330,17 @@ char **after;
 int afterc;
 {
     char cmd[1024];
-    
+    int acreate, atype, btype;
+
+    if (afterc < FS_CREATE) {
+       atype = acreate = 0;
+    } else {
+       atype = !strcmp(after[FS_TYPE], "AFS");
+       acreate = atoi(after[FS_CREATE]);
+    }
+
     if (beforec < FS_CREATE) {
-       if (afterc < FS_CREATE || atoi(after[FS_CREATE])==0 ||
-           strcmp(after[FS_TYPE], "AFS"))
-           return;
+       if (acreate == 0 || atype == 0) return;
 
        /* new locker creation */
        sprintf(cmd, "%s/perl -I%s %s/afs_create.pl %s %s %s %s %s %s",
@@ -339,35 +350,48 @@ int afterc;
        run_cmd(cmd);
        return;
     }
-
-    /* What do we do?  When do we use FS_CREATE?
-     * 
-     * TYPE change:  AFS->ERR, ERR->AFS: rename/unmount/remount
-     * LOCKERTYPE change: rename/remount
-     * PACK change: remount
-     * LABEL change: rename/remount
-     * Deletion: rename/unmount
-     */
+    
+    btype = !strcmp(before[FS_TYPE], "AFS");
     if (afterc < FS_CREATE) {
-       if (!strcmp(before[FS_TYPE], "AFS"))
+       if (btype)
            critical_alert("incremental",
-                          "Could not delete AFS filesystem %s: Operation not supported",
+                          "Cannot delete AFS filesystem %s: Operation not supported",
                           before[FS_NAME]);
        return;
     }
 
-    if (!strcmp(after[FS_TYPE], "AFS")) {
-       if (strcmp(before[FS_TYPE], "AFS")) {
-           critical_alert("incremental",
-                          "Cannot convert %s to an AFS filesystem: Operation not supported",
-                          after[FS_NAME]);
-       } else {
-           critical_alert("incremental",
-                          "Cannot change attributes of AFS filesystem %s: Operation not supported",
-                          after[FS_NAME]);
-       }
+    if (!acreate)
        return;
+
+    /* Are we dealing with AFS lockers (could be type ERR lockers) */
+    if (!atype && !btype)
+       if (strcmp(before[FS_TYPE], "ERR") || strcmp(after[FS_TYPE], "ERR"))
+           return;
+                                                   
+    /* By now, we know we are simply changing AFS filesystem attributes.
+     * Operations supported:
+     *    Name change:  rename/remount
+     *    Path change:  remount
+     *    Type change:  ERR<-->AFS
+     */
+
+#if 0
+    if (strcmp(before[FS_OWNER], after[FS_OWNER]) ||
+       strcmp(before[FS_OWNERS], after[FS_OWNERS]))
+    {
+       critical_alert("incremental",
+                      "Cannot change ownership of filesystem %s: Operation not yet supported",
+                      after[FS_NAME]);
     }
+#endif
+
+    sprintf(cmd, "%s/perl -I%s %s/afs_rename.pl %s %s %s %s %s %s %s %s %s %s",
+           BIN_DIR, BIN_DIR, BIN_DIR,
+           before[FS_NAME], before[FS_MACHINE], before[FS_TYPE],
+           before[FS_L_TYPE], before[FS_PACK],
+           after[FS_NAME], after[FS_MACHINE], after[FS_TYPE],
+           after[FS_L_TYPE], after[FS_PACK]);
+    run_cmd(cmd);
 }
 
 
@@ -486,7 +510,7 @@ long pr_try(fn, a1, a2, a3, a4, a5, a6, a7, a8)
     char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
 {
     static int initd=0;
-    register long code;
+    volatile register long code;
     register int tries = 0;
 #ifdef DEBUG
     char fname[64];
@@ -502,9 +526,8 @@ long pr_try(fn, a1, a2, a3, a4, a5, a6, a7, a8)
            return;
        }
        initd = 1;
-    } else {
-       sleep(1);                               /* give ptserver room */
     }
+    sleep(1);                                  /* give ptserver room */
 
     while (code = (*fn)(a1, a2, a3, a4, a5, a6, a7, a8)) {
 #ifdef DEBUG
@@ -519,16 +542,25 @@ long pr_try(fn, a1, a2, a3, a4, a5, a6, a7, a8)
        else if (fn == pr_ChangeEntry) strcpy(fname, "pr_ChangeEntry");
        else if (fn == pr_SetFieldsEntry) strcpy(fname, "pr_SetFieldsEntry");
        else if (fn == pr_AddToGroup) strcpy(fname, "pr_AddToGroup");
-       else {
+       else
            sprintf(fname, "pr_??? (0x%08x)", (long)fn);
-       }
 
-       com_err(whoami, code, "%s failed (try %d @%u)", fname, tries+1, t);
+       com_err(whoami, code, "%s failed (try %d @%u)", fname, tries+1, t);
 #endif
-       if (++tries > 2)
-           return code;
-       if (code == UNOQUORUM) { sleep(90); continue; }
-       else { sleep(15); continue; }
+       if (++tries > 2) break;         /* 3 tries */
+       
+       if (code == UNOQUORUM) sleep(90);
+       else sleep(15);
+
+       /* Re-initialize the prdb connection */
+       code=pr_Initialize(0, AFSCONF_CLIENTNAME, 0);
+       if (!code) code=pr_Initialize(1, AFSCONF_CLIENTNAME, 0);
+       if (code) {
+           critical_alert("incremental", "Couldn't re-initialize libprot: %s",
+                          error_message(code));
+           initd = 0;                          /* we lost */
+           break;
+       }
     }
     return code;
 }
This page took 0.039477 seconds and 4 git commands to generate.