Skip to content

Commit

Permalink
sync option for uzfs through CLI (openzfs#7)
Browse files Browse the repository at this point in the history
* [cstor#38] honoring sync option in uzfs
Signed-off-by: Vishnu Itta <[email protected]>
  • Loading branch information
vishnuitta authored and Jan Kryl committed Jun 26, 2018
1 parent 55716b3 commit fa02d18
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ script:
# run ztest and test supported zio backends
- if [ $ZFS_BUILD_TAGS = 0 ]; then
sudo mkdir /etc/zfs;
travis_wait 60 ./tests/cbtest/script/test_uzfs.sh || travis_terminate 1;
travis_wait 60 sudo bash ./tests/cbtest/script/test_uzfs.sh || travis_terminate 1;
else
sudo /sbin/modprobe zfs;
travis_wait 10 /sbin/ztest || travis_terminate 1;
Expand Down
79 changes: 49 additions & 30 deletions cmd/uzfs_test/uzfs_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ uint64_t active_size = 0;
uint64_t vol_size = 0;
int run_test = 0;
uint32_t uzfs_test_id = 0;
uint32_t create = 0;
char *pool = "testp";
char *ds = "ds0";

uzfs_test_info_t uzfs_tests[] = {
{ uzfs_zvol_zap_operation, "uzfs zap operation test" },
Expand Down Expand Up @@ -258,39 +261,39 @@ unit_test_create_pool_ds(void)
void *zv1, *zv2, *zv3, *zv4, *zv5, *zv;
int err, err1, err2, err3, err4, err5;

err1 = uzfs_create_pool("testp", "/tmp/uztest.xyz", &spa1);
err1 = uzfs_create_pool(pool, "/tmp/uztest.xyz", &spa1);
if (spa1 != NULL) {
printf("shouldn't create pool with non existing disk..\n");
exit(1);
}

err = uzfs_create_pool("testp", "/tmp/uztest.1a", &spa);
err = uzfs_create_pool(pool, "/tmp/uztest.1a", &spa);
if (err != 0 || spa == NULL) {
printf("creating pool errored %d..\n", err);
exit(1);
}

err1 = uzfs_create_pool("testp", "/tmp/uztest.1a", &spa1);
err2 = uzfs_create_pool("testp1", "/tmp/uztest.xyz", &spa2);
err3 = uzfs_open_pool("testp", &spa3);
err4 = uzfs_open_pool("testp1", &spa4);
err1 = uzfs_create_pool(pool, "/tmp/uztest.1a", &spa1);
err2 = uzfs_create_pool("testpxyz", "/tmp/uztest.xyz", &spa2);
err3 = uzfs_open_pool(pool, &spa3);
err4 = uzfs_open_pool("testpxyz", &spa4);
if (spa1 != NULL || spa2 != NULL || spa3 != NULL || spa4 != NULL ||
err1 == 0 || err2 == 0 || err3 == 0 || err4 == 0) {
printf("shouldn't create/open, but succeeded..\n");
exit(1);
}

err = uzfs_create_dataset(spa, "ds0", vol_size, block_size, 0, &zv);
err = uzfs_create_dataset(spa, ds, vol_size, block_size, &zv);
if (zv == NULL || err != 0) {
printf("creating ds errored %d..\n", err);
exit(1);
}

err1 = uzfs_create_dataset(spa, "ds0", vol_size, block_size, 0, &zv1);
err2 = uzfs_open_dataset(spa, "ds0", 0, &zv2);
err3 = uzfs_open_dataset(spa, "ds1", 0, &zv3);
err4 = uzfs_open_dataset(NULL, "ds1", 0, &zv4);
err5 = uzfs_create_dataset(NULL, "ds0", vol_size, block_size, 0, &zv5);
err1 = uzfs_create_dataset(spa, ds, vol_size, block_size, &zv1);
err2 = uzfs_open_dataset(spa, ds, &zv2);
err3 = uzfs_open_dataset(spa, "dsxyz", &zv3);
err4 = uzfs_open_dataset(NULL, "dsxyz", &zv4);
err5 = uzfs_create_dataset(NULL, ds, vol_size, block_size, &zv5);
if (zv1 != NULL || zv2 != NULL || zv3 != NULL || zv4 != NULL ||
zv5 != NULL || err1 == 0 || err2 == 0 || err3 == 0 || err4 == 0 ||
err5 == 0) {
Expand Down Expand Up @@ -325,10 +328,11 @@ static void usage(int num)
int count = sizeof (uzfs_tests) / sizeof (uzfs_tests[0]);

printf("uzfs_test -t <total_time_in_sec> -a <active data size>"
" -b <block_size> -i <io size> -v <vol size> -l(for log device)"
" -m <metadata to verify during replay>"
" -s(for sync on) -S(for silent) -V <data to verify during replay>"
" -w(for write during replay) -T <test id>\n");
" -b <block_size> -c -d <dsname> -i <io size> -v <vol size>"
" -l(for log device) -m <metadata to verify during replay>"
" -p <pool name> -s(for sync on) -S(for silent)"
" -V <data to verify during replay> -w(for write during replay)"
" -T <test id>\n");

printf("Test id:\n");

Expand Down Expand Up @@ -401,9 +405,17 @@ static void process_options(int argc, char **argv)
uint64_t val = 0;
uint64_t num_tests = sizeof (uzfs_tests) / sizeof (uzfs_tests[0]);

while ((opt = getopt(argc, argv, "a:b:i:lm:sSt:v:V:wT:n:")) != EOF) {
if (optarg != NULL)
val = nicenumtoull(optarg);
while ((opt = getopt(argc, argv, "a:b:cd:i:lm:p:sSt:v:V:wT:n:"))
!= EOF) {
switch (opt) {
case 'd':
case 'p':
break;
default:
if (optarg != NULL)
val = nicenumtoull(optarg);
break;
}
switch (opt) {
case 'a':
active_size = val;
Expand All @@ -416,17 +428,24 @@ static void process_options(int argc, char **argv)
case 'b':
block_size = val;
break;
case 'c':
create = 1;
break;
case 'd':
ds = optarg;
break;
case 'i':
io_block_size = val;
break;
case 'l':
log_device = 1;
break;
case 'm':
if (optarg != NULL)
val = nicenumtoull(optarg);
metaverify = val;
break;
case 'p':
pool = optarg;
break;
case 's':
sync_data = 1;
break;
Expand All @@ -445,8 +464,6 @@ static void process_options(int argc, char **argv)
? (active_size) : (vol_size);
break;
case 'V':
if (optarg != NULL)
val = nicenumtoull(optarg);
verify = val;
break;
case 'w':
Expand All @@ -469,8 +486,9 @@ static void process_options(int argc, char **argv)
active_size = vol_size = 1024*1024*1024ULL;

if (silent == 0) {
printf("vol size: %lu active size: %lu\n", vol_size,
active_size);
printf("vol size: %lu active size: %lu create: %d\n", vol_size,
active_size, create);
printf("pool: %s ds: %s\n", pool, ds);
printf("block size: %lu io blksize: %lu\n", block_size,
io_block_size);
printf("log: %d sync: %d silent: %d\n", log_device, sync_data,
Expand All @@ -484,12 +502,12 @@ void
open_pool_ds(void **spa, void **zv)
{
int err;
err = uzfs_open_pool("testp", spa);
err = uzfs_open_pool(pool, spa);
if (err != 0) {
printf("pool open errored.. %d\n", err);
exit(1);
}
err = uzfs_open_dataset(*spa, "ds0", sync_data, zv);
err = uzfs_open_dataset(*spa, ds, zv);
if (err != 0) {
printf("ds open errored.. %d\n", err);
exit(1);
Expand All @@ -512,9 +530,10 @@ unit_test_fn(void *arg)
mutex_init(&mtx, NULL, MUTEX_DEFAULT, NULL);
cv_init(&cv, NULL, CV_DEFAULT, NULL);

setup_unit_test();

unit_test_create_pool_ds();
if (create == 1) {
setup_unit_test();
unit_test_create_pool_ds();
}

open_pool_ds(&spa, &zv);

Expand Down
6 changes: 4 additions & 2 deletions cmd/uzfs_test/uzfs_test_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ replay_fn(void *arg)
zfs_txg_timeout = 30;

if (write_op == 1) {
setup_unit_test();
unit_test_create_pool_ds();
if (create == 1) {
setup_unit_test();
unit_test_create_pool_ds();
}
open_pool_ds(&spa, &zv);
} else if (verify != 0) {
open_pool_ds(&spa, &zv);
Expand Down
8 changes: 8 additions & 0 deletions cmd/uzfs_test/uzfs_test_sync.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
for i in {1..10}
do
log_must setup_uzfs_test nolog 4096 nosync
sudo $UZFS_TEST -S -w -T 1 > $PWD/$1/uzfs_sync_data
if [ $? != 0 ]; then
exit 1;
Expand All @@ -13,6 +14,7 @@ do
done
for i in {1..10}
do
log_must setup_uzfs_test log 4096 nosync
sudo $UZFS_TEST -S -l -T 1 -w > $PWD/$1/uzfs_sync_data
if [ $? != 0 ]; then
exit 1;
Expand All @@ -25,6 +27,7 @@ do
done
for i in {1..10}
do
log_must setup_uzfs_test nolog 4096 sync
sudo $UZFS_TEST -S -s -T 1 -w > $PWD/$1/uzfs_sync_data
if [ $? != 0 ]; then
exit 1;
Expand All @@ -37,6 +40,7 @@ do
done
for i in {1..10}
do
log_must setup_uzfs_test log 4096 sync
sudo $UZFS_TEST -S -l -s -T 1 -w > $PWD/$1/uzfs_sync_data
if [ $? != 0 ]; then
exit 1;
Expand All @@ -50,6 +54,7 @@ done

for i in {1..10}
do
log_must setup_uzfs_test nolog 65536 nosync
sudo $UZFS_TEST -S -i 8192 -b 65536 -T 1 -w > $PWD/$1/uzfs_sync_data
if [ $? != 0 ]; then
exit 1;
Expand All @@ -62,6 +67,7 @@ do
done
for i in {1..10}
do
log_must setup_uzfs_test log 65536 nosync
sudo $UZFS_TEST -S -i 8192 -b 65536 -l -T 1 -w > $PWD/$1/uzfs_sync_data
if [ $? != 0 ]; then
exit 1;
Expand All @@ -74,6 +80,7 @@ do
done
for i in {1..10}
do
log_must setup_uzfs_test nolog 65536 sync
sudo $UZFS_TEST -S -s -i 8192 -b 65536 -T 1 -w > $PWD/$1/uzfs_sync_data
if [ $? != 0 ]; then
exit 1;
Expand All @@ -86,6 +93,7 @@ do
done
for i in {1..10}
do
log_must setup_uzfs_test log 65536 sync
sudo $UZFS_TEST -S -i 8192 -b 65536 -l -s -T 1 -w > $PWD/$1/uzfs_sync_data
if [ $? != 0 ]; then
exit 1;
Expand Down
1 change: 0 additions & 1 deletion include/sys/uzfs_zvol.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ struct zvol_state {
zfs_rlock_t zv_range_lock; /* range lock */
zfs_rlock_t zv_mrange_lock; /* range lock */
spa_t *zv_spa; /* spa */
int zv_sync; /* sync property of zv */
uint64_t zv_volmetablocksize; /* meta block size */
uint64_t zv_volmetadatasize; /* volume meta data size */

Expand Down
4 changes: 2 additions & 2 deletions include/uzfs_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ extern int uzfs_create_pool(char *name, char *path, void **spa);
extern int uzfs_open_pool(char *name, void **spa);
extern int uzfs_vdev_add(void *spa, char *path, int ashift, int log);
extern int uzfs_create_dataset(void *spa, char *ds, uint64_t vol_size,
uint64_t block_size, int sync, void **zv);
extern int uzfs_open_dataset(void *spa, char *ds, int sync, void **zv);
uint64_t block_size, void **zv);
extern int uzfs_open_dataset(void *spa, char *ds, void **zv);
extern uint64_t uzfs_synced_txg(void *zv);
extern void uzfs_close_dataset(void *zv);
extern void uzfs_close_pool(void *spa);
Expand Down
3 changes: 3 additions & 0 deletions include/uzfs_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ extern int write_op;
extern int verify_err;
extern int verify;
extern int test_iterations;
extern uint32_t create;
extern char *pool;
extern char *ds;

extern unsigned long zfs_arc_max;
extern unsigned long zfs_arc_min;
Expand Down
1 change: 1 addition & 0 deletions lib/libzpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ USER_C = \
uzfs_io.c \
uzfs_task.c \
uzfs_mgmt.c \
uzfs_test_mgmt.c \
uzfs_zap.c \
vdev_disk_aio.c

Expand Down
3 changes: 2 additions & 1 deletion lib/libzpool/uzfs_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int
uzfs_write_data(zvol_state_t *zv, char *buf, uint64_t offset, uint64_t len,
blk_metadata_t *metadata)
{
uint64_t bytes = 0, sync = zv->zv_sync;
uint64_t bytes = 0, sync;
uint64_t volsize = zv->zv_volsize;
uint64_t blocksize = zv->zv_volblocksize;
uint64_t end = len + offset;
Expand All @@ -42,6 +42,7 @@ uzfs_write_data(zvol_state_t *zv, char *buf, uint64_t offset, uint64_t len,
uint64_t metadatasize = zv->zv_volmetadatasize;
uint64_t len_in_first_aligned_block = 0;

sync = dmu_objset_syncprop(os);
if (zv->zv_volmetablocksize == 0)
metadata = NULL;
/*
Expand Down
15 changes: 4 additions & 11 deletions lib/libzpool/uzfs_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ uzfs_objset_create_cb(objset_t *new_os, void *arg, cred_t *cr, dmu_tx_t *tx)

/* owns objset with name 'ds_name' in pool 'spa'. Sets 'sync' property */
int
uzfs_open_dataset(spa_t *spa, const char *ds_name, int sync, zvol_state_t **z)
uzfs_open_dataset(spa_t *spa, const char *ds_name, zvol_state_t **z)
{
char name[ZFS_MAX_DATASET_NAME_LEN];
zvol_state_t *zv = NULL;
Expand Down Expand Up @@ -331,7 +331,6 @@ uzfs_open_dataset(spa_t *spa, const char *ds_name, int sync, zvol_state_t **z)
}

zv->zv_zilog = zil_open(os, zvol_get_data);
zv->zv_sync = sync;
zv->zv_volblocksize = block_size;
zv->zv_volsize = vol_size;

Expand All @@ -349,11 +348,11 @@ uzfs_open_dataset(spa_t *spa, const char *ds_name, int sync, zvol_state_t **z)

/*
* Creates dataset 'ds_name' in pool 'spa' with volume size 'vol_size',
* block size as 'block_size' and with 'sync' property
* block size as 'block_size'
*/
int
uzfs_create_dataset(spa_t *spa, char *ds_name, uint64_t vol_size,
uint64_t block_size, int sync, zvol_state_t **z)
uint64_t block_size, zvol_state_t **z)
{
char name[ZFS_MAX_DATASET_NAME_LEN];
zvol_state_t *zv = NULL;
Expand All @@ -375,7 +374,7 @@ uzfs_create_dataset(spa_t *spa, char *ds_name, uint64_t vol_size,
if (error)
goto ret;

error = uzfs_open_dataset(spa, ds_name, sync, &zv);
error = uzfs_open_dataset(spa, ds_name, &zv);
if (error != 0) {
zv = NULL;
goto ret;
Expand All @@ -385,12 +384,6 @@ uzfs_create_dataset(spa_t *spa, char *ds_name, uint64_t vol_size,
return (error);
}

uint64_t
uzfs_synced_txg(zvol_state_t *zv)
{
return (spa_last_synced_txg(zv->zv_spa));
}

/* disowns, closes dataset */
void
uzfs_close_dataset(zvol_state_t *zv)
Expand Down
29 changes: 29 additions & 0 deletions lib/libzpool/uzfs_test_mgmt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

#include <sys/dmu_objset.h>
#include <sys/uzfs_zvol.h>

uint64_t
uzfs_synced_txg(zvol_state_t *zv)
{
return (spa_last_synced_txg(zv->zv_spa));
}
Loading

0 comments on commit fa02d18

Please sign in to comment.