-/* -------------------------------------------------------------------------
- * File: fs/jffs2/xattr.c
- * XATTR support on JFFS2 FileSystem
+/*
+ * JFFS2 -- Journalling Flash File System, Version 2.
*
- * Implemented by KaiGai Kohei <kaigai@ak.jp.nec.com>
- * Copyright (C) 2006 NEC Corporation
+ * Copyright (C) 2006 NEC Corporation
*
- * For licensing information, see the file 'LICENCE' in the jffs2 directory.
- * ------------------------------------------------------------------------- */
-
+ * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
+ *
+ * For licensing information, see the file 'LICENCE' in this directory.
+ *
+ */
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/fs.h>
* is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum().
* If xd need to call do_verify_xattr_datum() at first, it's called before calling
* do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum().
- * save_xattr_datum(c, xd, phys_ofs)
+ * save_xattr_datum(c, xd)
* is used to write xdatum to medium. xd->version will be incremented.
- * create_xattr_datum(c, xprefix, xname, xvalue, xsize, phys_ofs)
+ * create_xattr_datum(c, xprefix, xname, xvalue, xsize)
* is used to create new xdatum and write to medium.
* -------------------------------------------------- */
{
/* must be called under down_write(xattr_sem) */
struct jffs2_raw_xattr rx;
- uint32_t length;
+ size_t length;
int rc;
if (!xd->node) {
sizeof(struct jffs2_unknown_node),
&length, (char *)&rx);
if (rc || length != sizeof(struct jffs2_unknown_node)) {
- JFFS2_ERROR("jffs2_flash_read()=%d, req=%u, read=%u at %#08x\n",
+ JFFS2_ERROR("jffs2_flash_read()=%d, req=%zu, read=%zu at %#08x\n",
rc, sizeof(struct jffs2_unknown_node),
length, ref_offset(xd->node));
}
rc = jffs2_flash_write(c, ref_offset(xd->node), sizeof(rx),
&length, (char *)&rx);
if (rc || length != sizeof(struct jffs2_raw_xattr)) {
- JFFS2_ERROR("jffs2_flash_write()=%d, req=%u, wrote=%u ar %#08x\n",
+ JFFS2_ERROR("jffs2_flash_write()=%d, req=%zu, wrote=%zu ar %#08x\n",
rc, sizeof(rx), length, ref_offset(xd->node));
}
}
rc = jffs2_flash_read(c, ref_offset(xd->node), sizeof(rx), &readlen, (char *)&rx);
if (rc || readlen != sizeof(rx)) {
- JFFS2_WARNING("jffs2_flash_read()=%d, req=%u, read=%u at %#08x\n",
+ JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu at %#08x\n",
rc, sizeof(rx), readlen, ref_offset(xd->node));
return rc ? rc : -EIO;
}
length, &readlen, data);
if (ret || length!=readlen) {
- JFFS2_WARNING("jffs2_flash_read() returned %d, request=%d, readlen=%d, at %#08x\n",
+ JFFS2_WARNING("jffs2_flash_read() returned %d, request=%d, readlen=%zu, at %#08x\n",
ret, length, readlen, ref_offset(xd->node));
kfree(data);
return ret ? ret : -EIO;
return rc;
}
-static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd, uint32_t phys_ofs)
+static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
{
/* must be called under down_write(xattr_sem) */
- struct jffs2_raw_xattr rx;
struct jffs2_raw_node_ref *raw;
+ struct jffs2_raw_xattr rx;
struct kvec vecs[2];
- uint32_t length;
+ size_t length;
int rc, totlen;
+ uint32_t phys_ofs = write_ofs(c);
BUG_ON(!xd->xname);
vecs[1].iov_len = xd->name_len + 1 + xd->value_len;
totlen = vecs[0].iov_len + vecs[1].iov_len;
- raw = jffs2_alloc_raw_node_ref();
- if (!raw)
- return -ENOMEM;
- raw->flash_offset = phys_ofs;
- raw->__totlen = PAD(totlen);
- raw->next_phys = NULL;
- raw->next_in_ino = (void *)xd;
-
/* Setup raw-xattr */
rx.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
rx.nodetype = cpu_to_je16(JFFS2_NODETYPE_XATTR);
rc = jffs2_flash_writev(c, vecs, 2, phys_ofs, &length, 0);
if (rc || totlen != length) {
- JFFS2_WARNING("jffs2_flash_writev()=%d, req=%u, wrote=%u, at %#08x\n",
+ JFFS2_WARNING("jffs2_flash_writev()=%d, req=%u, wrote=%zu, at %#08x\n",
rc, totlen, length, phys_ofs);
rc = rc ? rc : -EIO;
- if (length) {
- raw->flash_offset |= REF_OBSOLETE;
- raw->next_in_ino = NULL;
- jffs2_add_physical_node_ref(c, raw);
- jffs2_mark_node_obsolete(c, raw);
- } else {
- jffs2_free_raw_node_ref(raw);
- }
+ if (length)
+ jffs2_add_physical_node_ref(c, phys_ofs | REF_OBSOLETE, PAD(totlen), NULL);
+
return rc;
}
- BUG_ON(raw->__totlen < sizeof(struct jffs2_raw_xattr));
+
/* success */
- raw->flash_offset |= REF_PRISTINE;
- jffs2_add_physical_node_ref(c, raw);
+ raw = jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(totlen), NULL);
+ /* FIXME */ raw->next_in_ino = (void *)xd;
+
if (xd->node)
delete_xattr_datum_node(c, xd);
xd->node = raw;
static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
int xprefix, const char *xname,
- const char *xvalue, int xsize,
- uint32_t phys_ofs)
+ const char *xvalue, int xsize)
{
/* must be called under down_write(xattr_sem) */
struct jffs2_xattr_datum *xd;
xd->value_len = xsize;
xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len);
- rc = save_xattr_datum(c, xd, phys_ofs);
+ rc = save_xattr_datum(c, xd);
if (rc) {
kfree(xd->xname);
jffs2_free_xattr_datum(xd);
return xd;
}
-/* -------- xdatum related functions ----------------
+/* -------- xref related functions ------------------
* verify_xattr_ref(c, ref)
* is used to load xref information from medium. Because summary data does not
* contain xid/ino, it's necessary to verify once while mounting process.
* delete_xattr_ref(c, ref)
* is used to delete jffs2_xattr_ref object. If the reference counter of xdatum
* is refered by this xref become 0, delete_xattr_datum() is called later.
- * save_xattr_ref(c, ref, phys_ofs)
+ * save_xattr_ref(c, ref)
* is used to write xref to medium.
- * create_xattr_ref(c, ic, xd, phys_ofs)
+ * create_xattr_ref(c, ic, xd)
* is used to create a new xref and write to medium.
* jffs2_xattr_delete_inode(c, ic)
* is called to remove xrefs related to obsolete inode when inode is unlinked.
* jffs2_xattr_free_inode(c, ic)
* is called to release xattr related objects when unmounting.
- * check_xattr_ref_ilist(c, ic)
+ * check_xattr_ref_inode(c, ic)
* is used to confirm inode does not have duplicate xattr name/value pair.
* -------------------------------------------------- */
static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
rc = jffs2_flash_read(c, ref_offset(ref->node), sizeof(rr), &readlen, (char *)&rr);
if (rc || sizeof(rr) != readlen) {
- JFFS2_WARNING("jffs2_flash_read()=%d, req=%u, read=%u, at %#08x\n",
+ JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu, at %#08x\n",
rc, sizeof(rr), readlen, ref_offset(ref->node));
return rc ? rc : -EIO;
}
|| je16_to_cpu(rr.nodetype) != JFFS2_NODETYPE_XREF
|| je32_to_cpu(rr.totlen) != PAD(sizeof(rr))) {
JFFS2_ERROR("inconsistent xref at %#08x, magic=%#04x/%#04x, "
- "nodetype=%#04x/%#04x, totlen=%u/%u\n",
+ "nodetype=%#04x/%#04x, totlen=%u/%zu\n",
ref_offset(ref->node), je16_to_cpu(rr.magic), JFFS2_MAGIC_BITMASK,
je16_to_cpu(rr.nodetype), JFFS2_NODETYPE_XREF,
je32_to_cpu(rr.totlen), PAD(sizeof(rr)));
static void delete_xattr_ref_node(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
{
struct jffs2_raw_xref rr;
- uint32_t length;
+ size_t length;
int rc;
if (jffs2_sum_active()) {
sizeof(struct jffs2_unknown_node),
&length, (char *)&rr);
if (rc || length != sizeof(struct jffs2_unknown_node)) {
- JFFS2_ERROR("jffs2_flash_read()=%d, req=%u, read=%u at %#08x\n",
+ JFFS2_ERROR("jffs2_flash_read()=%d, req=%zu, read=%zu at %#08x\n",
rc, sizeof(struct jffs2_unknown_node),
length, ref_offset(ref->node));
}
rc = jffs2_flash_write(c, ref_offset(ref->node), sizeof(rr),
&length, (char *)&rr);
if (rc || length != sizeof(struct jffs2_raw_xref)) {
- JFFS2_ERROR("jffs2_flash_write()=%d, req=%u, wrote=%u at %#08x\n",
+ JFFS2_ERROR("jffs2_flash_write()=%d, req=%zu, wrote=%zu at %#08x\n",
rc, sizeof(rr), length, ref_offset(ref->node));
}
}
BUG_ON(!ref->node);
delete_xattr_ref_node(c, ref);
- list_del(&ref->ilist);
xd = ref->xd;
xd->refcnt--;
if (!xd->refcnt)
jffs2_free_xattr_ref(ref);
}
-static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref, uint32_t phys_ofs)
+static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
{
/* must be called under down_write(xattr_sem) */
struct jffs2_raw_node_ref *raw;
struct jffs2_raw_xref rr;
- uint32_t length;
+ size_t length;
+ uint32_t phys_ofs = write_ofs(c);
int ret;
- raw = jffs2_alloc_raw_node_ref();
- if (!raw)
- return -ENOMEM;
- raw->flash_offset = phys_ofs;
- raw->__totlen = PAD(sizeof(rr));
- raw->next_phys = NULL;
- raw->next_in_ino = (void *)ref;
-
rr.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
rr.nodetype = cpu_to_je16(JFFS2_NODETYPE_XREF);
rr.totlen = cpu_to_je32(PAD(sizeof(rr)));
ret = jffs2_flash_write(c, phys_ofs, sizeof(rr), &length, (char *)&rr);
if (ret || sizeof(rr) != length) {
- JFFS2_WARNING("jffs2_flash_write() returned %d, request=%u, retlen=%u, at %#08x\n",
+ JFFS2_WARNING("jffs2_flash_write() returned %d, request=%zu, retlen=%zu, at %#08x\n",
ret, sizeof(rr), length, phys_ofs);
ret = ret ? ret : -EIO;
- if (length) {
- raw->flash_offset |= REF_OBSOLETE;
- raw->next_in_ino = NULL;
- jffs2_add_physical_node_ref(c, raw);
- jffs2_mark_node_obsolete(c, raw);
- } else {
- jffs2_free_raw_node_ref(raw);
- }
+ if (length)
+ jffs2_add_physical_node_ref(c, phys_ofs | REF_OBSOLETE, PAD(sizeof(rr)), NULL);
+
return ret;
}
- raw->flash_offset |= REF_PRISTINE;
- jffs2_add_physical_node_ref(c, raw);
+ raw = jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), NULL);
+ /* FIXME */ raw->next_in_ino = (void *)ref;
if (ref->node)
delete_xattr_ref_node(c, ref);
ref->node = raw;
}
static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic,
- struct jffs2_xattr_datum *xd, uint32_t phys_ofs)
+ struct jffs2_xattr_datum *xd)
{
/* must be called under down_write(xattr_sem) */
struct jffs2_xattr_ref *ref;
ref->ic = ic;
ref->xd = xd;
- ret = save_xattr_ref(c, ref, phys_ofs);
+ ret = save_xattr_ref(c, ref);
if (ret) {
jffs2_free_xattr_ref(ref);
return ERR_PTR(ret);
}
/* Chain to inode */
- list_add(&ref->ilist, &ic->ilist);
+ ref->next = ic->xref;
+ ic->xref = ref;
return ref; /* success */
}
return;
down_write(&c->xattr_sem);
- list_for_each_entry_safe(ref, _ref, &ic->ilist, ilist)
+ for (ref = ic->xref; ref; ref = _ref) {
+ _ref = ref->next;
delete_xattr_ref(c, ref);
+ }
+ ic->xref = NULL;
up_write(&c->xattr_sem);
}
struct jffs2_xattr_ref *ref, *_ref;
down_write(&c->xattr_sem);
- list_for_each_entry_safe(ref, _ref, &ic->ilist, ilist) {
- list_del(&ref->ilist);
+ for (ref = ic->xref; ref; ref = _ref) {
+ _ref = ref->next;
xd = ref->xd;
xd->refcnt--;
if (!xd->refcnt) {
}
jffs2_free_xattr_ref(ref);
}
+ ic->xref = NULL;
up_write(&c->xattr_sem);
}
-static int check_xattr_ref_ilist(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic)
+static int check_xattr_ref_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic)
{
- /* success of check_xattr_ref_ilist() means taht inode (ic) dose not have
+ /* success of check_xattr_ref_inode() means taht inode (ic) dose not have
* duplicate name/value pairs. If duplicate name/value pair would be found,
* one will be removed.
*/
- struct jffs2_xattr_ref *ref, *cmp;
+ struct jffs2_xattr_ref *ref, *cmp, **pref;
int rc = 0;
if (likely(ic->flags & INO_FLAGS_XATTR_CHECKED))
down_write(&c->xattr_sem);
retry:
rc = 0;
- list_for_each_entry(ref, &ic->ilist, ilist) {
+ for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) {
if (!ref->xd->xname) {
rc = load_xattr_datum(c, ref->xd);
if (unlikely(rc > 0)) {
+ *pref = ref->next;
delete_xattr_ref(c, ref);
goto retry;
} else if (unlikely(rc < 0))
goto out;
}
- cmp = ref;
- list_for_each_entry_continue(cmp, &ic->ilist, ilist) {
+ for (cmp=ref->next, pref=&ref->next; cmp; pref=&cmp->next, cmp=cmp->next) {
if (!cmp->xd->xname) {
ref->xd->flags |= JFFS2_XFLAGS_BIND;
rc = load_xattr_datum(c, cmp->xd);
ref->xd->flags &= ~JFFS2_XFLAGS_BIND;
if (unlikely(rc > 0)) {
+ *pref = cmp->next;
delete_xattr_ref(c, cmp);
goto retry;
} else if (unlikely(rc < 0))
}
if (ref->xd->xprefix == cmp->xd->xprefix
&& !strcmp(ref->xd->xname, cmp->xd->xname)) {
+ *pref = cmp->next;
delete_xattr_ref(c, cmp);
goto retry;
}
for (i=0; i < XATTRINDEX_HASHSIZE; i++)
INIT_LIST_HEAD(&c->xattrindex[i]);
- INIT_LIST_HEAD(&c->xattr_temp);
INIT_LIST_HEAD(&c->xattr_unchecked);
+ c->xref_temp = NULL;
init_rwsem(&c->xattr_sem);
c->xdatum_mem_usage = 0;
struct jffs2_xattr_ref *ref, *_ref;
int i;
- list_for_each_entry_safe(ref, _ref, &c->xattr_temp, ilist)
+ for (ref=c->xref_temp; ref; ref = _ref) {
+ _ref = ref->next;
jffs2_free_xattr_ref(ref);
+ }
+ c->xref_temp = NULL;
for (i=0; i < XATTRINDEX_HASHSIZE; i++) {
list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) {
BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
/* Phase.1 */
- list_for_each_entry_safe(ref, _ref, &c->xattr_temp, ilist) {
- list_del_init(&ref->ilist);
+ for (ref=c->xref_temp; ref; ref=_ref) {
+ _ref = ref->next;
/* checking REF_UNCHECKED nodes */
if (ref_flags(ref->node) != REF_PRISTINE) {
if (verify_xattr_ref(c, ref)) {
ref->xd = xd;
ref->ic = ic;
xd->refcnt++;
- list_add_tail(&ref->ilist, &ic->ilist);
+ ref->next = ic->xref;
+ ic->xref = ref;
xref_count++;
}
+ c->xref_temp = NULL;
/* After this, ref->xid/ino are NEVER used. */
/* Phase.2 */
struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
struct jffs2_inode_cache *ic = f->inocache;
- struct jffs2_xattr_ref *ref;
+ struct jffs2_xattr_ref *ref, **pref;
struct jffs2_xattr_datum *xd;
struct xattr_handler *xhandle;
ssize_t len, rc;
int retry = 0;
- rc = check_xattr_ref_ilist(c, ic);
+ rc = check_xattr_ref_inode(c, ic);
if (unlikely(rc))
return rc;
down_read(&c->xattr_sem);
retry:
len = 0;
- list_for_each_entry(ref, &ic->ilist, ilist) {
+ for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) {
BUG_ON(ref->ic != ic);
xd = ref->xd;
if (!xd->xname) {
} else {
rc = load_xattr_datum(c, xd);
if (unlikely(rc > 0)) {
+ *pref = ref->next;
delete_xattr_ref(c, ref);
goto retry;
} else if (unlikely(rc < 0))
struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
struct jffs2_inode_cache *ic = f->inocache;
struct jffs2_xattr_datum *xd;
- struct jffs2_xattr_ref *ref;
+ struct jffs2_xattr_ref *ref, **pref;
int rc, retry = 0;
- rc = check_xattr_ref_ilist(c, ic);
+ rc = check_xattr_ref_inode(c, ic);
if (unlikely(rc))
return rc;
down_read(&c->xattr_sem);
retry:
- list_for_each_entry(ref, &ic->ilist, ilist) {
+ for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) {
BUG_ON(ref->ic!=ic);
xd = ref->xd;
} else {
rc = load_xattr_datum(c, xd);
if (unlikely(rc > 0)) {
+ *pref = ref->next;
delete_xattr_ref(c, ref);
goto retry;
} else if (unlikely(rc < 0)) {
struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
struct jffs2_inode_cache *ic = f->inocache;
struct jffs2_xattr_datum *xd;
- struct jffs2_xattr_ref *ref, *newref;
- uint32_t phys_ofs, length, request;
+ struct jffs2_xattr_ref *ref, *newref, **pref;
+ uint32_t length, request;
int rc;
- rc = check_xattr_ref_ilist(c, ic);
+ rc = check_xattr_ref_inode(c, ic);
if (unlikely(rc))
return rc;
request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size);
- rc = jffs2_reserve_space(c, request, &phys_ofs, &length,
+ rc = jffs2_reserve_space(c, request, &length,
ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE);
if (rc) {
JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
/* Find existing xattr */
down_write(&c->xattr_sem);
retry:
- list_for_each_entry(ref, &ic->ilist, ilist) {
+ for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) {
xd = ref->xd;
if (xd->xprefix != xprefix)
continue;
if (!xd->xname) {
rc = load_xattr_datum(c, xd);
if (unlikely(rc > 0)) {
+ *pref = ref->next;
delete_xattr_ref(c, ref);
goto retry;
} else if (unlikely(rc < 0))
goto out;
}
if (!buffer) {
+ *pref = ref->next;
delete_xattr_ref(c, ref);
rc = 0;
goto out;
}
}
/* not found */
- ref = NULL;
if (flags & XATTR_REPLACE) {
rc = -ENODATA;
goto out;
goto out;
}
found:
- xd = create_xattr_datum(c, xprefix, xname, buffer, size, phys_ofs);
+ xd = create_xattr_datum(c, xprefix, xname, buffer, size);
if (IS_ERR(xd)) {
rc = PTR_ERR(xd);
goto out;
/* create xattr_ref */
request = PAD(sizeof(struct jffs2_raw_xref));
- rc = jffs2_reserve_space(c, request, &phys_ofs, &length,
+ rc = jffs2_reserve_space(c, request, &length,
ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE);
if (rc) {
JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
return rc;
}
down_write(&c->xattr_sem);
- newref = create_xattr_ref(c, ic, xd, phys_ofs);
+ if (ref)
+ *pref = ref->next;
+ newref = create_xattr_ref(c, ic, xd);
if (IS_ERR(newref)) {
+ if (ref) {
+ ref->next = ic->xref;
+ ic->xref = ref;
+ }
rc = PTR_ERR(newref);
xd->refcnt--;
if (!xd->refcnt)
delete_xattr_datum(c, xd);
} else if (ref) {
- /* If replaced xattr_ref exists */
delete_xattr_ref(c, ref);
}
out:
* is used to move xdatum into new node.
* jffs2_garbage_collect_xattr_ref(c, ref)
* is used to move xref into new node.
- * jffs2_garbage_collect_xattr(c, ic)
- * is used to call appropriate garbage collector function, if argument
- * pointer (ic) is the reference of xdatum/xref.
* jffs2_verify_xattr(c)
* is used to call do_verify_xattr_datum() before garbage collecting.
* -------------------------------------------------- */
-static int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c,
- struct jffs2_xattr_datum *xd)
+int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
{
- /* must be called under down_write(xattr_sem), and called from GC thread */
- uint32_t phys_ofs, totlen, length, old_ofs;
- int rc;
+ uint32_t totlen, length, old_ofs;
+ int rc = -EINVAL;
+ down_write(&c->xattr_sem);
BUG_ON(!xd->node);
old_ofs = ref_offset(xd->node);
totlen = ref_totlen(c, c->gcblock, xd->node);
if (totlen < sizeof(struct jffs2_raw_xattr))
- return -EINVAL;
+ goto out;
if (!xd->xname) {
rc = load_xattr_datum(c, xd);
if (unlikely(rc > 0)) {
delete_xattr_datum_node(c, xd);
- return 0;
+ rc = 0;
+ goto out;
} else if (unlikely(rc < 0))
- return -EINVAL;
+ goto out;
}
- rc = jffs2_reserve_space_gc(c, totlen, &phys_ofs, &length, JFFS2_SUMMARY_XATTR_SIZE);
+ rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XATTR_SIZE);
if (rc || length < totlen) {
JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, totlen);
- return rc ? rc : -EBADFD;
+ rc = rc ? rc : -EBADFD;
+ goto out;
}
- rc = save_xattr_datum(c, xd, phys_ofs);
+ rc = save_xattr_datum(c, xd);
if (!rc)
dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n",
xd->xid, xd->version, old_ofs, ref_offset(xd->node));
+ out:
+ up_write(&c->xattr_sem);
return rc;
}
-static int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c,
- struct jffs2_xattr_ref *ref)
+int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
{
- /* must be called under down(alloc_sem) */
- uint32_t phys_ofs, totlen, length, old_ofs;
- int rc;
+ uint32_t totlen, length, old_ofs;
+ int rc = -EINVAL;
+ down_write(&c->xattr_sem);
BUG_ON(!ref->node);
old_ofs = ref_offset(ref->node);
totlen = ref_totlen(c, c->gcblock, ref->node);
if (totlen != sizeof(struct jffs2_raw_xref))
- return -EINVAL;
- rc = jffs2_reserve_space_gc(c, totlen, &phys_ofs, &length, JFFS2_SUMMARY_XREF_SIZE);
+ goto out;
+
+ rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE);
if (rc || length < totlen) {
JFFS2_WARNING("%s: jffs2_reserve_space() = %d, request = %u\n",
__FUNCTION__, rc, totlen);
- return rc ? rc : -EBADFD;
+ rc = rc ? rc : -EBADFD;
+ goto out;
}
- rc = save_xattr_ref(c, ref, phys_ofs);
+ rc = save_xattr_ref(c, ref);
if (!rc)
dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));
+ out:
+ up_write(&c->xattr_sem);
return rc;
}
-int jffs2_garbage_collect_xattr(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic)
-{
- struct jffs2_xattr_datum *xd;
- struct jffs2_xattr_ref *ref;
- int ret;
-
- switch (ic->class) {
- case RAWNODE_CLASS_XATTR_DATUM:
- spin_unlock(&c->erase_completion_lock);
-
- down_write(&c->xattr_sem);
- xd = (struct jffs2_xattr_datum *)ic;
- ret = xd ? jffs2_garbage_collect_xattr_datum(c, xd) : 0;
- up_write(&c->xattr_sem);
- break;
- case RAWNODE_CLASS_XATTR_REF:
- spin_unlock(&c->erase_completion_lock);
-
- down_write(&c->xattr_sem);
- ref = (struct jffs2_xattr_ref *)ic;
- ret = ref ? jffs2_garbage_collect_xattr_ref(c, ref) : 0;
- up_write(&c->xattr_sem);
- break;
- default:
- /* This node is not xattr_datum/xattr_ref */
- ret = 1;
- break;
- }
- return ret;
-}
-
int jffs2_verify_xattr(struct jffs2_sb_info *c)
{
struct jffs2_xattr_datum *xd, *_xd;