make sure that 0 length files get their extattrs cleaned up on deletion

(there was an optimization to not call truncate if size == 0).
This commit is contained in:
christos 2020-04-12 23:52:20 +00:00
parent 44988dfe00
commit 97cf9247a5

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_extattr.c,v 1.1 2020/04/10 22:58:47 christos Exp $ */
/* $NetBSD: t_extattr.c,v 1.2 2020/04/12 23:52:20 christos Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_extattr.c,v 1.1 2020/04/10 22:58:47 christos Exp $");
__RCSID("$NetBSD: t_extattr.c,v 1.2 2020/04/12 23:52:20 christos Exp $");
#include <sys/types.h>
#include <sys/mount.h>
@ -51,14 +51,6 @@ __RCSID("$NetBSD: t_extattr.c,v 1.1 2020/04/10 22:58:47 christos Exp $");
#include "h_macros.h"
ATF_TC_WITH_CLEANUP(extattr);
ATF_TC_HEAD(extattr, tc)
{
atf_tc_set_md_var(tc, "descr", "test extended attribute support in "
"ffsv2");
atf_tc_set_md_var(tc, "timeout", "5");
}
#define IMGNAME "extattr.img"
#define G "/garage"
@ -90,12 +82,9 @@ check_list(const char *buf, ssize_t nr)
const char *newfs = "newfs -O 2 -F -s 10000 " IMGNAME;
#define FAKEBLK "/dev/formula1"
ATF_TC_BODY(extattr, tc)
{
static void
start(void) {
struct ufs_args args;
ssize_t nr;
int fd;
char buf[512];
if (system(newfs) == -1)
atf_tc_fail_errno("newfs failed");
@ -113,6 +102,33 @@ ATF_TC_BODY(extattr, tc)
/* create extattr */
if (rump_sys_chdir(G) == 1)
atf_tc_fail_errno("chdir");
}
static void
finish(void) {
if (rump_sys_chdir("/") == 1)
atf_tc_fail_errno("chdir");
if (rump_sys_unmount(G, 0) == -1)
atf_tc_fail_errno("unmount failed");
}
ATF_TC_WITH_CLEANUP(extattr_simple);
ATF_TC_HEAD(extattr_simple, tc)
{
atf_tc_set_md_var(tc, "descr", "test extended attribute creation"
" and removal ffsv2");
atf_tc_set_md_var(tc, "timeout", "5");
}
ATF_TC_BODY(extattr_simple, tc)
{
ssize_t nr;
int fd;
char buf[512];
start();
if ((fd = rump_sys_open(M, O_RDWR | O_CREAT, 0600)) == -1)
atf_tc_fail_errno("open");
if (rump_sys_write(fd, "hi mom\n", 7) != 7)
@ -161,9 +177,46 @@ ATF_TC_BODY(extattr, tc)
atf_tc_fail_errno("close");
if (rump_sys_unlink(M) == -1)
atf_tc_fail_errno("unlink");
finish();
}
ATF_TC_CLEANUP(extattr, tc)
ATF_TC_CLEANUP(extattr_simple, tc)
{
unlink(IMGNAME);
}
ATF_TC_WITH_CLEANUP(extattr_create_unlink);
ATF_TC_HEAD(extattr_create_unlink, tc)
{
atf_tc_set_md_var(tc, "descr", "test extended attribute creation"
" and unlinking file with ACLs");
atf_tc_set_md_var(tc, "timeout", "5");
}
ATF_TC_BODY(extattr_create_unlink, tc)
{
int fd;
start();
if ((fd = rump_sys_open(M, O_RDWR | O_CREAT, 0600)) == -1)
atf_tc_fail_errno("open");
if (rump_sys_close(fd) == -1)
atf_tc_fail_errno("close");
/* create extattr */
if (rump_sys_extattr_set_file(M, EXTATTR_NAMESPACE_USER, T, S, 9) == -1)
atf_tc_fail_errno("extattr_set_file");
if (rump_sys_unlink(M) == -1)
atf_tc_fail_errno("unlink");
finish();
}
ATF_TC_CLEANUP(extattr_create_unlink, tc)
{
unlink(IMGNAME);
@ -171,6 +224,7 @@ ATF_TC_CLEANUP(extattr, tc)
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, extattr);
ATF_TP_ADD_TC(tp, extattr_simple);
ATF_TP_ADD_TC(tp, extattr_create_unlink);
return atf_no_error();
}