Skip to content
Snippets Groups Projects
Commit 9ca6522a authored by Raphael S. Carvalho's avatar Raphael S. Carvalho Committed by Pekka Enberg
Browse files

mkfs: Code refactoring and allow instances of the same shared object


Besides refactoring the code, this patch makes mkfs support more than
one instance of the same shared object within the same mkfs instance,
i.e. by releasing the resources at the function prologue.

Signed-off-by: default avatarRaphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent cb5db36c
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (C) 2013 Cloudius Systems, Ltd.
* Copyright (C) 2013-2014 Cloudius Systems, Ltd.
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
......@@ -15,21 +15,32 @@
using namespace osv;
using namespace std;
// Created to guarantee that shared objects resources will
// be surely released at the function prologue.
void run_cmd(const char *cmdpath, vector<string> args)
{
int ret;
auto ok = run(cmdpath, args, &ret);
assert(ok && ret == 0);
}
void mkfs()
{
/* Create zfs device, then /etc/mnttab which is required by libzfs */
// Create zfs device, then /etc/mnttab which is required by libzfs
zfsdev::zfsdev_init();
// Manually create /etc/mnttab, a file required by libzfs.
mkdir("/etc", 0755);
int fd = creat("/etc/mnttab", 0644);
assert(fd != -1);
close(fd);
int ret;
auto ok = run("/zpool.so",
{"zpool", "create", "-f", "-R", "/zfs", "osv", "/dev/vblk0.1"}, &ret);
assert(ok && ret == 0);
ok = run("/zfs.so", {"zfs", "create", "osv/zfs"}, &ret);
assert(ok && ret == 0);
// Create zpool named osv
run_cmd("/zpool.so",
{"zpool", "create", "-f", "-R", "/zfs", "osv", "/dev/vblk0.1"});
// Create a zfs dataset within the pool named osv.
run_cmd("/zfs.so", {"zfs", "create", "osv/zfs"});
}
int main(int ac, char** av)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment