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; in squashfs_cache_get() local
58 spin_lock(&cache->lock); in squashfs_cache_get()
61 for (i = cache->curr_blk, n = 0; n < cache->entries; n++) { in squashfs_cache_get()
62 if (cache->entry[i].block == block) { in squashfs_cache_get()
63 cache->curr_blk = i; in squashfs_cache_get()
66 i = (i + 1) % cache->entries; in squashfs_cache_get()
69 if (n == cache->entries) { in squashfs_cache_get()
74 if (cache->unused == 0) { in squashfs_cache_get()
75 cache->num_waiters++; in squashfs_cache_get()
76 spin_unlock(&cache->lock); in squashfs_cache_get()
77 wait_event(cache->wait_queue, cache->unused); in squashfs_cache_get()
78 spin_lock(&cache->lock); in squashfs_cache_get()
79 cache->num_waiters--; in squashfs_cache_get()
84 * At least one unused cache entry. A simple in squashfs_cache_get()
85 * round-robin strategy is used to choose the entry to in squashfs_cache_get()
88 i = cache->next_blk; in squashfs_cache_get()
89 for (n = 0; n < cache->entries; n++) { in squashfs_cache_get()
90 if (cache->entry[i].refcount == 0) in squashfs_cache_get()
92 i = (i + 1) % cache->entries; in squashfs_cache_get()
95 cache->next_blk = (i + 1) % cache->entries; in squashfs_cache_get()
96 entry = &cache->entry[i]; in squashfs_cache_get()
99 * Initialise chosen cache entry, and fill it in from in squashfs_cache_get()
102 cache->unused--; in squashfs_cache_get()
103 entry->block = block; in squashfs_cache_get()
104 entry->refcount = 1; in squashfs_cache_get()
105 entry->pending = 1; in squashfs_cache_get()
106 entry->num_waiters = 0; in squashfs_cache_get()
107 entry->error = 0; in squashfs_cache_get()
108 spin_unlock(&cache->lock); in squashfs_cache_get()
110 entry->length = squashfs_read_data(sb, block, length, in squashfs_cache_get()
111 &entry->next_index, entry->actor); in squashfs_cache_get()
113 spin_lock(&cache->lock); in squashfs_cache_get()
115 if (entry->length < 0) in squashfs_cache_get()
116 entry->error = entry->length; in squashfs_cache_get()
118 entry->pending = 0; in squashfs_cache_get()
121 * While filling this entry one or more other processes in squashfs_cache_get()
125 if (entry->num_waiters) { in squashfs_cache_get()
126 spin_unlock(&cache->lock); in squashfs_cache_get()
127 wake_up_all(&entry->wait_queue); in squashfs_cache_get()
129 spin_unlock(&cache->lock); in squashfs_cache_get()
137 * previously unused there's one less cache entry available in squashfs_cache_get()
140 entry = &cache->entry[i]; in squashfs_cache_get()
141 if (entry->refcount == 0) in squashfs_cache_get()
142 cache->unused--; in squashfs_cache_get()
143 entry->refcount++; in squashfs_cache_get()
146 * If the entry is currently being filled in by another process in squashfs_cache_get()
149 if (entry->pending) { in squashfs_cache_get()
150 entry->num_waiters++; in squashfs_cache_get()
151 spin_unlock(&cache->lock); in squashfs_cache_get()
152 wait_event(entry->wait_queue, !entry->pending); in squashfs_cache_get()
154 spin_unlock(&cache->lock); in squashfs_cache_get()
161 cache->name, i, entry->block, entry->refcount, entry->error); in squashfs_cache_get()
163 if (entry->error) in squashfs_cache_get()
164 ERROR("Unable to read %s cache entry [%llx]\n", cache->name, in squashfs_cache_get()
166 return entry; in squashfs_cache_get()
171 * Release cache entry, once usage count is zero it can be reused.
173 void squashfs_cache_put(struct squashfs_cache_entry *entry) in squashfs_cache_put() argument
175 struct squashfs_cache *cache = entry->cache; in squashfs_cache_put()
177 spin_lock(&cache->lock); in squashfs_cache_put()
178 entry->refcount--; in squashfs_cache_put()
179 if (entry->refcount == 0) { in squashfs_cache_put()
180 cache->unused++; in squashfs_cache_put()
185 if (cache->num_waiters) { in squashfs_cache_put()
186 spin_unlock(&cache->lock); in squashfs_cache_put()
187 wake_up(&cache->wait_queue); in squashfs_cache_put()
191 spin_unlock(&cache->lock); in squashfs_cache_put()
204 for (i = 0; i < cache->entries; i++) { in squashfs_cache_delete()
205 if (cache->entry[i].data) { in squashfs_cache_delete()
206 for (j = 0; j < cache->pages; j++) in squashfs_cache_delete()
207 kfree(cache->entry[i].data[j]); in squashfs_cache_delete()
208 kfree(cache->entry[i].data); in squashfs_cache_delete()
210 kfree(cache->entry[i].actor); in squashfs_cache_delete()
213 kfree(cache->entry); in squashfs_cache_delete()
220 * size block_size. To avoid vmalloc fragmentation issues each entry
223 struct squashfs_cache *squashfs_cache_init(char *name, int entries, in squashfs_cache_init() argument
230 ERROR("Failed to allocate %s cache\n", name); in squashfs_cache_init()
234 cache->entry = kcalloc(entries, sizeof(*(cache->entry)), GFP_KERNEL); in squashfs_cache_init()
235 if (cache->entry == NULL) { in squashfs_cache_init()
236 ERROR("Failed to allocate %s cache\n", name); in squashfs_cache_init()
240 cache->curr_blk = 0; in squashfs_cache_init()
241 cache->next_blk = 0; in squashfs_cache_init()
242 cache->unused = entries; in squashfs_cache_init()
243 cache->entries = entries; in squashfs_cache_init()
244 cache->block_size = block_size; in squashfs_cache_init()
245 cache->pages = block_size >> PAGE_SHIFT; in squashfs_cache_init()
246 cache->pages = cache->pages ? cache->pages : 1; in squashfs_cache_init()
247 cache->name = name; in squashfs_cache_init()
248 cache->num_waiters = 0; in squashfs_cache_init()
249 spin_lock_init(&cache->lock); in squashfs_cache_init()
250 init_waitqueue_head(&cache->wait_queue); in squashfs_cache_init()
253 struct squashfs_cache_entry *entry = &cache->entry[i]; in squashfs_cache_init() local
255 init_waitqueue_head(&cache->entry[i].wait_queue); in squashfs_cache_init()
256 entry->cache = cache; in squashfs_cache_init()
257 entry->block = SQUASHFS_INVALID_BLK; in squashfs_cache_init()
258 entry->data = kcalloc(cache->pages, sizeof(void *), GFP_KERNEL); in squashfs_cache_init()
259 if (entry->data == NULL) { in squashfs_cache_init()
260 ERROR("Failed to allocate %s cache entry\n", name); in squashfs_cache_init()
264 for (j = 0; j < cache->pages; j++) { in squashfs_cache_init()
265 entry->data[j] = kmalloc(PAGE_SIZE, GFP_KERNEL); in squashfs_cache_init()
266 if (entry->data[j] == NULL) { in squashfs_cache_init()
267 ERROR("Failed to allocate %s buffer\n", name); in squashfs_cache_init()
272 entry->actor = squashfs_page_actor_init(entry->data, in squashfs_cache_init()
273 cache->pages, 0); in squashfs_cache_init()
274 if (entry->actor == NULL) { in squashfs_cache_init()
275 ERROR("Failed to allocate %s cache entry\n", name); in squashfs_cache_init()
289 * Copy up to length bytes from cache entry to buffer starting at offset bytes
290 * into the cache entry. If there's not length bytes then copy the number of
293 int squashfs_copy_data(void *buffer, struct squashfs_cache_entry *entry, in squashfs_copy_data() argument
301 return min(length, entry->length - offset); in squashfs_copy_data()
303 while (offset < entry->length) { in squashfs_copy_data()
304 void *buff = entry->data[offset / PAGE_SIZE] in squashfs_copy_data()
306 int bytes = min_t(int, entry->length - offset, in squashfs_copy_data()
307 PAGE_SIZE - (offset % PAGE_SIZE)); in squashfs_copy_data()
317 remaining -= bytes; in squashfs_copy_data()
321 return length - remaining; in squashfs_copy_data()
334 struct squashfs_sb_info *msblk = sb->s_fs_info; in squashfs_read_metadata()
336 struct squashfs_cache_entry *entry; in squashfs_read_metadata() local
341 return -EIO; in squashfs_read_metadata()
344 entry = squashfs_cache_get(sb, msblk->block_cache, *block, 0); in squashfs_read_metadata()
345 if (entry->error) { in squashfs_read_metadata()
346 res = entry->error; in squashfs_read_metadata()
348 } else if (*offset >= entry->length) { in squashfs_read_metadata()
349 res = -EIO; in squashfs_read_metadata()
353 bytes = squashfs_copy_data(buffer, entry, *offset, length); in squashfs_read_metadata()
356 length -= bytes; in squashfs_read_metadata()
359 if (*offset == entry->length) { in squashfs_read_metadata()
360 *block = entry->next_index; in squashfs_read_metadata()
364 squashfs_cache_put(entry); in squashfs_read_metadata()
370 squashfs_cache_put(entry); in squashfs_read_metadata()
376 * Look-up in the fragmment cache the fragment located at <start_block> in the
382 struct squashfs_sb_info *msblk = sb->s_fs_info; in squashfs_get_fragment()
384 return squashfs_cache_get(sb, msblk->fragment_cache, start_block, in squashfs_get_fragment()
397 struct squashfs_sb_info *msblk = sb->s_fs_info; in squashfs_get_datablock()
399 return squashfs_cache_get(sb, msblk->read_page, start_block, length); in squashfs_get_datablock()
408 int pages = (length + PAGE_SIZE - 1) >> PAGE_SHIFT; in squashfs_read_table()
415 return ERR_PTR(-ENOMEM); in squashfs_read_table()
419 res = -ENOMEM; in squashfs_read_table()
425 res = -ENOMEM; in squashfs_read_table()