changeset 805:543b2cf8aaf8

common: move nattr blksize and blkcount calculation into objstore backend Additionally, this fixes a bug - the number of blocks (st_blocks) is defined as the number of 512B blocks regardless of the preferred I/O size (st_blksize). Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sun, 05 Apr 2020 13:53:26 -0400
parents 9a5dfd13727c
children 3cb2237b2324
files src/common/attr.c src/objstore/posix/obj.c
diffstat 2 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/common/attr.c	Sun Apr 05 13:51:28 2020 -0400
+++ b/src/common/attr.c	Sun Apr 05 13:53:26 2020 -0400
@@ -107,8 +107,11 @@
 #endif
 	cvt_ntime(&stat->st_ctim, nattr->ctime);
 	cvt_ntime(&stat->st_mtim, nattr->mtime);
-	stat->st_blksize = 4096;
-	stat->st_blocks = (nattr->size + stat->st_blksize - 1) / stat->st_blksize;
+	stat->st_blksize = nattr->blksize;
+	stat->st_blocks = nattr->blocks;
+
+	STATIC_ASSERT(sizeof(stat->st_blksize) == sizeof(nattr->blksize));
+	STATIC_ASSERT(sizeof(stat->st_blocks) == sizeof(nattr->blocks));
 
 	/*
 	 * TODO: Illumos has a stat->st_fstype, should we zero it?  Linux
--- a/src/objstore/posix/obj.c	Sun Apr 05 13:51:28 2020 -0400
+++ b/src/objstore/posix/obj.c	Sun Apr 05 13:53:26 2020 -0400
@@ -311,6 +311,12 @@
 	attr->mtime = hdr->mtime;
 	attr->owner = hdr->owner;
 	attr->group = hdr->group;
+	attr->blksize = BLOCK_SIZE; /* preferred I/O size */
+	/*
+	 * The block count is a multiple of 512 bytes, and includes any
+	 * internal metadata (i.e., the header).
+	 */
+	attr->blocks = (attr->size + BLOCK_SIZE + 512 - 1) / 512;
 }
 
 static int posix_getattr(struct objver *ver, struct nattr *attr)