Commit 2c887e23 authored by KaiGai Kohei's avatar KaiGai Kohei Committed by David Woodhouse

[JFFS2][XATTR] Re-define xd->refcnt as atomic_t

In jffs2_release_xattr_datum(), it refers xd->refcnt to ensure
whether releasing xd is allowed or not.
But we can't hold xattr_sem since this function is called under
spin_lock(&c->erase_completion_lock). Thus we have to refer it
without any locking.

This patch redefine xd->refcnt as atomic_t. It enables to refer
xd->refcnt without any locking.
Signed-off-by: default avatarKaiGai Kohei <kaigai@ak.jp.nec.com>
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent 355ed4e1
...@@ -345,7 +345,7 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c, ...@@ -345,7 +345,7 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
&& xd->value_len==xsize && xd->value_len==xsize
&& !strcmp(xd->xname, xname) && !strcmp(xd->xname, xname)
&& !memcmp(xd->xvalue, xvalue, xsize)) { && !memcmp(xd->xvalue, xvalue, xsize)) {
xd->refcnt++; atomic_inc(&xd->refcnt);
return xd; return xd;
} }
} }
...@@ -365,7 +365,7 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c, ...@@ -365,7 +365,7 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
strcpy(data, xname); strcpy(data, xname);
memcpy(data + name_len + 1, xvalue, xsize); memcpy(data + name_len + 1, xvalue, xsize);
xd->refcnt = 1; atomic_set(&xd->refcnt, 1);
xd->xid = ++c->highest_xid; xd->xid = ++c->highest_xid;
xd->flags |= JFFS2_XFLAGS_HOT; xd->flags |= JFFS2_XFLAGS_HOT;
xd->xprefix = xprefix; xd->xprefix = xprefix;
...@@ -397,7 +397,7 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c, ...@@ -397,7 +397,7 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
static void delete_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) static void delete_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
{ {
/* must be called under down_write(xattr_sem) */ /* must be called under down_write(xattr_sem) */
BUG_ON(xd->refcnt); BUG_ON(atomic_read(&xd->refcnt));
unload_xattr_datum(c, xd); unload_xattr_datum(c, xd);
xd->flags |= JFFS2_XFLAGS_DEAD; xd->flags |= JFFS2_XFLAGS_DEAD;
...@@ -580,7 +580,7 @@ static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *re ...@@ -580,7 +580,7 @@ static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *re
dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) was removed.\n", dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) was removed.\n",
ref->ino, ref->xid, ref->xseqno); ref->ino, ref->xid, ref->xseqno);
if (!--xd->refcnt) if (atomic_dec_and_test(&xd->refcnt))
delete_xattr_datum(c, xd); delete_xattr_datum(c, xd);
} }
...@@ -612,8 +612,7 @@ void jffs2_xattr_free_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *i ...@@ -612,8 +612,7 @@ void jffs2_xattr_free_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *i
for (ref = ic->xref; ref; ref = _ref) { for (ref = ic->xref; ref; ref = _ref) {
_ref = ref->next; _ref = ref->next;
xd = ref->xd; xd = ref->xd;
xd->refcnt--; if (atomic_dec_and_test(&xd->refcnt)) {
if (!xd->refcnt) {
unload_xattr_datum(c, xd); unload_xattr_datum(c, xd);
jffs2_free_xattr_datum(xd); jffs2_free_xattr_datum(xd);
} }
...@@ -835,7 +834,7 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) ...@@ -835,7 +834,7 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
} }
ref->xd = xd; ref->xd = xd;
ref->ic = ic; ref->ic = ic;
xd->refcnt++; atomic_inc(&xd->refcnt);
ref->next = ic->xref; ref->next = ic->xref;
ic->xref = ref; ic->xref = ref;
} }
...@@ -846,7 +845,7 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) ...@@ -846,7 +845,7 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) { list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) {
xdatum_count++; xdatum_count++;
list_del_init(&xd->xindex); list_del_init(&xd->xindex);
if (!xd->refcnt) { if (!atomic_read(&xd->refcnt)) {
dbg_xattr("xdatum(xid=%u, version=%u) is orphan.\n", dbg_xattr("xdatum(xid=%u, version=%u) is orphan.\n",
xd->xid, xd->version); xd->xid, xd->version);
xd->flags |= JFFS2_XFLAGS_DEAD; xd->flags |= JFFS2_XFLAGS_DEAD;
...@@ -1120,7 +1119,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname, ...@@ -1120,7 +1119,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
ref->next = c->xref_dead_list; ref->next = c->xref_dead_list;
c->xref_dead_list = ref; c->xref_dead_list = ref;
spin_unlock(&c->erase_completion_lock); spin_unlock(&c->erase_completion_lock);
if (!--xd->refcnt) if (atomic_dec_and_test(&xd->refcnt))
delete_xattr_datum(c, xd); delete_xattr_datum(c, xd);
} else { } else {
ref->ic = ic; ref->ic = ic;
...@@ -1157,8 +1156,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname, ...@@ -1157,8 +1156,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
down_write(&c->xattr_sem); down_write(&c->xattr_sem);
if (rc) { if (rc) {
JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
xd->refcnt--; if (atomic_dec_and_test(&xd->refcnt))
if (!xd->refcnt)
delete_xattr_datum(c, xd); delete_xattr_datum(c, xd);
up_write(&c->xattr_sem); up_write(&c->xattr_sem);
return rc; return rc;
...@@ -1172,8 +1170,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname, ...@@ -1172,8 +1170,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
ic->xref = ref; ic->xref = ref;
} }
rc = PTR_ERR(newref); rc = PTR_ERR(newref);
xd->refcnt--; if (atomic_dec_and_test(&xd->refcnt))
if (!xd->refcnt)
delete_xattr_datum(c, xd); delete_xattr_datum(c, xd);
} else if (ref) { } else if (ref) {
delete_xattr_ref(c, ref); delete_xattr_ref(c, ref);
...@@ -1304,7 +1301,7 @@ int jffs2_verify_xattr(struct jffs2_sb_info *c) ...@@ -1304,7 +1301,7 @@ int jffs2_verify_xattr(struct jffs2_sb_info *c)
void jffs2_release_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) void jffs2_release_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
{ {
/* must be called under spin_lock(&c->erase_completion_lock) */ /* must be called under spin_lock(&c->erase_completion_lock) */
if (xd->refcnt > 0 || xd->node != (void *)xd) if (atomic_read(&xd->refcnt) || xd->node != (void *)xd)
return; return;
list_del(&xd->xindex); list_del(&xd->xindex);
......
...@@ -28,7 +28,7 @@ struct jffs2_xattr_datum ...@@ -28,7 +28,7 @@ struct jffs2_xattr_datum
uint16_t xprefix; /* see JFFS2_XATTR_PREFIX_* */ uint16_t xprefix; /* see JFFS2_XATTR_PREFIX_* */
struct list_head xindex; /* chained from c->xattrindex[n] */ struct list_head xindex; /* chained from c->xattrindex[n] */
uint32_t refcnt; /* # of xattr_ref refers this */ atomic_t refcnt; /* # of xattr_ref refers this */
uint32_t xid; uint32_t xid;
uint32_t version; uint32_t version;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment