~ubuntu-branches/ubuntu/karmic/openafs/karmic-updates

« back to all changes in this revision

Viewing changes to src/viced/viced.c

  • Committer: Bazaar Package Importer
  • Author(s): Russ Allbery
  • Date: 2008-09-22 19:07:02 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080922190702-59m13d7kn6gkw32d
Tags: 1.4.7.dfsg1-6
* Apply upstream patch to free /proc entries in the correct order.
  Thanks, Marc Dionne.  (Closes: #493914)
* Apply upstream deltas to support 2.6.27 kernels and to stop using
  COMMON_KERN_CFLAGS for all 2.6 kernels uniformly, which fixes
  problems on amd64 with newer kernels.  Thanks, Björn Torkelsson.
  (LP: #267504)
* Translation updates:
  - Swedish, thanks Martin Bagge.  (Closes: #493120)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <afs/param.h>
21
21
 
22
22
RCSID
23
 
    ("$Header: /cvs/openafs/src/viced/viced.c,v 1.58.2.18 2006/09/15 23:19:28 jaltman Exp $");
 
23
    ("$Header: /cvs/openafs/src/viced/viced.c,v 1.58.2.27 2008/03/11 17:40:55 shadow Exp $");
24
24
 
25
25
#include <stdio.h>
26
26
#include <stdlib.h>
27
27
#include <errno.h>
 
28
#include <string.h>
28
29
#include <sys/types.h>
29
30
#include <afs/procmgmt.h>       /* signal(), kill(), wait(), etc. */
30
31
#include <sys/stat.h>
39
40
#include <netdb.h>
40
41
#include <unistd.h>             /* sysconf() */
41
42
 
42
 
#ifdef HAVE_STRING_H
43
 
#include <string.h>
44
 
#else
45
 
#ifdef HAVE_STRINGS_H
46
 
#include <strings.h>
47
 
#endif
48
 
#endif
49
 
 
50
43
#ifndef ITIMER_REAL
51
44
#include <sys/time.h>
52
45
#endif /* ITIMER_REAL */
113
106
extern int LogLevel, etext;
114
107
extern afs_int32 BlocksSpare, PctSpare;
115
108
 
116
 
void ShutDown(void);
 
109
void *ShutDown(void *);
117
110
static void ClearXStatValues(), NewParms(), PrintCounters();
118
111
static void ResetCheckDescriptors(void), ResetCheckSignal(void);
119
 
static void CheckSignal(void);
 
112
static void *CheckSignal(void *);
120
113
extern int GetKeysFromToken();
121
114
extern int RXAFS_ExecuteRequest();
122
115
extern int RXSTATS_ExecuteRequest();
166
159
int printBanner = 0;
167
160
int rxJumbograms = 1;           /* default is to send and receive jumbograms. */
168
161
int rxBind = 0;         /* don't bind */
 
162
int rxkadDisableDotCheck = 0;      /* disable check for dot in principal name */ 
169
163
int rxMaxMTU = -1;
170
164
afs_int32 implicitAdminRights = PRSFS_LOOKUP;   /* The ADMINISTER right is 
171
165
                                                 * already implied */
220
214
 */
221
215
 
222
216
/* DEBUG HACK */
223
 
static void
224
 
CheckDescriptors()
 
217
static void *
 
218
CheckDescriptors(void *unused)
225
219
{
226
220
#ifndef AFS_NT40_ENV
227
221
    struct afs_stat status;
237
231
    fflush(stdout);
238
232
    ResetCheckDescriptors();
239
233
#endif
 
234
    return 0;
240
235
}                               /*CheckDescriptors */
241
236
 
242
237
 
244
239
void
245
240
CheckSignal_Signal(x)
246
241
{
247
 
    CheckSignal();
 
242
    CheckSignal(NULL);
248
243
}
249
244
 
250
245
void
251
246
ShutDown_Signal(x)
252
247
{
253
 
    ShutDown();
 
248
    ShutDown(NULL);
254
249
}
255
250
 
256
251
void
257
252
CheckDescriptors_Signal(x)
258
253
{
259
 
    CheckDescriptors();
 
254
    CheckDescriptors(NULL);
260
255
}
261
256
#else /* AFS_PTHREAD_ENV */
262
257
void
410
405
}
411
406
 
412
407
/* This LWP does things roughly every 5 minutes */
413
 
static void
414
 
FiveMinuteCheckLWP()
 
408
static void *
 
409
FiveMinuteCheckLWP(void *unused)
415
410
{
416
411
    static int msg = 0;
417
412
    char tbuffer[32];
451
446
            }
452
447
        }
453
448
    }
 
449
    return NULL;
454
450
}                               /*FiveMinuteCheckLWP */
455
451
 
456
452
 
458
454
 * other 5 minute activities because it may be delayed by timeouts when
459
455
 * it probes the workstations
460
456
 */
461
 
static void
462
 
HostCheckLWP()
 
457
static void *
 
458
HostCheckLWP(void *unused)
463
459
{
464
460
    ViceLog(1, ("Starting Host check process\n"));
465
461
    setThreadId("HostCheckLWP");
472
468
        ViceLog(2, ("Checking for dead venii & clients\n"));
473
469
        h_CheckHosts();
474
470
    }
 
471
    return NULL;
475
472
}                               /*HostCheckLWP */
476
473
 
477
474
/* This LWP does fsync checks every 5 minutes:  it should not be used for
478
475
 * other 5 minute activities because it may be delayed by timeouts when
479
476
 * it probes the workstations
480
477
 */
481
 
static
482
 
FsyncCheckLWP()
 
478
static void *
 
479
FsyncCheckLWP(void *unused)
483
480
{
484
481
    afs_int32 code;
485
482
#ifdef AFS_PTHREAD_ENV
489
486
 
490
487
    setThreadId("FsyncCheckLWP");
491
488
 
492
 
#ifdef AFS_PTHREAD_ENV
493
 
    assert(pthread_cond_init(&fsync_cond, NULL) == 0);
494
 
    assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
495
 
#endif
496
 
 
497
489
    while (1) {
498
490
        FSYNC_LOCK;
499
491
#ifdef AFS_PTHREAD_ENV
516
508
            code = BreakLaterCallBacks();
517
509
        } while (code != 0);
518
510
    }
 
511
    return NULL;
519
512
}
520
513
 
521
514
/*------------------------------------------------------------------------
630
623
 
631
624
 
632
625
 
633
 
static void
634
 
CheckSignal()
 
626
static void *
 
627
CheckSignal(void *unused)
635
628
{
636
629
    if (FS_registered > 0) {
637
630
        /*
645
638
    DumpCallBackState();
646
639
    PrintCounters();
647
640
    ResetCheckSignal();
648
 
 
 
641
    return NULL;
649
642
}                               /*CheckSignal */
650
643
 
651
644
void
699
692
        }
700
693
    }
701
694
 
 
695
    if (dopanic)
 
696
        assert(0);
 
697
 
702
698
    exit(0);
703
699
 
704
700
}                               /*ShutDown */
705
701
 
706
 
void
707
 
ShutDown(void)
 
702
void *
 
703
ShutDown(void *unused)
708
704
{                               /* backward compatibility */
709
705
    ShutDownAndCore(DONTPANIC);
 
706
    return NULL;
710
707
}
711
708
 
712
709
 
742
739
    strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
743
740
    strcat(buffer, "[-rxmaxmtu <bytes>] ");
744
741
    strcat(buffer, "[-rxbind (bind the Rx socket to one address)] ");
 
742
    strcat(buffer, "[-allow-dotted-principals (disable the rxkad principal name dot check)] ");
745
743
#if AFS_PTHREAD_ENV
746
744
    strcat(buffer, "[-vattachpar <number of volume attach threads>] ");
747
745
#endif
1060
1058
            rxJumbograms = 0;
1061
1059
        } else if (!strcmp(argv[i], "-rxbind")) {
1062
1060
            rxBind = 1;
 
1061
        } else if (!strcmp(argv[i], "-allow-dotted-principals")) {
 
1062
            rxkadDisableDotCheck = 1;
1063
1063
        } else if (!strcmp(argv[i], "-rxmaxmtu")) {
1064
1064
            if ((i + 1) >= argc) {
1065
1065
                fprintf(stderr, "missing argument for -rxmaxmtu\n"); 
1074
1074
                return -1;
1075
1075
            }
1076
1076
        } else if (!strcmp(argv[i], "-realm")) {
1077
 
            extern char local_realm[AFS_REALM_SZ];
 
1077
            extern char local_realms[AFS_NUM_LREALMS][AFS_REALM_SZ];
 
1078
            extern int  num_lrealms;
1078
1079
            if ((i + 1) >= argc) {
1079
1080
                fprintf(stderr, "missing argument for -realm\n"); 
1080
1081
                return -1; 
1085
1086
                     AFS_REALM_SZ);
1086
1087
                return -1;
1087
1088
            }
1088
 
            strncpy(local_realm, argv[i], AFS_REALM_SZ);
 
1089
            if (num_lrealms == -1)
 
1090
                num_lrealms = 0;
 
1091
            if (num_lrealms >= AFS_NUM_LREALMS) {
 
1092
                printf
 
1093
                    ("a maximum of %d -realm arguments can be specified.\n",
 
1094
                     AFS_NUM_LREALMS);
 
1095
                return -1;
 
1096
            }
 
1097
            strncpy(local_realms[num_lrealms++], argv[i], AFS_REALM_SZ);
1089
1098
        } else if (!strcmp(argv[i], "-udpsize")) {
1090
1099
            if ((i + 1) >= argc) {
1091
1100
                printf("You have to specify -udpsize <integer value>\n");
1444
1453
                 AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1445
1454
        return EIO;
1446
1455
    }
1447
 
    FS_HostAddr_cnt = nentries;
1448
 
    for (i = 0; i < nentries; i++) {
1449
 
        if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1450
 
            sizeof(afs_int32)) {
1451
 
            ViceLog(0,
1452
 
                    ("%s: Read of addresses failed (%d)\n",
1453
 
                     AFSDIR_SERVER_SYSID_FILEPATH, errno));
1454
 
            FS_HostAddr_cnt = 0;        /* reset it */
1455
 
            return EIO;
 
1456
    if (FS_HostAddr_cnt == 0) {
 
1457
        FS_HostAddr_cnt = nentries;
 
1458
        for (i = 0; i < nentries; i++) {
 
1459
            if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
 
1460
                sizeof(afs_int32)) {
 
1461
                ViceLog(0,
 
1462
                        ("%s: Read of addresses failed (%d)\n",
 
1463
                         AFSDIR_SERVER_SYSID_FILEPATH, errno));
 
1464
                FS_HostAddr_cnt = 0;    /* reset it */
 
1465
                return EIO;
 
1466
            }
1456
1467
        }
 
1468
    } else {
 
1469
        ViceLog(1,
 
1470
                ("%s: address list ignored (NetInfo/NetRestrict override)\n",
 
1471
                 AFSDIR_SERVER_SYSID_FILEPATH));
1457
1472
    }
1458
1473
    close(fd);
1459
1474
    return 0;
1817
1832
    rx_SetBusyThreshold(busy_threshold, VBUSY);
1818
1833
    rx_SetCallAbortThreshold(abort_threshold);
1819
1834
    rx_SetConnAbortThreshold(abort_threshold);
 
1835
#ifdef AFS_XBSD_ENV
 
1836
    stackSize = 128 * 1024;
 
1837
#else
1820
1838
    stackSize = lwps * 4000;
1821
1839
    if (stackSize < 32000)
1822
1840
        stackSize = 32000;
1823
1841
    else if (stackSize > 44000)
1824
1842
        stackSize = 44000;
1825
 
#if    defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
 
1843
#endif
 
1844
#if defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV) || defined(AFS_XBSD_ENV)
1826
1845
    rx_SetStackSize(1, stackSize);
1827
1846
#endif
1828
1847
    if (udpBufSize)
1857
1876
                ("Failed to initialize RX, probably two servers running.\n"));
1858
1877
        exit(-1);
1859
1878
    }
 
1879
    if (rxkadDisableDotCheck) {
 
1880
        rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
 
1881
                                    (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK,
 
1882
                                    NULL);
 
1883
    }
1860
1884
    rx_SetMinProcs(tservice, 3);
1861
1885
    rx_SetMaxProcs(tservice, lwps);
1862
1886
    rx_SetCheckReach(tservice, 1);
1907
1931
    /* allow super users to manage RX statistics */
1908
1932
    rx_SetRxStatUserOk(fs_rxstat_userok);
1909
1933
 
 
1934
#ifdef AFS_PTHREAD_ENV
 
1935
    assert(pthread_cond_init(&fsync_cond, NULL) == 0);
 
1936
    assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
 
1937
#endif
 
1938
 
1910
1939
    rx_StartServer(0);          /* now start handling requests */
1911
1940
 
1912
1941
    /* we ensure that there is enough space in the vnode buffer to satisfy
1952
1981
    assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
1953
1982
 
1954
1983
    assert(pthread_create
1955
 
           (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
 
1984
           (&serverPid, &tattr, FiveMinuteCheckLWP,
1956
1985
            &fiveminutes) == 0);
1957
1986
    assert(pthread_create
1958
 
           (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
 
1987
           (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0);
1959
1988
    assert(pthread_create
1960
 
           (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
 
1989
           (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0);
1961
1990
#else /* AFS_PTHREAD_ENV */
1962
1991
    ViceLog(5, ("Starting LWP\n"));
1963
1992
    assert(LWP_CreateProcess
1964
1993
           (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1965
 
            (void *)&fiveminutes, "FiveMinuteChecks",
 
1994
            &fiveminutes, "FiveMinuteChecks",
1966
1995
            &serverPid) == LWP_SUCCESS);
1967
1996
 
1968
1997
    assert(LWP_CreateProcess
1969
1998
           (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1970
 
            (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
 
1999
            &fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
1971
2000
    assert(LWP_CreateProcess
1972
2001
           (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1973
 
            (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
 
2002
            &fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
1974
2003
#endif /* AFS_PTHREAD_ENV */
1975
2004
 
1976
2005
    TM_GetTimeOfDay(&tp, 0);
2030
2059
#else /* AFS_PTHREAD_ENV */
2031
2060
    assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
2032
2061
#endif /* AFS_PTHREAD_ENV */
 
2062
    return 0;
2033
2063
}