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

TOMOYO Linux Cross Reference
Linux/fs/squashfs/decompressor_multi_percpu.c

Version: ~ [ linux-5.19-rc3 ] ~ [ linux-5.18.5 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.48 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.123 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.199 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.248 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.284 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.319 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ 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 /*
  2  * Copyright (c) 2013
  3  * Phillip Lougher <phillip@squashfs.org.uk>
  4  *
  5  * This work is licensed under the terms of the GNU GPL, version 2. See
  6  * the COPYING file in the top-level directory.
  7  */
  8 
  9 #include <linux/types.h>
 10 #include <linux/slab.h>
 11 #include <linux/percpu.h>
 12 #include <linux/buffer_head.h>
 13 
 14 #include "squashfs_fs.h"
 15 #include "squashfs_fs_sb.h"
 16 #include "decompressor.h"
 17 #include "squashfs.h"
 18 
 19 /*
 20  * This file implements multi-threaded decompression using percpu
 21  * variables, one thread per cpu core.
 22  */
 23 
 24 struct squashfs_stream {
 25         void            *stream;
 26 };
 27 
 28 void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
 29                                                 void *comp_opts)
 30 {
 31         struct squashfs_stream *stream;
 32         struct squashfs_stream __percpu *percpu;
 33         int err, cpu;
 34 
 35         percpu = alloc_percpu(struct squashfs_stream);
 36         if (percpu == NULL)
 37                 return ERR_PTR(-ENOMEM);
 38 
 39         for_each_possible_cpu(cpu) {
 40                 stream = per_cpu_ptr(percpu, cpu);
 41                 stream->stream = msblk->decompressor->init(msblk, comp_opts);
 42                 if (IS_ERR(stream->stream)) {
 43                         err = PTR_ERR(stream->stream);
 44                         goto out;
 45                 }
 46         }
 47 
 48         kfree(comp_opts);
 49         return (__force void *) percpu;
 50 
 51 out:
 52         for_each_possible_cpu(cpu) {
 53                 stream = per_cpu_ptr(percpu, cpu);
 54                 if (!IS_ERR_OR_NULL(stream->stream))
 55                         msblk->decompressor->free(stream->stream);
 56         }
 57         free_percpu(percpu);
 58         return ERR_PTR(err);
 59 }
 60 
 61 void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
 62 {
 63         struct squashfs_stream __percpu *percpu =
 64                         (struct squashfs_stream __percpu *) msblk->stream;
 65         struct squashfs_stream *stream;
 66         int cpu;
 67 
 68         if (msblk->stream) {
 69                 for_each_possible_cpu(cpu) {
 70                         stream = per_cpu_ptr(percpu, cpu);
 71                         msblk->decompressor->free(stream->stream);
 72                 }
 73                 free_percpu(percpu);
 74         }
 75 }
 76 
 77 int squashfs_decompress(struct squashfs_sb_info *msblk, struct buffer_head **bh,
 78         int b, int offset, int length, struct squashfs_page_actor *output)
 79 {
 80         struct squashfs_stream __percpu *percpu =
 81                         (struct squashfs_stream __percpu *) msblk->stream;
 82         struct squashfs_stream *stream = get_cpu_ptr(percpu);
 83         int res = msblk->decompressor->decompress(msblk, stream->stream, bh, b,
 84                 offset, length, output);
 85         put_cpu_ptr(stream);
 86 
 87         if (res < 0)
 88                 ERROR("%s decompression failed, data probably corrupt\n",
 89                         msblk->decompressor->name);
 90 
 91         return res;
 92 }
 93 
 94 int squashfs_max_decompressors(void)
 95 {
 96         return num_possible_cpus();
 97 }
 98 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp