blob: a605bea2e3a0ef69b70ce2d03c3b02a177214978 [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* AFS volume management
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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
David Howellsec268152007-04-26 15:49:28 -070012#ifndef AFS_VOLUME_H
13#define AFS_VOLUME_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include "types.h"
16#include "fsclient.h"
17#include "kafstimod.h"
18#include "kafsasyncd.h"
19#include "cache.h"
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021typedef 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070026} __attribute__((packed)) afs_vlocation_upd_t;
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028/*
29 * entry in the cached volume location catalogue
30 */
David Howellsec268152007-04-26 15:49:28 -070031struct afs_cache_vlocation {
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 uint8_t name[64]; /* volume name (lowercase, padded with NULs) */
33 uint8_t nservers; /* number of entries used in servers[] */
34 uint8_t vidmask; /* voltype mask for vid[] */
35 uint8_t srvtmask[8]; /* voltype masks for servers[] */
36#define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
37#define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
38#define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
39
40 afs_volid_t vid[3]; /* volume IDs for R/W, R/O and Bak volumes */
41 struct in_addr servers[8]; /* fileserver addresses */
42 time_t rtime; /* last retrieval time */
43};
44
45#ifdef AFS_CACHING_SUPPORT
46extern struct cachefs_index_def afs_vlocation_cache_index_def;
47#endif
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049/*
50 * volume -> vnode hash table entry
51 */
David Howellsec268152007-04-26 15:49:28 -070052struct afs_cache_vhash {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 afs_voltype_t vtype; /* which volume variation */
54 uint8_t hash_bucket; /* which hash bucket this represents */
55} __attribute__((packed));
56
57#ifdef AFS_CACHING_SUPPORT
58extern struct cachefs_index_def afs_volume_cache_index_def;
59#endif
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/*
62 * AFS volume location record
63 */
David Howellsec268152007-04-26 15:49:28 -070064struct afs_vlocation {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 atomic_t usage;
66 struct list_head link; /* link in cell volume location list */
67 struct afs_timer timeout; /* decaching timer */
68 struct afs_cell *cell; /* cell to which volume belongs */
69#ifdef AFS_CACHING_SUPPORT
70 struct cachefs_cookie *cache; /* caching cookie */
71#endif
72 struct afs_cache_vlocation vldb; /* volume information DB record */
73 struct afs_volume *vols[3]; /* volume access record pointer (index by type) */
74 rwlock_t lock; /* access lock */
75 unsigned long read_jif; /* time at which last read from vlserver */
76 struct afs_timer upd_timer; /* update timer */
77 struct afs_async_op upd_op; /* update operation */
78 afs_vlocation_upd_t upd_state; /* update state */
79 unsigned short upd_first_svix; /* first server index during update */
80 unsigned short upd_curr_svix; /* current server index during update */
81 unsigned short upd_rej_cnt; /* ENOMEDIUM count during update */
82 unsigned short upd_busy_cnt; /* EBUSY count during update */
83 unsigned short valid; /* T if valid */
84};
85
David Howellsec268152007-04-26 15:49:28 -070086extern int afs_vlocation_lookup(struct afs_cell *, const char *, unsigned,
87 struct afs_vlocation **);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89#define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0)
90
David Howellsec268152007-04-26 15:49:28 -070091extern void afs_put_vlocation(struct afs_vlocation *);
92extern void afs_vlocation_do_timeout(struct afs_vlocation *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/*
95 * AFS volume access record
96 */
David Howellsec268152007-04-26 15:49:28 -070097struct afs_volume {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 atomic_t usage;
99 struct afs_cell *cell; /* cell to which belongs (unrefd ptr) */
100 struct afs_vlocation *vlocation; /* volume location */
101#ifdef AFS_CACHING_SUPPORT
102 struct cachefs_cookie *cache; /* caching cookie */
103#endif
104 afs_volid_t vid; /* volume ID */
Jan Blunckbfc090c2006-01-08 01:05:08 -0800105 afs_voltype_t type; /* type of volume */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 char type_force; /* force volume type (suppress R/O -> R/W) */
107 unsigned short nservers; /* number of server slots filled */
108 unsigned short rjservers; /* number of servers discarded due to -ENOMEDIUM */
109 struct afs_server *servers[8]; /* servers on which volume resides (ordered) */
110 struct rw_semaphore server_sem; /* lock for accessing current server */
111};
112
David Howellsec268152007-04-26 15:49:28 -0700113extern int afs_volume_lookup(const char *, struct afs_cell *, int,
114 struct afs_volume **);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116#define afs_get_volume(V) do { atomic_inc(&(V)->usage); } while(0)
117
David Howellsec268152007-04-26 15:49:28 -0700118extern void afs_put_volume(struct afs_volume *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
David Howellsec268152007-04-26 15:49:28 -0700120extern int afs_volume_pick_fileserver(struct afs_volume *,
121 struct afs_server **);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
David Howellsec268152007-04-26 15:49:28 -0700123extern int afs_volume_release_fileserver(struct afs_volume *,
124 struct afs_server *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
David Howellsec268152007-04-26 15:49:28 -0700126#endif /* AFS_VOLUME_H */