Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / fs / afs / volume.h
1 /* volume.h: AFS volume management
2  *
3  * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #ifndef _LINUX_AFS_VOLUME_H
13 #define _LINUX_AFS_VOLUME_H
14
15 #include <linux/fscache.h>
16 #include "types.h"
17 #include "fsclient.h"
18 #include "kafstimod.h"
19 #include "kafsasyncd.h"
20
21 typedef enum {
22         AFS_VLUPD_SLEEP,                /* sleeping waiting for update timer to fire */
23         AFS_VLUPD_PENDING,              /* on pending queue */
24         AFS_VLUPD_INPROGRESS,           /* op in progress */
25         AFS_VLUPD_BUSYSLEEP,            /* sleeping because server returned EBUSY */
26         
27 } __attribute__((packed)) afs_vlocation_upd_t;
28
29 /*****************************************************************************/
30 /*
31  * entry in the cached volume location catalogue
32  */
33 struct afs_cache_vlocation
34 {
35         uint8_t                 name[64];       /* volume name (lowercase, padded with NULs) */
36         uint8_t                 nservers;       /* number of entries used in servers[] */
37         uint8_t                 vidmask;        /* voltype mask for vid[] */
38         uint8_t                 srvtmask[8];    /* voltype masks for servers[] */
39 #define AFS_VOL_VTM_RW  0x01 /* R/W version of the volume is available (on this server) */
40 #define AFS_VOL_VTM_RO  0x02 /* R/O version of the volume is available (on this server) */
41 #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
42
43         afs_volid_t             vid[3];         /* volume IDs for R/W, R/O and Bak volumes */
44         struct in_addr          servers[8];     /* fileserver addresses */
45         time_t                  rtime;          /* last retrieval time */
46 };
47
48 /*****************************************************************************/
49 /*
50  * AFS volume location record
51  */
52 struct afs_vlocation
53 {
54         atomic_t                usage;
55         struct list_head        link;           /* link in cell volume location list */
56         struct afs_timer        timeout;        /* decaching timer */
57         struct afs_cell         *cell;          /* cell to which volume belongs */
58 #ifdef CONFIG_AFS_FSCACHE
59         struct fscache_cookie   *cache;         /* caching cookie */
60 #endif
61         struct afs_cache_vlocation vldb;        /* volume information DB record */
62         struct afs_volume       *vols[3];       /* volume access record pointer (index by type) */
63         rwlock_t                lock;           /* access lock */
64         unsigned long           read_jif;       /* time at which last read from vlserver */
65         struct afs_timer        upd_timer;      /* update timer */
66         struct afs_async_op     upd_op;         /* update operation */
67         afs_vlocation_upd_t     upd_state;      /* update state */
68         unsigned short          upd_first_svix; /* first server index during update */
69         unsigned short          upd_curr_svix;  /* current server index during update */
70         unsigned short          upd_rej_cnt;    /* ENOMEDIUM count during update */
71         unsigned short          upd_busy_cnt;   /* EBUSY count during update */
72         unsigned short          valid;          /* T if valid */
73 };
74
75 extern int afs_vlocation_lookup(struct afs_cell *cell,
76                                 const char *name,
77                                 unsigned namesz,
78                                 struct afs_vlocation **_vlocation);
79
80 #define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0)
81
82 extern void afs_put_vlocation(struct afs_vlocation *vlocation);
83 extern void afs_vlocation_do_timeout(struct afs_vlocation *vlocation);
84
85 /*****************************************************************************/
86 /*
87  * AFS volume access record
88  */
89 struct afs_volume
90 {
91         atomic_t                usage;
92         struct afs_cell         *cell;          /* cell to which belongs (unrefd ptr) */
93         struct afs_vlocation    *vlocation;     /* volume location */
94 #ifdef CONFIG_AFS_FSCACHE
95         struct fscache_cookie   *cache;         /* caching cookie */
96 #endif
97         afs_volid_t             vid;            /* volume ID */
98         afs_voltype_t           type;           /* type of volume */
99         char                    type_force;     /* force volume type (suppress R/O -> R/W) */
100         unsigned short          nservers;       /* number of server slots filled */
101         unsigned short          rjservers;      /* number of servers discarded due to -ENOMEDIUM */
102         struct afs_server       *servers[8];    /* servers on which volume resides (ordered) */
103         struct rw_semaphore     server_sem;     /* lock for accessing current server */
104 };
105
106 extern int afs_volume_lookup(const char *name,
107                              struct afs_cell *cell,
108                              int rwpath,
109                              struct afs_volume **_volume);
110
111 #define afs_get_volume(V) do { atomic_inc(&(V)->usage); } while(0)
112
113 extern void afs_put_volume(struct afs_volume *volume);
114
115 extern int afs_volume_pick_fileserver(struct afs_volume *volume,
116                                       struct afs_server **_server);
117
118 extern int afs_volume_release_fileserver(struct afs_volume *volume,
119                                          struct afs_server *server,
120                                          int result);
121
122 #endif /* _LINUX_AFS_VOLUME_H */