Skip to content

Commit

Permalink
4951 ZFS administrative commands should use reserved space, not fail …
Browse files Browse the repository at this point in the history
…with ENOSPC

Reviewed by: John Kennedy <[email protected]>
Reviewed by: George Wilson <[email protected]>
Reviewed by: Christopher Siden <[email protected]>
Reviewed by: Dan McDonald <[email protected]>
Approved by: Garrett D'Amore <[email protected]>
  • Loading branch information
ahrens authored and Christopher Siden committed Jul 9, 2014
1 parent cd67d23 commit 7d46dc6
Show file tree
Hide file tree
Showing 26 changed files with 258 additions and 76 deletions.
7 changes: 5 additions & 2 deletions usr/src/cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013 by Delphix. All rights reserved.
* Copyright (c) 2011, 2014 by Delphix. All rights reserved.
* Copyright 2012 Milan Jurik. All rights reserved.
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
* Copyright (c) 2013 Steven Hartland. All rights reserved.
Expand Down Expand Up @@ -6708,6 +6708,9 @@ zfs_do_bookmark(int argc, char **argv)
case ENOTSUP:
err_msg = "bookmark feature not enabled";
break;
case ENOSPC:
err_msg = "out of space";
break;
default:
err_msg = "unknown error";
break;
Expand All @@ -6716,7 +6719,7 @@ zfs_do_bookmark(int argc, char **argv)
dgettext(TEXT_DOMAIN, err_msg));
}

return (ret);
return (ret != 0);

usage:
usage(B_FALSE);
Expand Down
7 changes: 4 additions & 3 deletions usr/src/cmd/zhack/zhack.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

/*
* Copyright (c) 2013 by Delphix. All rights reserved.
* Copyright (c) 2011, 2014 by Delphix. All rights reserved.
* Copyright (c) 2013 Steven Hartland. All rights reserved.
*/

Expand Down Expand Up @@ -362,7 +362,7 @@ zhack_do_feature_enable(int argc, char **argv)
feature.fi_guid);

VERIFY0(dsl_sync_task(spa_name(spa), NULL,
zhack_feature_enable_sync, &feature, 5));
zhack_feature_enable_sync, &feature, 5, ZFS_SPACE_CHECK_NORMAL));

spa_close(spa, FTAG);

Expand Down Expand Up @@ -473,7 +473,8 @@ zhack_do_feature_ref(int argc, char **argv)
}

VERIFY0(dsl_sync_task(spa_name(spa), NULL,
decr ? feature_decr_sync : feature_incr_sync, &feature, 5));
decr ? feature_decr_sync : feature_incr_sync, &feature,
5, ZFS_SPACE_CHECK_NORMAL));

spa_close(spa, FTAG);
}
Expand Down
3 changes: 2 additions & 1 deletion usr/src/pkg/manifests/system-test-zfstest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#

#
# Copyright (c) 2013 by Delphix. All rights reserved.
# Copyright (c) 2012, 2014 by Delphix. All rights reserved.
# Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
#

Expand Down Expand Up @@ -1817,6 +1817,7 @@ file path=opt/zfs-tests/tests/functional/nestedfs/setup mode=0555
file path=opt/zfs-tests/tests/functional/no_space/cleanup mode=0555
file path=opt/zfs-tests/tests/functional/no_space/enospc.cfg mode=0555
file path=opt/zfs-tests/tests/functional/no_space/enospc_001_pos mode=0555
file path=opt/zfs-tests/tests/functional/no_space/enospc_002_pos mode=0555
file path=opt/zfs-tests/tests/functional/no_space/setup mode=0555
file path=opt/zfs-tests/tests/functional/nopwrite/cleanup mode=0555
file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite.shlib mode=0555
Expand Down
4 changes: 2 additions & 2 deletions usr/src/test/zfs-tests/runfiles/delphix.run
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#

#
# Copyright (c) 2013 by Delphix. All rights reserved.
# Copyright (c) 2012, 2014 by Delphix. All rights reserved.
#

[DEFAULT]
Expand Down Expand Up @@ -397,7 +397,7 @@ tests = ['mv_files_001_pos', 'mv_files_002_pos']
tests = ['nestedfs_001_pos']

[/opt/zfs-tests/tests/functional/no_space]
tests = ['enospc_001_pos']
tests = ['enospc_001_pos', 'enospc_002_pos']

[/opt/zfs-tests/tests/functional/nopwrite]
tests = ['nopwrite_copies', 'nopwrite_mtime', 'nopwrite_negative',
Expand Down
2 changes: 1 addition & 1 deletion usr/src/test/zfs-tests/runfiles/omnios.run
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ tests = ['mv_files_001_pos', 'mv_files_002_pos']
tests = ['nestedfs_001_pos']

[/opt/zfs-tests/tests/functional/no_space]
tests = ['enospc_001_pos']
tests = ['enospc_001_pos', 'enospc_002_pos']

[/opt/zfs-tests/tests/functional/nopwrite]
tests = ['nopwrite_copies', 'nopwrite_mtime', 'nopwrite_negative',
Expand Down
2 changes: 1 addition & 1 deletion usr/src/test/zfs-tests/runfiles/openindiana.run
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ tests = ['mv_files_001_pos', 'mv_files_002_pos']
tests = ['nestedfs_001_pos']

[/opt/zfs-tests/tests/functional/no_space]
tests = ['enospc_001_pos']
tests = ['enospc_001_pos', 'enospc_002_pos']

[/opt/zfs-tests/tests/functional/nopwrite]
tests = ['nopwrite_copies', 'nopwrite_mtime', 'nopwrite_negative',
Expand Down
3 changes: 2 additions & 1 deletion usr/src/test/zfs-tests/tests/functional/no_space/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#

#
# Copyright (c) 2013 by Delphix. All rights reserved.
# Copyright (c) 2013, 2014 by Delphix. All rights reserved.
#

include $(SRC)/Makefile.master
Expand All @@ -20,6 +20,7 @@ TESTDIR = $(ROOTOPTPKG)/tests/functional/no_space

PROGS = cleanup \
enospc_001_pos \
enospc_002_pos \
setup

FILES = enospc.cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Use is subject to license terms.
#
#
# Copyright (c) 2013 by Delphix. All rights reserved.
# Copyright (c) 2013, 2014 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib
Expand All @@ -46,6 +46,14 @@

verify_runnable "both"

function cleanup
{
rm -f $TESTDIR/$TESTFILE0
rm -f $TESTDIR/$TESTFILE1
}

log_onexit cleanup

log_assert "ENOSPC is returned when file system is full."
log_must $ZFS set compression=off $TESTPOOL/$TESTFS

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#

#
# Copyright (c) 2014 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/no_space/enospc.cfg

#
# DESCRIPTION:
# After filling a filesystem, certain zfs commands are allowed.
#

verify_runnable "both"

log_assert "ENOSPC is returned when file system is full."
sync
log_must $ZFS set compression=off $TESTPOOL/$TESTFS
log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap

log_note "Writing file: $TESTFILE0 until ENOSPC."
$FILE_WRITE -o create -f $TESTDIR/$TESTFILE0 -b $BLOCKSZ \
-c $NUM_WRITES -d $DATA
ret=$?

(( $ret != $ENOSPC )) && \
log_fail "$TESTFILE0 returned: $ret rather than ENOSPC."

log_mustnot_expect space $ZFS create $TESTPOOL/$TESTFS/subfs
log_mustnot_expect space $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/clone
log_mustnot_expect space $ZFS snapshot $TESTPOOL/$TESTFS@snap2
log_mustnot_expect space $ZFS bookmark \
$TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS#bookmark

log_must $ZFS send $TESTPOOL/$TESTFS@snap >/tmp/stream.$$
log_mustnot_expect space $ZFS receive $TESTPOOL/$TESTFS/recvd </tmp/stream.$$
log_must rm /tmp/stream.$$

log_must $ZFS rename $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS@snap_newname
log_must $ZFS rename $TESTPOOL/$TESTFS@snap_newname $TESTPOOL/$TESTFS@snap
log_must $ZFS rename $TESTPOOL/$TESTFS $TESTPOOL/${TESTFS}_newname
log_must $ZFS rename $TESTPOOL/${TESTFS}_newname $TESTPOOL/$TESTFS
log_must $ZFS allow staff snapshot $TESTPOOL/$TESTFS
log_must $ZFS unallow staff snapshot $TESTPOOL/$TESTFS
log_must $ZFS set user:prop=value $TESTPOOL/$TESTFS
log_must $ZFS set quota=1EB $TESTPOOL/$TESTFS
log_must $ZFS set quota=none $TESTPOOL/$TESTFS
log_must $ZFS set reservation=1KB $TESTPOOL/$TESTFS
log_must $ZFS set reservation=none $TESTPOOL/$TESTFS
log_must $ZPOOL scrub $TESTPOOL
$ZPOOL scrub -s $TESTPOOL
log_must $ZPOOL set comment="Use the force, Luke." $TESTPOOL
log_must $ZPOOL set comment="" $TESTPOOL

# destructive tests must come last
log_must $ZFS rollback $TESTPOOL/$TESTFS@snap
log_must $ZFS destroy $TESTPOOL/$TESTFS@snap

log_pass "ENOSPC returned as expected."
6 changes: 4 additions & 2 deletions usr/src/uts/common/fs/zfs/dmu_objset.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,8 @@ dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
doca.doca_type = type;

return (dsl_sync_task(name,
dmu_objset_create_check, dmu_objset_create_sync, &doca, 5));
dmu_objset_create_check, dmu_objset_create_sync, &doca,
5, ZFS_SPACE_CHECK_NORMAL));
}

typedef struct dmu_objset_clone_arg {
Expand Down Expand Up @@ -931,7 +932,8 @@ dmu_objset_clone(const char *clone, const char *origin)
doca.doca_cred = CRED();

return (dsl_sync_task(clone,
dmu_objset_clone_check, dmu_objset_clone_sync, &doca, 5));
dmu_objset_clone_check, dmu_objset_clone_sync, &doca,
5, ZFS_SPACE_CHECK_NORMAL));
}

int
Expand Down
6 changes: 3 additions & 3 deletions usr/src/uts/common/fs/zfs/dmu_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ dmu_recv_begin(char *tofs, char *tosnap, struct drr_begin *drrb,
drba.drba_cred = CRED();

return (dsl_sync_task(tofs, dmu_recv_begin_check, dmu_recv_begin_sync,
&drba, 5));
&drba, 5, ZFS_SPACE_CHECK_NORMAL));
}

struct restorearg {
Expand Down Expand Up @@ -2022,7 +2022,7 @@ dmu_recv_existing_end(dmu_recv_cookie_t *drc)

error = dsl_sync_task(drc->drc_tofs,
dmu_recv_end_check, dmu_recv_end_sync, drc,
dmu_recv_end_modified_blocks);
dmu_recv_end_modified_blocks, ZFS_SPACE_CHECK_NORMAL);

if (error != 0)
dmu_recv_cleanup_ds(drc);
Expand All @@ -2036,7 +2036,7 @@ dmu_recv_new_end(dmu_recv_cookie_t *drc)

error = dsl_sync_task(drc->drc_tofs,
dmu_recv_end_check, dmu_recv_end_sync, drc,
dmu_recv_end_modified_blocks);
dmu_recv_end_modified_blocks, ZFS_SPACE_CHECK_NORMAL);

if (error != 0) {
dmu_recv_cleanup_ds(drc);
Expand Down
8 changes: 5 additions & 3 deletions usr/src/uts/common/fs/zfs/dsl_bookmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* CDDL HEADER END
*/
/*
* Copyright (c) 2013 by Delphix. All rights reserved.
* Copyright (c) 2013, 2014 by Delphix. All rights reserved.
*/

#include <sys/zfs_context.h>
Expand Down Expand Up @@ -246,7 +246,8 @@ dsl_bookmark_create(nvlist_t *bmarks, nvlist_t *errors)
dbca.dbca_errors = errors;

return (dsl_sync_task(nvpair_name(pair), dsl_bookmark_create_check,
dsl_bookmark_create_sync, &dbca, fnvlist_num_pairs(bmarks)));
dsl_bookmark_create_sync, &dbca,
fnvlist_num_pairs(bmarks), ZFS_SPACE_CHECK_NORMAL));
}

int
Expand Down Expand Up @@ -448,7 +449,8 @@ dsl_bookmark_destroy(nvlist_t *bmarks, nvlist_t *errors)
dbda.dbda_success = fnvlist_alloc();

rv = dsl_sync_task(nvpair_name(pair), dsl_bookmark_destroy_check,
dsl_bookmark_destroy_sync, &dbda, fnvlist_num_pairs(bmarks));
dsl_bookmark_destroy_sync, &dbda, fnvlist_num_pairs(bmarks),
ZFS_SPACE_CHECK_RESERVED);
fnvlist_free(dbda.dbda_success);
return (rv);
}
18 changes: 11 additions & 7 deletions usr/src/uts/common/fs/zfs/dsl_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ dsl_dataset_snapshot(nvlist_t *snaps, nvlist_t *props, nvlist_t *errors)
if (error == 0) {
error = dsl_sync_task(firstname, dsl_dataset_snapshot_check,
dsl_dataset_snapshot_sync, &ddsa,
fnvlist_num_pairs(snaps) * 3);
fnvlist_num_pairs(snaps) * 3, ZFS_SPACE_CHECK_NORMAL);
}

if (suspended != NULL) {
Expand Down Expand Up @@ -1454,7 +1454,7 @@ dsl_dataset_snapshot_tmp(const char *fsname, const char *snapname,
}

error = dsl_sync_task(fsname, dsl_dataset_snapshot_tmp_check,
dsl_dataset_snapshot_tmp_sync, &ddsta, 3);
dsl_dataset_snapshot_tmp_sync, &ddsta, 3, ZFS_SPACE_CHECK_RESERVED);

if (needsuspend)
zil_resume(cookie);
Expand Down Expand Up @@ -1805,7 +1805,8 @@ dsl_dataset_rename_snapshot(const char *fsname,
ddrsa.ddrsa_recursive = recursive;

return (dsl_sync_task(fsname, dsl_dataset_rename_snapshot_check,
dsl_dataset_rename_snapshot_sync, &ddrsa, 1));
dsl_dataset_rename_snapshot_sync, &ddrsa,
1, ZFS_SPACE_CHECK_RESERVED));
}

/*
Expand Down Expand Up @@ -1980,7 +1981,8 @@ dsl_dataset_rollback(const char *fsname, void *owner, nvlist_t *result)
ddra.ddra_result = result;

return (dsl_sync_task(fsname, dsl_dataset_rollback_check,
dsl_dataset_rollback_sync, &ddra, 1));
dsl_dataset_rollback_sync, &ddra,
1, ZFS_SPACE_CHECK_RESERVED));
}

struct promotenode {
Expand Down Expand Up @@ -2501,7 +2503,8 @@ dsl_dataset_promote(const char *name, char *conflsnap)
ddpa.cr = CRED();

return (dsl_sync_task(name, dsl_dataset_promote_check,
dsl_dataset_promote_sync, &ddpa, 2 + numsnaps));
dsl_dataset_promote_sync, &ddpa,
2 + numsnaps, ZFS_SPACE_CHECK_RESERVED));
}

int
Expand Down Expand Up @@ -2846,7 +2849,7 @@ dsl_dataset_set_refquota(const char *dsname, zprop_source_t source,
ddsqra.ddsqra_value = refquota;

return (dsl_sync_task(dsname, dsl_dataset_set_refquota_check,
dsl_dataset_set_refquota_sync, &ddsqra, 0));
dsl_dataset_set_refquota_sync, &ddsqra, 0, ZFS_SPACE_CHECK_NONE));
}

static int
Expand Down Expand Up @@ -2961,7 +2964,8 @@ dsl_dataset_set_refreservation(const char *dsname, zprop_source_t source,
ddsqra.ddsqra_value = refreservation;

return (dsl_sync_task(dsname, dsl_dataset_set_refreservation_check,
dsl_dataset_set_refreservation_sync, &ddsqra, 0));
dsl_dataset_set_refreservation_sync, &ddsqra,
0, ZFS_SPACE_CHECK_NONE));
}

/*
Expand Down
4 changes: 2 additions & 2 deletions usr/src/uts/common/fs/zfs/dsl_deleg.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013 by Delphix. All rights reserved.
* Copyright (c) 2011, 2014 by Delphix. All rights reserved.
*/

/*
Expand Down Expand Up @@ -282,7 +282,7 @@ dsl_deleg_set(const char *ddname, nvlist_t *nvp, boolean_t unset)

return (dsl_sync_task(ddname, dsl_deleg_check,
unset ? dsl_deleg_unset_sync : dsl_deleg_set_sync,
&dda, fnvlist_num_pairs(nvp)));
&dda, fnvlist_num_pairs(nvp), ZFS_SPACE_CHECK_RESERVED));
}

/*
Expand Down
Loading

0 comments on commit 7d46dc6

Please sign in to comment.