viced: Don't use fasttime
authorSimon Wilkinson <sxw@your-file-system.com>
Thu, 24 May 2012 09:55:07 +0000 (10:55 +0100)
committerDerrick Brashear <shadow@dementix.org>
Tue, 4 Sep 2012 13:52:52 +0000 (06:52 -0700)
For pthreaded builds, the FT_ routines are just wrappers around
gettimeofday() and time(). As viced is now an entirely pthreaded
directory, improve readibility, and reduce our dependencies, by
just calling the operating system routines directly.

Change-Id: I3812ac31bc5eb7d2fcbe47d037d4af3d489d3b81
Reviewed-on: http://gerrit.openafs.org/8029
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>

src/viced/afsfileprocs.c
src/viced/callback.c
src/viced/fsstats.c
src/viced/host.c
src/viced/serialize_state.c
src/viced/viced.c

index f99326e..8cb791c 100644 (file)
@@ -389,7 +389,7 @@ CallPreamble(struct rx_call *acall, int activecall,
        goto retry;
     }
 
-    tclient->LastCall = thost->LastCall = FT_ApproxTime();
+    tclient->LastCall = thost->LastCall = time(NULL);
     if (activecall)            /* For all but "GetTime", "GetStats", and "GetCaps" calls */
        thost->ActiveCall = thost->LastCall;
 
@@ -574,7 +574,7 @@ CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
                if (restartedat.tv_sec == 0) {
                    /* I'm not really worried about when we restarted, I'm   */
                    /* just worried about when the first VBUSY was returned. */
-                   FT_GetTimeOfDay(&restartedat, 0);
+                   gettimeofday(&restartedat, 0);
                    if (busyonrst) {
                        FS_LOCK;
                        afs_perfstats.fs_nBusies++;
@@ -583,7 +583,7 @@ CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
                    return (busyonrst ? VBUSY : restarting);
                } else {
                    struct timeval now;
-                   FT_GetTimeOfDay(&now, 0);
+                   gettimeofday(&now, 0);
                    if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
                        if (busyonrst) {
                            FS_LOCK;
@@ -1532,6 +1532,7 @@ Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
     Date currDate;             /*Current date */
     int writeIdx;              /*Write index to bump */
     int timeIdx;               /*Authorship time index to bump */
+    time_t now;
 
     parentptr->disk.dataVersion++;
     newlength = (afs_fsize_t) afs_dir_Length(dir);
@@ -1568,7 +1569,8 @@ Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
      * directory operation.  Get the current time, decide to which time
      * slot this operation belongs, and bump the appropriate slot.
      */
-    currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
+    now = time(NULL);
+    currDate = (time(NULL) - parentptr->disk.unixModifyTime);
     timeIdx =
        (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
         VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
@@ -1583,8 +1585,8 @@ Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
 
     parentptr->disk.author = author;
     parentptr->disk.linkCount = linkcount;
-    parentptr->disk.unixModifyTime = FT_ApproxTime();  /* This should be set from CLIENT!! */
-    parentptr->disk.serverModifyTime = FT_ApproxTime();
+    parentptr->disk.unixModifyTime = time(NULL);       /* This should be set from CLIENT!! */
+    parentptr->disk.serverModifyTime = time(NULL);
     parentptr->changed_newTime = 1;    /* vnode changed, write it back. */
 }
 
@@ -1643,7 +1645,7 @@ Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
         * file operation.  Get the current time, decide to which time
         * slot this operation belongs, and bump the appropriate slot.
         */
-       currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
+       currDate = (time(NULL) - targetptr->disk.unixModifyTime);
        timeIdx =
            (currDate <
             VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
@@ -1677,7 +1679,7 @@ Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
     } else {                   /* other: date always changes, but perhaps to what is specified by caller */
        targetptr->disk.unixModifyTime =
            (InStatus->Mask & AFS_SETMODTIME ? InStatus->
-            ClientModTime : FT_ApproxTime());
+            ClientModTime : time(NULL));
     }
     if (InStatus->Mask & AFS_SETOWNER) {
        /* admin is allowed to do chmod, chown as well as chown, chmod. */
@@ -1721,7 +1723,7 @@ Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
            }
        }
     }
-    targetptr->disk.serverModifyTime = FT_ApproxTime();
+    targetptr->disk.serverModifyTime = time(NULL);
     if (InStatus->Mask & AFS_SETGROUP)
        targetptr->disk.group = InStatus->Group;
     /* vnode changed : to be written back by VPutVnode */
@@ -1742,7 +1744,7 @@ SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
        ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
        CallBack->ExpirationTime = 0;
     } else
-       CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
+       CallBack->ExpirationTime = CallBackTime - time(NULL);
     CallBack->CallBackVersion = CALLBACK_VERSION;
     CallBack->CallBackType = CB_SHARED;        /* The default for now */
 
@@ -1897,7 +1899,7 @@ HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLo
     int writeVnode = targetptr->changed_oldTime;       /* save original status */
 
     targetptr->changed_oldTime = 1;    /* locking doesn't affect any time stamp */
-    Time = FT_ApproxTime();
+    Time = time(NULL);
     switch (LockingType) {
     case LockRead:
     case LockWrite:
@@ -2135,7 +2137,7 @@ static
 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
          afs_int32 anyrights, Vnode * parentptr)
 {
-    int Time =FT_ApproxTime();
+    int Time = time(NULL);
 
     /* initialize return status from a vnode  */
     status->InterfaceVersion = 1;
@@ -4933,11 +4935,8 @@ SetSystemStats(struct AFSStatistics *stats)
 {
     /* Fix this sometime soon.. */
     /* Because hey, it's not like we have a network monitoring protocol... */
-    struct timeval time;
 
-    /* this works on all system types */
-    FT_GetTimeOfDay(&time, 0);
-    stats->CurrentTime = time.tv_sec;
+    stats->CurrentTime = time(NULL);
 }                              /*SetSystemStats */
 
 void
@@ -4978,7 +4977,7 @@ SetAFSStats(struct AFSStatistics *stats)
     FS_UNLOCK;
     h_GetWorkStats((int *)&(stats->WorkStations),
                   (int *)&(stats->ActiveWorkStations), (int *)0,
-                  (afs_int32) (FT_ApproxTime()) - (15 * 60));
+                  (afs_int32) (time(NULL)) - (15 * 60));
 
 }                              /*SetAFSStats */
 
@@ -5049,7 +5048,6 @@ SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatis
     struct rx_connection *tcon = rx_ConnectionOf(acall);
     struct host *thost;
     struct client *t_client = NULL;    /* tmp ptr to client data */
-    struct timeval time;
     struct fsstats fsstats;
 
     fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
@@ -5102,13 +5100,9 @@ SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatis
     h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
                      &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
                     0,
-                     (afs_int32) (FT_ApproxTime()) - (15 * 60));
+                     (afs_int32) (time(NULL)) - (15 * 60));
 
-
-
-    /* this works on all system types */
-    FT_GetTimeOfDay(&time, 0);
-    Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
+    Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time(NULL);
 
   Bad_GetStatistics64:
     code = CallPostamble(tcon, code, thost);
@@ -5336,7 +5330,7 @@ SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
      * Record the time of day and the server version number.
      */
     *a_srvVersionNumP = AFS_XSTAT_VERSION;
-    *a_timeP = FT_ApproxTime();
+    *a_timeP = (afs_int32) time(NULL);
 
     /*
      * Stuff the appropriate data in there (assume victory)
@@ -5778,7 +5772,7 @@ TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
            rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
        rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
     }
-    if (down && (FT_ApproxTime() < lastDownTime + 180)) {
+    if (down && (time(NULL) < lastDownTime + 180)) {
        return 1;               /* failure */
     }
 
@@ -5787,7 +5781,7 @@ TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
        down = 0;               /* call worked */
     if (code) {
        if (code < 0) {
-           lastDownTime = FT_ApproxTime();     /* last time we tried an RPC */
+           lastDownTime = time(NULL);  /* last time we tried an RPC */
            down = 1;
        }
        return code;
@@ -6079,7 +6073,7 @@ SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
     FS_LOCK;
     AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
     FS_UNLOCK;
-    FT_GetTimeOfDay(&tpl, 0);
+    gettimeofday(&tpl, 0);
     *Seconds = tpl.tv_sec;
     *USeconds = tpl.tv_usec;
 
@@ -6153,7 +6147,7 @@ FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
        rx_Write(Call, (char *)&zero, sizeof(afs_int32));       /* send 0-length  */
        return (0);
     }
-    FT_GetTimeOfDay(&StartTime, 0);
+    gettimeofday(&StartTime, 0);
     ihP = targetptr->handle;
     fdP = IH_OPEN(ihP);
     if (fdP == NULL) {
@@ -6259,7 +6253,7 @@ FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
     FreeSendBuffer((struct afs_buffer *)tbuffer);
 #endif /* HAVE_PIOV */
     FDH_CLOSE(fdP);
-    FT_GetTimeOfDay(&StopTime, 0);
+    gettimeofday(&StopTime, 0);
 
     /* Adjust all Fetch Data related stats */
     FS_LOCK;
@@ -6482,7 +6476,7 @@ StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
     /* this bit means that the locks are set and protections are OK */
     rx_SetLocalStatus(Call, 1);
 
-    FT_GetTimeOfDay(&StartTime, 0);
+    gettimeofday(&StartTime, 0);
 
     optSize = sendBufSize;
     ViceLog(25,
@@ -6581,7 +6575,7 @@ StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
     }
     FDH_CLOSE(fdP);
 
-    FT_GetTimeOfDay(&StopTime, 0);
+    gettimeofday(&StopTime, 0);
 
     VN_SET_LEN(targetptr, NewLength);
 
index 53cea3a..99fdead 100644 (file)
@@ -421,7 +421,7 @@ int
 InitCallBack(int nblks)
 {
     H_LOCK;
-    tfirst = CBtime(FT_ApproxTime());
+    tfirst = CBtime(time(NULL));
     /* N.B. The "-1", below, is because
      * FE[0] and CB[0] are not used--and not allocated */
     FE = ((struct FileEntry *)(calloc(nblks, sizeof(struct FileEntry))));
@@ -558,18 +558,18 @@ AddCallBack1_r(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
     fe = FindFE(fid);
     if (type == CB_NORMAL) {
        time_out =
-           TimeCeiling(FT_ApproxTime() + TimeOut(fe ? fe->ncbs : 0) +
+           TimeCeiling(time(NULL) + TimeOut(fe ? fe->ncbs : 0) +
                        ServerBias);
        Thead = THead(CBtime(time_out));
     } else if (type == CB_VOLUME) {
-       time_out = TimeCeiling((60 * 120 + FT_ApproxTime()) + ServerBias);
+       time_out = TimeCeiling((60 * 120 + time(NULL)) + ServerBias);
        Thead = THead(CBtime(time_out));
     } else if (type == CB_BULK) {
        /* bulk status can get so many callbacks all at once, and most of them
         * are probably not for things that will be used for long.
         */
        time_out =
-           TimeCeiling(FT_ApproxTime() + ServerBias +
+           TimeCeiling(time(NULL) + ServerBias +
                        TimeOut(22 + (fe ? fe->ncbs : 0)));
        Thead = THead(CBtime(time_out));
     }
@@ -1351,7 +1351,7 @@ CleanupTimedOutCallBacks(void)
 int
 CleanupTimedOutCallBacks_r(void)
 {
-    afs_uint32 now = CBtime(FT_ApproxTime());
+    afs_uint32 now = CBtime(time(NULL));
     afs_uint32 *thead;
     struct CallBack *cb;
     int ntimedout = 0;
@@ -2643,7 +2643,7 @@ static int
 DumpCallBackState_r(void)
 {
     int fd, oflag;
-    afs_uint32 magic = MAGICV2, now = (afs_int32) FT_ApproxTime(), freelisthead;
+    afs_uint32 magic = MAGICV2, now = (afs_int32) time(NULL), freelisthead;
 
     oflag = O_WRONLY | O_CREAT | O_TRUNC;
 #ifdef AFS_NT40_ENV
index d48c370..3c2c552 100644 (file)
@@ -30,7 +30,7 @@ fsstats_StartOp(struct fsstats *stats, int index)
     FS_LOCK;
     (stats->opP->numOps)++;
     FS_UNLOCK;
-    FT_GetTimeOfDay(&stats->opStartTime, NULL);
+    gettimeofday(&stats->opStartTime, NULL);
 }
 
 void
@@ -38,7 +38,7 @@ fsstats_FinishOp(struct fsstats *stats, int code)
 {
     struct timeval opStopTime, elapsedTime;
 
-    FT_GetTimeOfDay(&opStopTime, NULL);
+    gettimeofday(&opStopTime, NULL);
     if (code == 0) {
        FS_LOCK;
        (stats->opP->numSuccesses)++;
@@ -59,7 +59,7 @@ void
 fsstats_StartXfer(struct fsstats *stats, int index)
 {
     assert(index >= 0 && index < FS_STATS_NUM_XFER_OPS);
-    FT_GetTimeOfDay(&stats->xferStartTime, NULL);
+    gettimeofday(&stats->xferStartTime, NULL);
     stats->xferP = &(afs_FullPerfStats.det.xferOpTimes[index]);
 }
 
@@ -77,7 +77,7 @@ fsstats_FinishXfer(struct fsstats *stats, int code,
      * integrate the transfer size and elapsed time into the stats.  If the
      * operation failed, we jump to the appropriate point.
      */
-    FT_GetTimeOfDay(&xferStopTime, 0);
+    gettimeofday(&xferStopTime, 0);
     FS_LOCK;
     (stats->xferP->numXfers)++;
     if (code == 0) {
index 264e951..7b4d772 100644 (file)
@@ -575,7 +575,7 @@ h_gethostcps_r(struct host *host, afs_int32 now)
        free(host->hcps.prlist_val);    /* this is for hostaclRefresh */
     host->hcps.prlist_val = NULL;
     host->hcps.prlist_len = 0;
-    host->cpsCall = slept ? (FT_ApproxTime()) : (now);
+    host->cpsCall = slept ? time(NULL) : (now);
 
     H_UNLOCK;
     code = hpr_GetHostCPS(ntohl(host->host), &host->hcps);
@@ -687,7 +687,7 @@ h_Alloc_r(struct rx_connection *r_con)
     /* Make a callback channel even for the console, on the off chance that it
      * makes a request that causes a break call back.  It shouldn't. */
     h_SetupCallbackConn_r(host);
-    host->LastCall = host->cpsCall = host->ActiveCall = FT_ApproxTime();
+    host->LastCall = host->cpsCall = host->ActiveCall = time(NULL);
     host->hostFlags = 0;
     host->hcps.prlist_val = NULL;
     host->hcps.prlist_len = 0;
@@ -760,7 +760,7 @@ h_Lookup_r(afs_uint32 haddr, afs_uint16 hport, struct host **hostp)
                goto restart;
            }
            h_Unlock_r(host);
-           now = FT_ApproxTime();      /* always evaluate "now" */
+           now = time(NULL);   /* always evaluate "now" */
            if (host->hcpsfailed || (host->cpsCall + hostaclRefresh < now)) {
                /*
                 * Every hostaclRefresh period (def 2 hrs) get the new
@@ -1943,7 +1943,7 @@ h_GetHost_r(struct rx_connection *tcon)
        host = h_Alloc_r(tcon); /* returned held and locked */
        if (!host)
            goto gethost_out;
-       h_gethostcps_r(host, FT_ApproxTime());
+       h_gethostcps_r(host, time(NULL));
        if (!(host->Console & 1)) {
            int pident = 0;
            cb_conn = host->callback_rxcon;
@@ -2811,7 +2811,7 @@ h_PrintClients(void)
                 AFSDIR_SERVER_CLNTDUMP_FILEPATH));
        return;
     }
-    now = FT_ApproxTime();
+    now = time(NULL);
     strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
             localtime_r(&now, &tm));
     snprintf(tmpStr, sizeof tmpStr, "List of active users at %s\n\n",
@@ -2885,7 +2885,7 @@ h_DumpHosts(void)
                 AFSDIR_SERVER_HOSTDUMP_FILEPATH));
        return;
     }
-    now = FT_ApproxTime();
+    now = time(NULL);
     strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
             localtime_r(&now, &tm));
     snprintf(tmpStr, sizeof tmpStr, "List of active hosts at %s\n\n", tbuffer);
@@ -3982,7 +3982,7 @@ CheckHost_r(struct host *host, void *dummy)
 void
 h_CheckHosts(void)
 {
-    afs_uint32 now = FT_ApproxTime();
+    afs_uint32 now = time(NULL);
 
     memset(&zerofid, 0, sizeof(zerofid));
     /*
index bda5e09..efbb394 100644 (file)
@@ -452,7 +452,7 @@ fs_stateLoadDump(struct fs_dump_state * state)
     afs_uint64 z;
     int fd, ret = 0;
     struct afs_stat status;
-    afs_int32 now = FT_ApproxTime();
+    afs_int32 now = time(NULL);
 
     ZeroInt64(z);
 
@@ -926,7 +926,7 @@ fs_stateFillHeader(struct fs_state_header * hdr)
 #else
     hdr->sys_name = 0xFFFFFFFF;
 #endif
-    hdr->timestamp = FT_ApproxTime();
+    hdr->timestamp = time(NULL);
     hdr->server_uuid = FS_HostUUID;
     hdr->valid = 1;
 #ifdef WORDS_BIGENDIAN
index 7dc5a75..fd4b3ef 100644 (file)
@@ -433,7 +433,7 @@ FiveMinuteCheckLWP(void *unused)
            Do_VLRegisterRPC();
        /* Force wakeup in case we missed something; pthreads does timedwait */
        if (printBanner && (++msg & 1)) {       /* Every 10 minutes */
-           time_t now = FT_ApproxTime();
+           time_t now = time(NULL);
            struct tm tm;
            strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
                     localtime_r(&now, &tm));
@@ -643,7 +643,7 @@ PrintCounters(void)
     int stats_flags = 0;
 #endif
 
-    FT_GetTimeOfDay(&tpl, 0);
+    gettimeofday(&tpl, 0);
     Statistics = 1;
     strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
             localtime_r(&StartTime, &tm));
@@ -2161,7 +2161,7 @@ main(int argc, char *argv[])
     osi_Assert(pthread_create
           (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
 
-    FT_GetTimeOfDay(&tp, 0);
+    gettimeofday(&tp, 0);
 
     /*
      * Figure out the FileServer's name and primary address.