Commit 0b6c0bb3f9621b128011bcd5f65047c73afdde3b
Committed by
Josh Boyer
1 parent
79b9cd586f
Exists in
master
and in
7 other branches
fs/jffs2/xattr.c: remove dead code
This patch removes some obvious dead code spotted by the Coverity checker. Signed-off-by: Adrian Bunk <bunk@stusta.de> Signed-off-by: Josh Boyer <jwboyer@gmail.com>
Showing 1 changed file with 0 additions and 1 deletions Inline Diff
fs/jffs2/xattr.c
1 | /* | 1 | /* |
2 | * JFFS2 -- Journalling Flash File System, Version 2. | 2 | * JFFS2 -- Journalling Flash File System, Version 2. |
3 | * | 3 | * |
4 | * Copyright (C) 2006 NEC Corporation | 4 | * Copyright (C) 2006 NEC Corporation |
5 | * | 5 | * |
6 | * Created by KaiGai Kohei <kaigai@ak.jp.nec.com> | 6 | * Created by KaiGai Kohei <kaigai@ak.jp.nec.com> |
7 | * | 7 | * |
8 | * For licensing information, see the file 'LICENCE' in this directory. | 8 | * For licensing information, see the file 'LICENCE' in this directory. |
9 | * | 9 | * |
10 | */ | 10 | */ |
11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/fs.h> | 13 | #include <linux/fs.h> |
14 | #include <linux/time.h> | 14 | #include <linux/time.h> |
15 | #include <linux/pagemap.h> | 15 | #include <linux/pagemap.h> |
16 | #include <linux/highmem.h> | 16 | #include <linux/highmem.h> |
17 | #include <linux/crc32.h> | 17 | #include <linux/crc32.h> |
18 | #include <linux/jffs2.h> | 18 | #include <linux/jffs2.h> |
19 | #include <linux/xattr.h> | 19 | #include <linux/xattr.h> |
20 | #include <linux/mtd/mtd.h> | 20 | #include <linux/mtd/mtd.h> |
21 | #include "nodelist.h" | 21 | #include "nodelist.h" |
22 | /* -------- xdatum related functions ---------------- | 22 | /* -------- xdatum related functions ---------------- |
23 | * xattr_datum_hashkey(xprefix, xname, xvalue, xsize) | 23 | * xattr_datum_hashkey(xprefix, xname, xvalue, xsize) |
24 | * is used to calcurate xdatum hashkey. The reminder of hashkey into XATTRINDEX_HASHSIZE is | 24 | * is used to calcurate xdatum hashkey. The reminder of hashkey into XATTRINDEX_HASHSIZE is |
25 | * the index of the xattr name/value pair cache (c->xattrindex). | 25 | * the index of the xattr name/value pair cache (c->xattrindex). |
26 | * is_xattr_datum_unchecked(c, xd) | 26 | * is_xattr_datum_unchecked(c, xd) |
27 | * returns 1, if xdatum contains any unchecked raw nodes. if all raw nodes are not | 27 | * returns 1, if xdatum contains any unchecked raw nodes. if all raw nodes are not |
28 | * unchecked, it returns 0. | 28 | * unchecked, it returns 0. |
29 | * unload_xattr_datum(c, xd) | 29 | * unload_xattr_datum(c, xd) |
30 | * is used to release xattr name/value pair and detach from c->xattrindex. | 30 | * is used to release xattr name/value pair and detach from c->xattrindex. |
31 | * reclaim_xattr_datum(c) | 31 | * reclaim_xattr_datum(c) |
32 | * is used to reclaim xattr name/value pairs on the xattr name/value pair cache when | 32 | * is used to reclaim xattr name/value pairs on the xattr name/value pair cache when |
33 | * memory usage by cache is over c->xdatum_mem_threshold. Currentry, this threshold | 33 | * memory usage by cache is over c->xdatum_mem_threshold. Currentry, this threshold |
34 | * is hard coded as 32KiB. | 34 | * is hard coded as 32KiB. |
35 | * do_verify_xattr_datum(c, xd) | 35 | * do_verify_xattr_datum(c, xd) |
36 | * is used to load the xdatum informations without name/value pair from the medium. | 36 | * is used to load the xdatum informations without name/value pair from the medium. |
37 | * It's necessary once, because those informations are not collected during mounting | 37 | * It's necessary once, because those informations are not collected during mounting |
38 | * process when EBS is enabled. | 38 | * process when EBS is enabled. |
39 | * 0 will be returned, if success. An negative return value means recoverable error, and | 39 | * 0 will be returned, if success. An negative return value means recoverable error, and |
40 | * positive return value means unrecoverable error. Thus, caller must remove this xdatum | 40 | * positive return value means unrecoverable error. Thus, caller must remove this xdatum |
41 | * and xref when it returned positive value. | 41 | * and xref when it returned positive value. |
42 | * do_load_xattr_datum(c, xd) | 42 | * do_load_xattr_datum(c, xd) |
43 | * is used to load name/value pair from the medium. | 43 | * is used to load name/value pair from the medium. |
44 | * The meanings of return value is same as do_verify_xattr_datum(). | 44 | * The meanings of return value is same as do_verify_xattr_datum(). |
45 | * load_xattr_datum(c, xd) | 45 | * load_xattr_datum(c, xd) |
46 | * is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum(). | 46 | * is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum(). |
47 | * If xd need to call do_verify_xattr_datum() at first, it's called before calling | 47 | * If xd need to call do_verify_xattr_datum() at first, it's called before calling |
48 | * do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum(). | 48 | * do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum(). |
49 | * save_xattr_datum(c, xd) | 49 | * save_xattr_datum(c, xd) |
50 | * is used to write xdatum to medium. xd->version will be incremented. | 50 | * is used to write xdatum to medium. xd->version will be incremented. |
51 | * create_xattr_datum(c, xprefix, xname, xvalue, xsize) | 51 | * create_xattr_datum(c, xprefix, xname, xvalue, xsize) |
52 | * is used to create new xdatum and write to medium. | 52 | * is used to create new xdatum and write to medium. |
53 | * unrefer_xattr_datum(c, xd) | 53 | * unrefer_xattr_datum(c, xd) |
54 | * is used to delete a xdatum. When nobody refers this xdatum, JFFS2_XFLAGS_DEAD | 54 | * is used to delete a xdatum. When nobody refers this xdatum, JFFS2_XFLAGS_DEAD |
55 | * is set on xd->flags and chained xattr_dead_list or release it immediately. | 55 | * is set on xd->flags and chained xattr_dead_list or release it immediately. |
56 | * In the first case, the garbage collector release it later. | 56 | * In the first case, the garbage collector release it later. |
57 | * -------------------------------------------------- */ | 57 | * -------------------------------------------------- */ |
58 | static uint32_t xattr_datum_hashkey(int xprefix, const char *xname, const char *xvalue, int xsize) | 58 | static uint32_t xattr_datum_hashkey(int xprefix, const char *xname, const char *xvalue, int xsize) |
59 | { | 59 | { |
60 | int name_len = strlen(xname); | 60 | int name_len = strlen(xname); |
61 | 61 | ||
62 | return crc32(xprefix, xname, name_len) ^ crc32(xprefix, xvalue, xsize); | 62 | return crc32(xprefix, xname, name_len) ^ crc32(xprefix, xvalue, xsize); |
63 | } | 63 | } |
64 | 64 | ||
65 | static int is_xattr_datum_unchecked(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) | 65 | static int is_xattr_datum_unchecked(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) |
66 | { | 66 | { |
67 | struct jffs2_raw_node_ref *raw; | 67 | struct jffs2_raw_node_ref *raw; |
68 | int rc = 0; | 68 | int rc = 0; |
69 | 69 | ||
70 | spin_lock(&c->erase_completion_lock); | 70 | spin_lock(&c->erase_completion_lock); |
71 | for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) { | 71 | for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) { |
72 | if (ref_flags(raw) == REF_UNCHECKED) { | 72 | if (ref_flags(raw) == REF_UNCHECKED) { |
73 | rc = 1; | 73 | rc = 1; |
74 | break; | 74 | break; |
75 | } | 75 | } |
76 | } | 76 | } |
77 | spin_unlock(&c->erase_completion_lock); | 77 | spin_unlock(&c->erase_completion_lock); |
78 | return rc; | 78 | return rc; |
79 | } | 79 | } |
80 | 80 | ||
81 | static void unload_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) | 81 | static void unload_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) |
82 | { | 82 | { |
83 | /* must be called under down_write(xattr_sem) */ | 83 | /* must be called under down_write(xattr_sem) */ |
84 | D1(dbg_xattr("%s: xid=%u, version=%u\n", __FUNCTION__, xd->xid, xd->version)); | 84 | D1(dbg_xattr("%s: xid=%u, version=%u\n", __FUNCTION__, xd->xid, xd->version)); |
85 | if (xd->xname) { | 85 | if (xd->xname) { |
86 | c->xdatum_mem_usage -= (xd->name_len + 1 + xd->value_len); | 86 | c->xdatum_mem_usage -= (xd->name_len + 1 + xd->value_len); |
87 | kfree(xd->xname); | 87 | kfree(xd->xname); |
88 | } | 88 | } |
89 | 89 | ||
90 | list_del_init(&xd->xindex); | 90 | list_del_init(&xd->xindex); |
91 | xd->hashkey = 0; | 91 | xd->hashkey = 0; |
92 | xd->xname = NULL; | 92 | xd->xname = NULL; |
93 | xd->xvalue = NULL; | 93 | xd->xvalue = NULL; |
94 | } | 94 | } |
95 | 95 | ||
96 | static void reclaim_xattr_datum(struct jffs2_sb_info *c) | 96 | static void reclaim_xattr_datum(struct jffs2_sb_info *c) |
97 | { | 97 | { |
98 | /* must be called under down_write(xattr_sem) */ | 98 | /* must be called under down_write(xattr_sem) */ |
99 | struct jffs2_xattr_datum *xd, *_xd; | 99 | struct jffs2_xattr_datum *xd, *_xd; |
100 | uint32_t target, before; | 100 | uint32_t target, before; |
101 | static int index = 0; | 101 | static int index = 0; |
102 | int count; | 102 | int count; |
103 | 103 | ||
104 | if (c->xdatum_mem_threshold > c->xdatum_mem_usage) | 104 | if (c->xdatum_mem_threshold > c->xdatum_mem_usage) |
105 | return; | 105 | return; |
106 | 106 | ||
107 | before = c->xdatum_mem_usage; | 107 | before = c->xdatum_mem_usage; |
108 | target = c->xdatum_mem_usage * 4 / 5; /* 20% reduction */ | 108 | target = c->xdatum_mem_usage * 4 / 5; /* 20% reduction */ |
109 | for (count = 0; count < XATTRINDEX_HASHSIZE; count++) { | 109 | for (count = 0; count < XATTRINDEX_HASHSIZE; count++) { |
110 | list_for_each_entry_safe(xd, _xd, &c->xattrindex[index], xindex) { | 110 | list_for_each_entry_safe(xd, _xd, &c->xattrindex[index], xindex) { |
111 | if (xd->flags & JFFS2_XFLAGS_HOT) { | 111 | if (xd->flags & JFFS2_XFLAGS_HOT) { |
112 | xd->flags &= ~JFFS2_XFLAGS_HOT; | 112 | xd->flags &= ~JFFS2_XFLAGS_HOT; |
113 | } else if (!(xd->flags & JFFS2_XFLAGS_BIND)) { | 113 | } else if (!(xd->flags & JFFS2_XFLAGS_BIND)) { |
114 | unload_xattr_datum(c, xd); | 114 | unload_xattr_datum(c, xd); |
115 | } | 115 | } |
116 | if (c->xdatum_mem_usage <= target) | 116 | if (c->xdatum_mem_usage <= target) |
117 | goto out; | 117 | goto out; |
118 | } | 118 | } |
119 | index = (index+1) % XATTRINDEX_HASHSIZE; | 119 | index = (index+1) % XATTRINDEX_HASHSIZE; |
120 | } | 120 | } |
121 | out: | 121 | out: |
122 | JFFS2_NOTICE("xdatum_mem_usage from %u byte to %u byte (%u byte reclaimed)\n", | 122 | JFFS2_NOTICE("xdatum_mem_usage from %u byte to %u byte (%u byte reclaimed)\n", |
123 | before, c->xdatum_mem_usage, before - c->xdatum_mem_usage); | 123 | before, c->xdatum_mem_usage, before - c->xdatum_mem_usage); |
124 | } | 124 | } |
125 | 125 | ||
126 | static int do_verify_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) | 126 | static int do_verify_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) |
127 | { | 127 | { |
128 | /* must be called under down_write(xattr_sem) */ | 128 | /* must be called under down_write(xattr_sem) */ |
129 | struct jffs2_eraseblock *jeb; | 129 | struct jffs2_eraseblock *jeb; |
130 | struct jffs2_raw_node_ref *raw; | 130 | struct jffs2_raw_node_ref *raw; |
131 | struct jffs2_raw_xattr rx; | 131 | struct jffs2_raw_xattr rx; |
132 | size_t readlen; | 132 | size_t readlen; |
133 | uint32_t crc, offset, totlen; | 133 | uint32_t crc, offset, totlen; |
134 | int rc; | 134 | int rc; |
135 | 135 | ||
136 | spin_lock(&c->erase_completion_lock); | 136 | spin_lock(&c->erase_completion_lock); |
137 | offset = ref_offset(xd->node); | 137 | offset = ref_offset(xd->node); |
138 | if (ref_flags(xd->node) == REF_PRISTINE) | 138 | if (ref_flags(xd->node) == REF_PRISTINE) |
139 | goto complete; | 139 | goto complete; |
140 | spin_unlock(&c->erase_completion_lock); | 140 | spin_unlock(&c->erase_completion_lock); |
141 | 141 | ||
142 | rc = jffs2_flash_read(c, offset, sizeof(rx), &readlen, (char *)&rx); | 142 | rc = jffs2_flash_read(c, offset, sizeof(rx), &readlen, (char *)&rx); |
143 | if (rc || readlen != sizeof(rx)) { | 143 | if (rc || readlen != sizeof(rx)) { |
144 | JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu at %#08x\n", | 144 | JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu at %#08x\n", |
145 | rc, sizeof(rx), readlen, offset); | 145 | rc, sizeof(rx), readlen, offset); |
146 | return rc ? rc : -EIO; | 146 | return rc ? rc : -EIO; |
147 | } | 147 | } |
148 | crc = crc32(0, &rx, sizeof(rx) - 4); | 148 | crc = crc32(0, &rx, sizeof(rx) - 4); |
149 | if (crc != je32_to_cpu(rx.node_crc)) { | 149 | if (crc != je32_to_cpu(rx.node_crc)) { |
150 | JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", | 150 | JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", |
151 | offset, je32_to_cpu(rx.hdr_crc), crc); | 151 | offset, je32_to_cpu(rx.hdr_crc), crc); |
152 | xd->flags |= JFFS2_XFLAGS_INVALID; | 152 | xd->flags |= JFFS2_XFLAGS_INVALID; |
153 | return EIO; | 153 | return EIO; |
154 | } | 154 | } |
155 | totlen = PAD(sizeof(rx) + rx.name_len + 1 + je16_to_cpu(rx.value_len)); | 155 | totlen = PAD(sizeof(rx) + rx.name_len + 1 + je16_to_cpu(rx.value_len)); |
156 | if (je16_to_cpu(rx.magic) != JFFS2_MAGIC_BITMASK | 156 | if (je16_to_cpu(rx.magic) != JFFS2_MAGIC_BITMASK |
157 | || je16_to_cpu(rx.nodetype) != JFFS2_NODETYPE_XATTR | 157 | || je16_to_cpu(rx.nodetype) != JFFS2_NODETYPE_XATTR |
158 | || je32_to_cpu(rx.totlen) != totlen | 158 | || je32_to_cpu(rx.totlen) != totlen |
159 | || je32_to_cpu(rx.xid) != xd->xid | 159 | || je32_to_cpu(rx.xid) != xd->xid |
160 | || je32_to_cpu(rx.version) != xd->version) { | 160 | || je32_to_cpu(rx.version) != xd->version) { |
161 | JFFS2_ERROR("inconsistent xdatum at %#08x, magic=%#04x/%#04x, " | 161 | JFFS2_ERROR("inconsistent xdatum at %#08x, magic=%#04x/%#04x, " |
162 | "nodetype=%#04x/%#04x, totlen=%u/%u, xid=%u/%u, version=%u/%u\n", | 162 | "nodetype=%#04x/%#04x, totlen=%u/%u, xid=%u/%u, version=%u/%u\n", |
163 | offset, je16_to_cpu(rx.magic), JFFS2_MAGIC_BITMASK, | 163 | offset, je16_to_cpu(rx.magic), JFFS2_MAGIC_BITMASK, |
164 | je16_to_cpu(rx.nodetype), JFFS2_NODETYPE_XATTR, | 164 | je16_to_cpu(rx.nodetype), JFFS2_NODETYPE_XATTR, |
165 | je32_to_cpu(rx.totlen), totlen, | 165 | je32_to_cpu(rx.totlen), totlen, |
166 | je32_to_cpu(rx.xid), xd->xid, | 166 | je32_to_cpu(rx.xid), xd->xid, |
167 | je32_to_cpu(rx.version), xd->version); | 167 | je32_to_cpu(rx.version), xd->version); |
168 | xd->flags |= JFFS2_XFLAGS_INVALID; | 168 | xd->flags |= JFFS2_XFLAGS_INVALID; |
169 | return EIO; | 169 | return EIO; |
170 | } | 170 | } |
171 | xd->xprefix = rx.xprefix; | 171 | xd->xprefix = rx.xprefix; |
172 | xd->name_len = rx.name_len; | 172 | xd->name_len = rx.name_len; |
173 | xd->value_len = je16_to_cpu(rx.value_len); | 173 | xd->value_len = je16_to_cpu(rx.value_len); |
174 | xd->data_crc = je32_to_cpu(rx.data_crc); | 174 | xd->data_crc = je32_to_cpu(rx.data_crc); |
175 | 175 | ||
176 | spin_lock(&c->erase_completion_lock); | 176 | spin_lock(&c->erase_completion_lock); |
177 | complete: | 177 | complete: |
178 | for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) { | 178 | for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) { |
179 | jeb = &c->blocks[ref_offset(raw) / c->sector_size]; | 179 | jeb = &c->blocks[ref_offset(raw) / c->sector_size]; |
180 | totlen = PAD(ref_totlen(c, jeb, raw)); | 180 | totlen = PAD(ref_totlen(c, jeb, raw)); |
181 | if (ref_flags(raw) == REF_UNCHECKED) { | 181 | if (ref_flags(raw) == REF_UNCHECKED) { |
182 | c->unchecked_size -= totlen; c->used_size += totlen; | 182 | c->unchecked_size -= totlen; c->used_size += totlen; |
183 | jeb->unchecked_size -= totlen; jeb->used_size += totlen; | 183 | jeb->unchecked_size -= totlen; jeb->used_size += totlen; |
184 | } | 184 | } |
185 | raw->flash_offset = ref_offset(raw) | ((xd->node==raw) ? REF_PRISTINE : REF_NORMAL); | 185 | raw->flash_offset = ref_offset(raw) | ((xd->node==raw) ? REF_PRISTINE : REF_NORMAL); |
186 | } | 186 | } |
187 | spin_unlock(&c->erase_completion_lock); | 187 | spin_unlock(&c->erase_completion_lock); |
188 | 188 | ||
189 | /* unchecked xdatum is chained with c->xattr_unchecked */ | 189 | /* unchecked xdatum is chained with c->xattr_unchecked */ |
190 | list_del_init(&xd->xindex); | 190 | list_del_init(&xd->xindex); |
191 | 191 | ||
192 | dbg_xattr("success on verfying xdatum (xid=%u, version=%u)\n", | 192 | dbg_xattr("success on verfying xdatum (xid=%u, version=%u)\n", |
193 | xd->xid, xd->version); | 193 | xd->xid, xd->version); |
194 | 194 | ||
195 | return 0; | 195 | return 0; |
196 | } | 196 | } |
197 | 197 | ||
198 | static int do_load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) | 198 | static int do_load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) |
199 | { | 199 | { |
200 | /* must be called under down_write(xattr_sem) */ | 200 | /* must be called under down_write(xattr_sem) */ |
201 | char *data; | 201 | char *data; |
202 | size_t readlen; | 202 | size_t readlen; |
203 | uint32_t crc, length; | 203 | uint32_t crc, length; |
204 | int i, ret, retry = 0; | 204 | int i, ret, retry = 0; |
205 | 205 | ||
206 | BUG_ON(ref_flags(xd->node) != REF_PRISTINE); | 206 | BUG_ON(ref_flags(xd->node) != REF_PRISTINE); |
207 | BUG_ON(!list_empty(&xd->xindex)); | 207 | BUG_ON(!list_empty(&xd->xindex)); |
208 | retry: | 208 | retry: |
209 | length = xd->name_len + 1 + xd->value_len; | 209 | length = xd->name_len + 1 + xd->value_len; |
210 | data = kmalloc(length, GFP_KERNEL); | 210 | data = kmalloc(length, GFP_KERNEL); |
211 | if (!data) | 211 | if (!data) |
212 | return -ENOMEM; | 212 | return -ENOMEM; |
213 | 213 | ||
214 | ret = jffs2_flash_read(c, ref_offset(xd->node)+sizeof(struct jffs2_raw_xattr), | 214 | ret = jffs2_flash_read(c, ref_offset(xd->node)+sizeof(struct jffs2_raw_xattr), |
215 | length, &readlen, data); | 215 | length, &readlen, data); |
216 | 216 | ||
217 | if (ret || length!=readlen) { | 217 | if (ret || length!=readlen) { |
218 | JFFS2_WARNING("jffs2_flash_read() returned %d, request=%d, readlen=%zu, at %#08x\n", | 218 | JFFS2_WARNING("jffs2_flash_read() returned %d, request=%d, readlen=%zu, at %#08x\n", |
219 | ret, length, readlen, ref_offset(xd->node)); | 219 | ret, length, readlen, ref_offset(xd->node)); |
220 | kfree(data); | 220 | kfree(data); |
221 | return ret ? ret : -EIO; | 221 | return ret ? ret : -EIO; |
222 | } | 222 | } |
223 | 223 | ||
224 | data[xd->name_len] = '\0'; | 224 | data[xd->name_len] = '\0'; |
225 | crc = crc32(0, data, length); | 225 | crc = crc32(0, data, length); |
226 | if (crc != xd->data_crc) { | 226 | if (crc != xd->data_crc) { |
227 | JFFS2_WARNING("node CRC failed (JFFS2_NODETYPE_XREF)" | 227 | JFFS2_WARNING("node CRC failed (JFFS2_NODETYPE_XREF)" |
228 | " at %#08x, read: 0x%08x calculated: 0x%08x\n", | 228 | " at %#08x, read: 0x%08x calculated: 0x%08x\n", |
229 | ref_offset(xd->node), xd->data_crc, crc); | 229 | ref_offset(xd->node), xd->data_crc, crc); |
230 | kfree(data); | 230 | kfree(data); |
231 | xd->flags |= JFFS2_XFLAGS_INVALID; | 231 | xd->flags |= JFFS2_XFLAGS_INVALID; |
232 | return EIO; | 232 | return EIO; |
233 | } | 233 | } |
234 | 234 | ||
235 | xd->flags |= JFFS2_XFLAGS_HOT; | 235 | xd->flags |= JFFS2_XFLAGS_HOT; |
236 | xd->xname = data; | 236 | xd->xname = data; |
237 | xd->xvalue = data + xd->name_len+1; | 237 | xd->xvalue = data + xd->name_len+1; |
238 | 238 | ||
239 | c->xdatum_mem_usage += length; | 239 | c->xdatum_mem_usage += length; |
240 | 240 | ||
241 | xd->hashkey = xattr_datum_hashkey(xd->xprefix, xd->xname, xd->xvalue, xd->value_len); | 241 | xd->hashkey = xattr_datum_hashkey(xd->xprefix, xd->xname, xd->xvalue, xd->value_len); |
242 | i = xd->hashkey % XATTRINDEX_HASHSIZE; | 242 | i = xd->hashkey % XATTRINDEX_HASHSIZE; |
243 | list_add(&xd->xindex, &c->xattrindex[i]); | 243 | list_add(&xd->xindex, &c->xattrindex[i]); |
244 | if (!retry) { | 244 | if (!retry) { |
245 | retry = 1; | 245 | retry = 1; |
246 | reclaim_xattr_datum(c); | 246 | reclaim_xattr_datum(c); |
247 | if (!xd->xname) | 247 | if (!xd->xname) |
248 | goto retry; | 248 | goto retry; |
249 | } | 249 | } |
250 | 250 | ||
251 | dbg_xattr("success on loading xdatum (xid=%u, xprefix=%u, xname='%s')\n", | 251 | dbg_xattr("success on loading xdatum (xid=%u, xprefix=%u, xname='%s')\n", |
252 | xd->xid, xd->xprefix, xd->xname); | 252 | xd->xid, xd->xprefix, xd->xname); |
253 | 253 | ||
254 | return 0; | 254 | return 0; |
255 | } | 255 | } |
256 | 256 | ||
257 | static int load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) | 257 | static int load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) |
258 | { | 258 | { |
259 | /* must be called under down_write(xattr_sem); | 259 | /* must be called under down_write(xattr_sem); |
260 | * rc < 0 : recoverable error, try again | 260 | * rc < 0 : recoverable error, try again |
261 | * rc = 0 : success | 261 | * rc = 0 : success |
262 | * rc > 0 : Unrecoverable error, this node should be deleted. | 262 | * rc > 0 : Unrecoverable error, this node should be deleted. |
263 | */ | 263 | */ |
264 | int rc = 0; | 264 | int rc = 0; |
265 | 265 | ||
266 | BUG_ON(xd->flags & JFFS2_XFLAGS_DEAD); | 266 | BUG_ON(xd->flags & JFFS2_XFLAGS_DEAD); |
267 | if (xd->xname) | 267 | if (xd->xname) |
268 | return 0; | 268 | return 0; |
269 | if (xd->flags & JFFS2_XFLAGS_INVALID) | 269 | if (xd->flags & JFFS2_XFLAGS_INVALID) |
270 | return EIO; | 270 | return EIO; |
271 | if (unlikely(is_xattr_datum_unchecked(c, xd))) | 271 | if (unlikely(is_xattr_datum_unchecked(c, xd))) |
272 | rc = do_verify_xattr_datum(c, xd); | 272 | rc = do_verify_xattr_datum(c, xd); |
273 | if (!rc) | 273 | if (!rc) |
274 | rc = do_load_xattr_datum(c, xd); | 274 | rc = do_load_xattr_datum(c, xd); |
275 | return rc; | 275 | return rc; |
276 | } | 276 | } |
277 | 277 | ||
278 | static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) | 278 | static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) |
279 | { | 279 | { |
280 | /* must be called under down_write(xattr_sem) */ | 280 | /* must be called under down_write(xattr_sem) */ |
281 | struct jffs2_raw_xattr rx; | 281 | struct jffs2_raw_xattr rx; |
282 | struct kvec vecs[2]; | 282 | struct kvec vecs[2]; |
283 | size_t length; | 283 | size_t length; |
284 | int rc, totlen; | 284 | int rc, totlen; |
285 | uint32_t phys_ofs = write_ofs(c); | 285 | uint32_t phys_ofs = write_ofs(c); |
286 | 286 | ||
287 | BUG_ON(!xd->xname); | 287 | BUG_ON(!xd->xname); |
288 | BUG_ON(xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID)); | 288 | BUG_ON(xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID)); |
289 | 289 | ||
290 | vecs[0].iov_base = ℞ | 290 | vecs[0].iov_base = ℞ |
291 | vecs[0].iov_len = sizeof(rx); | 291 | vecs[0].iov_len = sizeof(rx); |
292 | vecs[1].iov_base = xd->xname; | 292 | vecs[1].iov_base = xd->xname; |
293 | vecs[1].iov_len = xd->name_len + 1 + xd->value_len; | 293 | vecs[1].iov_len = xd->name_len + 1 + xd->value_len; |
294 | totlen = vecs[0].iov_len + vecs[1].iov_len; | 294 | totlen = vecs[0].iov_len + vecs[1].iov_len; |
295 | 295 | ||
296 | /* Setup raw-xattr */ | 296 | /* Setup raw-xattr */ |
297 | memset(&rx, 0, sizeof(rx)); | 297 | memset(&rx, 0, sizeof(rx)); |
298 | rx.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); | 298 | rx.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); |
299 | rx.nodetype = cpu_to_je16(JFFS2_NODETYPE_XATTR); | 299 | rx.nodetype = cpu_to_je16(JFFS2_NODETYPE_XATTR); |
300 | rx.totlen = cpu_to_je32(PAD(totlen)); | 300 | rx.totlen = cpu_to_je32(PAD(totlen)); |
301 | rx.hdr_crc = cpu_to_je32(crc32(0, &rx, sizeof(struct jffs2_unknown_node) - 4)); | 301 | rx.hdr_crc = cpu_to_je32(crc32(0, &rx, sizeof(struct jffs2_unknown_node) - 4)); |
302 | 302 | ||
303 | rx.xid = cpu_to_je32(xd->xid); | 303 | rx.xid = cpu_to_je32(xd->xid); |
304 | rx.version = cpu_to_je32(++xd->version); | 304 | rx.version = cpu_to_je32(++xd->version); |
305 | rx.xprefix = xd->xprefix; | 305 | rx.xprefix = xd->xprefix; |
306 | rx.name_len = xd->name_len; | 306 | rx.name_len = xd->name_len; |
307 | rx.value_len = cpu_to_je16(xd->value_len); | 307 | rx.value_len = cpu_to_je16(xd->value_len); |
308 | rx.data_crc = cpu_to_je32(crc32(0, vecs[1].iov_base, vecs[1].iov_len)); | 308 | rx.data_crc = cpu_to_je32(crc32(0, vecs[1].iov_base, vecs[1].iov_len)); |
309 | rx.node_crc = cpu_to_je32(crc32(0, &rx, sizeof(struct jffs2_raw_xattr) - 4)); | 309 | rx.node_crc = cpu_to_je32(crc32(0, &rx, sizeof(struct jffs2_raw_xattr) - 4)); |
310 | 310 | ||
311 | rc = jffs2_flash_writev(c, vecs, 2, phys_ofs, &length, 0); | 311 | rc = jffs2_flash_writev(c, vecs, 2, phys_ofs, &length, 0); |
312 | if (rc || totlen != length) { | 312 | if (rc || totlen != length) { |
313 | JFFS2_WARNING("jffs2_flash_writev()=%d, req=%u, wrote=%zu, at %#08x\n", | 313 | JFFS2_WARNING("jffs2_flash_writev()=%d, req=%u, wrote=%zu, at %#08x\n", |
314 | rc, totlen, length, phys_ofs); | 314 | rc, totlen, length, phys_ofs); |
315 | rc = rc ? rc : -EIO; | 315 | rc = rc ? rc : -EIO; |
316 | if (length) | 316 | if (length) |
317 | jffs2_add_physical_node_ref(c, phys_ofs | REF_OBSOLETE, PAD(totlen), NULL); | 317 | jffs2_add_physical_node_ref(c, phys_ofs | REF_OBSOLETE, PAD(totlen), NULL); |
318 | 318 | ||
319 | return rc; | 319 | return rc; |
320 | } | 320 | } |
321 | /* success */ | 321 | /* success */ |
322 | jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(totlen), (void *)xd); | 322 | jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(totlen), (void *)xd); |
323 | 323 | ||
324 | dbg_xattr("success on saving xdatum (xid=%u, version=%u, xprefix=%u, xname='%s')\n", | 324 | dbg_xattr("success on saving xdatum (xid=%u, version=%u, xprefix=%u, xname='%s')\n", |
325 | xd->xid, xd->version, xd->xprefix, xd->xname); | 325 | xd->xid, xd->version, xd->xprefix, xd->xname); |
326 | 326 | ||
327 | return 0; | 327 | return 0; |
328 | } | 328 | } |
329 | 329 | ||
330 | static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c, | 330 | static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c, |
331 | int xprefix, const char *xname, | 331 | int xprefix, const char *xname, |
332 | const char *xvalue, int xsize) | 332 | const char *xvalue, int xsize) |
333 | { | 333 | { |
334 | /* must be called under down_write(xattr_sem) */ | 334 | /* must be called under down_write(xattr_sem) */ |
335 | struct jffs2_xattr_datum *xd; | 335 | struct jffs2_xattr_datum *xd; |
336 | uint32_t hashkey, name_len; | 336 | uint32_t hashkey, name_len; |
337 | char *data; | 337 | char *data; |
338 | int i, rc; | 338 | int i, rc; |
339 | 339 | ||
340 | /* Search xattr_datum has same xname/xvalue by index */ | 340 | /* Search xattr_datum has same xname/xvalue by index */ |
341 | hashkey = xattr_datum_hashkey(xprefix, xname, xvalue, xsize); | 341 | hashkey = xattr_datum_hashkey(xprefix, xname, xvalue, xsize); |
342 | i = hashkey % XATTRINDEX_HASHSIZE; | 342 | i = hashkey % XATTRINDEX_HASHSIZE; |
343 | list_for_each_entry(xd, &c->xattrindex[i], xindex) { | 343 | list_for_each_entry(xd, &c->xattrindex[i], xindex) { |
344 | if (xd->hashkey==hashkey | 344 | if (xd->hashkey==hashkey |
345 | && xd->xprefix==xprefix | 345 | && xd->xprefix==xprefix |
346 | && xd->value_len==xsize | 346 | && xd->value_len==xsize |
347 | && !strcmp(xd->xname, xname) | 347 | && !strcmp(xd->xname, xname) |
348 | && !memcmp(xd->xvalue, xvalue, xsize)) { | 348 | && !memcmp(xd->xvalue, xvalue, xsize)) { |
349 | atomic_inc(&xd->refcnt); | 349 | atomic_inc(&xd->refcnt); |
350 | return xd; | 350 | return xd; |
351 | } | 351 | } |
352 | } | 352 | } |
353 | 353 | ||
354 | /* Not found, Create NEW XATTR-Cache */ | 354 | /* Not found, Create NEW XATTR-Cache */ |
355 | name_len = strlen(xname); | 355 | name_len = strlen(xname); |
356 | 356 | ||
357 | xd = jffs2_alloc_xattr_datum(); | 357 | xd = jffs2_alloc_xattr_datum(); |
358 | if (!xd) | 358 | if (!xd) |
359 | return ERR_PTR(-ENOMEM); | 359 | return ERR_PTR(-ENOMEM); |
360 | 360 | ||
361 | data = kmalloc(name_len + 1 + xsize, GFP_KERNEL); | 361 | data = kmalloc(name_len + 1 + xsize, GFP_KERNEL); |
362 | if (!data) { | 362 | if (!data) { |
363 | jffs2_free_xattr_datum(xd); | 363 | jffs2_free_xattr_datum(xd); |
364 | return ERR_PTR(-ENOMEM); | 364 | return ERR_PTR(-ENOMEM); |
365 | } | 365 | } |
366 | strcpy(data, xname); | 366 | strcpy(data, xname); |
367 | memcpy(data + name_len + 1, xvalue, xsize); | 367 | memcpy(data + name_len + 1, xvalue, xsize); |
368 | 368 | ||
369 | atomic_set(&xd->refcnt, 1); | 369 | atomic_set(&xd->refcnt, 1); |
370 | xd->xid = ++c->highest_xid; | 370 | xd->xid = ++c->highest_xid; |
371 | xd->flags |= JFFS2_XFLAGS_HOT; | 371 | xd->flags |= JFFS2_XFLAGS_HOT; |
372 | xd->xprefix = xprefix; | 372 | xd->xprefix = xprefix; |
373 | 373 | ||
374 | xd->hashkey = hashkey; | 374 | xd->hashkey = hashkey; |
375 | xd->xname = data; | 375 | xd->xname = data; |
376 | xd->xvalue = data + name_len + 1; | 376 | xd->xvalue = data + name_len + 1; |
377 | xd->name_len = name_len; | 377 | xd->name_len = name_len; |
378 | xd->value_len = xsize; | 378 | xd->value_len = xsize; |
379 | xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len); | 379 | xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len); |
380 | 380 | ||
381 | rc = save_xattr_datum(c, xd); | 381 | rc = save_xattr_datum(c, xd); |
382 | if (rc) { | 382 | if (rc) { |
383 | kfree(xd->xname); | 383 | kfree(xd->xname); |
384 | jffs2_free_xattr_datum(xd); | 384 | jffs2_free_xattr_datum(xd); |
385 | return ERR_PTR(rc); | 385 | return ERR_PTR(rc); |
386 | } | 386 | } |
387 | 387 | ||
388 | /* Insert Hash Index */ | 388 | /* Insert Hash Index */ |
389 | i = hashkey % XATTRINDEX_HASHSIZE; | 389 | i = hashkey % XATTRINDEX_HASHSIZE; |
390 | list_add(&xd->xindex, &c->xattrindex[i]); | 390 | list_add(&xd->xindex, &c->xattrindex[i]); |
391 | 391 | ||
392 | c->xdatum_mem_usage += (xd->name_len + 1 + xd->value_len); | 392 | c->xdatum_mem_usage += (xd->name_len + 1 + xd->value_len); |
393 | reclaim_xattr_datum(c); | 393 | reclaim_xattr_datum(c); |
394 | 394 | ||
395 | return xd; | 395 | return xd; |
396 | } | 396 | } |
397 | 397 | ||
398 | static void unrefer_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) | 398 | static void unrefer_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) |
399 | { | 399 | { |
400 | /* must be called under down_write(xattr_sem) */ | 400 | /* must be called under down_write(xattr_sem) */ |
401 | if (atomic_dec_and_lock(&xd->refcnt, &c->erase_completion_lock)) { | 401 | if (atomic_dec_and_lock(&xd->refcnt, &c->erase_completion_lock)) { |
402 | uint32_t xid = xd->xid, version = xd->version; | 402 | uint32_t xid = xd->xid, version = xd->version; |
403 | 403 | ||
404 | unload_xattr_datum(c, xd); | 404 | unload_xattr_datum(c, xd); |
405 | xd->flags |= JFFS2_XFLAGS_DEAD; | 405 | xd->flags |= JFFS2_XFLAGS_DEAD; |
406 | if (xd->node == (void *)xd) { | 406 | if (xd->node == (void *)xd) { |
407 | BUG_ON(!(xd->flags & JFFS2_XFLAGS_INVALID)); | 407 | BUG_ON(!(xd->flags & JFFS2_XFLAGS_INVALID)); |
408 | jffs2_free_xattr_datum(xd); | 408 | jffs2_free_xattr_datum(xd); |
409 | } else { | 409 | } else { |
410 | list_add(&xd->xindex, &c->xattr_dead_list); | 410 | list_add(&xd->xindex, &c->xattr_dead_list); |
411 | } | 411 | } |
412 | spin_unlock(&c->erase_completion_lock); | 412 | spin_unlock(&c->erase_completion_lock); |
413 | 413 | ||
414 | dbg_xattr("xdatum(xid=%u, version=%u) was removed.\n", xid, version); | 414 | dbg_xattr("xdatum(xid=%u, version=%u) was removed.\n", xid, version); |
415 | } | 415 | } |
416 | } | 416 | } |
417 | 417 | ||
418 | /* -------- xref related functions ------------------ | 418 | /* -------- xref related functions ------------------ |
419 | * verify_xattr_ref(c, ref) | 419 | * verify_xattr_ref(c, ref) |
420 | * is used to load xref information from medium. Because summary data does not | 420 | * is used to load xref information from medium. Because summary data does not |
421 | * contain xid/ino, it's necessary to verify once while mounting process. | 421 | * contain xid/ino, it's necessary to verify once while mounting process. |
422 | * save_xattr_ref(c, ref) | 422 | * save_xattr_ref(c, ref) |
423 | * is used to write xref to medium. If delete marker is marked, it write | 423 | * is used to write xref to medium. If delete marker is marked, it write |
424 | * a delete marker of xref into medium. | 424 | * a delete marker of xref into medium. |
425 | * create_xattr_ref(c, ic, xd) | 425 | * create_xattr_ref(c, ic, xd) |
426 | * is used to create a new xref and write to medium. | 426 | * is used to create a new xref and write to medium. |
427 | * delete_xattr_ref(c, ref) | 427 | * delete_xattr_ref(c, ref) |
428 | * is used to delete jffs2_xattr_ref. It marks xref XREF_DELETE_MARKER, | 428 | * is used to delete jffs2_xattr_ref. It marks xref XREF_DELETE_MARKER, |
429 | * and allows GC to reclaim those physical nodes. | 429 | * and allows GC to reclaim those physical nodes. |
430 | * jffs2_xattr_delete_inode(c, ic) | 430 | * jffs2_xattr_delete_inode(c, ic) |
431 | * is called to remove xrefs related to obsolete inode when inode is unlinked. | 431 | * is called to remove xrefs related to obsolete inode when inode is unlinked. |
432 | * jffs2_xattr_free_inode(c, ic) | 432 | * jffs2_xattr_free_inode(c, ic) |
433 | * is called to release xattr related objects when unmounting. | 433 | * is called to release xattr related objects when unmounting. |
434 | * check_xattr_ref_inode(c, ic) | 434 | * check_xattr_ref_inode(c, ic) |
435 | * is used to confirm inode does not have duplicate xattr name/value pair. | 435 | * is used to confirm inode does not have duplicate xattr name/value pair. |
436 | * -------------------------------------------------- */ | 436 | * -------------------------------------------------- */ |
437 | static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) | 437 | static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) |
438 | { | 438 | { |
439 | struct jffs2_eraseblock *jeb; | 439 | struct jffs2_eraseblock *jeb; |
440 | struct jffs2_raw_node_ref *raw; | 440 | struct jffs2_raw_node_ref *raw; |
441 | struct jffs2_raw_xref rr; | 441 | struct jffs2_raw_xref rr; |
442 | size_t readlen; | 442 | size_t readlen; |
443 | uint32_t crc, offset, totlen; | 443 | uint32_t crc, offset, totlen; |
444 | int rc; | 444 | int rc; |
445 | 445 | ||
446 | spin_lock(&c->erase_completion_lock); | 446 | spin_lock(&c->erase_completion_lock); |
447 | if (ref_flags(ref->node) != REF_UNCHECKED) | 447 | if (ref_flags(ref->node) != REF_UNCHECKED) |
448 | goto complete; | 448 | goto complete; |
449 | offset = ref_offset(ref->node); | 449 | offset = ref_offset(ref->node); |
450 | spin_unlock(&c->erase_completion_lock); | 450 | spin_unlock(&c->erase_completion_lock); |
451 | 451 | ||
452 | rc = jffs2_flash_read(c, offset, sizeof(rr), &readlen, (char *)&rr); | 452 | rc = jffs2_flash_read(c, offset, sizeof(rr), &readlen, (char *)&rr); |
453 | if (rc || sizeof(rr) != readlen) { | 453 | if (rc || sizeof(rr) != readlen) { |
454 | JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu, at %#08x\n", | 454 | JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu, at %#08x\n", |
455 | rc, sizeof(rr), readlen, offset); | 455 | rc, sizeof(rr), readlen, offset); |
456 | return rc ? rc : -EIO; | 456 | return rc ? rc : -EIO; |
457 | } | 457 | } |
458 | /* obsolete node */ | 458 | /* obsolete node */ |
459 | crc = crc32(0, &rr, sizeof(rr) - 4); | 459 | crc = crc32(0, &rr, sizeof(rr) - 4); |
460 | if (crc != je32_to_cpu(rr.node_crc)) { | 460 | if (crc != je32_to_cpu(rr.node_crc)) { |
461 | JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", | 461 | JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", |
462 | offset, je32_to_cpu(rr.node_crc), crc); | 462 | offset, je32_to_cpu(rr.node_crc), crc); |
463 | return EIO; | 463 | return EIO; |
464 | } | 464 | } |
465 | if (je16_to_cpu(rr.magic) != JFFS2_MAGIC_BITMASK | 465 | if (je16_to_cpu(rr.magic) != JFFS2_MAGIC_BITMASK |
466 | || je16_to_cpu(rr.nodetype) != JFFS2_NODETYPE_XREF | 466 | || je16_to_cpu(rr.nodetype) != JFFS2_NODETYPE_XREF |
467 | || je32_to_cpu(rr.totlen) != PAD(sizeof(rr))) { | 467 | || je32_to_cpu(rr.totlen) != PAD(sizeof(rr))) { |
468 | JFFS2_ERROR("inconsistent xref at %#08x, magic=%#04x/%#04x, " | 468 | JFFS2_ERROR("inconsistent xref at %#08x, magic=%#04x/%#04x, " |
469 | "nodetype=%#04x/%#04x, totlen=%u/%zu\n", | 469 | "nodetype=%#04x/%#04x, totlen=%u/%zu\n", |
470 | offset, je16_to_cpu(rr.magic), JFFS2_MAGIC_BITMASK, | 470 | offset, je16_to_cpu(rr.magic), JFFS2_MAGIC_BITMASK, |
471 | je16_to_cpu(rr.nodetype), JFFS2_NODETYPE_XREF, | 471 | je16_to_cpu(rr.nodetype), JFFS2_NODETYPE_XREF, |
472 | je32_to_cpu(rr.totlen), PAD(sizeof(rr))); | 472 | je32_to_cpu(rr.totlen), PAD(sizeof(rr))); |
473 | return EIO; | 473 | return EIO; |
474 | } | 474 | } |
475 | ref->ino = je32_to_cpu(rr.ino); | 475 | ref->ino = je32_to_cpu(rr.ino); |
476 | ref->xid = je32_to_cpu(rr.xid); | 476 | ref->xid = je32_to_cpu(rr.xid); |
477 | ref->xseqno = je32_to_cpu(rr.xseqno); | 477 | ref->xseqno = je32_to_cpu(rr.xseqno); |
478 | if (ref->xseqno > c->highest_xseqno) | 478 | if (ref->xseqno > c->highest_xseqno) |
479 | c->highest_xseqno = (ref->xseqno & ~XREF_DELETE_MARKER); | 479 | c->highest_xseqno = (ref->xseqno & ~XREF_DELETE_MARKER); |
480 | 480 | ||
481 | spin_lock(&c->erase_completion_lock); | 481 | spin_lock(&c->erase_completion_lock); |
482 | complete: | 482 | complete: |
483 | for (raw=ref->node; raw != (void *)ref; raw=raw->next_in_ino) { | 483 | for (raw=ref->node; raw != (void *)ref; raw=raw->next_in_ino) { |
484 | jeb = &c->blocks[ref_offset(raw) / c->sector_size]; | 484 | jeb = &c->blocks[ref_offset(raw) / c->sector_size]; |
485 | totlen = PAD(ref_totlen(c, jeb, raw)); | 485 | totlen = PAD(ref_totlen(c, jeb, raw)); |
486 | if (ref_flags(raw) == REF_UNCHECKED) { | 486 | if (ref_flags(raw) == REF_UNCHECKED) { |
487 | c->unchecked_size -= totlen; c->used_size += totlen; | 487 | c->unchecked_size -= totlen; c->used_size += totlen; |
488 | jeb->unchecked_size -= totlen; jeb->used_size += totlen; | 488 | jeb->unchecked_size -= totlen; jeb->used_size += totlen; |
489 | } | 489 | } |
490 | raw->flash_offset = ref_offset(raw) | ((ref->node==raw) ? REF_PRISTINE : REF_NORMAL); | 490 | raw->flash_offset = ref_offset(raw) | ((ref->node==raw) ? REF_PRISTINE : REF_NORMAL); |
491 | } | 491 | } |
492 | spin_unlock(&c->erase_completion_lock); | 492 | spin_unlock(&c->erase_completion_lock); |
493 | 493 | ||
494 | dbg_xattr("success on verifying xref (ino=%u, xid=%u) at %#08x\n", | 494 | dbg_xattr("success on verifying xref (ino=%u, xid=%u) at %#08x\n", |
495 | ref->ino, ref->xid, ref_offset(ref->node)); | 495 | ref->ino, ref->xid, ref_offset(ref->node)); |
496 | return 0; | 496 | return 0; |
497 | } | 497 | } |
498 | 498 | ||
499 | static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) | 499 | static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) |
500 | { | 500 | { |
501 | /* must be called under down_write(xattr_sem) */ | 501 | /* must be called under down_write(xattr_sem) */ |
502 | struct jffs2_raw_xref rr; | 502 | struct jffs2_raw_xref rr; |
503 | size_t length; | 503 | size_t length; |
504 | uint32_t xseqno, phys_ofs = write_ofs(c); | 504 | uint32_t xseqno, phys_ofs = write_ofs(c); |
505 | int ret; | 505 | int ret; |
506 | 506 | ||
507 | rr.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); | 507 | rr.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); |
508 | rr.nodetype = cpu_to_je16(JFFS2_NODETYPE_XREF); | 508 | rr.nodetype = cpu_to_je16(JFFS2_NODETYPE_XREF); |
509 | rr.totlen = cpu_to_je32(PAD(sizeof(rr))); | 509 | rr.totlen = cpu_to_je32(PAD(sizeof(rr))); |
510 | rr.hdr_crc = cpu_to_je32(crc32(0, &rr, sizeof(struct jffs2_unknown_node) - 4)); | 510 | rr.hdr_crc = cpu_to_je32(crc32(0, &rr, sizeof(struct jffs2_unknown_node) - 4)); |
511 | 511 | ||
512 | xseqno = (c->highest_xseqno += 2); | 512 | xseqno = (c->highest_xseqno += 2); |
513 | if (is_xattr_ref_dead(ref)) { | 513 | if (is_xattr_ref_dead(ref)) { |
514 | xseqno |= XREF_DELETE_MARKER; | 514 | xseqno |= XREF_DELETE_MARKER; |
515 | rr.ino = cpu_to_je32(ref->ino); | 515 | rr.ino = cpu_to_je32(ref->ino); |
516 | rr.xid = cpu_to_je32(ref->xid); | 516 | rr.xid = cpu_to_je32(ref->xid); |
517 | } else { | 517 | } else { |
518 | rr.ino = cpu_to_je32(ref->ic->ino); | 518 | rr.ino = cpu_to_je32(ref->ic->ino); |
519 | rr.xid = cpu_to_je32(ref->xd->xid); | 519 | rr.xid = cpu_to_je32(ref->xd->xid); |
520 | } | 520 | } |
521 | rr.xseqno = cpu_to_je32(xseqno); | 521 | rr.xseqno = cpu_to_je32(xseqno); |
522 | rr.node_crc = cpu_to_je32(crc32(0, &rr, sizeof(rr) - 4)); | 522 | rr.node_crc = cpu_to_je32(crc32(0, &rr, sizeof(rr) - 4)); |
523 | 523 | ||
524 | ret = jffs2_flash_write(c, phys_ofs, sizeof(rr), &length, (char *)&rr); | 524 | ret = jffs2_flash_write(c, phys_ofs, sizeof(rr), &length, (char *)&rr); |
525 | if (ret || sizeof(rr) != length) { | 525 | if (ret || sizeof(rr) != length) { |
526 | JFFS2_WARNING("jffs2_flash_write() returned %d, request=%zu, retlen=%zu, at %#08x\n", | 526 | JFFS2_WARNING("jffs2_flash_write() returned %d, request=%zu, retlen=%zu, at %#08x\n", |
527 | ret, sizeof(rr), length, phys_ofs); | 527 | ret, sizeof(rr), length, phys_ofs); |
528 | ret = ret ? ret : -EIO; | 528 | ret = ret ? ret : -EIO; |
529 | if (length) | 529 | if (length) |
530 | jffs2_add_physical_node_ref(c, phys_ofs | REF_OBSOLETE, PAD(sizeof(rr)), NULL); | 530 | jffs2_add_physical_node_ref(c, phys_ofs | REF_OBSOLETE, PAD(sizeof(rr)), NULL); |
531 | 531 | ||
532 | return ret; | 532 | return ret; |
533 | } | 533 | } |
534 | /* success */ | 534 | /* success */ |
535 | ref->xseqno = xseqno; | 535 | ref->xseqno = xseqno; |
536 | jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), (void *)ref); | 536 | jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), (void *)ref); |
537 | 537 | ||
538 | dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid); | 538 | dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid); |
539 | 539 | ||
540 | return 0; | 540 | return 0; |
541 | } | 541 | } |
542 | 542 | ||
543 | static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, | 543 | static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, |
544 | struct jffs2_xattr_datum *xd) | 544 | struct jffs2_xattr_datum *xd) |
545 | { | 545 | { |
546 | /* must be called under down_write(xattr_sem) */ | 546 | /* must be called under down_write(xattr_sem) */ |
547 | struct jffs2_xattr_ref *ref; | 547 | struct jffs2_xattr_ref *ref; |
548 | int ret; | 548 | int ret; |
549 | 549 | ||
550 | ref = jffs2_alloc_xattr_ref(); | 550 | ref = jffs2_alloc_xattr_ref(); |
551 | if (!ref) | 551 | if (!ref) |
552 | return ERR_PTR(-ENOMEM); | 552 | return ERR_PTR(-ENOMEM); |
553 | ref->ic = ic; | 553 | ref->ic = ic; |
554 | ref->xd = xd; | 554 | ref->xd = xd; |
555 | 555 | ||
556 | ret = save_xattr_ref(c, ref); | 556 | ret = save_xattr_ref(c, ref); |
557 | if (ret) { | 557 | if (ret) { |
558 | jffs2_free_xattr_ref(ref); | 558 | jffs2_free_xattr_ref(ref); |
559 | return ERR_PTR(ret); | 559 | return ERR_PTR(ret); |
560 | } | 560 | } |
561 | 561 | ||
562 | /* Chain to inode */ | 562 | /* Chain to inode */ |
563 | ref->next = ic->xref; | 563 | ref->next = ic->xref; |
564 | ic->xref = ref; | 564 | ic->xref = ref; |
565 | 565 | ||
566 | return ref; /* success */ | 566 | return ref; /* success */ |
567 | } | 567 | } |
568 | 568 | ||
569 | static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) | 569 | static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) |
570 | { | 570 | { |
571 | /* must be called under down_write(xattr_sem) */ | 571 | /* must be called under down_write(xattr_sem) */ |
572 | struct jffs2_xattr_datum *xd; | 572 | struct jffs2_xattr_datum *xd; |
573 | 573 | ||
574 | xd = ref->xd; | 574 | xd = ref->xd; |
575 | ref->xseqno |= XREF_DELETE_MARKER; | 575 | ref->xseqno |= XREF_DELETE_MARKER; |
576 | ref->ino = ref->ic->ino; | 576 | ref->ino = ref->ic->ino; |
577 | ref->xid = ref->xd->xid; | 577 | ref->xid = ref->xd->xid; |
578 | spin_lock(&c->erase_completion_lock); | 578 | spin_lock(&c->erase_completion_lock); |
579 | ref->next = c->xref_dead_list; | 579 | ref->next = c->xref_dead_list; |
580 | c->xref_dead_list = ref; | 580 | c->xref_dead_list = ref; |
581 | spin_unlock(&c->erase_completion_lock); | 581 | spin_unlock(&c->erase_completion_lock); |
582 | 582 | ||
583 | dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) was removed.\n", | 583 | dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) was removed.\n", |
584 | ref->ino, ref->xid, ref->xseqno); | 584 | ref->ino, ref->xid, ref->xseqno); |
585 | 585 | ||
586 | unrefer_xattr_datum(c, xd); | 586 | unrefer_xattr_datum(c, xd); |
587 | } | 587 | } |
588 | 588 | ||
589 | void jffs2_xattr_delete_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic) | 589 | void jffs2_xattr_delete_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic) |
590 | { | 590 | { |
591 | /* It's called from jffs2_clear_inode() on inode removing. | 591 | /* It's called from jffs2_clear_inode() on inode removing. |
592 | When an inode with XATTR is removed, those XATTRs must be removed. */ | 592 | When an inode with XATTR is removed, those XATTRs must be removed. */ |
593 | struct jffs2_xattr_ref *ref, *_ref; | 593 | struct jffs2_xattr_ref *ref, *_ref; |
594 | 594 | ||
595 | if (!ic || ic->nlink > 0) | 595 | if (!ic || ic->nlink > 0) |
596 | return; | 596 | return; |
597 | 597 | ||
598 | down_write(&c->xattr_sem); | 598 | down_write(&c->xattr_sem); |
599 | for (ref = ic->xref; ref; ref = _ref) { | 599 | for (ref = ic->xref; ref; ref = _ref) { |
600 | _ref = ref->next; | 600 | _ref = ref->next; |
601 | delete_xattr_ref(c, ref); | 601 | delete_xattr_ref(c, ref); |
602 | } | 602 | } |
603 | ic->xref = NULL; | 603 | ic->xref = NULL; |
604 | up_write(&c->xattr_sem); | 604 | up_write(&c->xattr_sem); |
605 | } | 605 | } |
606 | 606 | ||
607 | void jffs2_xattr_free_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic) | 607 | void jffs2_xattr_free_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic) |
608 | { | 608 | { |
609 | /* It's called from jffs2_free_ino_caches() until unmounting FS. */ | 609 | /* It's called from jffs2_free_ino_caches() until unmounting FS. */ |
610 | struct jffs2_xattr_datum *xd; | 610 | struct jffs2_xattr_datum *xd; |
611 | struct jffs2_xattr_ref *ref, *_ref; | 611 | struct jffs2_xattr_ref *ref, *_ref; |
612 | 612 | ||
613 | down_write(&c->xattr_sem); | 613 | down_write(&c->xattr_sem); |
614 | for (ref = ic->xref; ref; ref = _ref) { | 614 | for (ref = ic->xref; ref; ref = _ref) { |
615 | _ref = ref->next; | 615 | _ref = ref->next; |
616 | xd = ref->xd; | 616 | xd = ref->xd; |
617 | if (atomic_dec_and_test(&xd->refcnt)) { | 617 | if (atomic_dec_and_test(&xd->refcnt)) { |
618 | unload_xattr_datum(c, xd); | 618 | unload_xattr_datum(c, xd); |
619 | jffs2_free_xattr_datum(xd); | 619 | jffs2_free_xattr_datum(xd); |
620 | } | 620 | } |
621 | jffs2_free_xattr_ref(ref); | 621 | jffs2_free_xattr_ref(ref); |
622 | } | 622 | } |
623 | ic->xref = NULL; | 623 | ic->xref = NULL; |
624 | up_write(&c->xattr_sem); | 624 | up_write(&c->xattr_sem); |
625 | } | 625 | } |
626 | 626 | ||
627 | static int check_xattr_ref_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic) | 627 | static int check_xattr_ref_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic) |
628 | { | 628 | { |
629 | /* success of check_xattr_ref_inode() means taht inode (ic) dose not have | 629 | /* success of check_xattr_ref_inode() means taht inode (ic) dose not have |
630 | * duplicate name/value pairs. If duplicate name/value pair would be found, | 630 | * duplicate name/value pairs. If duplicate name/value pair would be found, |
631 | * one will be removed. | 631 | * one will be removed. |
632 | */ | 632 | */ |
633 | struct jffs2_xattr_ref *ref, *cmp, **pref, **pcmp; | 633 | struct jffs2_xattr_ref *ref, *cmp, **pref, **pcmp; |
634 | int rc = 0; | 634 | int rc = 0; |
635 | 635 | ||
636 | if (likely(ic->flags & INO_FLAGS_XATTR_CHECKED)) | 636 | if (likely(ic->flags & INO_FLAGS_XATTR_CHECKED)) |
637 | return 0; | 637 | return 0; |
638 | down_write(&c->xattr_sem); | 638 | down_write(&c->xattr_sem); |
639 | retry: | 639 | retry: |
640 | rc = 0; | 640 | rc = 0; |
641 | for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) { | 641 | for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) { |
642 | if (!ref->xd->xname) { | 642 | if (!ref->xd->xname) { |
643 | rc = load_xattr_datum(c, ref->xd); | 643 | rc = load_xattr_datum(c, ref->xd); |
644 | if (unlikely(rc > 0)) { | 644 | if (unlikely(rc > 0)) { |
645 | *pref = ref->next; | 645 | *pref = ref->next; |
646 | delete_xattr_ref(c, ref); | 646 | delete_xattr_ref(c, ref); |
647 | goto retry; | 647 | goto retry; |
648 | } else if (unlikely(rc < 0)) | 648 | } else if (unlikely(rc < 0)) |
649 | goto out; | 649 | goto out; |
650 | } | 650 | } |
651 | for (cmp=ref->next, pcmp=&ref->next; cmp; pcmp=&cmp->next, cmp=cmp->next) { | 651 | for (cmp=ref->next, pcmp=&ref->next; cmp; pcmp=&cmp->next, cmp=cmp->next) { |
652 | if (!cmp->xd->xname) { | 652 | if (!cmp->xd->xname) { |
653 | ref->xd->flags |= JFFS2_XFLAGS_BIND; | 653 | ref->xd->flags |= JFFS2_XFLAGS_BIND; |
654 | rc = load_xattr_datum(c, cmp->xd); | 654 | rc = load_xattr_datum(c, cmp->xd); |
655 | ref->xd->flags &= ~JFFS2_XFLAGS_BIND; | 655 | ref->xd->flags &= ~JFFS2_XFLAGS_BIND; |
656 | if (unlikely(rc > 0)) { | 656 | if (unlikely(rc > 0)) { |
657 | *pcmp = cmp->next; | 657 | *pcmp = cmp->next; |
658 | delete_xattr_ref(c, cmp); | 658 | delete_xattr_ref(c, cmp); |
659 | goto retry; | 659 | goto retry; |
660 | } else if (unlikely(rc < 0)) | 660 | } else if (unlikely(rc < 0)) |
661 | goto out; | 661 | goto out; |
662 | } | 662 | } |
663 | if (ref->xd->xprefix == cmp->xd->xprefix | 663 | if (ref->xd->xprefix == cmp->xd->xprefix |
664 | && !strcmp(ref->xd->xname, cmp->xd->xname)) { | 664 | && !strcmp(ref->xd->xname, cmp->xd->xname)) { |
665 | if (ref->xseqno > cmp->xseqno) { | 665 | if (ref->xseqno > cmp->xseqno) { |
666 | *pcmp = cmp->next; | 666 | *pcmp = cmp->next; |
667 | delete_xattr_ref(c, cmp); | 667 | delete_xattr_ref(c, cmp); |
668 | } else { | 668 | } else { |
669 | *pref = ref->next; | 669 | *pref = ref->next; |
670 | delete_xattr_ref(c, ref); | 670 | delete_xattr_ref(c, ref); |
671 | } | 671 | } |
672 | goto retry; | 672 | goto retry; |
673 | } | 673 | } |
674 | } | 674 | } |
675 | } | 675 | } |
676 | ic->flags |= INO_FLAGS_XATTR_CHECKED; | 676 | ic->flags |= INO_FLAGS_XATTR_CHECKED; |
677 | out: | 677 | out: |
678 | up_write(&c->xattr_sem); | 678 | up_write(&c->xattr_sem); |
679 | 679 | ||
680 | return rc; | 680 | return rc; |
681 | } | 681 | } |
682 | 682 | ||
683 | /* -------- xattr subsystem functions --------------- | 683 | /* -------- xattr subsystem functions --------------- |
684 | * jffs2_init_xattr_subsystem(c) | 684 | * jffs2_init_xattr_subsystem(c) |
685 | * is used to initialize semaphore and list_head, and some variables. | 685 | * is used to initialize semaphore and list_head, and some variables. |
686 | * jffs2_find_xattr_datum(c, xid) | 686 | * jffs2_find_xattr_datum(c, xid) |
687 | * is used to lookup xdatum while scanning process. | 687 | * is used to lookup xdatum while scanning process. |
688 | * jffs2_clear_xattr_subsystem(c) | 688 | * jffs2_clear_xattr_subsystem(c) |
689 | * is used to release any xattr related objects. | 689 | * is used to release any xattr related objects. |
690 | * jffs2_build_xattr_subsystem(c) | 690 | * jffs2_build_xattr_subsystem(c) |
691 | * is used to associate xdatum and xref while super block building process. | 691 | * is used to associate xdatum and xref while super block building process. |
692 | * jffs2_setup_xattr_datum(c, xid, version) | 692 | * jffs2_setup_xattr_datum(c, xid, version) |
693 | * is used to insert xdatum while scanning process. | 693 | * is used to insert xdatum while scanning process. |
694 | * -------------------------------------------------- */ | 694 | * -------------------------------------------------- */ |
695 | void jffs2_init_xattr_subsystem(struct jffs2_sb_info *c) | 695 | void jffs2_init_xattr_subsystem(struct jffs2_sb_info *c) |
696 | { | 696 | { |
697 | int i; | 697 | int i; |
698 | 698 | ||
699 | for (i=0; i < XATTRINDEX_HASHSIZE; i++) | 699 | for (i=0; i < XATTRINDEX_HASHSIZE; i++) |
700 | INIT_LIST_HEAD(&c->xattrindex[i]); | 700 | INIT_LIST_HEAD(&c->xattrindex[i]); |
701 | INIT_LIST_HEAD(&c->xattr_unchecked); | 701 | INIT_LIST_HEAD(&c->xattr_unchecked); |
702 | INIT_LIST_HEAD(&c->xattr_dead_list); | 702 | INIT_LIST_HEAD(&c->xattr_dead_list); |
703 | c->xref_dead_list = NULL; | 703 | c->xref_dead_list = NULL; |
704 | c->xref_temp = NULL; | 704 | c->xref_temp = NULL; |
705 | 705 | ||
706 | init_rwsem(&c->xattr_sem); | 706 | init_rwsem(&c->xattr_sem); |
707 | c->highest_xid = 0; | 707 | c->highest_xid = 0; |
708 | c->highest_xseqno = 0; | 708 | c->highest_xseqno = 0; |
709 | c->xdatum_mem_usage = 0; | 709 | c->xdatum_mem_usage = 0; |
710 | c->xdatum_mem_threshold = 32 * 1024; /* Default 32KB */ | 710 | c->xdatum_mem_threshold = 32 * 1024; /* Default 32KB */ |
711 | } | 711 | } |
712 | 712 | ||
713 | static struct jffs2_xattr_datum *jffs2_find_xattr_datum(struct jffs2_sb_info *c, uint32_t xid) | 713 | static struct jffs2_xattr_datum *jffs2_find_xattr_datum(struct jffs2_sb_info *c, uint32_t xid) |
714 | { | 714 | { |
715 | struct jffs2_xattr_datum *xd; | 715 | struct jffs2_xattr_datum *xd; |
716 | int i = xid % XATTRINDEX_HASHSIZE; | 716 | int i = xid % XATTRINDEX_HASHSIZE; |
717 | 717 | ||
718 | /* It's only used in scanning/building process. */ | 718 | /* It's only used in scanning/building process. */ |
719 | BUG_ON(!(c->flags & (JFFS2_SB_FLAG_SCANNING|JFFS2_SB_FLAG_BUILDING))); | 719 | BUG_ON(!(c->flags & (JFFS2_SB_FLAG_SCANNING|JFFS2_SB_FLAG_BUILDING))); |
720 | 720 | ||
721 | list_for_each_entry(xd, &c->xattrindex[i], xindex) { | 721 | list_for_each_entry(xd, &c->xattrindex[i], xindex) { |
722 | if (xd->xid==xid) | 722 | if (xd->xid==xid) |
723 | return xd; | 723 | return xd; |
724 | } | 724 | } |
725 | return NULL; | 725 | return NULL; |
726 | } | 726 | } |
727 | 727 | ||
728 | void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c) | 728 | void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c) |
729 | { | 729 | { |
730 | struct jffs2_xattr_datum *xd, *_xd; | 730 | struct jffs2_xattr_datum *xd, *_xd; |
731 | struct jffs2_xattr_ref *ref, *_ref; | 731 | struct jffs2_xattr_ref *ref, *_ref; |
732 | int i; | 732 | int i; |
733 | 733 | ||
734 | for (ref=c->xref_temp; ref; ref = _ref) { | 734 | for (ref=c->xref_temp; ref; ref = _ref) { |
735 | _ref = ref->next; | 735 | _ref = ref->next; |
736 | jffs2_free_xattr_ref(ref); | 736 | jffs2_free_xattr_ref(ref); |
737 | } | 737 | } |
738 | 738 | ||
739 | for (ref=c->xref_dead_list; ref; ref = _ref) { | 739 | for (ref=c->xref_dead_list; ref; ref = _ref) { |
740 | _ref = ref->next; | 740 | _ref = ref->next; |
741 | jffs2_free_xattr_ref(ref); | 741 | jffs2_free_xattr_ref(ref); |
742 | } | 742 | } |
743 | 743 | ||
744 | for (i=0; i < XATTRINDEX_HASHSIZE; i++) { | 744 | for (i=0; i < XATTRINDEX_HASHSIZE; i++) { |
745 | list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) { | 745 | list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) { |
746 | list_del(&xd->xindex); | 746 | list_del(&xd->xindex); |
747 | if (xd->xname) | 747 | if (xd->xname) |
748 | kfree(xd->xname); | 748 | kfree(xd->xname); |
749 | jffs2_free_xattr_datum(xd); | 749 | jffs2_free_xattr_datum(xd); |
750 | } | 750 | } |
751 | } | 751 | } |
752 | 752 | ||
753 | list_for_each_entry_safe(xd, _xd, &c->xattr_dead_list, xindex) { | 753 | list_for_each_entry_safe(xd, _xd, &c->xattr_dead_list, xindex) { |
754 | list_del(&xd->xindex); | 754 | list_del(&xd->xindex); |
755 | jffs2_free_xattr_datum(xd); | 755 | jffs2_free_xattr_datum(xd); |
756 | } | 756 | } |
757 | } | 757 | } |
758 | 758 | ||
759 | #define XREF_TMPHASH_SIZE (128) | 759 | #define XREF_TMPHASH_SIZE (128) |
760 | void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) | 760 | void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) |
761 | { | 761 | { |
762 | struct jffs2_xattr_ref *ref, *_ref; | 762 | struct jffs2_xattr_ref *ref, *_ref; |
763 | struct jffs2_xattr_ref *xref_tmphash[XREF_TMPHASH_SIZE]; | 763 | struct jffs2_xattr_ref *xref_tmphash[XREF_TMPHASH_SIZE]; |
764 | struct jffs2_xattr_datum *xd, *_xd; | 764 | struct jffs2_xattr_datum *xd, *_xd; |
765 | struct jffs2_inode_cache *ic; | 765 | struct jffs2_inode_cache *ic; |
766 | struct jffs2_raw_node_ref *raw; | 766 | struct jffs2_raw_node_ref *raw; |
767 | int i, xdatum_count = 0, xdatum_unchecked_count = 0, xref_count = 0; | 767 | int i, xdatum_count = 0, xdatum_unchecked_count = 0, xref_count = 0; |
768 | int xdatum_orphan_count = 0, xref_orphan_count = 0, xref_dead_count = 0; | 768 | int xdatum_orphan_count = 0, xref_orphan_count = 0, xref_dead_count = 0; |
769 | 769 | ||
770 | BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING)); | 770 | BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING)); |
771 | 771 | ||
772 | /* Phase.1 : Merge same xref */ | 772 | /* Phase.1 : Merge same xref */ |
773 | for (i=0; i < XREF_TMPHASH_SIZE; i++) | 773 | for (i=0; i < XREF_TMPHASH_SIZE; i++) |
774 | xref_tmphash[i] = NULL; | 774 | xref_tmphash[i] = NULL; |
775 | for (ref=c->xref_temp; ref; ref=_ref) { | 775 | for (ref=c->xref_temp; ref; ref=_ref) { |
776 | struct jffs2_xattr_ref *tmp; | 776 | struct jffs2_xattr_ref *tmp; |
777 | 777 | ||
778 | _ref = ref->next; | 778 | _ref = ref->next; |
779 | if (ref_flags(ref->node) != REF_PRISTINE) { | 779 | if (ref_flags(ref->node) != REF_PRISTINE) { |
780 | if (verify_xattr_ref(c, ref)) { | 780 | if (verify_xattr_ref(c, ref)) { |
781 | BUG_ON(ref->node->next_in_ino != (void *)ref); | 781 | BUG_ON(ref->node->next_in_ino != (void *)ref); |
782 | ref->node->next_in_ino = NULL; | 782 | ref->node->next_in_ino = NULL; |
783 | jffs2_mark_node_obsolete(c, ref->node); | 783 | jffs2_mark_node_obsolete(c, ref->node); |
784 | jffs2_free_xattr_ref(ref); | 784 | jffs2_free_xattr_ref(ref); |
785 | continue; | 785 | continue; |
786 | } | 786 | } |
787 | } | 787 | } |
788 | 788 | ||
789 | i = (ref->ino ^ ref->xid) % XREF_TMPHASH_SIZE; | 789 | i = (ref->ino ^ ref->xid) % XREF_TMPHASH_SIZE; |
790 | for (tmp=xref_tmphash[i]; tmp; tmp=tmp->next) { | 790 | for (tmp=xref_tmphash[i]; tmp; tmp=tmp->next) { |
791 | if (tmp->ino == ref->ino && tmp->xid == ref->xid) | 791 | if (tmp->ino == ref->ino && tmp->xid == ref->xid) |
792 | break; | 792 | break; |
793 | } | 793 | } |
794 | if (tmp) { | 794 | if (tmp) { |
795 | raw = ref->node; | 795 | raw = ref->node; |
796 | if (ref->xseqno > tmp->xseqno) { | 796 | if (ref->xseqno > tmp->xseqno) { |
797 | tmp->xseqno = ref->xseqno; | 797 | tmp->xseqno = ref->xseqno; |
798 | raw->next_in_ino = tmp->node; | 798 | raw->next_in_ino = tmp->node; |
799 | tmp->node = raw; | 799 | tmp->node = raw; |
800 | } else { | 800 | } else { |
801 | raw->next_in_ino = tmp->node->next_in_ino; | 801 | raw->next_in_ino = tmp->node->next_in_ino; |
802 | tmp->node->next_in_ino = raw; | 802 | tmp->node->next_in_ino = raw; |
803 | } | 803 | } |
804 | jffs2_free_xattr_ref(ref); | 804 | jffs2_free_xattr_ref(ref); |
805 | continue; | 805 | continue; |
806 | } else { | 806 | } else { |
807 | ref->next = xref_tmphash[i]; | 807 | ref->next = xref_tmphash[i]; |
808 | xref_tmphash[i] = ref; | 808 | xref_tmphash[i] = ref; |
809 | } | 809 | } |
810 | } | 810 | } |
811 | c->xref_temp = NULL; | 811 | c->xref_temp = NULL; |
812 | 812 | ||
813 | /* Phase.2 : Bind xref with inode_cache and xattr_datum */ | 813 | /* Phase.2 : Bind xref with inode_cache and xattr_datum */ |
814 | for (i=0; i < XREF_TMPHASH_SIZE; i++) { | 814 | for (i=0; i < XREF_TMPHASH_SIZE; i++) { |
815 | for (ref=xref_tmphash[i]; ref; ref=_ref) { | 815 | for (ref=xref_tmphash[i]; ref; ref=_ref) { |
816 | xref_count++; | 816 | xref_count++; |
817 | _ref = ref->next; | 817 | _ref = ref->next; |
818 | if (is_xattr_ref_dead(ref)) { | 818 | if (is_xattr_ref_dead(ref)) { |
819 | ref->next = c->xref_dead_list; | 819 | ref->next = c->xref_dead_list; |
820 | c->xref_dead_list = ref; | 820 | c->xref_dead_list = ref; |
821 | xref_dead_count++; | 821 | xref_dead_count++; |
822 | continue; | 822 | continue; |
823 | } | 823 | } |
824 | /* At this point, ref->xid and ref->ino contain XID and inode number. | 824 | /* At this point, ref->xid and ref->ino contain XID and inode number. |
825 | ref->xd and ref->ic are not valid yet. */ | 825 | ref->xd and ref->ic are not valid yet. */ |
826 | xd = jffs2_find_xattr_datum(c, ref->xid); | 826 | xd = jffs2_find_xattr_datum(c, ref->xid); |
827 | ic = jffs2_get_ino_cache(c, ref->ino); | 827 | ic = jffs2_get_ino_cache(c, ref->ino); |
828 | if (!xd || !ic) { | 828 | if (!xd || !ic) { |
829 | dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) is orphan.\n", | 829 | dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) is orphan.\n", |
830 | ref->ino, ref->xid, ref->xseqno); | 830 | ref->ino, ref->xid, ref->xseqno); |
831 | ref->xseqno |= XREF_DELETE_MARKER; | 831 | ref->xseqno |= XREF_DELETE_MARKER; |
832 | ref->next = c->xref_dead_list; | 832 | ref->next = c->xref_dead_list; |
833 | c->xref_dead_list = ref; | 833 | c->xref_dead_list = ref; |
834 | xref_orphan_count++; | 834 | xref_orphan_count++; |
835 | continue; | 835 | continue; |
836 | } | 836 | } |
837 | ref->xd = xd; | 837 | ref->xd = xd; |
838 | ref->ic = ic; | 838 | ref->ic = ic; |
839 | atomic_inc(&xd->refcnt); | 839 | atomic_inc(&xd->refcnt); |
840 | ref->next = ic->xref; | 840 | ref->next = ic->xref; |
841 | ic->xref = ref; | 841 | ic->xref = ref; |
842 | } | 842 | } |
843 | } | 843 | } |
844 | 844 | ||
845 | /* Phase.3 : Link unchecked xdatum to xattr_unchecked list */ | 845 | /* Phase.3 : Link unchecked xdatum to xattr_unchecked list */ |
846 | for (i=0; i < XATTRINDEX_HASHSIZE; i++) { | 846 | for (i=0; i < XATTRINDEX_HASHSIZE; i++) { |
847 | list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) { | 847 | list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) { |
848 | xdatum_count++; | 848 | xdatum_count++; |
849 | list_del_init(&xd->xindex); | 849 | list_del_init(&xd->xindex); |
850 | if (!atomic_read(&xd->refcnt)) { | 850 | if (!atomic_read(&xd->refcnt)) { |
851 | dbg_xattr("xdatum(xid=%u, version=%u) is orphan.\n", | 851 | dbg_xattr("xdatum(xid=%u, version=%u) is orphan.\n", |
852 | xd->xid, xd->version); | 852 | xd->xid, xd->version); |
853 | xd->flags |= JFFS2_XFLAGS_DEAD; | 853 | xd->flags |= JFFS2_XFLAGS_DEAD; |
854 | list_add(&xd->xindex, &c->xattr_unchecked); | 854 | list_add(&xd->xindex, &c->xattr_unchecked); |
855 | xdatum_orphan_count++; | 855 | xdatum_orphan_count++; |
856 | continue; | 856 | continue; |
857 | } | 857 | } |
858 | if (is_xattr_datum_unchecked(c, xd)) { | 858 | if (is_xattr_datum_unchecked(c, xd)) { |
859 | dbg_xattr("unchecked xdatum(xid=%u, version=%u)\n", | 859 | dbg_xattr("unchecked xdatum(xid=%u, version=%u)\n", |
860 | xd->xid, xd->version); | 860 | xd->xid, xd->version); |
861 | list_add(&xd->xindex, &c->xattr_unchecked); | 861 | list_add(&xd->xindex, &c->xattr_unchecked); |
862 | xdatum_unchecked_count++; | 862 | xdatum_unchecked_count++; |
863 | } | 863 | } |
864 | } | 864 | } |
865 | } | 865 | } |
866 | /* build complete */ | 866 | /* build complete */ |
867 | JFFS2_NOTICE("complete building xattr subsystem, %u of xdatum" | 867 | JFFS2_NOTICE("complete building xattr subsystem, %u of xdatum" |
868 | " (%u unchecked, %u orphan) and " | 868 | " (%u unchecked, %u orphan) and " |
869 | "%u of xref (%u dead, %u orphan) found.\n", | 869 | "%u of xref (%u dead, %u orphan) found.\n", |
870 | xdatum_count, xdatum_unchecked_count, xdatum_orphan_count, | 870 | xdatum_count, xdatum_unchecked_count, xdatum_orphan_count, |
871 | xref_count, xref_dead_count, xref_orphan_count); | 871 | xref_count, xref_dead_count, xref_orphan_count); |
872 | } | 872 | } |
873 | 873 | ||
874 | struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c, | 874 | struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c, |
875 | uint32_t xid, uint32_t version) | 875 | uint32_t xid, uint32_t version) |
876 | { | 876 | { |
877 | struct jffs2_xattr_datum *xd; | 877 | struct jffs2_xattr_datum *xd; |
878 | 878 | ||
879 | xd = jffs2_find_xattr_datum(c, xid); | 879 | xd = jffs2_find_xattr_datum(c, xid); |
880 | if (!xd) { | 880 | if (!xd) { |
881 | xd = jffs2_alloc_xattr_datum(); | 881 | xd = jffs2_alloc_xattr_datum(); |
882 | if (!xd) | 882 | if (!xd) |
883 | return ERR_PTR(-ENOMEM); | 883 | return ERR_PTR(-ENOMEM); |
884 | xd->xid = xid; | 884 | xd->xid = xid; |
885 | xd->version = version; | 885 | xd->version = version; |
886 | if (xd->xid > c->highest_xid) | 886 | if (xd->xid > c->highest_xid) |
887 | c->highest_xid = xd->xid; | 887 | c->highest_xid = xd->xid; |
888 | list_add_tail(&xd->xindex, &c->xattrindex[xid % XATTRINDEX_HASHSIZE]); | 888 | list_add_tail(&xd->xindex, &c->xattrindex[xid % XATTRINDEX_HASHSIZE]); |
889 | } | 889 | } |
890 | return xd; | 890 | return xd; |
891 | } | 891 | } |
892 | 892 | ||
893 | /* -------- xattr subsystem functions --------------- | 893 | /* -------- xattr subsystem functions --------------- |
894 | * xprefix_to_handler(xprefix) | 894 | * xprefix_to_handler(xprefix) |
895 | * is used to translate xprefix into xattr_handler. | 895 | * is used to translate xprefix into xattr_handler. |
896 | * jffs2_listxattr(dentry, buffer, size) | 896 | * jffs2_listxattr(dentry, buffer, size) |
897 | * is an implementation of listxattr handler on jffs2. | 897 | * is an implementation of listxattr handler on jffs2. |
898 | * do_jffs2_getxattr(inode, xprefix, xname, buffer, size) | 898 | * do_jffs2_getxattr(inode, xprefix, xname, buffer, size) |
899 | * is an implementation of getxattr handler on jffs2. | 899 | * is an implementation of getxattr handler on jffs2. |
900 | * do_jffs2_setxattr(inode, xprefix, xname, buffer, size, flags) | 900 | * do_jffs2_setxattr(inode, xprefix, xname, buffer, size, flags) |
901 | * is an implementation of setxattr handler on jffs2. | 901 | * is an implementation of setxattr handler on jffs2. |
902 | * -------------------------------------------------- */ | 902 | * -------------------------------------------------- */ |
903 | struct xattr_handler *jffs2_xattr_handlers[] = { | 903 | struct xattr_handler *jffs2_xattr_handlers[] = { |
904 | &jffs2_user_xattr_handler, | 904 | &jffs2_user_xattr_handler, |
905 | #ifdef CONFIG_JFFS2_FS_SECURITY | 905 | #ifdef CONFIG_JFFS2_FS_SECURITY |
906 | &jffs2_security_xattr_handler, | 906 | &jffs2_security_xattr_handler, |
907 | #endif | 907 | #endif |
908 | #ifdef CONFIG_JFFS2_FS_POSIX_ACL | 908 | #ifdef CONFIG_JFFS2_FS_POSIX_ACL |
909 | &jffs2_acl_access_xattr_handler, | 909 | &jffs2_acl_access_xattr_handler, |
910 | &jffs2_acl_default_xattr_handler, | 910 | &jffs2_acl_default_xattr_handler, |
911 | #endif | 911 | #endif |
912 | &jffs2_trusted_xattr_handler, | 912 | &jffs2_trusted_xattr_handler, |
913 | NULL | 913 | NULL |
914 | }; | 914 | }; |
915 | 915 | ||
916 | static struct xattr_handler *xprefix_to_handler(int xprefix) { | 916 | static struct xattr_handler *xprefix_to_handler(int xprefix) { |
917 | struct xattr_handler *ret; | 917 | struct xattr_handler *ret; |
918 | 918 | ||
919 | switch (xprefix) { | 919 | switch (xprefix) { |
920 | case JFFS2_XPREFIX_USER: | 920 | case JFFS2_XPREFIX_USER: |
921 | ret = &jffs2_user_xattr_handler; | 921 | ret = &jffs2_user_xattr_handler; |
922 | break; | 922 | break; |
923 | #ifdef CONFIG_JFFS2_FS_SECURITY | 923 | #ifdef CONFIG_JFFS2_FS_SECURITY |
924 | case JFFS2_XPREFIX_SECURITY: | 924 | case JFFS2_XPREFIX_SECURITY: |
925 | ret = &jffs2_security_xattr_handler; | 925 | ret = &jffs2_security_xattr_handler; |
926 | break; | 926 | break; |
927 | #endif | 927 | #endif |
928 | #ifdef CONFIG_JFFS2_FS_POSIX_ACL | 928 | #ifdef CONFIG_JFFS2_FS_POSIX_ACL |
929 | case JFFS2_XPREFIX_ACL_ACCESS: | 929 | case JFFS2_XPREFIX_ACL_ACCESS: |
930 | ret = &jffs2_acl_access_xattr_handler; | 930 | ret = &jffs2_acl_access_xattr_handler; |
931 | break; | 931 | break; |
932 | case JFFS2_XPREFIX_ACL_DEFAULT: | 932 | case JFFS2_XPREFIX_ACL_DEFAULT: |
933 | ret = &jffs2_acl_default_xattr_handler; | 933 | ret = &jffs2_acl_default_xattr_handler; |
934 | break; | 934 | break; |
935 | #endif | 935 | #endif |
936 | case JFFS2_XPREFIX_TRUSTED: | 936 | case JFFS2_XPREFIX_TRUSTED: |
937 | ret = &jffs2_trusted_xattr_handler; | 937 | ret = &jffs2_trusted_xattr_handler; |
938 | break; | 938 | break; |
939 | default: | 939 | default: |
940 | ret = NULL; | 940 | ret = NULL; |
941 | break; | 941 | break; |
942 | } | 942 | } |
943 | return ret; | 943 | return ret; |
944 | } | 944 | } |
945 | 945 | ||
946 | ssize_t jffs2_listxattr(struct dentry *dentry, char *buffer, size_t size) | 946 | ssize_t jffs2_listxattr(struct dentry *dentry, char *buffer, size_t size) |
947 | { | 947 | { |
948 | struct inode *inode = dentry->d_inode; | 948 | struct inode *inode = dentry->d_inode; |
949 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); | 949 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); |
950 | struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); | 950 | struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); |
951 | struct jffs2_inode_cache *ic = f->inocache; | 951 | struct jffs2_inode_cache *ic = f->inocache; |
952 | struct jffs2_xattr_ref *ref, **pref; | 952 | struct jffs2_xattr_ref *ref, **pref; |
953 | struct jffs2_xattr_datum *xd; | 953 | struct jffs2_xattr_datum *xd; |
954 | struct xattr_handler *xhandle; | 954 | struct xattr_handler *xhandle; |
955 | ssize_t len, rc; | 955 | ssize_t len, rc; |
956 | int retry = 0; | 956 | int retry = 0; |
957 | 957 | ||
958 | rc = check_xattr_ref_inode(c, ic); | 958 | rc = check_xattr_ref_inode(c, ic); |
959 | if (unlikely(rc)) | 959 | if (unlikely(rc)) |
960 | return rc; | 960 | return rc; |
961 | 961 | ||
962 | down_read(&c->xattr_sem); | 962 | down_read(&c->xattr_sem); |
963 | retry: | 963 | retry: |
964 | len = 0; | 964 | len = 0; |
965 | for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) { | 965 | for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) { |
966 | BUG_ON(ref->ic != ic); | 966 | BUG_ON(ref->ic != ic); |
967 | xd = ref->xd; | 967 | xd = ref->xd; |
968 | if (!xd->xname) { | 968 | if (!xd->xname) { |
969 | /* xdatum is unchached */ | 969 | /* xdatum is unchached */ |
970 | if (!retry) { | 970 | if (!retry) { |
971 | retry = 1; | 971 | retry = 1; |
972 | up_read(&c->xattr_sem); | 972 | up_read(&c->xattr_sem); |
973 | down_write(&c->xattr_sem); | 973 | down_write(&c->xattr_sem); |
974 | goto retry; | 974 | goto retry; |
975 | } else { | 975 | } else { |
976 | rc = load_xattr_datum(c, xd); | 976 | rc = load_xattr_datum(c, xd); |
977 | if (unlikely(rc > 0)) { | 977 | if (unlikely(rc > 0)) { |
978 | *pref = ref->next; | 978 | *pref = ref->next; |
979 | delete_xattr_ref(c, ref); | 979 | delete_xattr_ref(c, ref); |
980 | goto retry; | 980 | goto retry; |
981 | } else if (unlikely(rc < 0)) | 981 | } else if (unlikely(rc < 0)) |
982 | goto out; | 982 | goto out; |
983 | } | 983 | } |
984 | } | 984 | } |
985 | xhandle = xprefix_to_handler(xd->xprefix); | 985 | xhandle = xprefix_to_handler(xd->xprefix); |
986 | if (!xhandle) | 986 | if (!xhandle) |
987 | continue; | 987 | continue; |
988 | if (buffer) { | 988 | if (buffer) { |
989 | rc = xhandle->list(inode, buffer+len, size-len, xd->xname, xd->name_len); | 989 | rc = xhandle->list(inode, buffer+len, size-len, xd->xname, xd->name_len); |
990 | } else { | 990 | } else { |
991 | rc = xhandle->list(inode, NULL, 0, xd->xname, xd->name_len); | 991 | rc = xhandle->list(inode, NULL, 0, xd->xname, xd->name_len); |
992 | } | 992 | } |
993 | if (rc < 0) | 993 | if (rc < 0) |
994 | goto out; | 994 | goto out; |
995 | len += rc; | 995 | len += rc; |
996 | } | 996 | } |
997 | rc = len; | 997 | rc = len; |
998 | out: | 998 | out: |
999 | if (!retry) { | 999 | if (!retry) { |
1000 | up_read(&c->xattr_sem); | 1000 | up_read(&c->xattr_sem); |
1001 | } else { | 1001 | } else { |
1002 | up_write(&c->xattr_sem); | 1002 | up_write(&c->xattr_sem); |
1003 | } | 1003 | } |
1004 | return rc; | 1004 | return rc; |
1005 | } | 1005 | } |
1006 | 1006 | ||
1007 | int do_jffs2_getxattr(struct inode *inode, int xprefix, const char *xname, | 1007 | int do_jffs2_getxattr(struct inode *inode, int xprefix, const char *xname, |
1008 | char *buffer, size_t size) | 1008 | char *buffer, size_t size) |
1009 | { | 1009 | { |
1010 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); | 1010 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); |
1011 | struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); | 1011 | struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); |
1012 | struct jffs2_inode_cache *ic = f->inocache; | 1012 | struct jffs2_inode_cache *ic = f->inocache; |
1013 | struct jffs2_xattr_datum *xd; | 1013 | struct jffs2_xattr_datum *xd; |
1014 | struct jffs2_xattr_ref *ref, **pref; | 1014 | struct jffs2_xattr_ref *ref, **pref; |
1015 | int rc, retry = 0; | 1015 | int rc, retry = 0; |
1016 | 1016 | ||
1017 | rc = check_xattr_ref_inode(c, ic); | 1017 | rc = check_xattr_ref_inode(c, ic); |
1018 | if (unlikely(rc)) | 1018 | if (unlikely(rc)) |
1019 | return rc; | 1019 | return rc; |
1020 | 1020 | ||
1021 | down_read(&c->xattr_sem); | 1021 | down_read(&c->xattr_sem); |
1022 | retry: | 1022 | retry: |
1023 | for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) { | 1023 | for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) { |
1024 | BUG_ON(ref->ic!=ic); | 1024 | BUG_ON(ref->ic!=ic); |
1025 | 1025 | ||
1026 | xd = ref->xd; | 1026 | xd = ref->xd; |
1027 | if (xd->xprefix != xprefix) | 1027 | if (xd->xprefix != xprefix) |
1028 | continue; | 1028 | continue; |
1029 | if (!xd->xname) { | 1029 | if (!xd->xname) { |
1030 | /* xdatum is unchached */ | 1030 | /* xdatum is unchached */ |
1031 | if (!retry) { | 1031 | if (!retry) { |
1032 | retry = 1; | 1032 | retry = 1; |
1033 | up_read(&c->xattr_sem); | 1033 | up_read(&c->xattr_sem); |
1034 | down_write(&c->xattr_sem); | 1034 | down_write(&c->xattr_sem); |
1035 | goto retry; | 1035 | goto retry; |
1036 | } else { | 1036 | } else { |
1037 | rc = load_xattr_datum(c, xd); | 1037 | rc = load_xattr_datum(c, xd); |
1038 | if (unlikely(rc > 0)) { | 1038 | if (unlikely(rc > 0)) { |
1039 | *pref = ref->next; | 1039 | *pref = ref->next; |
1040 | delete_xattr_ref(c, ref); | 1040 | delete_xattr_ref(c, ref); |
1041 | goto retry; | 1041 | goto retry; |
1042 | } else if (unlikely(rc < 0)) { | 1042 | } else if (unlikely(rc < 0)) { |
1043 | goto out; | 1043 | goto out; |
1044 | } | 1044 | } |
1045 | } | 1045 | } |
1046 | } | 1046 | } |
1047 | if (!strcmp(xname, xd->xname)) { | 1047 | if (!strcmp(xname, xd->xname)) { |
1048 | rc = xd->value_len; | 1048 | rc = xd->value_len; |
1049 | if (buffer) { | 1049 | if (buffer) { |
1050 | if (size < rc) { | 1050 | if (size < rc) { |
1051 | rc = -ERANGE; | 1051 | rc = -ERANGE; |
1052 | } else { | 1052 | } else { |
1053 | memcpy(buffer, xd->xvalue, rc); | 1053 | memcpy(buffer, xd->xvalue, rc); |
1054 | } | 1054 | } |
1055 | } | 1055 | } |
1056 | goto out; | 1056 | goto out; |
1057 | } | 1057 | } |
1058 | } | 1058 | } |
1059 | rc = -ENODATA; | 1059 | rc = -ENODATA; |
1060 | out: | 1060 | out: |
1061 | if (!retry) { | 1061 | if (!retry) { |
1062 | up_read(&c->xattr_sem); | 1062 | up_read(&c->xattr_sem); |
1063 | } else { | 1063 | } else { |
1064 | up_write(&c->xattr_sem); | 1064 | up_write(&c->xattr_sem); |
1065 | } | 1065 | } |
1066 | return rc; | 1066 | return rc; |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname, | 1069 | int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname, |
1070 | const char *buffer, size_t size, int flags) | 1070 | const char *buffer, size_t size, int flags) |
1071 | { | 1071 | { |
1072 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); | 1072 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); |
1073 | struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); | 1073 | struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); |
1074 | struct jffs2_inode_cache *ic = f->inocache; | 1074 | struct jffs2_inode_cache *ic = f->inocache; |
1075 | struct jffs2_xattr_datum *xd; | 1075 | struct jffs2_xattr_datum *xd; |
1076 | struct jffs2_xattr_ref *ref, *newref, **pref; | 1076 | struct jffs2_xattr_ref *ref, *newref, **pref; |
1077 | uint32_t length, request; | 1077 | uint32_t length, request; |
1078 | int rc; | 1078 | int rc; |
1079 | 1079 | ||
1080 | rc = check_xattr_ref_inode(c, ic); | 1080 | rc = check_xattr_ref_inode(c, ic); |
1081 | if (unlikely(rc)) | 1081 | if (unlikely(rc)) |
1082 | return rc; | 1082 | return rc; |
1083 | 1083 | ||
1084 | request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size); | 1084 | request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size); |
1085 | rc = jffs2_reserve_space(c, request, &length, | 1085 | rc = jffs2_reserve_space(c, request, &length, |
1086 | ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE); | 1086 | ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE); |
1087 | if (rc) { | 1087 | if (rc) { |
1088 | JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); | 1088 | JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); |
1089 | return rc; | 1089 | return rc; |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | /* Find existing xattr */ | 1092 | /* Find existing xattr */ |
1093 | down_write(&c->xattr_sem); | 1093 | down_write(&c->xattr_sem); |
1094 | retry: | 1094 | retry: |
1095 | for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) { | 1095 | for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) { |
1096 | xd = ref->xd; | 1096 | xd = ref->xd; |
1097 | if (xd->xprefix != xprefix) | 1097 | if (xd->xprefix != xprefix) |
1098 | continue; | 1098 | continue; |
1099 | if (!xd->xname) { | 1099 | if (!xd->xname) { |
1100 | rc = load_xattr_datum(c, xd); | 1100 | rc = load_xattr_datum(c, xd); |
1101 | if (unlikely(rc > 0)) { | 1101 | if (unlikely(rc > 0)) { |
1102 | *pref = ref->next; | 1102 | *pref = ref->next; |
1103 | delete_xattr_ref(c, ref); | 1103 | delete_xattr_ref(c, ref); |
1104 | goto retry; | 1104 | goto retry; |
1105 | } else if (unlikely(rc < 0)) | 1105 | } else if (unlikely(rc < 0)) |
1106 | goto out; | 1106 | goto out; |
1107 | } | 1107 | } |
1108 | if (!strcmp(xd->xname, xname)) { | 1108 | if (!strcmp(xd->xname, xname)) { |
1109 | if (flags & XATTR_CREATE) { | 1109 | if (flags & XATTR_CREATE) { |
1110 | rc = -EEXIST; | 1110 | rc = -EEXIST; |
1111 | goto out; | 1111 | goto out; |
1112 | } | 1112 | } |
1113 | if (!buffer) { | 1113 | if (!buffer) { |
1114 | ref->ino = ic->ino; | 1114 | ref->ino = ic->ino; |
1115 | ref->xid = xd->xid; | 1115 | ref->xid = xd->xid; |
1116 | ref->xseqno |= XREF_DELETE_MARKER; | 1116 | ref->xseqno |= XREF_DELETE_MARKER; |
1117 | rc = save_xattr_ref(c, ref); | 1117 | rc = save_xattr_ref(c, ref); |
1118 | if (!rc) { | 1118 | if (!rc) { |
1119 | *pref = ref->next; | 1119 | *pref = ref->next; |
1120 | spin_lock(&c->erase_completion_lock); | 1120 | spin_lock(&c->erase_completion_lock); |
1121 | ref->next = c->xref_dead_list; | 1121 | ref->next = c->xref_dead_list; |
1122 | c->xref_dead_list = ref; | 1122 | c->xref_dead_list = ref; |
1123 | spin_unlock(&c->erase_completion_lock); | 1123 | spin_unlock(&c->erase_completion_lock); |
1124 | unrefer_xattr_datum(c, xd); | 1124 | unrefer_xattr_datum(c, xd); |
1125 | } else { | 1125 | } else { |
1126 | ref->ic = ic; | 1126 | ref->ic = ic; |
1127 | ref->xd = xd; | 1127 | ref->xd = xd; |
1128 | ref->xseqno &= ~XREF_DELETE_MARKER; | 1128 | ref->xseqno &= ~XREF_DELETE_MARKER; |
1129 | } | 1129 | } |
1130 | goto out; | 1130 | goto out; |
1131 | } | 1131 | } |
1132 | goto found; | 1132 | goto found; |
1133 | } | 1133 | } |
1134 | } | 1134 | } |
1135 | /* not found */ | 1135 | /* not found */ |
1136 | if (flags & XATTR_REPLACE) { | 1136 | if (flags & XATTR_REPLACE) { |
1137 | rc = -ENODATA; | 1137 | rc = -ENODATA; |
1138 | goto out; | 1138 | goto out; |
1139 | } | 1139 | } |
1140 | if (!buffer) { | 1140 | if (!buffer) { |
1141 | rc = -ENODATA; | 1141 | rc = -ENODATA; |
1142 | goto out; | 1142 | goto out; |
1143 | } | 1143 | } |
1144 | found: | 1144 | found: |
1145 | xd = create_xattr_datum(c, xprefix, xname, buffer, size); | 1145 | xd = create_xattr_datum(c, xprefix, xname, buffer, size); |
1146 | if (IS_ERR(xd)) { | 1146 | if (IS_ERR(xd)) { |
1147 | rc = PTR_ERR(xd); | 1147 | rc = PTR_ERR(xd); |
1148 | goto out; | 1148 | goto out; |
1149 | } | 1149 | } |
1150 | up_write(&c->xattr_sem); | 1150 | up_write(&c->xattr_sem); |
1151 | jffs2_complete_reservation(c); | 1151 | jffs2_complete_reservation(c); |
1152 | 1152 | ||
1153 | /* create xattr_ref */ | 1153 | /* create xattr_ref */ |
1154 | request = PAD(sizeof(struct jffs2_raw_xref)); | 1154 | request = PAD(sizeof(struct jffs2_raw_xref)); |
1155 | rc = jffs2_reserve_space(c, request, &length, | 1155 | rc = jffs2_reserve_space(c, request, &length, |
1156 | ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE); | 1156 | ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE); |
1157 | down_write(&c->xattr_sem); | 1157 | down_write(&c->xattr_sem); |
1158 | if (rc) { | 1158 | if (rc) { |
1159 | JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); | 1159 | JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); |
1160 | unrefer_xattr_datum(c, xd); | 1160 | unrefer_xattr_datum(c, xd); |
1161 | up_write(&c->xattr_sem); | 1161 | up_write(&c->xattr_sem); |
1162 | return rc; | 1162 | return rc; |
1163 | } | 1163 | } |
1164 | if (ref) | 1164 | if (ref) |
1165 | *pref = ref->next; | 1165 | *pref = ref->next; |
1166 | newref = create_xattr_ref(c, ic, xd); | 1166 | newref = create_xattr_ref(c, ic, xd); |
1167 | if (IS_ERR(newref)) { | 1167 | if (IS_ERR(newref)) { |
1168 | if (ref) { | 1168 | if (ref) { |
1169 | ref->next = ic->xref; | 1169 | ref->next = ic->xref; |
1170 | ic->xref = ref; | 1170 | ic->xref = ref; |
1171 | } | 1171 | } |
1172 | rc = PTR_ERR(newref); | 1172 | rc = PTR_ERR(newref); |
1173 | unrefer_xattr_datum(c, xd); | 1173 | unrefer_xattr_datum(c, xd); |
1174 | } else if (ref) { | 1174 | } else if (ref) { |
1175 | delete_xattr_ref(c, ref); | 1175 | delete_xattr_ref(c, ref); |
1176 | } | 1176 | } |
1177 | out: | 1177 | out: |
1178 | up_write(&c->xattr_sem); | 1178 | up_write(&c->xattr_sem); |
1179 | jffs2_complete_reservation(c); | 1179 | jffs2_complete_reservation(c); |
1180 | return rc; | 1180 | return rc; |
1181 | } | 1181 | } |
1182 | 1182 | ||
1183 | /* -------- garbage collector functions ------------- | 1183 | /* -------- garbage collector functions ------------- |
1184 | * jffs2_garbage_collect_xattr_datum(c, xd, raw) | 1184 | * jffs2_garbage_collect_xattr_datum(c, xd, raw) |
1185 | * is used to move xdatum into new node. | 1185 | * is used to move xdatum into new node. |
1186 | * jffs2_garbage_collect_xattr_ref(c, ref, raw) | 1186 | * jffs2_garbage_collect_xattr_ref(c, ref, raw) |
1187 | * is used to move xref into new node. | 1187 | * is used to move xref into new node. |
1188 | * jffs2_verify_xattr(c) | 1188 | * jffs2_verify_xattr(c) |
1189 | * is used to call do_verify_xattr_datum() before garbage collecting. | 1189 | * is used to call do_verify_xattr_datum() before garbage collecting. |
1190 | * jffs2_release_xattr_datum(c, xd) | 1190 | * jffs2_release_xattr_datum(c, xd) |
1191 | * is used to release an in-memory object of xdatum. | 1191 | * is used to release an in-memory object of xdatum. |
1192 | * jffs2_release_xattr_ref(c, ref) | 1192 | * jffs2_release_xattr_ref(c, ref) |
1193 | * is used to release an in-memory object of xref. | 1193 | * is used to release an in-memory object of xref. |
1194 | * -------------------------------------------------- */ | 1194 | * -------------------------------------------------- */ |
1195 | int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd, | 1195 | int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd, |
1196 | struct jffs2_raw_node_ref *raw) | 1196 | struct jffs2_raw_node_ref *raw) |
1197 | { | 1197 | { |
1198 | uint32_t totlen, length, old_ofs; | 1198 | uint32_t totlen, length, old_ofs; |
1199 | int rc = 0; | 1199 | int rc = 0; |
1200 | 1200 | ||
1201 | down_write(&c->xattr_sem); | 1201 | down_write(&c->xattr_sem); |
1202 | if (xd->node != raw) | 1202 | if (xd->node != raw) |
1203 | goto out; | 1203 | goto out; |
1204 | if (xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID)) | 1204 | if (xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID)) |
1205 | goto out; | 1205 | goto out; |
1206 | 1206 | ||
1207 | rc = load_xattr_datum(c, xd); | 1207 | rc = load_xattr_datum(c, xd); |
1208 | if (unlikely(rc)) { | 1208 | if (unlikely(rc)) { |
1209 | rc = (rc > 0) ? 0 : rc; | 1209 | rc = (rc > 0) ? 0 : rc; |
1210 | goto out; | 1210 | goto out; |
1211 | } | 1211 | } |
1212 | old_ofs = ref_offset(xd->node); | 1212 | old_ofs = ref_offset(xd->node); |
1213 | totlen = PAD(sizeof(struct jffs2_raw_xattr) | 1213 | totlen = PAD(sizeof(struct jffs2_raw_xattr) |
1214 | + xd->name_len + 1 + xd->value_len); | 1214 | + xd->name_len + 1 + xd->value_len); |
1215 | rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XATTR_SIZE); | 1215 | rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XATTR_SIZE); |
1216 | if (rc) { | 1216 | if (rc) { |
1217 | JFFS2_WARNING("jffs2_reserve_space_gc()=%d, request=%u\n", rc, totlen); | 1217 | JFFS2_WARNING("jffs2_reserve_space_gc()=%d, request=%u\n", rc, totlen); |
1218 | rc = rc ? rc : -EBADFD; | ||
1219 | goto out; | 1218 | goto out; |
1220 | } | 1219 | } |
1221 | rc = save_xattr_datum(c, xd); | 1220 | rc = save_xattr_datum(c, xd); |
1222 | if (!rc) | 1221 | if (!rc) |
1223 | dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n", | 1222 | dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n", |
1224 | xd->xid, xd->version, old_ofs, ref_offset(xd->node)); | 1223 | xd->xid, xd->version, old_ofs, ref_offset(xd->node)); |
1225 | out: | 1224 | out: |
1226 | if (!rc) | 1225 | if (!rc) |
1227 | jffs2_mark_node_obsolete(c, raw); | 1226 | jffs2_mark_node_obsolete(c, raw); |
1228 | up_write(&c->xattr_sem); | 1227 | up_write(&c->xattr_sem); |
1229 | return rc; | 1228 | return rc; |
1230 | } | 1229 | } |
1231 | 1230 | ||
1232 | int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref, | 1231 | int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref, |
1233 | struct jffs2_raw_node_ref *raw) | 1232 | struct jffs2_raw_node_ref *raw) |
1234 | { | 1233 | { |
1235 | uint32_t totlen, length, old_ofs; | 1234 | uint32_t totlen, length, old_ofs; |
1236 | int rc = 0; | 1235 | int rc = 0; |
1237 | 1236 | ||
1238 | down_write(&c->xattr_sem); | 1237 | down_write(&c->xattr_sem); |
1239 | BUG_ON(!ref->node); | 1238 | BUG_ON(!ref->node); |
1240 | 1239 | ||
1241 | if (ref->node != raw) | 1240 | if (ref->node != raw) |
1242 | goto out; | 1241 | goto out; |
1243 | if (is_xattr_ref_dead(ref) && (raw->next_in_ino == (void *)ref)) | 1242 | if (is_xattr_ref_dead(ref) && (raw->next_in_ino == (void *)ref)) |
1244 | goto out; | 1243 | goto out; |
1245 | 1244 | ||
1246 | old_ofs = ref_offset(ref->node); | 1245 | old_ofs = ref_offset(ref->node); |
1247 | totlen = ref_totlen(c, c->gcblock, ref->node); | 1246 | totlen = ref_totlen(c, c->gcblock, ref->node); |
1248 | 1247 | ||
1249 | rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE); | 1248 | rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE); |
1250 | if (rc) { | 1249 | if (rc) { |
1251 | JFFS2_WARNING("%s: jffs2_reserve_space_gc() = %d, request = %u\n", | 1250 | JFFS2_WARNING("%s: jffs2_reserve_space_gc() = %d, request = %u\n", |
1252 | __FUNCTION__, rc, totlen); | 1251 | __FUNCTION__, rc, totlen); |
1253 | rc = rc ? rc : -EBADFD; | 1252 | rc = rc ? rc : -EBADFD; |
1254 | goto out; | 1253 | goto out; |
1255 | } | 1254 | } |
1256 | rc = save_xattr_ref(c, ref); | 1255 | rc = save_xattr_ref(c, ref); |
1257 | if (!rc) | 1256 | if (!rc) |
1258 | dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n", | 1257 | dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n", |
1259 | ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node)); | 1258 | ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node)); |
1260 | out: | 1259 | out: |
1261 | if (!rc) | 1260 | if (!rc) |
1262 | jffs2_mark_node_obsolete(c, raw); | 1261 | jffs2_mark_node_obsolete(c, raw); |
1263 | up_write(&c->xattr_sem); | 1262 | up_write(&c->xattr_sem); |
1264 | return rc; | 1263 | return rc; |
1265 | } | 1264 | } |
1266 | 1265 | ||
1267 | int jffs2_verify_xattr(struct jffs2_sb_info *c) | 1266 | int jffs2_verify_xattr(struct jffs2_sb_info *c) |
1268 | { | 1267 | { |
1269 | struct jffs2_xattr_datum *xd, *_xd; | 1268 | struct jffs2_xattr_datum *xd, *_xd; |
1270 | struct jffs2_eraseblock *jeb; | 1269 | struct jffs2_eraseblock *jeb; |
1271 | struct jffs2_raw_node_ref *raw; | 1270 | struct jffs2_raw_node_ref *raw; |
1272 | uint32_t totlen; | 1271 | uint32_t totlen; |
1273 | int rc; | 1272 | int rc; |
1274 | 1273 | ||
1275 | down_write(&c->xattr_sem); | 1274 | down_write(&c->xattr_sem); |
1276 | list_for_each_entry_safe(xd, _xd, &c->xattr_unchecked, xindex) { | 1275 | list_for_each_entry_safe(xd, _xd, &c->xattr_unchecked, xindex) { |
1277 | rc = do_verify_xattr_datum(c, xd); | 1276 | rc = do_verify_xattr_datum(c, xd); |
1278 | if (rc < 0) | 1277 | if (rc < 0) |
1279 | continue; | 1278 | continue; |
1280 | list_del_init(&xd->xindex); | 1279 | list_del_init(&xd->xindex); |
1281 | spin_lock(&c->erase_completion_lock); | 1280 | spin_lock(&c->erase_completion_lock); |
1282 | for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) { | 1281 | for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) { |
1283 | if (ref_flags(raw) != REF_UNCHECKED) | 1282 | if (ref_flags(raw) != REF_UNCHECKED) |
1284 | continue; | 1283 | continue; |
1285 | jeb = &c->blocks[ref_offset(raw) / c->sector_size]; | 1284 | jeb = &c->blocks[ref_offset(raw) / c->sector_size]; |
1286 | totlen = PAD(ref_totlen(c, jeb, raw)); | 1285 | totlen = PAD(ref_totlen(c, jeb, raw)); |
1287 | c->unchecked_size -= totlen; c->used_size += totlen; | 1286 | c->unchecked_size -= totlen; c->used_size += totlen; |
1288 | jeb->unchecked_size -= totlen; jeb->used_size += totlen; | 1287 | jeb->unchecked_size -= totlen; jeb->used_size += totlen; |
1289 | raw->flash_offset = ref_offset(raw) | 1288 | raw->flash_offset = ref_offset(raw) |
1290 | | ((xd->node == (void *)raw) ? REF_PRISTINE : REF_NORMAL); | 1289 | | ((xd->node == (void *)raw) ? REF_PRISTINE : REF_NORMAL); |
1291 | } | 1290 | } |
1292 | if (xd->flags & JFFS2_XFLAGS_DEAD) | 1291 | if (xd->flags & JFFS2_XFLAGS_DEAD) |
1293 | list_add(&xd->xindex, &c->xattr_dead_list); | 1292 | list_add(&xd->xindex, &c->xattr_dead_list); |
1294 | spin_unlock(&c->erase_completion_lock); | 1293 | spin_unlock(&c->erase_completion_lock); |
1295 | } | 1294 | } |
1296 | up_write(&c->xattr_sem); | 1295 | up_write(&c->xattr_sem); |
1297 | return list_empty(&c->xattr_unchecked) ? 1 : 0; | 1296 | return list_empty(&c->xattr_unchecked) ? 1 : 0; |
1298 | } | 1297 | } |
1299 | 1298 | ||
1300 | void jffs2_release_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) | 1299 | void jffs2_release_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) |
1301 | { | 1300 | { |
1302 | /* must be called under spin_lock(&c->erase_completion_lock) */ | 1301 | /* must be called under spin_lock(&c->erase_completion_lock) */ |
1303 | if (atomic_read(&xd->refcnt) || xd->node != (void *)xd) | 1302 | if (atomic_read(&xd->refcnt) || xd->node != (void *)xd) |
1304 | return; | 1303 | return; |
1305 | 1304 | ||
1306 | list_del(&xd->xindex); | 1305 | list_del(&xd->xindex); |
1307 | jffs2_free_xattr_datum(xd); | 1306 | jffs2_free_xattr_datum(xd); |
1308 | } | 1307 | } |
1309 | 1308 | ||
1310 | void jffs2_release_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) | 1309 | void jffs2_release_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) |
1311 | { | 1310 | { |
1312 | /* must be called under spin_lock(&c->erase_completion_lock) */ | 1311 | /* must be called under spin_lock(&c->erase_completion_lock) */ |
1313 | struct jffs2_xattr_ref *tmp, **ptmp; | 1312 | struct jffs2_xattr_ref *tmp, **ptmp; |
1314 | 1313 | ||
1315 | if (ref->node != (void *)ref) | 1314 | if (ref->node != (void *)ref) |
1316 | return; | 1315 | return; |
1317 | 1316 | ||
1318 | for (tmp=c->xref_dead_list, ptmp=&c->xref_dead_list; tmp; ptmp=&tmp->next, tmp=tmp->next) { | 1317 | for (tmp=c->xref_dead_list, ptmp=&c->xref_dead_list; tmp; ptmp=&tmp->next, tmp=tmp->next) { |
1319 | if (ref == tmp) { | 1318 | if (ref == tmp) { |
1320 | *ptmp = tmp->next; | 1319 | *ptmp = tmp->next; |
1321 | break; | 1320 | break; |
1322 | } | 1321 | } |
1323 | } | 1322 | } |
1324 | jffs2_free_xattr_ref(ref); | 1323 | jffs2_free_xattr_ref(ref); |
1325 | } | 1324 | } |
1326 | 1325 |