[LTP] [PATCH 1/2] fallocate05: Check that deallocated file range is marked as a hole

Petr Vorel pvorel@suse.cz
Fri Sep 6 10:36:28 CEST 2024


> On 06. 09. 24 10:17, Petr Vorel wrote:
> > Hi Martin,

> > > The new lseek(SEEK_HOLE/SEEK_DATA) checks will be useful for diagnosing
> > > why the final write() check fails with ENOSPC. If the hole doesn't get
> > > created at all, the lseek() checks will fail.

> > Thank you!

> > ...
> > > +	/* Check that the deallocated file range is marked as a hole */
> > > +	TEST(lseek(fd, 0, SEEK_HOLE));
> > > +
> > > +	if (TST_RET == 0) {
> > > +		tst_res(TPASS, "Test file contains hole at offset 0");
> > > +	} else if (TST_RET == -1) {
> > > +		tst_res(TFAIL | TTERRNO, "lseek(SEEK_HOLE) failed");
> > > +	} else {
> > > +		tst_res(TFAIL | TTERRNO,
> > > +			"Unexpected lseek(SEEK_HOLE) return value %ld",
> > > +			TST_RET);
> > > +	}
> > nit: maybe just using SAFE_LSEEK()?

> Definitely no SAFE_LSEEK() here because I want to continue to the second
> lseek() even if the first one fails.

OK, fair enough.

> > > +
> > > +	TEST(lseek(fd, 0, SEEK_DATA));
> > > +
> > > +	if (TST_RET == holesize) {
> > > +		tst_res(TPASS, "Test file data start at offset %ld", TST_RET);
> > > +	} else if (TST_RET == -1) {
> > > +		tst_res(TFAIL | TTERRNO, "lseek(SEEK_DATA) failed");
> > > +	} else {
> > > +		tst_res(TFAIL | TTERRNO,
> > > +			"Unexpected lseek(SEEK_DATA) return value %ld",
> > > +			TST_RET);
> > > +	}

> > nit: and here just:

> > TEST(SAFE_LSEEK(fd, 0, SEEK_DATA));
> > if (TST_RET == holesize)
> > 	tst_res(TPASS, "Test file data start at offset %ld", TST_RET);

> We could use SAFE_LSEEK() here at least until someone decides to add another
> sanity check below it. But we still need the "else" branch to report wrong
> hole size. I'd say it's slightly better to keep it as is for the more
> descriptive error messages.

Fair enough, thx for info.

Kind regards,
Petr


More information about the ltp mailing list