~ubuntu-branches/ubuntu/oneiric/openafs/oneiric-201305130334

« back to all changes in this revision

Viewing changes to src/viced/callback.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:
83
83
#include <afs/param.h>
84
84
 
85
85
RCSID
86
 
    ("$Header: /cvs/openafs/src/viced/callback.c,v 1.55.2.14 2006/02/02 21:48:39 jaltman Exp $");
 
86
    ("$Header: /cvs/openafs/src/viced/callback.c,v 1.55.2.27 2008/03/11 17:40:55 shadow Exp $");
87
87
 
88
88
#include <stdio.h>
89
89
#include <stdlib.h>             /* for malloc() */
90
90
#include <time.h>               /* ANSI standard location for time stuff */
 
91
#include <string.h>
91
92
#ifdef AFS_NT40_ENV
92
93
#include <fcntl.h>
93
94
#include <io.h>
95
96
#include <sys/time.h>
96
97
#include <sys/file.h>
97
98
#endif
98
 
#ifdef HAVE_STRING_H
99
 
#include <string.h>
100
 
#else
101
 
#ifdef HAVE_STRINGS_H
102
 
#include <strings.h>
103
 
#endif
104
 
#endif
105
99
#include <afs/assert.h>
106
100
 
107
101
#include <afs/stds.h>
310
304
#define FreeCB(cb) iFreeCB((struct CallBack *)cb, &cbstuff.nCBs)
311
305
#define FreeFE(fe) iFreeFE((struct FileEntry *)fe, &cbstuff.nFEs)
312
306
 
313
 
/* Other protos - move out sometime */
314
 
extern void ShutDown();
315
 
 
316
307
#define VHASH 512               /* Power of 2 */
317
308
static afs_uint32 HashTable[VHASH];     /* File entry hash table */
318
309
#define VHash(volume, unique) (((volume)+(unique))&(VHASH-1))
493
484
        CcdelB++;
494
485
    *cbp = cb->cnext;
495
486
    FreeCB(cb);
496
 
    if (deletefe && (--fe->ncbs == 0))
 
487
    if ((--fe->ncbs == 0) && deletefe)
497
488
        FDel(fe);
498
489
    return 0;
499
490
}
646
637
    struct CallBack *newcb = 0;
647
638
    int safety;
648
639
 
 
640
    cbstuff.AddCallBacks++;
 
641
 
649
642
    host->Console |= 2;
650
643
 
651
644
    /* allocate these guys first, since we can't call the allocator with
753
746
    return 0;
754
747
}
755
748
 
 
749
static int
 
750
CompareCBA(const void *e1, const void *e2)
 
751
{
 
752
    const struct cbstruct *cba1 = (const struct cbstruct *)e1;
 
753
    const struct cbstruct *cba2 = (const struct cbstruct *)e2;
 
754
    return ((cba1->hp)->index - (cba2->hp)->index);
 
755
}
 
756
 
756
757
/* Take an array full of hosts, all held.  Break callbacks to them, and 
757
758
 * release the holds once you're done, except don't release xhost.  xhost 
758
759
 * may be NULL.  Currently only works for a single Fid in afidp array.
782
783
 
783
784
    assert(ncbas <= MAX_CB_HOSTS);
784
785
 
 
786
    /* sort cba list to avoid makecall issues */
 
787
    qsort(cba, ncbas, sizeof(struct cbstruct), CompareCBA);
 
788
 
785
789
    /* set up conns for multi-call */
786
790
    for (i = 0, j = 0; i < ncbas; i++) {
787
791
        struct host *thishost = cba[i].hp;
969
973
    register afs_uint32 *pcb;
970
974
    char hoststr[16];
971
975
 
 
976
    H_LOCK;
972
977
    cbstuff.DeleteCallBacks++;
973
978
 
974
 
    H_LOCK;
975
979
    h_Lock_r(host);
976
980
    fe = FindFE(fid);
977
981
    if (!fe) {
1030
1034
        TDel(cb);
1031
1035
        HDel(cb);
1032
1036
        FreeCB(cb);
 
1037
        fe->ncbs--;
1033
1038
    }
1034
1039
    FDel(fe);
1035
1040
    H_UNLOCK;
1181
1186
 
1182
1187
    cbstuff.nbreakers--;
1183
1188
    /* If we succeeded it's always ok to unset HFE_LATER */
1184
 
    if (!host->hostFlags & VENUSDOWN)
 
1189
    if (!(host->hostFlags & VENUSDOWN))
1185
1190
        host->hostFlags &= ~HFE_LATER;
1186
1191
    return (host->hostFlags & VENUSDOWN);
1187
1192
}
1437
1442
                         fe->volid));
1438
1443
                fid.Volume = fe->volid;
1439
1444
                *feip = fe->fnext;
 
1445
                fe->status &= ~FE_LATER;
1440
1446
                /* Works since volid is deeper than the largest pointer */
1441
1447
                tmpfe = (struct object *)fe;
1442
1448
                tmpfe->next = (struct object *)myfe;
1797
1803
int
1798
1804
DumpCallBackState(void)
1799
1805
{
1800
 
    int fd;
 
1806
    int fd, oflag;
1801
1807
    afs_uint32 magic = MAGIC, now = FT_ApproxTime(), freelisthead;
1802
1808
 
1803
 
    fd = open(AFSDIR_SERVER_CBKDUMP_FILEPATH, O_WRONLY | O_CREAT | O_TRUNC,
1804
 
              0666);
 
1809
    oflag = O_WRONLY | O_CREAT | O_TRUNC;
 
1810
#ifdef AFS_NT40_ENV
 
1811
    oflag |= O_BINARY;
 
1812
#endif
 
1813
    fd = open(AFSDIR_SERVER_CBKDUMP_FILEPATH, oflag, 0666);
1805
1814
    if (fd < 0) {
1806
1815
        ViceLog(0,
1807
1816
                ("Couldn't create callback dump file %s\n",
1835
1844
time_t
1836
1845
ReadDump(char *file)
1837
1846
{
1838
 
    int fd;
 
1847
    int fd, oflag;
1839
1848
    afs_uint32 magic, freelisthead;
1840
 
    time_t now;
 
1849
    afs_uint32 now;
1841
1850
 
1842
 
    fd = open(file, O_RDONLY);
 
1851
    oflag = O_RDONLY;
 
1852
#ifdef AFS_NT40_ENV
 
1853
    oflag |= O_BINARY;
 
1854
#endif
 
1855
    fd = open(file, oflag);
1843
1856
    if (fd < 0) {
1844
1857
        fprintf(stderr, "Couldn't read dump file %s\n", file);
1845
1858
        exit(1);
1860
1873
    read(fd, &tfirst, sizeof(tfirst));
1861
1874
    read(fd, &freelisthead, sizeof(freelisthead));
1862
1875
    CB = ((struct CallBack
1863
 
           *)(calloc(cbstuff.nblks, sizeof(struct FileEntry)))) - 1;
 
1876
           *)(calloc(cbstuff.nblks, sizeof(struct CallBack)))) - 1;
1864
1877
    FE = ((struct FileEntry
1865
1878
           *)(calloc(cbstuff.nblks, sizeof(struct FileEntry)))) - 1;
1866
1879
    CBfree = (struct CallBack *)itocb(freelisthead);
1993
2006
            printf("%d:%12x%12x%12x%12x\n", i, p[0], p[1], p[2], p[3]);
1994
2007
        }
1995
2008
    }
 
2009
    return 0;
1996
2010
}
1997
2011
 
1998
2012
int
2004
2018
    printf("vol=%u vn=%u cbs=%d hi=%d st=%d fest=%d, exp in %d secs at %s",
2005
2019
           fe->volid, fe->vnode, fe->ncbs, cb->hhead, cb->status, fe->status,
2006
2020
           expires - now, ctime(&expires));
 
2021
    return 0;
2007
2022
}
2008
2023
 
2009
2024
#endif
2039
2054
    if (!host->interface)
2040
2055
        return 1;               /* failure */
2041
2056
 
2042
 
    assert(host->interface->numberOfInterfaces > 0);
2043
 
 
2044
2057
    /* the only address is the primary interface */
2045
 
    if (host->interface->numberOfInterfaces == 1)
 
2058
    if (host->interface->numberOfInterfaces <= 1)
2046
2059
        return 1;               /* failure */
2047
2060
 
2048
2061
    /* initialise a security object only once */
2087
2100
            if (host->callback_rxcon)
2088
2101
                rx_DestroyConnection(host->callback_rxcon);
2089
2102
            host->callback_rxcon = conns[multi_i];
 
2103
            hashDelete_r(host->host, host->port, host);
2090
2104
            host->host = interfaces[multi_i].addr;
2091
2105
            host->port = interfaces[multi_i].port;
 
2106
            hashInsert_r(host->host, host->port, host);
2092
2107
            connSuccess = conns[multi_i];
2093
2108
            rx_SetConnDeadTime(host->callback_rxcon, 50);
2094
2109
            rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME);
2134
2149
    if (!host->interface)
2135
2150
        return 1;               /* failure */
2136
2151
 
2137
 
    assert(host->interface->numberOfInterfaces > 0);
2138
 
 
2139
2152
    /* the only address is the primary interface */
2140
 
    if (host->interface->numberOfInterfaces == 1)
2141
 
        return 1;               /* failure */
 
2153
    if (host->interface->numberOfInterfaces <= 1)
 
2154
        return 1;               /* failure */
2142
2155
 
2143
2156
    /* initialise a security object only once */
2144
2157
    if (!sc)
2161
2174
 
2162
2175
        interfaces[j] = host->interface->interface[i];
2163
2176
        conns[j] =
2164
 
            rx_NewConnection(interfaces[i].addr, 
2165
 
                             interfaces[i].port, 1, sc, 0);
 
2177
            rx_NewConnection(interfaces[j].addr, 
 
2178
                             interfaces[j].port, 1, sc, 0);
2166
2179
        rx_SetConnDeadTime(conns[j], 2);
2167
2180
        rx_SetConnHardDeadTime(conns[j], AFS_HARDDEADTIME);
2168
2181
        j++;
2180
2193
            H_LOCK;
2181
2194
            if (host->callback_rxcon)
2182
2195
                rx_DestroyConnection(host->callback_rxcon);
 
2196
            hashDelete_r(host->host, host->port, host);
2183
2197
            host->callback_rxcon = conns[multi_i];
2184
2198
            host->host = interfaces[multi_i].addr;
2185
2199
            host->port = interfaces[multi_i].port;
 
2200
            hashInsert_r(host->host, host->port, host);
2186
2201
            connSuccess = conns[multi_i];
2187
2202
            rx_SetConnDeadTime(host->callback_rxcon, 50);
2188
2203
            rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME);
2189
2204
            ViceLog(125,
2190
 
                    ("multiprobe success with addr %s\n",
2191
 
                     afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr)));
 
2205
                    ("multiprobe success for host %x; new primary addr %s:%d\n",
 
2206
                     host, afs_inet_ntoa_r(host->host, hoststr),
 
2207
                     ntohs(host->port)));
2192
2208
            H_UNLOCK;
2193
2209
            multi_Abort;
2194
2210
        } else {
2195
2211
            ViceLog(125,
2196
 
                    ("multiprobe failure with addr %s\n",
2197
 
                     afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr)));
 
2212
                    ("multiprobe failure with addr %s:%d\n",
 
2213
                     afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),
 
2214
                     ntohs(interfaces[multi_i].port)));
2198
2215
            
2199
2216
            /* This is less than desirable but its the best we can do.
2200
2217
             * The AFS Cache Manager will return either 0 for a Uuid  
2204
2221
             * Uuid and fix the host tables.
2205
2222
             */
2206
2223
            if (multi_error == 1) {
2207
 
                struct host * newhost;
2208
 
 
2209
2224
                /* remove the current alternate address from this host */
2210
2225
                H_LOCK;
2211
 
                for (i = 0, j = 0; i < host->interface->numberOfInterfaces; i++) {
2212
 
                    if (interfaces[multi_i].addr != host->interface->interface[i].addr &&
2213
 
                        interfaces[multi_i].port != host->interface->interface[i].port) {
2214
 
                        host->interface->interface[j] = host->interface->interface[i];
2215
 
                        j++;
2216
 
                    }
2217
 
                }
2218
 
                host->interface->numberOfInterfaces--;
 
2226
                removeInterfaceAddr_r(host, interfaces[multi_i].addr, interfaces[multi_i].port);
2219
2227
                H_UNLOCK;
2220
2228
            }
2221
2229
        }