Skip to content

Commit fa02d18

Browse files
vishnuittaJan Kryl
authored andcommitted
sync option for uzfs through CLI (openzfs#7)
* [cstor#38] honoring sync option in uzfs Signed-off-by: Vishnu Itta <[email protected]>
1 parent 55716b3 commit fa02d18

File tree

12 files changed

+168
-51
lines changed

12 files changed

+168
-51
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ script:
5252
# run ztest and test supported zio backends
5353
- if [ $ZFS_BUILD_TAGS = 0 ]; then
5454
sudo mkdir /etc/zfs;
55-
travis_wait 60 ./tests/cbtest/script/test_uzfs.sh || travis_terminate 1;
55+
travis_wait 60 sudo bash ./tests/cbtest/script/test_uzfs.sh || travis_terminate 1;
5656
else
5757
sudo /sbin/modprobe zfs;
5858
travis_wait 10 /sbin/ztest || travis_terminate 1;

cmd/uzfs_test/uzfs_test.c

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ uint64_t active_size = 0;
3434
uint64_t vol_size = 0;
3535
int run_test = 0;
3636
uint32_t uzfs_test_id = 0;
37+
uint32_t create = 0;
38+
char *pool = "testp";
39+
char *ds = "ds0";
3740

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

261-
err1 = uzfs_create_pool("testp", "/tmp/uztest.xyz", &spa1);
264+
err1 = uzfs_create_pool(pool, "/tmp/uztest.xyz", &spa1);
262265
if (spa1 != NULL) {
263266
printf("shouldn't create pool with non existing disk..\n");
264267
exit(1);
265268
}
266269

267-
err = uzfs_create_pool("testp", "/tmp/uztest.1a", &spa);
270+
err = uzfs_create_pool(pool, "/tmp/uztest.1a", &spa);
268271
if (err != 0 || spa == NULL) {
269272
printf("creating pool errored %d..\n", err);
270273
exit(1);
271274
}
272275

273-
err1 = uzfs_create_pool("testp", "/tmp/uztest.1a", &spa1);
274-
err2 = uzfs_create_pool("testp1", "/tmp/uztest.xyz", &spa2);
275-
err3 = uzfs_open_pool("testp", &spa3);
276-
err4 = uzfs_open_pool("testp1", &spa4);
276+
err1 = uzfs_create_pool(pool, "/tmp/uztest.1a", &spa1);
277+
err2 = uzfs_create_pool("testpxyz", "/tmp/uztest.xyz", &spa2);
278+
err3 = uzfs_open_pool(pool, &spa3);
279+
err4 = uzfs_open_pool("testpxyz", &spa4);
277280
if (spa1 != NULL || spa2 != NULL || spa3 != NULL || spa4 != NULL ||
278281
err1 == 0 || err2 == 0 || err3 == 0 || err4 == 0) {
279282
printf("shouldn't create/open, but succeeded..\n");
280283
exit(1);
281284
}
282285

283-
err = uzfs_create_dataset(spa, "ds0", vol_size, block_size, 0, &zv);
286+
err = uzfs_create_dataset(spa, ds, vol_size, block_size, &zv);
284287
if (zv == NULL || err != 0) {
285288
printf("creating ds errored %d..\n", err);
286289
exit(1);
287290
}
288291

289-
err1 = uzfs_create_dataset(spa, "ds0", vol_size, block_size, 0, &zv1);
290-
err2 = uzfs_open_dataset(spa, "ds0", 0, &zv2);
291-
err3 = uzfs_open_dataset(spa, "ds1", 0, &zv3);
292-
err4 = uzfs_open_dataset(NULL, "ds1", 0, &zv4);
293-
err5 = uzfs_create_dataset(NULL, "ds0", vol_size, block_size, 0, &zv5);
292+
err1 = uzfs_create_dataset(spa, ds, vol_size, block_size, &zv1);
293+
err2 = uzfs_open_dataset(spa, ds, &zv2);
294+
err3 = uzfs_open_dataset(spa, "dsxyz", &zv3);
295+
err4 = uzfs_open_dataset(NULL, "dsxyz", &zv4);
296+
err5 = uzfs_create_dataset(NULL, ds, vol_size, block_size, &zv5);
294297
if (zv1 != NULL || zv2 != NULL || zv3 != NULL || zv4 != NULL ||
295298
zv5 != NULL || err1 == 0 || err2 == 0 || err3 == 0 || err4 == 0 ||
296299
err5 == 0) {
@@ -325,10 +328,11 @@ static void usage(int num)
325328
int count = sizeof (uzfs_tests) / sizeof (uzfs_tests[0]);
326329

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

333337
printf("Test id:\n");
334338

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

404-
while ((opt = getopt(argc, argv, "a:b:i:lm:sSt:v:V:wT:n:")) != EOF) {
405-
if (optarg != NULL)
406-
val = nicenumtoull(optarg);
408+
while ((opt = getopt(argc, argv, "a:b:cd:i:lm:p:sSt:v:V:wT:n:"))
409+
!= EOF) {
410+
switch (opt) {
411+
case 'd':
412+
case 'p':
413+
break;
414+
default:
415+
if (optarg != NULL)
416+
val = nicenumtoull(optarg);
417+
break;
418+
}
407419
switch (opt) {
408420
case 'a':
409421
active_size = val;
@@ -416,17 +428,24 @@ static void process_options(int argc, char **argv)
416428
case 'b':
417429
block_size = val;
418430
break;
431+
case 'c':
432+
create = 1;
433+
break;
434+
case 'd':
435+
ds = optarg;
436+
break;
419437
case 'i':
420438
io_block_size = val;
421439
break;
422440
case 'l':
423441
log_device = 1;
424442
break;
425443
case 'm':
426-
if (optarg != NULL)
427-
val = nicenumtoull(optarg);
428444
metaverify = val;
429445
break;
446+
case 'p':
447+
pool = optarg;
448+
break;
430449
case 's':
431450
sync_data = 1;
432451
break;
@@ -445,8 +464,6 @@ static void process_options(int argc, char **argv)
445464
? (active_size) : (vol_size);
446465
break;
447466
case 'V':
448-
if (optarg != NULL)
449-
val = nicenumtoull(optarg);
450467
verify = val;
451468
break;
452469
case 'w':
@@ -469,8 +486,9 @@ static void process_options(int argc, char **argv)
469486
active_size = vol_size = 1024*1024*1024ULL;
470487

471488
if (silent == 0) {
472-
printf("vol size: %lu active size: %lu\n", vol_size,
473-
active_size);
489+
printf("vol size: %lu active size: %lu create: %d\n", vol_size,
490+
active_size, create);
491+
printf("pool: %s ds: %s\n", pool, ds);
474492
printf("block size: %lu io blksize: %lu\n", block_size,
475493
io_block_size);
476494
printf("log: %d sync: %d silent: %d\n", log_device, sync_data,
@@ -484,12 +502,12 @@ void
484502
open_pool_ds(void **spa, void **zv)
485503
{
486504
int err;
487-
err = uzfs_open_pool("testp", spa);
505+
err = uzfs_open_pool(pool, spa);
488506
if (err != 0) {
489507
printf("pool open errored.. %d\n", err);
490508
exit(1);
491509
}
492-
err = uzfs_open_dataset(*spa, "ds0", sync_data, zv);
510+
err = uzfs_open_dataset(*spa, ds, zv);
493511
if (err != 0) {
494512
printf("ds open errored.. %d\n", err);
495513
exit(1);
@@ -512,9 +530,10 @@ unit_test_fn(void *arg)
512530
mutex_init(&mtx, NULL, MUTEX_DEFAULT, NULL);
513531
cv_init(&cv, NULL, CV_DEFAULT, NULL);
514532

515-
setup_unit_test();
516-
517-
unit_test_create_pool_ds();
533+
if (create == 1) {
534+
setup_unit_test();
535+
unit_test_create_pool_ds();
536+
}
518537

519538
open_pool_ds(&spa, &zv);
520539

cmd/uzfs_test/uzfs_test_sync.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ replay_fn(void *arg)
144144
zfs_txg_timeout = 30;
145145

146146
if (write_op == 1) {
147-
setup_unit_test();
148-
unit_test_create_pool_ds();
147+
if (create == 1) {
148+
setup_unit_test();
149+
unit_test_create_pool_ds();
150+
}
149151
open_pool_ds(&spa, &zv);
150152
} else if (verify != 0) {
151153
open_pool_ds(&spa, &zv);

cmd/uzfs_test/uzfs_test_sync.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
for i in {1..10}
33
do
4+
log_must setup_uzfs_test nolog 4096 nosync
45
sudo $UZFS_TEST -S -w -T 1 > $PWD/$1/uzfs_sync_data
56
if [ $? != 0 ]; then
67
exit 1;
@@ -13,6 +14,7 @@ do
1314
done
1415
for i in {1..10}
1516
do
17+
log_must setup_uzfs_test log 4096 nosync
1618
sudo $UZFS_TEST -S -l -T 1 -w > $PWD/$1/uzfs_sync_data
1719
if [ $? != 0 ]; then
1820
exit 1;
@@ -25,6 +27,7 @@ do
2527
done
2628
for i in {1..10}
2729
do
30+
log_must setup_uzfs_test nolog 4096 sync
2831
sudo $UZFS_TEST -S -s -T 1 -w > $PWD/$1/uzfs_sync_data
2932
if [ $? != 0 ]; then
3033
exit 1;
@@ -37,6 +40,7 @@ do
3740
done
3841
for i in {1..10}
3942
do
43+
log_must setup_uzfs_test log 4096 sync
4044
sudo $UZFS_TEST -S -l -s -T 1 -w > $PWD/$1/uzfs_sync_data
4145
if [ $? != 0 ]; then
4246
exit 1;
@@ -50,6 +54,7 @@ done
5054

5155
for i in {1..10}
5256
do
57+
log_must setup_uzfs_test nolog 65536 nosync
5358
sudo $UZFS_TEST -S -i 8192 -b 65536 -T 1 -w > $PWD/$1/uzfs_sync_data
5459
if [ $? != 0 ]; then
5560
exit 1;
@@ -62,6 +67,7 @@ do
6267
done
6368
for i in {1..10}
6469
do
70+
log_must setup_uzfs_test log 65536 nosync
6571
sudo $UZFS_TEST -S -i 8192 -b 65536 -l -T 1 -w > $PWD/$1/uzfs_sync_data
6672
if [ $? != 0 ]; then
6773
exit 1;
@@ -74,6 +80,7 @@ do
7480
done
7581
for i in {1..10}
7682
do
83+
log_must setup_uzfs_test nolog 65536 sync
7784
sudo $UZFS_TEST -S -s -i 8192 -b 65536 -T 1 -w > $PWD/$1/uzfs_sync_data
7885
if [ $? != 0 ]; then
7986
exit 1;
@@ -86,6 +93,7 @@ do
8693
done
8794
for i in {1..10}
8895
do
96+
log_must setup_uzfs_test log 65536 sync
8997
sudo $UZFS_TEST -S -i 8192 -b 65536 -l -s -T 1 -w > $PWD/$1/uzfs_sync_data
9098
if [ $? != 0 ]; then
9199
exit 1;

include/sys/uzfs_zvol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ struct zvol_state {
6060
zfs_rlock_t zv_range_lock; /* range lock */
6161
zfs_rlock_t zv_mrange_lock; /* range lock */
6262
spa_t *zv_spa; /* spa */
63-
int zv_sync; /* sync property of zv */
6463
uint64_t zv_volmetablocksize; /* meta block size */
6564
uint64_t zv_volmetadatasize; /* volume meta data size */
6665

include/uzfs_mgmt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ extern int uzfs_create_pool(char *name, char *path, void **spa);
2828
extern int uzfs_open_pool(char *name, void **spa);
2929
extern int uzfs_vdev_add(void *spa, char *path, int ashift, int log);
3030
extern int uzfs_create_dataset(void *spa, char *ds, uint64_t vol_size,
31-
uint64_t block_size, int sync, void **zv);
32-
extern int uzfs_open_dataset(void *spa, char *ds, int sync, void **zv);
31+
uint64_t block_size, void **zv);
32+
extern int uzfs_open_dataset(void *spa, char *ds, void **zv);
3333
extern uint64_t uzfs_synced_txg(void *zv);
3434
extern void uzfs_close_dataset(void *zv);
3535
extern void uzfs_close_pool(void *spa);

include/uzfs_test.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ extern int write_op;
3333
extern int verify_err;
3434
extern int verify;
3535
extern int test_iterations;
36+
extern uint32_t create;
37+
extern char *pool;
38+
extern char *ds;
3639

3740
extern unsigned long zfs_arc_max;
3841
extern unsigned long zfs_arc_min;

lib/libzpool/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ USER_C = \
2121
uzfs_io.c \
2222
uzfs_task.c \
2323
uzfs_mgmt.c \
24+
uzfs_test_mgmt.c \
2425
uzfs_zap.c \
2526
vdev_disk_aio.c
2627

lib/libzpool/uzfs_io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int
2828
uzfs_write_data(zvol_state_t *zv, char *buf, uint64_t offset, uint64_t len,
2929
blk_metadata_t *metadata)
3030
{
31-
uint64_t bytes = 0, sync = zv->zv_sync;
31+
uint64_t bytes = 0, sync;
3232
uint64_t volsize = zv->zv_volsize;
3333
uint64_t blocksize = zv->zv_volblocksize;
3434
uint64_t end = len + offset;
@@ -42,6 +42,7 @@ uzfs_write_data(zvol_state_t *zv, char *buf, uint64_t offset, uint64_t len,
4242
uint64_t metadatasize = zv->zv_volmetadatasize;
4343
uint64_t len_in_first_aligned_block = 0;
4444

45+
sync = dmu_objset_syncprop(os);
4546
if (zv->zv_volmetablocksize == 0)
4647
metadata = NULL;
4748
/*

lib/libzpool/uzfs_mgmt.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ uzfs_objset_create_cb(objset_t *new_os, void *arg, cred_t *cr, dmu_tx_t *tx)
261261

262262
/* owns objset with name 'ds_name' in pool 'spa'. Sets 'sync' property */
263263
int
264-
uzfs_open_dataset(spa_t *spa, const char *ds_name, int sync, zvol_state_t **z)
264+
uzfs_open_dataset(spa_t *spa, const char *ds_name, zvol_state_t **z)
265265
{
266266
char name[ZFS_MAX_DATASET_NAME_LEN];
267267
zvol_state_t *zv = NULL;
@@ -331,7 +331,6 @@ uzfs_open_dataset(spa_t *spa, const char *ds_name, int sync, zvol_state_t **z)
331331
}
332332

333333
zv->zv_zilog = zil_open(os, zvol_get_data);
334-
zv->zv_sync = sync;
335334
zv->zv_volblocksize = block_size;
336335
zv->zv_volsize = vol_size;
337336

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

350349
/*
351350
* Creates dataset 'ds_name' in pool 'spa' with volume size 'vol_size',
352-
* block size as 'block_size' and with 'sync' property
351+
* block size as 'block_size'
353352
*/
354353
int
355354
uzfs_create_dataset(spa_t *spa, char *ds_name, uint64_t vol_size,
356-
uint64_t block_size, int sync, zvol_state_t **z)
355+
uint64_t block_size, zvol_state_t **z)
357356
{
358357
char name[ZFS_MAX_DATASET_NAME_LEN];
359358
zvol_state_t *zv = NULL;
@@ -375,7 +374,7 @@ uzfs_create_dataset(spa_t *spa, char *ds_name, uint64_t vol_size,
375374
if (error)
376375
goto ret;
377376

378-
error = uzfs_open_dataset(spa, ds_name, sync, &zv);
377+
error = uzfs_open_dataset(spa, ds_name, &zv);
379378
if (error != 0) {
380379
zv = NULL;
381380
goto ret;
@@ -385,12 +384,6 @@ uzfs_create_dataset(spa_t *spa, char *ds_name, uint64_t vol_size,
385384
return (error);
386385
}
387386

388-
uint64_t
389-
uzfs_synced_txg(zvol_state_t *zv)
390-
{
391-
return (spa_last_synced_txg(zv->zv_spa));
392-
}
393-
394387
/* disowns, closes dataset */
395388
void
396389
uzfs_close_dataset(zvol_state_t *zv)

lib/libzpool/uzfs_test_mgmt.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9+
* or http://www.opensolaris.org/os/licensing.
10+
* See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*
13+
* When distributing Covered Code, include this CDDL HEADER in each
14+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15+
* If applicable, add the following below this CDDL HEADER, with the
16+
* fields enclosed by brackets "[]" replaced with your own identifying
17+
* information: Portions Copyright [yyyy] [name of copyright owner]
18+
*
19+
* CDDL HEADER END
20+
*/
21+
22+
#include <sys/dmu_objset.h>
23+
#include <sys/uzfs_zvol.h>
24+
25+
uint64_t
26+
uzfs_synced_txg(zvol_state_t *zv)
27+
{
28+
return (spa_last_synced_txg(zv->zv_spa));
29+
}

0 commit comments

Comments
 (0)