de-printf the cache manager
[openafs.git] / src / afs / afs_disconnected.c
index b4feef7..65d34af 100644 (file)
@@ -7,7 +7,6 @@
 #include <afsconfig.h>
 #include "afs/param.h"
  
-RCSID("$Header$");
  
 #include "afs/sysincludes.h"
 #include "afsincludes.h"
@@ -51,8 +50,7 @@ enum {
 
 afs_int32 afs_ConflictPolicy = SERVER_WINS;
 
-static void afs_DisconResetVCache(struct vcache *, struct AFS_UCRED *);
-static void afs_DisconDiscardAllShadows(int, struct AFS_UCRED *);
+static void afs_DisconDiscardAllShadows(int, afs_ucred_t *);
 void afs_DbgListDirEntries(struct VenusFid *afid);
 
 
@@ -65,7 +63,8 @@ void afs_DbgListDirEntries(struct VenusFid *afid);
  *
  * \return The found dcache or NULL.
  */
-struct dcache *afs_FindDCacheByFid(struct VenusFid *afid)
+struct dcache *
+afs_FindDCacheByFid(struct VenusFid *afid)
 {
     afs_int32 i, index;
     struct dcache *tdc = NULL;
@@ -101,7 +100,8 @@ struct dcache *afs_FindDCacheByFid(struct VenusFid *afid)
  *
  * \return Mask of operations.
  */
-int afs_GenStoreStatus(struct vcache *avc, struct AFSStoreStatus *astat)
+int
+afs_GenStoreStatus(struct vcache *avc, struct AFSStoreStatus *astat)
 {
     if (!avc || !astat || !avc->f.ddirty_flags)
        return 0;
@@ -131,10 +131,9 @@ int afs_GenStoreStatus(struct vcache *avc, struct AFSStoreStatus *astat)
  *
  * \param hdata The fid to be filled.
  */
-int get_parent_dir_fid_hook(void *hdata,
-                               char *aname,
-                               afs_int32 vnode,
-                               afs_int32 unique)
+static int
+get_parent_dir_fid_hook(void *hdata, char *aname, afs_int32 vnode,
+                       afs_int32 unique)
 {
     struct VenusFid *tfid = (struct VenusFid *) hdata;
 
@@ -156,7 +155,8 @@ int get_parent_dir_fid_hook(void *hdata,
  *
  * \return 0 on success, -1 on failure
  */
-int afs_GetParentDirFid(struct vcache *avc, struct VenusFid *afid)
+int
+afs_GetParentDirFid(struct vcache *avc, struct VenusFid *afid)
 {
     struct dcache *tdc;
 
@@ -205,10 +205,9 @@ struct NameAndFid {
  * \param hdata NameAndFid structure containin a pointer to a fid
  * and an allocate name. The name will be filled when hit.
  */
-int get_vnode_name_hook(void *hdata,
-                               char *aname,
-                               afs_int32 vnode,
-                               afs_int32 unique)
+static int
+get_vnode_name_hook(void *hdata, char *aname, afs_int32 vnode,
+                   afs_int32 unique)
 {
     struct NameAndFid *nf = (struct NameAndFid *) hdata;
 
@@ -234,10 +233,9 @@ int get_vnode_name_hook(void *hdata,
  * \param deleted Has this file been deleted? If yes, use the shadow
  * dir for looking up the name.
  */
-int afs_GetVnodeName(struct vcache *avc,
-                       struct VenusFid *afid,
-                       char *aname,
-                       int deleted)
+int
+afs_GetVnodeName(struct vcache *avc, struct VenusFid *afid, char *aname,
+                int deleted)
 {
     int code = 0;
     struct dcache *tdc;
@@ -295,7 +293,7 @@ int afs_GetVnodeName(struct vcache *avc,
        if (tnf.name_len == -1)
            code = ENOENT;
     } else {
-       printf("Directory dcache not found!\n");
+       /* printf("Directory dcache not found!\n"); */
         code = ENOENT;
     }
 
@@ -310,10 +308,9 @@ struct DirtyChildrenCount {
 /*!
  * Lookup dirty deleted vnodes in this dir.
  */
-int chk_del_children_hook(void *hdata,
-                               char *aname,
-                               afs_int32 vnode,
-                               afs_int32 unique)
+static int
+chk_del_children_hook(void *hdata, char *aname, afs_int32 vnode,
+                     afs_int32 unique)
 {
     struct VenusFid tfid;
     struct DirtyChildrenCount *v = (struct DirtyChildrenCount *) hdata;
@@ -342,7 +339,7 @@ int chk_del_children_hook(void *hdata,
     /* Count unfinished dirty children. */
     if (tvc) {
        ObtainReadLock(&tvc->lock);
-       if (tvc->f.ddirty_flags || tvc->f.shadow.vnode)
+       if (tvc->f.ddirty_flags)
            v->count++;
        ReleaseReadLock(&tvc->lock);
 
@@ -360,7 +357,8 @@ int chk_del_children_hook(void *hdata,
  *
  * \note afs_DDirtyVCListLock must be write locked.
  */
-int afs_CheckDeletedChildren(struct vcache *avc)
+int
+afs_CheckDeletedChildren(struct vcache *avc)
 {
     struct dcache *tdc;
     struct DirtyChildrenCount dcc;
@@ -391,10 +389,9 @@ int afs_CheckDeletedChildren(struct vcache *avc)
 /*!
  * Changes a file's parent fid references.
  */
-int fix_children_fids_hook(void *hdata,
-                               char *aname,
-                               afs_int32 vnode,
-                               afs_int32 unique)
+static int
+fix_children_fids_hook(void *hdata, char *aname, afs_int32 vnode,
+                      afs_int32 unique)
 {
     struct VenusFid tfid;
     struct VenusFid *afid = (struct VenusFid *) hdata;
@@ -454,7 +451,8 @@ int fix_children_fids_hook(void *hdata,
  * \param old_fid The current dir's fid.
  * \param new_fid The new dir's fid.
  */
-void afs_FixChildrenFids(struct VenusFid *old_fid, struct VenusFid *new_fid)
+void
+afs_FixChildrenFids(struct VenusFid *old_fid, struct VenusFid *new_fid)
 {
     struct dcache *tdc;
 
@@ -467,13 +465,15 @@ void afs_FixChildrenFids(struct VenusFid *old_fid, struct VenusFid *new_fid)
     }
 }
 
-int list_dir_hook(void *hdata, char *aname, afs_int32 vnode, afs_int32 unique)
+static int
+list_dir_hook(void *hdata, char *aname, afs_int32 vnode, afs_int32 unique)
 {
-    printf("list_dir_hook: %s v:%u u:%u\n", aname, vnode, unique);
+    /* printf("list_dir_hook: %s v:%u u:%u\n", aname, vnode, unique); */
     return 0;
 }
 
-void afs_DbgListDirEntries(struct VenusFid *afid)
+void
+afs_DbgListDirEntries(struct VenusFid *afid)
 {
     struct dcache *tdc;
 
@@ -507,13 +507,13 @@ afs_GetParentVCache(struct vcache *avc, int deleted, struct VenusFid *afid,
     *adp = NULL;
 
     if (afs_GetParentDirFid(avc, afid)) {
-       printf("afs_GetParentVCache: Couldn't find parent dir's FID.\n");
+       /* printf("afs_GetParentVCache: Couldn't find parent dir's FID.\n"); */
        return ENOENT;
     }
 
     code = afs_GetVnodeName(avc, afid, aname, deleted);
     if (code) {
-       printf("afs_GetParentVCache: Couldn't find file name\n");
+       /* printf("afs_GetParentVCache: Couldn't find file name\n"); */
        goto end;
     }
 
@@ -521,13 +521,13 @@ afs_GetParentVCache(struct vcache *avc, int deleted, struct VenusFid *afid,
     *adp = afs_FindVCache(afid, 0, 1);
     ReleaseSharedLock(&afs_xvcache);
     if (!*adp) {
-       printf("afs_GetParentVCache: Couldn't find parent dir's vcache\n");
+       /* printf("afs_GetParentVCache: Couldn't find parent dir's vcache\n"); */
        code = ENOENT;
        goto end;
     }
 
     if ((*adp)->f.ddirty_flags & VDisconCreate) {
-       printf("afs_GetParentVCache: deferring until parent exists\n");
+       /* printf("afs_GetParentVCache: deferring until parent exists\n"); */
        code = EAGAIN;
        goto end;
     }
@@ -545,7 +545,8 @@ end:
  * - Get the new name from the current dir.
  * - Old dir fid and new dir fid are collected along the way.
  * */
-int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
+int
+afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
 {
     struct VenusFid old_pdir_fid, new_pdir_fid;
     char *old_name = NULL, *new_name = NULL;
@@ -564,19 +565,19 @@ int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
     /* Get old name. */
     old_name = (char *) afs_osi_Alloc(AFSNAMEMAX);
     if (!old_name) {
-       printf("afs_ProcessOpRename: Couldn't alloc space for old name.\n");
+       /* printf("afs_ProcessOpRename: Couldn't alloc space for old name.\n"); */
        return ENOMEM;
     }
     code = afs_GetVnodeName(avc, &old_pdir_fid, old_name, 1);
     if (code) {
-       printf("afs_ProcessOpRename: Couldn't find old name.\n");
+       /* printf("afs_ProcessOpRename: Couldn't find old name.\n"); */
        goto done;
     }
 
     /* Alloc data first. */
     new_name = (char *) afs_osi_Alloc(AFSNAMEMAX);
     if (!new_name) {
-       printf("afs_ProcessOpRename: Couldn't alloc space for new name.\n");
+       /* printf("afs_ProcessOpRename: Couldn't alloc space for new name.\n"); */
        code = ENOMEM;
        goto done;
     }
@@ -589,7 +590,7 @@ int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
     } else {
        /* Get parent dir's FID.*/
        if (afs_GetParentDirFid(avc, &new_pdir_fid)) {
-           printf("afs_ProcessOpRename: Couldn't find new parent dir FID.\n");
+           /* printf("afs_ProcessOpRename: Couldn't find new parent dir FID.\n"); */
            code = ENOENT;
            goto done;
         }
@@ -598,7 +599,7 @@ int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
     /* And finally get the new name. */
     code = afs_GetVnodeName(avc, &new_pdir_fid, new_name, 0);
     if (code) {
-       printf("afs_ProcessOpRename: Couldn't find new name.\n");
+       /* printf("afs_ProcessOpRename: Couldn't find new name.\n"); */
        goto done;
     }
 
@@ -629,8 +630,7 @@ int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
                SHARED_LOCK,
                NULL));
 
-    if (code)
-       printf("afs_ProcessOpRename: server code=%u\n", code);
+    /* if (code) printf("afs_ProcessOpRename: server code=%u\n", code); */
 done:
     if (new_name)
        afs_osi_Free(new_name, AFSNAMEMAX);
@@ -646,8 +646,9 @@ done:
  * - Handle errors.
  * - Reorder vhash and dcaches in their hashes, using the newly acquired fid.
  */
-int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
-                       struct AFS_UCRED *acred)
+int
+afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
+                   afs_ucred_t *acred)
 {
     char *tname = NULL, *ttargetName = NULL;
     struct AFSStoreStatus InStatus;
@@ -660,7 +661,7 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
     struct afs_conn *tc;
     afs_int32 hash, new_hash, index;
     afs_size_t tlen;
-    int code, op;
+    int code, op = 0;
     XSTATS_DECLS;
 
     tname = afs_osi_Alloc(AFSNAMEMAX);
@@ -705,14 +706,13 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
        afs_CFileClose(tfile);
        ReleaseReadLock(&tdc->lock);
        afs_PutDCache(tdc);
-       printf("Read target name as %s\n",ttargetName);
     }
        
     /* Set status. */
     InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE | AFS_SETGROUP;
     InStatus.ClientModTime = avc->f.m.Date;
     InStatus.Owner = avc->f.m.Owner;
-    InStatus.Group = (afs_int32) acred->cr_gid;
+    InStatus.Group = (afs_int32) afs_cr_gid(acred);
     /* Only care about protection bits. */
     InStatus.UnixModeBits = avc->f.m.Mode & 0xffff;
 
@@ -771,7 +771,7 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
 
     /* TODO: Handle errors. */
     if (code) {
-       printf("afs_ProcessOpCreate: error while creating vnode on server, code=%d .\n", code);
+       /* printf("afs_ProcessOpCreate: error while creating vnode on server, code=%d .\n", code); */
        goto end;
     }
 
@@ -903,7 +903,8 @@ end:
  *
  * \note avc must be write locked.
  */
-int afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
+int
+afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
 {
     char *tname = NULL;
     struct AFSFetchStatus OutDirStatus;
@@ -916,7 +917,7 @@ int afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
 
     tname = afs_osi_Alloc(AFSNAMEMAX);
     if (!tname) {
-       printf("afs_ProcessOpRemove: Couldn't alloc space for file name\n");
+       /* printf("afs_ProcessOpRemove: Couldn't alloc space for file name\n"); */
        return ENOMEM;
     }
 
@@ -983,8 +984,7 @@ int afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
 
     }                          /* if (vType(avc) == VREG) */
 
-    if (code)
-       printf("afs_ProcessOpRemove: server returned code=%u\n", code);
+    /* if (code) printf("afs_ProcessOpRemove: server returned code=%u\n", code); */
 
 end:
     afs_osi_Free(tname, AFSNAMEMAX);
@@ -1001,7 +1001,8 @@ end:
  *
  * \return 0 for success. On failure, other error codes.
  */
-int afs_SendChanges(struct vcache *avc, struct vrequest *areq)
+int
+afs_SendChanges(struct vcache *avc, struct vrequest *areq)
 {
     struct afs_conn *tc;
     struct AFSStoreStatus sstat;
@@ -1097,7 +1098,8 @@ int afs_SendChanges(struct vcache *avc, struct vrequest *areq)
  * \note For now, it's the request from the PDiscon pioctl.
  *
  */
-int afs_ResyncDisconFiles(struct vrequest *areq, struct AFS_UCRED *acred)
+int
+afs_ResyncDisconFiles(struct vrequest *areq, afs_ucred_t *acred)
 {
     struct afs_conn *tc;
     struct vcache *tvc;
@@ -1105,10 +1107,9 @@ int afs_ResyncDisconFiles(struct vrequest *areq, struct AFS_UCRED *acred)
     struct AFSCallBack callback;
     struct AFSVolSync tsync;
     int code = 0;
-    int ucode;
     afs_int32 start = 0;
     XSTATS_DECLS;
-    //AFS_STATCNT(afs_ResyncDisconFiles);
+    /*AFS_STATCNT(afs_ResyncDisconFiles);*/
 
     ObtainWriteLock(&afs_disconDirtyLock, 707);
 
@@ -1223,7 +1224,7 @@ int afs_ResyncDisconFiles(struct vrequest *areq, struct AFS_UCRED *acred)
            afs_ResetVCache(tvc, acred);
            tvc->f.truncPos = AFS_NOTRUNC;
        } else {
-           printf("afs_ResyncDisconFiles: no resolution policy selected.\n");
+           /* printf("afs_ResyncDisconFiles: no resolution policy selected.\n"); */
        }               /* if DV match or client wins policy */
 
 unlock_srv_file:
@@ -1300,7 +1301,7 @@ next_file:
  */
 
 static void
-afs_DisconDiscardAllShadows(int squash, struct AFS_UCRED *acred) {
+afs_DisconDiscardAllShadows(int squash, afs_ucred_t *acred) {
    struct vcache *tvc;
 
    while (!QEmpty(&afs_disconShadow)) {
@@ -1317,10 +1318,8 @@ afs_DisconDiscardAllShadows(int squash, struct AFS_UCRED *acred) {
        if (squash)
           afs_ResetVCache(tvc, acred);
 
-       ObtainWriteLock(&afs_disconDirtyLock, 709);
-       QRemove(&tvc->shadowq);
-
        ReleaseWriteLock(&tvc->lock);
+       ObtainWriteLock(&afs_disconDirtyLock, 709);
     }                          /* while (tvc) */
 }
 
@@ -1333,7 +1332,7 @@ afs_DisconDiscardAllShadows(int squash, struct AFS_UCRED *acred) {
  *
  */
 void 
-afs_DisconDiscardAll(struct AFS_UCRED *acred) {
+afs_DisconDiscardAll(afs_ucred_t *acred) {
     struct vcache *tvc;
 
     ObtainWriteLock(&afs_disconDirtyLock, 717);
@@ -1359,19 +1358,20 @@ afs_DisconDiscardAll(struct AFS_UCRED *acred) {
  *
  * \note Call with afs_DDirtyVCListLock read locked.
  */
-void afs_DbgDisconFiles()
+void
+afs_DbgDisconFiles(void)
 {
     struct vcache *tvc;
     struct afs_q *q;
     int i = 0;
 
-    printf("List of dirty files: \n");
+    afs_warn("List of dirty files: \n");
 
     ObtainReadLock(&afs_disconDirtyLock);
     for (q = QPrev(&afs_disconDirty); q != &afs_disconDirty; q = QPrev(q)) {
         tvc = QEntry(q, struct vcache, dirtyq);
 
-       printf("Cell=%u Volume=%u VNode=%u Unique=%u\n",
+       afs_warn("Cell=%u Volume=%u VNode=%u Unique=%u\n",
                tvc->f.fid.Cell,
                tvc->f.fid.Fid.Volume,
                tvc->f.fid.Fid.Vnode,
@@ -1394,7 +1394,8 @@ void afs_DbgDisconFiles()
  *
  * \note Don't forget to fill in afid with Cell and Volume.
  */
-void afs_GenShadowFid(struct VenusFid *afid)
+void
+afs_GenShadowFid(struct VenusFid *afid)
 {
     afs_uint32 i, index, max_unique = 1;
     struct vcache *tvc = NULL;
@@ -1440,7 +1441,8 @@ void afs_GenShadowFid(struct VenusFid *afid)
  *
  * \note The cell number must be completed somewhere else.
  */
-void afs_GenFakeFid(struct VenusFid *afid, afs_uint32 avtype, int lock)
+void
+afs_GenFakeFid(struct VenusFid *afid, afs_uint32 avtype, int lock)
 {
     struct vcache *tvc;
     afs_uint32 max_unique = 0, i;
@@ -1483,9 +1485,10 @@ void afs_GenFakeFid(struct VenusFid *afid, afs_uint32 avtype, int lock)
  *
  * \note Call with avc write locked.
  */
-void afs_GenDisconStatus(struct vcache *adp, struct vcache *avc, 
-                        struct VenusFid *afid, struct vattr *attrs,
-                        struct vrequest *areq, int file_type)
+void
+afs_GenDisconStatus(struct vcache *adp, struct vcache *avc,
+                   struct VenusFid *afid, struct vattr *attrs,
+                   struct vrequest *areq, int file_type)
 {
     memcpy(&avc->f.fid, afid, sizeof(struct VenusFid));
     avc->f.m.Mode = attrs->va_mode;