Lines Matching +full:1 +full:- +full:cell
1 // SPDX-License-Identifier: GPL-2.0-or-later
17 * Insert a volume into a cell. If there's an existing volume record, that is
20 static struct afs_volume *afs_insert_volume_into_cell(struct afs_cell *cell, in afs_insert_volume_into_cell() argument
26 write_seqlock(&cell->volume_lock); in afs_insert_volume_into_cell()
28 pp = &cell->volumes.rb_node; in afs_insert_volume_into_cell()
32 if (p->vid < volume->vid) { in afs_insert_volume_into_cell()
33 pp = &(*pp)->rb_left; in afs_insert_volume_into_cell()
34 } else if (p->vid > volume->vid) { in afs_insert_volume_into_cell()
35 pp = &(*pp)->rb_right; in afs_insert_volume_into_cell()
42 set_bit(AFS_VOLUME_RM_TREE, &volume->flags); in afs_insert_volume_into_cell()
43 rb_replace_node_rcu(&p->cell_node, &volume->cell_node, &cell->volumes); in afs_insert_volume_into_cell()
47 rb_link_node_rcu(&volume->cell_node, parent, pp); in afs_insert_volume_into_cell()
48 rb_insert_color(&volume->cell_node, &cell->volumes); in afs_insert_volume_into_cell()
49 hlist_add_head_rcu(&volume->proc_link, &cell->proc_volumes); in afs_insert_volume_into_cell()
52 write_sequnlock(&cell->volume_lock); in afs_insert_volume_into_cell()
59 struct afs_cell *cell = volume->cell; in afs_remove_volume_from_cell() local
61 if (!hlist_unhashed(&volume->proc_link)) { in afs_remove_volume_from_cell()
62 trace_afs_volume(volume->vid, refcount_read(&cell->ref), in afs_remove_volume_from_cell()
64 write_seqlock(&cell->volume_lock); in afs_remove_volume_from_cell()
65 hlist_del_rcu(&volume->proc_link); in afs_remove_volume_from_cell()
66 if (!test_and_set_bit(AFS_VOLUME_RM_TREE, &volume->flags)) in afs_remove_volume_from_cell()
67 rb_erase(&volume->cell_node, &cell->volumes); in afs_remove_volume_from_cell()
68 write_sequnlock(&cell->volume_lock); in afs_remove_volume_from_cell()
81 int ret = -ENOMEM, i; in afs_alloc_volume()
87 volume->vid = vldb->vid[params->type]; in afs_alloc_volume()
88 volume->update_at = ktime_get_real_seconds() + afs_volume_record_life; in afs_alloc_volume()
89 volume->cell = afs_get_cell(params->cell, afs_cell_trace_get_vol); in afs_alloc_volume()
90 volume->type = params->type; in afs_alloc_volume()
91 volume->type_force = params->force; in afs_alloc_volume()
92 volume->name_len = vldb->name_len; in afs_alloc_volume()
93 volume->creation_time = TIME64_MIN; in afs_alloc_volume()
94 volume->update_time = TIME64_MIN; in afs_alloc_volume()
96 refcount_set(&volume->ref, 1); in afs_alloc_volume()
97 INIT_HLIST_NODE(&volume->proc_link); in afs_alloc_volume()
98 INIT_WORK(&volume->destructor, afs_destroy_volume); in afs_alloc_volume()
99 rwlock_init(&volume->servers_lock); in afs_alloc_volume()
100 mutex_init(&volume->volsync_lock); in afs_alloc_volume()
101 mutex_init(&volume->cb_check_lock); in afs_alloc_volume()
102 rwlock_init(&volume->cb_v_break_lock); in afs_alloc_volume()
103 INIT_LIST_HEAD(&volume->open_mmaps); in afs_alloc_volume()
104 init_rwsem(&volume->open_mmaps_lock); in afs_alloc_volume()
105 memcpy(volume->name, vldb->name, vldb->name_len + 1); in afs_alloc_volume()
108 volume->vids[i] = vldb->vid[i]; in afs_alloc_volume()
110 slist = afs_alloc_server_list(volume, params->key, vldb); in afs_alloc_volume()
117 rcu_assign_pointer(volume->servers, slist); in afs_alloc_volume()
118 trace_afs_volume(volume->vid, 1, afs_volume_trace_alloc); in afs_alloc_volume()
122 afs_put_cell(volume->cell, afs_cell_trace_put_vol); in afs_alloc_volume()
141 volume = afs_insert_volume_into_cell(params->cell, candidate); in afs_lookup_volume()
152 static struct afs_vldb_entry *afs_vl_lookup_vldb(struct afs_cell *cell, in afs_vl_lookup_vldb() argument
157 struct afs_vldb_entry *vldb = ERR_PTR(-EDESTADDRREQ); in afs_vl_lookup_vldb()
161 if (!afs_begin_vlserver_operation(&vc, cell, key)) in afs_vl_lookup_vldb()
162 return ERR_PTR(-ERESTARTSYS); in afs_vl_lookup_vldb()
177 * "%[cell:]volume[.]" R/W volume
178 * "#[cell:]volume[.]" R/O or R/W volume (rwparent=0),
179 * or R/W (rwparent=1) volume
180 * "%[cell:]volume.readonly" R/O volume
181 * "#[cell:]volume.readonly" R/O volume
182 * "%[cell:]volume.backup" Backup volume
183 * "#[cell:]volume.backup" Backup volume
185 * The cell name is optional, and defaults to the current cell.
189 * - Rule 1: Explicit type suffix forces access of that type or nothing
191 * - Rule 2: If parent volume is R/O, then mount R/O volume by preference, R/W
193 * - Rule 3: If parent volume is R/W, then only mount R/W volume unless
200 unsigned long type_mask = 1UL << params->type; in afs_create_volume()
202 vldb = afs_vl_lookup_vldb(params->cell, params->key, in afs_create_volume()
203 params->volname, params->volnamesz); in afs_create_volume()
207 if (test_bit(AFS_VLDB_QUERY_ERROR, &vldb->flags)) { in afs_create_volume()
208 volume = ERR_PTR(vldb->error); in afs_create_volume()
213 volume = ERR_PTR(-ENOMEDIUM); in afs_create_volume()
214 if (params->force) { in afs_create_volume()
215 if (!(vldb->flags & type_mask)) in afs_create_volume()
217 } else if (test_bit(AFS_VLDB_HAS_RO, &vldb->flags)) { in afs_create_volume()
218 params->type = AFSVL_ROVOL; in afs_create_volume()
219 } else if (test_bit(AFS_VLDB_HAS_RW, &vldb->flags)) { in afs_create_volume()
220 params->type = AFSVL_RWVOL; in afs_create_volume()
238 struct afs_server_list *slist = rcu_access_pointer(volume->servers); in afs_destroy_volume()
243 ASSERTCMP(volume->cache, ==, NULL); in afs_destroy_volume()
248 afs_put_serverlist(volume->cell->net, slist); in afs_destroy_volume()
249 afs_put_cell(volume->cell, afs_cell_trace_put_vol); in afs_destroy_volume()
250 trace_afs_volume(volume->vid, refcount_read(&volume->ref), in afs_destroy_volume()
264 if (__refcount_inc_not_zero(&volume->ref, &r)) { in afs_try_get_volume()
265 trace_afs_volume(volume->vid, r + 1, reason); in afs_try_get_volume()
280 __refcount_inc(&volume->ref, &r); in afs_get_volume()
281 trace_afs_volume(volume->vid, r + 1, reason); in afs_get_volume()
293 afs_volid_t vid = volume->vid; in afs_put_volume()
297 zero = __refcount_dec_and_test(&volume->ref, &r); in afs_put_volume()
298 trace_afs_volume(vid, r - 1, reason); in afs_put_volume()
300 schedule_work(&volume->destructor); in afs_put_volume()
314 volume->cell->name, volume->vid); in afs_activate_volume()
316 return -ENOMEM; in afs_activate_volume()
320 if (vcookie != ERR_PTR(-EBUSY)) { in afs_activate_volume()
327 volume->cache = vcookie; in afs_activate_volume()
338 _enter("%s", volume->name); in afs_deactivate_volume()
341 fscache_relinquish_volume(volume->cache, NULL, in afs_deactivate_volume()
342 test_bit(AFS_VOLUME_DELETED, &volume->flags)); in afs_deactivate_volume()
343 volume->cache = NULL; in afs_deactivate_volume()
364 idsz = snprintf(idbuf, sizeof(idbuf), "%llu", volume->vid); in afs_update_volume_status()
366 vldb = afs_vl_lookup_vldb(volume->cell, key, idbuf, idsz); in afs_update_volume_status()
373 if (vldb->name_len != volume->name_len || in afs_update_volume_status()
374 memcmp(vldb->name, volume->name, vldb->name_len) != 0) { in afs_update_volume_status()
376 memcpy(volume->name, vldb->name, AFS_MAXVOLNAME); in afs_update_volume_status()
377 volume->name_len = vldb->name_len; in afs_update_volume_status()
387 write_lock(&volume->servers_lock); in afs_update_volume_status()
390 old = rcu_dereference_protected(volume->servers, in afs_update_volume_status()
391 lockdep_is_held(&volume->servers_lock)); in afs_update_volume_status()
393 new->seq = volume->servers_seq + 1; in afs_update_volume_status()
394 rcu_assign_pointer(volume->servers, new); in afs_update_volume_status()
396 volume->servers_seq++; in afs_update_volume_status()
401 if (new->ro_replicating) in afs_update_volume_status()
402 volume->update_at = ktime_get_real_seconds() + 10 * 60; in afs_update_volume_status()
404 volume->update_at = ktime_get_real_seconds() + afs_volume_record_life; in afs_update_volume_status()
405 write_unlock(&volume->servers_lock); in afs_update_volume_status()
409 afs_put_serverlist(volume->cell->net, discard); in afs_update_volume_status()
428 if (test_bit(AFS_VOLUME_WAIT, &volume->flags)) in afs_check_volume_status()
430 if (volume->update_at <= ktime_get_real_seconds() || in afs_check_volume_status()
431 test_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags)) in afs_check_volume_status()
437 if (!test_and_set_bit_lock(AFS_VOLUME_UPDATING, &volume->flags)) { in afs_check_volume_status()
438 clear_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags); in afs_check_volume_status()
439 ret = afs_update_volume_status(volume, op->key); in afs_check_volume_status()
441 set_bit(AFS_VOLUME_NEEDS_UPDATE, &volume->flags); in afs_check_volume_status()
442 clear_bit_unlock(AFS_VOLUME_WAIT, &volume->flags); in afs_check_volume_status()
443 clear_bit_unlock(AFS_VOLUME_UPDATING, &volume->flags); in afs_check_volume_status()
444 wake_up_bit(&volume->flags, AFS_VOLUME_WAIT); in afs_check_volume_status()
450 if (!test_bit(AFS_VOLUME_WAIT, &volume->flags)) { in afs_check_volume_status()
455 ret = wait_on_bit(&volume->flags, AFS_VOLUME_WAIT, in afs_check_volume_status()
456 (op->flags & AFS_OPERATION_UNINTR) ? in afs_check_volume_status()
458 if (ret == -ERESTARTSYS) { in afs_check_volume_status()
465 _leave(" = -ESTALE"); in afs_check_volume_status()
466 return -ESTALE; in afs_check_volume_status()