Skip to content

Commit c9f700f

Browse files
KaiGai Koheidwmw2
authored andcommitted
[JFFS2][XATTR] using 'delete marker' for xdatum/xref deletion
- When xdatum is removed, a new xdatum with 'delete marker' is written. (version==0xffffffff means 'delete marker') - When xref is removed, a new xref with 'delete marker' is written. (odd-numbered xseqno means 'delete marker') - delete_xattr_(datum/xref)_delay() are new deletion functions are added. We can only use them if we can detect the target obsolete xdatum/xref as a orphan or errir one. (e.g when inode deletion, or detecting crc error) [1/3] jffs2-xattr-v6-01-delete_marker.patch Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
1 parent 6d4f822 commit c9f700f

10 files changed

Lines changed: 584 additions & 339 deletions

File tree

‎fs/jffs2/erase.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ static inline void jffs2_remove_node_refs_from_ino_list(struct jffs2_sb_info *c,
230230
at the end of the linked list. Stash it and continue
231231
from the beginning of the list */
232232
ic = (struct jffs2_inode_cache *)(*prev);
233-
BUG_ON(ic->class != RAWNODE_CLASS_INODE_CACHE);
234233
prev = &ic->nodes;
235234
continue;
236235
}
@@ -254,7 +253,8 @@ static inline void jffs2_remove_node_refs_from_ino_list(struct jffs2_sb_info *c,
254253

255254
/* PARANOIA */
256255
if (!ic) {
257-
printk(KERN_WARNING "inode_cache not found in remove_node_refs()!!\n");
256+
JFFS2_WARNING("inode_cache/xattr_datum/xattr_ref"
257+
" not found in remove_node_refs()!!\n");
258258
return;
259259
}
260260

@@ -279,8 +279,19 @@ static inline void jffs2_remove_node_refs_from_ino_list(struct jffs2_sb_info *c,
279279
printk("\n");
280280
});
281281

282-
if (ic->nodes == (void *)ic && ic->nlink == 0)
283-
jffs2_del_ino_cache(c, ic);
282+
switch (ic->class) {
283+
#ifdef CONFIG_JFFS2_FS_XATTR
284+
case RAWNODE_CLASS_XATTR_DATUM:
285+
jffs2_release_xattr_datum(c, (struct jffs2_xattr_datum *)ic);
286+
break;
287+
case RAWNODE_CLASS_XATTR_REF:
288+
jffs2_release_xattr_ref(c, (struct jffs2_xattr_ref *)ic);
289+
break;
290+
#endif
291+
default:
292+
if (ic->nodes == (void *)ic && ic->nlink == 0)
293+
jffs2_del_ino_cache(c, ic);
294+
}
284295
}
285296

286297
void jffs2_free_jeb_node_refs(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)

‎fs/jffs2/gc.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,12 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
275275
* We can decide whether this node is inode or xattr by ic->class. */
276276
if (ic->class == RAWNODE_CLASS_XATTR_DATUM
277277
|| ic->class == RAWNODE_CLASS_XATTR_REF) {
278-
BUG_ON(raw->next_in_ino != (void *)ic);
279278
spin_unlock(&c->erase_completion_lock);
280279

281280
if (ic->class == RAWNODE_CLASS_XATTR_DATUM) {
282-
ret = jffs2_garbage_collect_xattr_datum(c, (struct jffs2_xattr_datum *)ic);
281+
ret = jffs2_garbage_collect_xattr_datum(c, (struct jffs2_xattr_datum *)ic, raw);
283282
} else {
284-
ret = jffs2_garbage_collect_xattr_ref(c, (struct jffs2_xattr_ref *)ic);
283+
ret = jffs2_garbage_collect_xattr_ref(c, (struct jffs2_xattr_ref *)ic, raw);
285284
}
286285
goto release_sem;
287286
}

‎fs/jffs2/jffs2_fs_sb.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ struct jffs2_sb_info {
119119
#ifdef CONFIG_JFFS2_FS_XATTR
120120
#define XATTRINDEX_HASHSIZE (57)
121121
uint32_t highest_xid;
122+
uint32_t highest_xseqno;
122123
struct list_head xattrindex[XATTRINDEX_HASHSIZE];
123124
struct list_head xattr_unchecked;
125+
struct list_head xattr_dead_list;
126+
struct jffs2_xattr_ref *xref_dead_list;
124127
struct jffs2_xattr_ref *xref_temp;
125128
struct rw_semaphore xattr_sem;
126129
uint32_t xdatum_mem_usage;

‎fs/jffs2/malloc.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ struct jffs2_xattr_datum *jffs2_alloc_xattr_datum(void)
291291

292292
memset(xd, 0, sizeof(struct jffs2_xattr_datum));
293293
xd->class = RAWNODE_CLASS_XATTR_DATUM;
294+
xd->node = (void *)xd;
294295
INIT_LIST_HEAD(&xd->xindex);
295296
return xd;
296297
}
@@ -309,6 +310,7 @@ struct jffs2_xattr_ref *jffs2_alloc_xattr_ref(void)
309310

310311
memset(ref, 0, sizeof(struct jffs2_xattr_ref));
311312
ref->class = RAWNODE_CLASS_XATTR_REF;
313+
ref->node = (void *)ref;
312314
return ref;
313315
}
314316

‎fs/jffs2/nodemgmt.c‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -684,19 +684,26 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
684684
spin_lock(&c->erase_completion_lock);
685685

686686
ic = jffs2_raw_ref_to_ic(ref);
687-
/* It seems we should never call jffs2_mark_node_obsolete() for
688-
XATTR nodes.... yet. Make sure we notice if/when we change
689-
that :) */
690-
BUG_ON(ic->class != RAWNODE_CLASS_INODE_CACHE);
691687
for (p = &ic->nodes; (*p) != ref; p = &((*p)->next_in_ino))
692688
;
693689

694690
*p = ref->next_in_ino;
695691
ref->next_in_ino = NULL;
696692

697-
if (ic->nodes == (void *)ic && ic->nlink == 0)
698-
jffs2_del_ino_cache(c, ic);
699-
693+
switch (ic->class) {
694+
#ifdef CONFIG_JFFS2_FS_XATTR
695+
case RAWNODE_CLASS_XATTR_DATUM:
696+
jffs2_release_xattr_datum(c, (struct jffs2_xattr_datum *)ic);
697+
break;
698+
case RAWNODE_CLASS_XATTR_REF:
699+
jffs2_release_xattr_ref(c, (struct jffs2_xattr_ref *)ic);
700+
break;
701+
#endif
702+
default:
703+
if (ic->nodes == (void *)ic && ic->nlink == 0)
704+
jffs2_del_ino_cache(c, ic);
705+
break;
706+
}
700707
spin_unlock(&c->erase_completion_lock);
701708
}
702709

‎fs/jffs2/scan.c‎

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,25 @@ static int jffs2_scan_xattr_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
317317
struct jffs2_summary *s)
318318
{
319319
struct jffs2_xattr_datum *xd;
320-
uint32_t totlen, crc;
320+
uint32_t xid, version, totlen, crc;
321321
int err;
322322

323323
crc = crc32(0, rx, sizeof(struct jffs2_raw_xattr) - 4);
324324
if (crc != je32_to_cpu(rx->node_crc)) {
325-
if (je32_to_cpu(rx->node_crc) != 0xffffffff)
326-
JFFS2_WARNING("node CRC failed at %#08x, read=%#08x, calc=%#08x\n",
327-
ofs, je32_to_cpu(rx->node_crc), crc);
325+
JFFS2_WARNING("node CRC failed at %#08x, read=%#08x, calc=%#08x\n",
326+
ofs, je32_to_cpu(rx->node_crc), crc);
328327
if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rx->totlen))))
329328
return err;
330329
return 0;
331330
}
332331

333-
totlen = PAD(sizeof(*rx) + rx->name_len + 1 + je16_to_cpu(rx->value_len));
332+
xid = je32_to_cpu(rx->xid);
333+
version = je32_to_cpu(rx->version);
334+
335+
totlen = sizeof(struct jffs2_raw_xattr);
336+
if (version != XDATUM_DELETE_MARKER)
337+
totlen += rx->name_len + 1 + je16_to_cpu(rx->value_len);
338+
totlen = PAD(totlen);
334339
if (totlen != je32_to_cpu(rx->totlen)) {
335340
JFFS2_WARNING("node length mismatch at %#08x, read=%u, calc=%u\n",
336341
ofs, je32_to_cpu(rx->totlen), totlen);
@@ -339,22 +344,24 @@ static int jffs2_scan_xattr_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
339344
return 0;
340345
}
341346

342-
xd = jffs2_setup_xattr_datum(c, je32_to_cpu(rx->xid), je32_to_cpu(rx->version));
343-
if (IS_ERR(xd)) {
344-
if (PTR_ERR(xd) == -EEXIST) {
345-
if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rx->totlen)))))
346-
return err;
347-
return 0;
348-
}
347+
xd = jffs2_setup_xattr_datum(c, xid, version);
348+
if (IS_ERR(xd))
349349
return PTR_ERR(xd);
350-
}
351-
xd->xprefix = rx->xprefix;
352-
xd->name_len = rx->name_len;
353-
xd->value_len = je16_to_cpu(rx->value_len);
354-
xd->data_crc = je32_to_cpu(rx->data_crc);
355350

356-
xd->node = jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, totlen, NULL);
357-
/* FIXME */ xd->node->next_in_ino = (void *)xd;
351+
if (xd->version > version) {
352+
struct jffs2_raw_node_ref *raw
353+
= jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, totlen, NULL);
354+
raw->next_in_ino = xd->node->next_in_ino;
355+
xd->node->next_in_ino = raw;
356+
} else {
357+
xd->version = version;
358+
xd->xprefix = rx->xprefix;
359+
xd->name_len = rx->name_len;
360+
xd->value_len = je16_to_cpu(rx->value_len);
361+
xd->data_crc = je32_to_cpu(rx->data_crc);
362+
363+
jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, totlen, (void *)xd);
364+
}
358365

359366
if (jffs2_sum_active())
360367
jffs2_sum_add_xattr_mem(s, rx, ofs - jeb->offset);
@@ -373,9 +380,8 @@ static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock
373380

374381
crc = crc32(0, rr, sizeof(*rr) - 4);
375382
if (crc != je32_to_cpu(rr->node_crc)) {
376-
if (je32_to_cpu(rr->node_crc) != 0xffffffff)
377-
JFFS2_WARNING("node CRC failed at %#08x, read=%#08x, calc=%#08x\n",
378-
ofs, je32_to_cpu(rr->node_crc), crc);
383+
JFFS2_WARNING("node CRC failed at %#08x, read=%#08x, calc=%#08x\n",
384+
ofs, je32_to_cpu(rr->node_crc), crc);
379385
if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rr->totlen)))))
380386
return err;
381387
return 0;
@@ -395,6 +401,7 @@ static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock
395401
return -ENOMEM;
396402

397403
/* BEFORE jffs2_build_xattr_subsystem() called,
404+
* and AFTER xattr_ref is marked as a dead xref,
398405
* ref->xid is used to store 32bit xid, xd is not used
399406
* ref->ino is used to store 32bit inode-number, ic is not used
400407
* Thoes variables are declared as union, thus using those
@@ -404,11 +411,13 @@ static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock
404411
*/
405412
ref->ino = je32_to_cpu(rr->ino);
406413
ref->xid = je32_to_cpu(rr->xid);
414+
ref->xseqno = je32_to_cpu(rr->xseqno);
415+
if (ref->xseqno > c->highest_xseqno)
416+
c->highest_xseqno = (ref->xseqno & ~XREF_DELETE_MARKER);
407417
ref->next = c->xref_temp;
408418
c->xref_temp = ref;
409419

410-
ref->node = jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, PAD(je32_to_cpu(rr->totlen)), NULL);
411-
/* FIXME */ ref->node->next_in_ino = (void *)ref;
420+
jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, PAD(je32_to_cpu(rr->totlen)), (void *)ref);
412421

413422
if (jffs2_sum_active())
414423
jffs2_sum_add_xref_mem(s, rr, ofs - jeb->offset);

‎fs/jffs2/summary.c‎

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
310310
#ifdef CONFIG_JFFS2_FS_XATTR
311311
case JFFS2_NODETYPE_XATTR: {
312312
struct jffs2_sum_xattr_mem *temp;
313-
if (je32_to_cpu(node->x.version) == 0xffffffff)
314-
return 0;
315313
temp = kmalloc(sizeof(struct jffs2_sum_xattr_mem), GFP_KERNEL);
316314
if (!temp)
317315
goto no_mem;
@@ -327,10 +325,6 @@ int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
327325
}
328326
case JFFS2_NODETYPE_XREF: {
329327
struct jffs2_sum_xref_mem *temp;
330-
331-
if (je32_to_cpu(node->r.ino) == 0xffffffff
332-
&& je32_to_cpu(node->r.xid) == 0xffffffff)
333-
return 0;
334328
temp = kmalloc(sizeof(struct jffs2_sum_xref_mem), GFP_KERNEL);
335329
if (!temp)
336330
goto no_mem;
@@ -483,22 +477,20 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
483477

484478
xd = jffs2_setup_xattr_datum(c, je32_to_cpu(spx->xid),
485479
je32_to_cpu(spx->version));
486-
if (IS_ERR(xd)) {
487-
if (PTR_ERR(xd) == -EEXIST) {
488-
/* a newer version of xd exists */
489-
if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(spx->totlen))))
490-
return err;
491-
sp += JFFS2_SUMMARY_XATTR_SIZE;
492-
break;
493-
}
494-
JFFS2_NOTICE("allocation of xattr_datum failed\n");
480+
if (IS_ERR(xd))
495481
return PTR_ERR(xd);
482+
if (xd->version > je32_to_cpu(spx->version)) {
483+
/* node is not the newest one */
484+
struct jffs2_raw_node_ref *raw
485+
= sum_link_node_ref(c, jeb, je32_to_cpu(spx->offset) | REF_UNCHECKED,
486+
PAD(je32_to_cpu(spx->totlen)), NULL);
487+
raw->next_in_ino = xd->node->next_in_ino;
488+
xd->node->next_in_ino = raw;
489+
} else {
490+
xd->version = je32_to_cpu(spx->version);
491+
sum_link_node_ref(c, jeb, je32_to_cpu(spx->offset) | REF_UNCHECKED,
492+
PAD(je32_to_cpu(spx->totlen)), (void *)xd);
496493
}
497-
498-
xd->node = sum_link_node_ref(c, jeb, je32_to_cpu(spx->offset) | REF_UNCHECKED,
499-
PAD(je32_to_cpu(spx->totlen)), NULL);
500-
/* FIXME */ xd->node->next_in_ino = (void *)xd;
501-
502494
*pseudo_random += je32_to_cpu(spx->xid);
503495
sp += JFFS2_SUMMARY_XATTR_SIZE;
504496

@@ -519,14 +511,11 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
519511
JFFS2_NOTICE("allocation of xattr_datum failed\n");
520512
return -ENOMEM;
521513
}
522-
ref->ino = 0xfffffffe;
523-
ref->xid = 0xfffffffd;
524514
ref->next = c->xref_temp;
525515
c->xref_temp = ref;
526516

527-
ref->node = sum_link_node_ref(c, jeb, je32_to_cpu(spr->offset) | REF_UNCHECKED,
528-
PAD(sizeof(struct jffs2_raw_xref)), NULL);
529-
/* FIXME */ ref->node->next_in_ino = (void *)ref;
517+
sum_link_node_ref(c, jeb, je32_to_cpu(spr->offset) | REF_UNCHECKED,
518+
PAD(sizeof(struct jffs2_raw_xref)), (void *)ref);
530519

531520
*pseudo_random += ref->node->flash_offset;
532521
sp += JFFS2_SUMMARY_XREF_SIZE;

0 commit comments

Comments
 (0)