Lines Matching +full:entry +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Squashfs - a compressed read only filesystem for Linux
23 * are decompressed and cached in the page-cache in the normal way. The
29 * have been packed with it, these because of locality-of-reference may be read
49 * Look-up block in cache, and increment usage count. If not in cache, read
56 struct squashfs_cache_entry *entry;
58 spin_lock(&cache->lock);
61 for (i = cache->curr_blk, n = 0; n < cache->entries; n++) {
62 if (cache->entry[i].block == block) {
63 cache->curr_blk = i;
66 i = (i + 1) % cache->entries;
69 if (n == cache->entries) {
74 if (cache->unused == 0) {
75 cache->num_waiters++;
76 spin_unlock(&cache->lock);
77 wait_event(cache->wait_queue, cache->unused);
78 spin_lock(&cache->lock);
79 cache->num_waiters--;
84 * At least one unused cache entry. A simple
85 * round-robin strategy is used to choose the entry to
88 i = cache->next_blk;
89 for (n = 0; n < cache->entries; n++) {
90 if (cache->entry[i].refcount == 0)
92 i = (i + 1) % cache->entries;
95 cache->next_blk = (i + 1) % cache->entries;
96 entry = &cache->entry[i];
99 * Initialise chosen cache entry, and fill it in from
102 cache->unused--;
103 entry->block = block;
104 entry->refcount = 1;
105 entry->pending = 1;
106 entry->num_waiters = 0;
107 entry->error = 0;
108 spin_unlock(&cache->lock);
110 entry->length = squashfs_read_data(sb, block, length,
111 &entry->next_index, entry->actor);
113 spin_lock(&cache->lock);
115 if (entry->length < 0)
116 entry->error = entry->length;
118 entry->pending = 0;
121 * While filling this entry one or more other processes
125 if (entry->num_waiters) {
126 spin_unlock(&cache->lock);
127 wake_up_all(&entry->wait_queue);
129 spin_unlock(&cache->lock);
137 * previously unused there's one less cache entry available
140 entry = &cache->entry[i];
141 if (entry->refcount == 0)
142 cache->unused--;
143 entry->refcount++;
146 * If the entry is currently being filled in by another process
149 if (entry->pending) {
150 entry->num_waiters++;
151 spin_unlock(&cache->lock);
152 wait_event(entry->wait_queue, !entry->pending);
154 spin_unlock(&cache->lock);
161 cache->name, i, entry->block, entry->refcount, entry->error);
163 if (entry->error)
164 ERROR("Unable to read %s cache entry [%llx]\n", cache->name,
166 return entry;
171 * Release cache entry, once usage count is zero it can be reused.
173 void squashfs_cache_put(struct squashfs_cache_entry *entry)
175 struct squashfs_cache *cache = entry->cache;
177 spin_lock(&cache->lock);
178 entry->refcount--;
179 if (entry->refcount == 0) {
180 cache->unused++;
185 if (cache->num_waiters) {
186 spin_unlock(&cache->lock);
187 wake_up(&cache->wait_queue);
191 spin_unlock(&cache->lock);
204 for (i = 0; i < cache->entries; i++) {
205 if (cache->entry[i].data) {
206 for (j = 0; j < cache->pages; j++)
207 kfree(cache->entry[i].data[j]);
208 kfree(cache->entry[i].data);
210 kfree(cache->entry[i].actor);
213 kfree(cache->entry);
220 * size block_size. To avoid vmalloc fragmentation issues each entry
223 struct squashfs_cache *squashfs_cache_init(char *name, int entries,
234 ERROR("Failed to allocate %s cache\n", name);
235 return ERR_PTR(-ENOMEM);
238 cache->entry = kcalloc(entries, sizeof(*(cache->entry)), GFP_KERNEL);
239 if (cache->entry == NULL) {
240 ERROR("Failed to allocate %s cache\n", name);
244 cache->curr_blk = 0;
245 cache->next_blk = 0;
246 cache->unused = entries;
247 cache->entries = entries;
248 cache->block_size = block_size;
249 cache->pages = block_size >> PAGE_SHIFT;
250 cache->pages = cache->pages ? cache->pages : 1;
251 cache->name = name;
252 cache->num_waiters = 0;
253 spin_lock_init(&cache->lock);
254 init_waitqueue_head(&cache->wait_queue);
257 struct squashfs_cache_entry *entry = &cache->entry[i];
259 init_waitqueue_head(&cache->entry[i].wait_queue);
260 entry->cache = cache;
261 entry->block = SQUASHFS_INVALID_BLK;
262 entry->data = kcalloc(cache->pages, sizeof(void *), GFP_KERNEL);
263 if (entry->data == NULL) {
264 ERROR("Failed to allocate %s cache entry\n", name);
268 for (j = 0; j < cache->pages; j++) {
269 entry->data[j] = kmalloc(PAGE_SIZE, GFP_KERNEL);
270 if (entry->data[j] == NULL) {
271 ERROR("Failed to allocate %s buffer\n", name);
276 entry->actor = squashfs_page_actor_init(entry->data,
277 cache->pages, 0);
278 if (entry->actor == NULL) {
279 ERROR("Failed to allocate %s cache entry\n", name);
288 return ERR_PTR(-ENOMEM);
293 * Copy up to length bytes from cache entry to buffer starting at offset bytes
294 * into the cache entry. If there's not length bytes then copy the number of
297 int squashfs_copy_data(void *buffer, struct squashfs_cache_entry *entry,
305 return min(length, entry->length - offset);
307 while (offset < entry->length) {
308 void *buff = entry->data[offset / PAGE_SIZE]
310 int bytes = min_t(int, entry->length - offset,
311 PAGE_SIZE - (offset % PAGE_SIZE));
321 remaining -= bytes;
325 return length - remaining;
338 struct squashfs_sb_info *msblk = sb->s_fs_info;
340 struct squashfs_cache_entry *entry;
345 return -EIO;
348 entry = squashfs_cache_get(sb, msblk->block_cache, *block, 0);
349 if (entry->error) {
350 res = entry->error;
352 } else if (*offset >= entry->length) {
353 res = -EIO;
357 bytes = squashfs_copy_data(buffer, entry, *offset, length);
360 length -= bytes;
363 if (*offset == entry->length) {
364 *block = entry->next_index;
368 squashfs_cache_put(entry);
374 squashfs_cache_put(entry);
380 * Look-up in the fragmment cache the fragment located at <start_block> in the
386 struct squashfs_sb_info *msblk = sb->s_fs_info;
388 return squashfs_cache_get(sb, msblk->fragment_cache, start_block,
401 struct squashfs_sb_info *msblk = sb->s_fs_info;
403 return squashfs_cache_get(sb, msblk->read_page, start_block, length);
412 int pages = (length + PAGE_SIZE - 1) >> PAGE_SHIFT;
419 return ERR_PTR(-ENOMEM);
423 res = -ENOMEM;
429 res = -ENOMEM;