From nobody Tue Jan 07 14:32:31 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YSD6767VXz5kfSS; Tue, 07 Jan 2025 14:32:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YSD671cnpz4JJ8; Tue, 7 Jan 2025 14:32:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736260351; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LLyf8BYKr27rbRn/R5D5lmlNIS+q/tZ+jfB+FNhbazw=; b=fQAXI4mDaFn4ztOxsUdifVTAiA9ekMZbfR1EOgUgkKTqIkVV+4Fjk7Ep4scjYGnDcwD0mM oGv6ChaNCydn4xT1py0/1QSzd7PORRXUM4GUmHEs7TIRbtcLUvuuyr4sWEFV4ogdPjCp8l Ll71vBdhF68ynKizemRp5H5tjEIASSuVVyVkjXsJrqG8unpO1waoatBPDKhIoRvkA7X1na KL+MCLvES8Ahi+xslvzWBqjk9YLjSsNjKjYRr55zbqba9SsDwtoTpSRvAQTiVgmowg4RjS W427fg7Hwa3E931uJCbvtRiNF4xmE/DaRPz8STpSPM7zffJaaa2Mcfqt/V/2cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736260351; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LLyf8BYKr27rbRn/R5D5lmlNIS+q/tZ+jfB+FNhbazw=; b=c25c7KDloopD1P69qeqWH2FNWOLvAm4HIEHyMpfbs1MVC93l0ZxPrm0WX432scJHLdfBKz TbZ2PxNHEhs0Tk9qpj2IYaz/QIW/ELB7iZgA9+oghEA1dW19YkufgD7DJhnQWQBSkIDrcs fjCLvlIyp9MBifJ4o/0atJomM25cnM1TBDGunvtitR6UhoKaylkYur7l+jcwaAX1TLZ//6 LYv/KgNnmF6PyL5v4eAJ7hE+GygS24MUZLiVf2mr2Svf4/t7iKiCMpFxnHqDVhf0A9hnQC Cp8izH5oLsebJvUUq5R0qHFaoCVt0LC0jsWP6WlM/yNZAftwvIoNUPO4RUWeaQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736260351; a=rsa-sha256; cv=none; b=C5bm++XzmoB3DcBw2crYRDn2QJEkYyTeJZYQl9k+2SJvYPodEoijxaQaUK67vnxd5PMGDp tIG2GWfgKSzltveknMiLp1wXjAfRN3vXiSQTW7JMiPNXF8aEEukMurGxA9oneQefhyELQE wIJ6bxekFWYQe51oRHPEwduJnpGvyYuEbpdoLAT3KQuuZmULT+/lOMXawmApwGO7RgLaCi vuuKdVxh4WZ0qH0TcpxKrjvD8lKz8lMMv6KDRCz2tjxfZdq/iwI7VV++ZkoHF40iumL6Qv l0dJRSoftG2hO/4z5lhZbhBPf0dxIb6HHrjg/D5Kv8xsbhpa5x/IMBs3kxzzdA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YSD6719mwz1CcY; Tue, 07 Jan 2025 14:32:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 507EWV01015585; Tue, 7 Jan 2025 14:32:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 507EWVrt015582; Tue, 7 Jan 2025 14:32:31 GMT (envelope-from git) Date: Tue, 7 Jan 2025 14:32:31 GMT Message-Id: <202501071432.507EWVrt015582@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: ce878284318e - main - makefs: Handle special file types when creating a zpool List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ce878284318e71217d8d8f43f7d590b6c338d3aa Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ce878284318e71217d8d8f43f7d590b6c338d3aa commit ce878284318e71217d8d8f43f7d590b6c338d3aa Author: Mark Johnston AuthorDate: 2025-01-07 14:31:02 +0000 Commit: Mark Johnston CommitDate: 2025-01-07 14:32:20 +0000 makefs: Handle special file types when creating a zpool Previously, anything other than a regular file, directory or symlink would cause makefs to exit with an assertion failure. Make it a bit more resilient to user error: print a warning and skip the file. Add a regression test wherein we create an image from a devfs mount. PR: 283583 MFC after: 2 weeks --- usr.sbin/makefs/tests/makefs_zfs_tests.sh | 22 +++++++++++++++++ usr.sbin/makefs/zfs/fs.c | 39 +++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/usr.sbin/makefs/tests/makefs_zfs_tests.sh b/usr.sbin/makefs/tests/makefs_zfs_tests.sh index aeda889d9a5c..3d5819439a73 100644 --- a/usr.sbin/makefs/tests/makefs_zfs_tests.sh +++ b/usr.sbin/makefs/tests/makefs_zfs_tests.sh @@ -148,6 +148,27 @@ dataset_removal_cleanup() common_cleanup } +# +# Make sure that we can handle some special file types. Anything other than +# regular files, symlinks and directories are ignored. +# +atf_test_case devfs cleanup +devfs_body() +{ + atf_check mkdir dev + atf_check mount -t devfs none ./dev + + atf_check -e match:"skipping unhandled" $MAKEFS -s 1g -o rootpath=/ \ + -o poolname=$ZFS_POOL_NAME $TEST_IMAGE ./dev + + import_image +} +devfs_cleanup() +{ + common_cleanup + umount -f ./dev +} + # # Make sure that we can create and remove an empty directory. # @@ -842,6 +863,7 @@ atf_init_test_cases() atf_add_test_case autoexpand atf_add_test_case basic atf_add_test_case dataset_removal + atf_add_test_case devfs atf_add_test_case empty_dir atf_add_test_case empty_fs atf_add_test_case file_extend diff --git a/usr.sbin/makefs/zfs/fs.c b/usr.sbin/makefs/zfs/fs.c index 9413241da0c7..073dce3ce697 100644 --- a/usr.sbin/makefs/zfs/fs.c +++ b/usr.sbin/makefs/zfs/fs.c @@ -177,6 +177,13 @@ fsnode_isroot(const fsnode *cur) return (strcmp(cur->name, ".") == 0); } +static bool +fsnode_valid(const fsnode *cur) +{ + return (cur->type == S_IFREG || cur->type == S_IFDIR || + cur->type == S_IFLNK); +} + /* * Visit each node in a directory hierarchy, in pre-order depth-first order. */ @@ -186,9 +193,11 @@ fsnode_foreach(fsnode *root, int (*cb)(fsnode *, void *), void *arg) assert(root->type == S_IFDIR); for (fsnode *cur = root; cur != NULL; cur = cur->next) { - assert(cur->type == S_IFREG || cur->type == S_IFDIR || - cur->type == S_IFLNK); - + if (!fsnode_valid(cur)) { + warnx("skipping unhandled %s %s/%s", + inode_type(cur->type), cur->path, cur->name); + continue; + } if (cb(cur, arg) == 0) continue; if (cur->type == S_IFDIR && cur->child != NULL) @@ -381,9 +390,15 @@ fs_populate_sattrs(struct fs_populate_arg *arg, const fsnode *cur, */ for (fsnode *c = fsnode_isroot(cur) ? cur->next : cur->child; c != NULL; c = c->next) { - if (c->type == S_IFDIR) + switch (c->type) { + case S_IFDIR: links++; - objsize++; + /* FALLTHROUGH */ + case S_IFREG: + case S_IFLNK: + objsize++; + break; + } } /* The root directory is its own parent. */ @@ -652,6 +667,16 @@ fs_populate_symlink(fsnode *cur, struct fs_populate_arg *arg) fs_populate_sattrs(arg, cur, dnode); } +static fsnode * +fsnode_next(fsnode *cur) +{ + for (cur = cur->next; cur != NULL; cur = cur->next) { + if (fsnode_valid(cur)) + return (cur); + } + return (NULL); +} + static int fs_foreach_populate(fsnode *cur, void *_arg) { @@ -678,7 +703,7 @@ fs_foreach_populate(fsnode *cur, void *_arg) ret = (cur->inode->flags & FI_ROOT) != 0 ? 0 : 1; - if (cur->next == NULL && + if (fsnode_next(cur) == NULL && (cur->child == NULL || (cur->inode->flags & FI_ROOT) != 0)) { /* * We reached a terminal node in a subtree. Walk back up and @@ -694,7 +719,7 @@ fs_foreach_populate(fsnode *cur, void *_arg) eclose(dir->dirfd); free(dir); cur = cur->parent; - } while (cur != NULL && cur->next == NULL && + } while (cur != NULL && fsnode_next(cur) == NULL && (cur->inode->flags & FI_ROOT) == 0); }