[PATCH 12/14] Add ngnfs_dir_mkdir() and debugfs command

Zach Brown zab at zabbo.net
Fri Feb 28 15:37:45 PST 2025


On Thu, Feb 27, 2025 at 03:16:21PM +0100, Valerie Aurora wrote:
> Makes a directory of the specified name in the current working
> directory in debugfs.

> +/*
> + * Create a new directory and add a directory entry referencing it.
> + */
> +int ngnfs_dir_mkdir(struct ngnfs_fs_info *nfi, u64 dir_ino, umode_t mode, char *name,
> +		    size_t name_len)
> +{
> +	struct {
> +		struct ngnfs_transaction txn;
> +		struct ngnfs_inode_txn_ref dir;
> +		struct ngnfs_inode_txn_ref new_dir;
> +		u64 ino;
> +		u64 nsec;
> +		struct dirent_args da;
> +	} *op;
> +	int ret;
> +
> +	op = kmalloc(sizeof(*op), GFP_NOFS);
> +	if (!op) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
> +
> +	ngnfs_txn_init(&op->txn);
> +	op->nsec = ktime_to_ns(ktime_get_real());
> +	init_dirent_args(&op->da, name, name_len, 0, mode | S_IFDIR);
> +
> +	do {
> +		ret = ngnfs_inode_get(nfi, &op->txn, NBF_WRITE, dir_ino, &op->dir)		?:
> +		      check_ifmt(op->dir.ninode, S_IFDIR, -ENOTDIR)				?:
> +		      ngnfs_inode_alloc(nfi, &op->txn, &op->ino, &op->new_dir)			?:
> +		      ngnfs_inode_init(&op->new_dir, op->ino, 1, 2, mode | S_IFDIR, op->nsec,
> +				       dir_ino)							?:
> +		      update_dirent_args_ino(&op->da, op->ino)					?:
> +		      insert_dirent(nfi, &op->txn, &op->dir, &op->da)				?:
> +		      update_dir(op->dir.tblk, op->dir.ninode, &op->da, 1);
> +
> +	} while (ngnfs_txn_retry(nfi, &op->txn, &ret));
> +
> +	ngnfs_txn_teardown(nfi, &op->txn);
> +	kfree(op);
> +out:
> +	return ret;
> +}

This is just _create() with different nlink and mode, right?  We
probably do want different _create, _mkdir, _symlink, _mknod exposed
calls, but we can have them each call a core_create(), or whatever, that
takes nlink and dev_t provided by each calling shim.

- z



More information about the ngnfs-devel mailing list