Lines Matching refs:volume

2 /* AFS volume management
15 * Insert a volume into a cell. If there's an existing volume record, that is
19 struct afs_volume *volume)
30 if (p->vid < volume->vid) {
32 } else if (p->vid > volume->vid) {
36 volume = p;
40 set_bit(AFS_VOLUME_RM_TREE, &volume->flags);
41 rb_replace_node_rcu(&p->cell_node, &volume->cell_node, &cell->volumes);
45 rb_link_node_rcu(&volume->cell_node, parent, pp);
46 rb_insert_color(&volume->cell_node, &cell->volumes);
47 hlist_add_head_rcu(&volume->proc_link, &cell->proc_volumes);
51 return volume;
55 static void afs_remove_volume_from_cell(struct afs_volume *volume)
57 struct afs_cell *cell = volume->cell;
59 if (!hlist_unhashed(&volume->proc_link)) {
60 trace_afs_volume(volume->vid, refcount_read(&cell->ref),
63 hlist_del_rcu(&volume->proc_link);
64 if (!test_and_set_bit(AFS_VOLUME_RM_TREE, &volume->flags))
65 rb_erase(&volume->cell_node, &cell->volumes);
71 * Allocate a volume record and load it up from a vldb record.
78 struct afs_volume *volume;
81 volume = kzalloc(sizeof(struct afs_volume), GFP_KERNEL);
82 if (!volume)
85 volume->vid = vldb->vid[params->type];
86 volume->update_at = ktime_get_real_seconds() + afs_volume_record_life;
87 volume->cell = afs_get_cell(params->cell, afs_cell_trace_get_vol);
88 volume->type = params->type;
89 volume->type_force = params->force;
90 volume->name_len = vldb->name_len;
92 refcount_set(&volume->ref, 1);
93 INIT_HLIST_NODE(&volume->proc_link);
94 rwlock_init(&volume->servers_lock);
95 rwlock_init(&volume->cb_v_break_lock);
96 memcpy(volume->name, vldb->name, vldb->name_len + 1);
105 rcu_assign_pointer(volume->servers, slist);
106 trace_afs_volume(volume->vid, 1, afs_volume_trace_alloc);
107 return volume;
110 afs_put_cell(volume->cell, afs_cell_trace_put_vol);
111 kfree(volume);
117 * Look up or allocate a volume record.
123 struct afs_volume *candidate, *volume;
129 volume = afs_insert_volume_into_cell(params->cell, candidate);
130 if (volume != candidate)
132 return volume;
136 * Look up a VLDB record for a volume.
159 * Look up a volume in the VL server and create a candidate volume record for
162 * The volume name can be one of the following:
163 * "%[cell:]volume[.]" R/W volume
164 * "#[cell:]volume[.]" R/O or R/W volume (rwparent=0),
165 * or R/W (rwparent=1) volume
166 * "%[cell:]volume.readonly" R/O volume
167 * "#[cell:]volume.readonly" R/O volume
168 * "%[cell:]volume.backup" Backup volume
169 * "#[cell:]volume.backup" Backup volume
177 * - Rule 2: If parent volume is R/O, then mount R/O volume by preference, R/W
179 * - Rule 3: If parent volume is R/W, then only mount R/W volume unless
185 struct afs_volume *volume;
194 volume = ERR_PTR(vldb->error);
199 volume = ERR_PTR(-ENOMEDIUM);
212 volume = afs_lookup_volume(params, vldb, type_mask);
216 return volume;
220 * Destroy a volume record
222 static void afs_destroy_volume(struct afs_net *net, struct afs_volume *volume)
224 _enter("%p", volume);
227 ASSERTCMP(volume->cache, ==, NULL);
230 afs_remove_volume_from_cell(volume);
231 afs_put_serverlist(net, rcu_access_pointer(volume->servers));
232 afs_put_cell(volume->cell, afs_cell_trace_put_vol);
233 trace_afs_volume(volume->vid, refcount_read(&volume->ref),
235 kfree_rcu(volume, rcu);
241 * Try to get a reference on a volume record.
243 bool afs_try_get_volume(struct afs_volume *volume, enum afs_volume_trace reason)
247 if (__refcount_inc_not_zero(&volume->ref, &r)) {
248 trace_afs_volume(volume->vid, r + 1, reason);
255 * Get a reference on a volume record.
257 struct afs_volume *afs_get_volume(struct afs_volume *volume,
260 if (volume) {
263 __refcount_inc(&volume->ref, &r);
264 trace_afs_volume(volume->vid, r + 1, reason);
266 return volume;
271 * Drop a reference on a volume record.
273 void afs_put_volume(struct afs_net *net, struct afs_volume *volume,
276 if (volume) {
277 afs_volid_t vid = volume->vid;
281 zero = __refcount_dec_and_test(&volume->ref, &r);
284 afs_destroy_volume(net, volume);
289 * Activate a volume.
291 int afs_activate_volume(struct afs_volume *volume)
298 volume->cell->name, volume->vid);
308 pr_err("AFS: Cache volume key already in use (%s)\n", name);
311 volume->cache = vcookie;
318 * Deactivate a volume.
320 void afs_deactivate_volume(struct afs_volume *volume)
322 _enter("%s", volume->name);
325 fscache_relinquish_volume(volume->cache, NULL,
326 test_bit(AFS_VOLUME_DELETED, &volume->flags));
327 volume->cache = NULL;
334 * Query the VL service to update the volume status.
336 static int afs_update_volume_status(struct afs_volume *volume, struct key *key)
348 idsz = snprintf(idbuf, sizeof(idbuf), "%llu", volume->vid);
350 vldb = afs_vl_lookup_vldb(volume->cell, key, idbuf, idsz);
356 /* See if the volume got renamed. */
357 if (vldb->name_len != volume->name_len ||
358 memcmp(vldb->name, volume->name, vldb->name_len) != 0) {
360 memcpy(volume->name, vldb->name, AFS_MAXVOLNAME);
361 volume->name_len = vldb->name_len;
364 /* See if the volume's server list got updated. */
365 new = afs_alloc_server_list(volume->cell, key,
366 vldb, (1 << volume->type));
372 write_lock(&volume->servers_lock);
375 old = rcu_dereference_protected(volume->servers,
376 lockdep_is_held(&volume->servers_lock));
378 new->seq = volume->servers_seq + 1;
379 rcu_assign_pointer(volume->servers, new);
381 volume->servers_seq++;
385 volume->update_at = ktime_get_real_seconds() + afs_volume_record_life;
386 write_unlock(&volume->servers_lock);
389 afs_put_serverlist(volume->cell->net, discard);
398 * Make sure the volume record is up to date.
400 int afs_check_volume_status(struct afs_volume *volume, struct afs_operation *op)
407 if (test_bit(AFS_VOLUME_WAIT, &volume->flags))
409 if (volume->update_at <= ktime_get_real_seconds() ||
410 test_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags))
416 if (!test_and_set_bit_lock(AFS_VOLUME_UPDATING, &volume->flags)) {
417 clear_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags);
418 ret = afs_update_volume_status(volume, op->key);
420 set_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags);
421 clear_bit_unlock(AFS_VOLUME_WAIT, &volume->flags);
422 clear_bit_unlock(AFS_VOLUME_UPDATING, &volume->flags);
423 wake_up_bit(&volume->flags, AFS_VOLUME_WAIT);
429 if (!test_bit(AFS_VOLUME_WAIT, &volume->flags)) {
434 ret = wait_on_bit(&volume->flags, AFS_VOLUME_WAIT,