changeset 754:774cb4e33bc5

objstore: add 'all_deleted' flag to dirents This flag summarizes the targets - indicating whether or not all its targets are marked as deleted. Currently, nothing checks this flag. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sun, 29 Mar 2020 17:27:41 -0400
parents 3a2501dd5123
children 3b1f99adbb41
files src/objstore/dir.h src/objstore/dirblock.c src/objstore/dirent.c
diffstat 3 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/objstore/dir.h	Sun Mar 29 17:19:40 2020 -0400
+++ b/src/objstore/dir.h	Sun Mar 29 17:27:41 2020 -0400
@@ -85,7 +85,8 @@
 
 #define MAX_NAME_LEN	UINT8_MAX
 #define NDIRENT_FLAG_CONFLICTS	0x8000 /* >1 non-deleted target */
-#define NDIRENT_NTGTS_MASK	0x7fff
+#define NDIRENT_FLAG_ALL_DELS	0x4000 /* 0 non-deleted targets */
+#define NDIRENT_NTGTS_MASK	0x3fff
 struct ndirent_phys {
 	uint16_t tgtoff; /* blk offset with target array */
 	uint16_t ntgts_and_flags;  /* number of targets; flags in the MSBs */
@@ -109,6 +110,7 @@
 	uint16_t nameoff;/* blk offset with name */
 	uint8_t namelen; /* name length */
 	bool conflicts; /* more than one non-deleted target */
+	bool all_deleted; /* all targets are deleted */
 };
 
 /*
--- a/src/objstore/dirblock.c	Sun Mar 29 17:19:40 2020 -0400
+++ b/src/objstore/dirblock.c	Sun Mar 29 17:27:41 2020 -0400
@@ -44,7 +44,8 @@
 	ASSERT3U(block->entries[dirent].dirent.namelen, <=, MAX_NAME_LEN);
 
 	/*
-	 * Check that dirent's 'conflicts' flag matches the targets
+	 * Check that dirent's 'conflicts' and 'all_deleted' flags matche
+	 * the targets
 	 */
 	non_deleted_targets = 0;
 	for (tgt = 0; tgt < block->entries[dirent].dirent.ntgts; tgt++)
@@ -55,6 +56,11 @@
 		VERIFY3U(non_deleted_targets, >, 1);
 	else
 		VERIFY3U(non_deleted_targets, <=, 1);
+
+	if (block->entries[dirent].dirent.all_deleted)
+		VERIFY3U(non_deleted_targets, ==, 0);
+	else
+		VERIFY3U(non_deleted_targets, >=, 1);
 }
 
 int dirblock_serialize(struct dirblock *block, struct buffer *buf)
@@ -177,6 +183,7 @@
 	block->entries[idx].dirent.nameoff = DIRBLOCK_DIRENT_OFFSET_POISON;
 	block->entries[idx].dirent.namelen = namelen;
 	block->entries[idx].dirent.conflicts = false;
+	block->entries[idx].dirent.all_deleted = false;
 	block->entries[idx].tgts = &block->tgts[block->ntgts];
 
 	/* save the name */
--- a/src/objstore/dirent.c	Sun Mar 29 17:19:40 2020 -0400
+++ b/src/objstore/dirent.c	Sun Mar 29 17:27:41 2020 -0400
@@ -33,8 +33,13 @@
 	ASSERT3U(mem->nameoff + mem->namelen, <=, DIR_BLOCK_SIZE);
 	ASSERT3U(mem->namelen, >, 0);
 
-	if (mem->conflicts)
+	if (mem->conflicts) {
 		ASSERT3U(mem->ntgts, >, 1);
+		ASSERT(!mem->all_deleted);
+	}
+
+	if (mem->all_deleted)
+		ASSERT(!mem->conflicts);
 }
 
 void dirent_cpu2be(struct ndirent_phys *phys, const struct ndirent_mem *mem)
@@ -45,6 +50,7 @@
 
 	ntgts_and_flags = mem->ntgts;
 	ntgts_and_flags |= mem->conflicts ? NDIRENT_FLAG_CONFLICTS : 0;
+	ntgts_and_flags |= mem->all_deleted ? NDIRENT_FLAG_ALL_DELS : 0;
 
 	phys->tgtoff  = cpu16_to_be(mem->tgtoff);
 	phys->ntgts_and_flags = cpu16_to_be(ntgts_and_flags);
@@ -60,6 +66,7 @@
 	ntgts_and_flags = be16_to_cpu(phys->ntgts_and_flags);
 	mem->ntgts     = ntgts_and_flags & NDIRENT_NTGTS_MASK;
 	mem->conflicts = !!(ntgts_and_flags & NDIRENT_FLAG_CONFLICTS);
+	mem->all_deleted = !!(ntgts_and_flags & NDIRENT_FLAG_ALL_DELS);
 	mem->nameoff   = be16_to_cpu(phys->nameoff);
 	mem->namelen   = be8_to_cpu(phys->namelen);