hyperv: Add processing of MTU reduced by the host
[linux/fpc-iii.git] / fs / squashfs / decompressor_multi_percpu.c
blob23a9c28ad8ea68e6e1b4679ccbbda74bfafcc115
1 /*
2 * Copyright (c) 2013
3 * Phillip Lougher <phillip@squashfs.org.uk>
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 */
9 #include <linux/types.h>
10 #include <linux/slab.h>
11 #include <linux/percpu.h>
12 #include <linux/buffer_head.h>
14 #include "squashfs_fs.h"
15 #include "squashfs_fs_sb.h"
16 #include "decompressor.h"
17 #include "squashfs.h"
20 * This file implements multi-threaded decompression using percpu
21 * variables, one thread per cpu core.
24 struct squashfs_stream {
25 void *stream;
28 void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
29 void *comp_opts)
31 struct squashfs_stream *stream;
32 struct squashfs_stream __percpu *percpu;
33 int err, cpu;
35 percpu = alloc_percpu(struct squashfs_stream);
36 if (percpu == NULL)
37 return ERR_PTR(-ENOMEM);
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;
48 kfree(comp_opts);
49 return (__force void *) percpu;
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);
57 free_percpu(percpu);
58 return ERR_PTR(err);
61 void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
63 struct squashfs_stream __percpu *percpu =
64 (struct squashfs_stream __percpu *) msblk->stream;
65 struct squashfs_stream *stream;
66 int cpu;
68 if (msblk->stream) {
69 for_each_possible_cpu(cpu) {
70 stream = per_cpu_ptr(percpu, cpu);
71 msblk->decompressor->free(stream->stream);
73 free_percpu(percpu);
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)
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);
87 if (res < 0)
88 ERROR("%s decompression failed, data probably corrupt\n",
89 msblk->decompressor->name);
91 return res;
94 int squashfs_max_decompressors(void)
96 return num_possible_cpus();