~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/cachefiles/volume.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /* Volume handling.
  3  *
  4  * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
  5  * Written by David Howells (dhowells@redhat.com)
  6  */
  7 
  8 #include <linux/fs.h>
  9 #include <linux/slab.h>
 10 #include "internal.h"
 11 #include <trace/events/fscache.h>
 12 
 13 /*
 14  * Allocate and set up a volume representation.  We make sure all the fanout
 15  * directories are created and pinned.
 16  */
 17 void cachefiles_acquire_volume(struct fscache_volume *vcookie)
 18 {
 19         struct cachefiles_volume *volume;
 20         struct cachefiles_cache *cache = vcookie->cache->cache_priv;
 21         const struct cred *saved_cred;
 22         struct dentry *vdentry, *fan;
 23         size_t len;
 24         char *name;
 25         bool is_new = false;
 26         int ret, n_accesses, i;
 27 
 28         _enter("");
 29 
 30         volume = kzalloc(sizeof(struct cachefiles_volume), GFP_KERNEL);
 31         if (!volume)
 32                 return;
 33         volume->vcookie = vcookie;
 34         volume->cache = cache;
 35         INIT_LIST_HEAD(&volume->cache_link);
 36 
 37         cachefiles_begin_secure(cache, &saved_cred);
 38 
 39         len = vcookie->key[0];
 40         name = kmalloc(len + 3, GFP_NOFS);
 41         if (!name)
 42                 goto error_vol;
 43         name[0] = 'I';
 44         memcpy(name + 1, vcookie->key + 1, len);
 45         name[len + 1] = 0;
 46 
 47 retry:
 48         vdentry = cachefiles_get_directory(cache, cache->store, name, &is_new);
 49         if (IS_ERR(vdentry))
 50                 goto error_name;
 51         volume->dentry = vdentry;
 52 
 53         if (is_new) {
 54                 if (!cachefiles_set_volume_xattr(volume))
 55                         goto error_dir;
 56         } else {
 57                 ret = cachefiles_check_volume_xattr(volume);
 58                 if (ret < 0) {
 59                         if (ret != -ESTALE)
 60                                 goto error_dir;
 61                         inode_lock_nested(d_inode(cache->store), I_MUTEX_PARENT);
 62                         cachefiles_bury_object(cache, NULL, cache->store, vdentry,
 63                                                FSCACHE_VOLUME_IS_WEIRD);
 64                         cachefiles_put_directory(volume->dentry);
 65                         cond_resched();
 66                         goto retry;
 67                 }
 68         }
 69         
 70         for (i = 0; i < 256; i++) {
 71                 sprintf(name, "@%02x", i);
 72                 fan = cachefiles_get_directory(cache, vdentry, name, NULL);
 73                 if (IS_ERR(fan))
 74                         goto error_fan;
 75                 volume->fanout[i] = fan;
 76         }
 77 
 78         cachefiles_end_secure(cache, saved_cred);
 79 
 80         vcookie->cache_priv = volume;
 81         n_accesses = atomic_inc_return(&vcookie->n_accesses); /* Stop wakeups on dec-to-0 */
 82         trace_fscache_access_volume(vcookie->debug_id, 0,
 83                                     refcount_read(&vcookie->ref),
 84                                     n_accesses, fscache_access_cache_pin);
 85 
 86         spin_lock(&cache->object_list_lock);
 87         list_add(&volume->cache_link, &volume->cache->volumes);
 88         spin_unlock(&cache->object_list_lock);
 89 
 90         kfree(name);
 91         return;
 92 
 93 error_fan:
 94         for (i = 0; i < 256; i++)
 95                 cachefiles_put_directory(volume->fanout[i]);
 96 error_dir:
 97         cachefiles_put_directory(volume->dentry);
 98 error_name:
 99         kfree(name);
100 error_vol:
101         kfree(volume);
102         cachefiles_end_secure(cache, saved_cred);
103 }
104 
105 /*
106  * Release a volume representation.
107  */
108 static void __cachefiles_free_volume(struct cachefiles_volume *volume)
109 {
110         int i;
111 
112         _enter("");
113 
114         volume->vcookie->cache_priv = NULL;
115 
116         for (i = 0; i < 256; i++)
117                 cachefiles_put_directory(volume->fanout[i]);
118         cachefiles_put_directory(volume->dentry);
119         kfree(volume);
120 }
121 
122 void cachefiles_free_volume(struct fscache_volume *vcookie)
123 {
124         struct cachefiles_volume *volume = vcookie->cache_priv;
125 
126         if (volume) {
127                 spin_lock(&volume->cache->object_list_lock);
128                 list_del_init(&volume->cache_link);
129                 spin_unlock(&volume->cache->object_list_lock);
130                 __cachefiles_free_volume(volume);
131         }
132 }
133 
134 void cachefiles_withdraw_volume(struct cachefiles_volume *volume)
135 {
136         cachefiles_set_volume_xattr(volume);
137         __cachefiles_free_volume(volume);
138 }
139 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php