Skip to content

Commit 831baf0

Browse files
Keith M Wesolowskibehlendorf
authored andcommitted
Illumos #3875
3875 panic in zfs_root() after failed rollback Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Matthew Ahrens <mahrens@delphix.com> Approved by: Gordon Ross <gwr@nexenta.com> References: https://www.illumos.org/issues/3875 illumos/illumos-gate@91948b5 Ported-by: Richard Yao <ryao@gentoo.org> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #1775
1 parent 1958067 commit 831baf0

File tree

8 files changed

+167
-70
lines changed

8 files changed

+167
-70
lines changed

include/sys/dmu_objset.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct objset {
136136
int dmu_objset_hold(const char *name, void *tag, objset_t **osp);
137137
int dmu_objset_own(const char *name, dmu_objset_type_t type,
138138
boolean_t readonly, void *tag, objset_t **osp);
139+
void dmu_objset_refresh_ownership(objset_t *os, void *tag);
139140
void dmu_objset_rele(objset_t *os, void *tag);
140141
void dmu_objset_disown(objset_t *os, void *tag);
141142
int dmu_objset_from_ds(struct dsl_dataset *ds, objset_t **osp);

include/sys/dmu_send.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ typedef struct dmu_recv_cookie {
5555
struct avl_tree *drc_guid_to_ds_map;
5656
zio_cksum_t drc_cksum;
5757
uint64_t drc_newsnapobj;
58+
void *drc_owner;
5859
} dmu_recv_cookie_t;
5960

6061
int dmu_recv_begin(char *tofs, char *tosnap, struct drr_begin *drrb,
6162
boolean_t force, char *origin, dmu_recv_cookie_t *drc);
6263
int dmu_recv_stream(dmu_recv_cookie_t *drc, struct vnode *vp, offset_t *voffp,
6364
int cleanup_fd, uint64_t *action_handlep);
64-
int dmu_recv_end(dmu_recv_cookie_t *drc);
65+
int dmu_recv_end(dmu_recv_cookie_t *drc, void *owner);
6566

6667
#endif /* _DMU_SEND_H */

include/sys/dsl_dataset.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void dsl_dataset_long_rele(dsl_dataset_t *ds, void *tag);
248248
boolean_t dsl_dataset_long_held(dsl_dataset_t *ds);
249249

250250
int dsl_dataset_clone_swap_check_impl(dsl_dataset_t *clone,
251-
dsl_dataset_t *origin_head, boolean_t force);
251+
dsl_dataset_t *origin_head, boolean_t force, void *owner, dmu_tx_t *tx);
252252
void dsl_dataset_clone_swap_sync_impl(dsl_dataset_t *clone,
253253
dsl_dataset_t *origin_head, dmu_tx_t *tx);
254254
int dsl_dataset_snapshot_check_impl(dsl_dataset_t *ds, const char *snapname,
@@ -265,7 +265,7 @@ int dsl_dataset_snap_lookup(dsl_dataset_t *ds, const char *name,
265265
int dsl_dataset_snap_remove(dsl_dataset_t *ds, const char *name, dmu_tx_t *tx);
266266
void dsl_dataset_set_refreservation_sync_impl(dsl_dataset_t *ds,
267267
zprop_source_t source, uint64_t value, dmu_tx_t *tx);
268-
int dsl_dataset_rollback(const char *fsname);
268+
int dsl_dataset_rollback(const char *fsname, void *owner);
269269

270270
#ifdef ZFS_DEBUG
271271
#define dprintf_ds(ds, fmt, ...) do { \

module/zfs/dmu_objset.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,38 @@ dmu_objset_rele(objset_t *os, void *tag)
517517
dsl_pool_rele(dp, tag);
518518
}
519519

520+
/*
521+
* When we are called, os MUST refer to an objset associated with a dataset
522+
* that is owned by 'tag'; that is, is held and long held by 'tag' and ds_owner
523+
* == tag. We will then release and reacquire ownership of the dataset while
524+
* holding the pool config_rwlock to avoid intervening namespace or ownership
525+
* changes may occur.
526+
*
527+
* This exists solely to accommodate zfs_ioc_userspace_upgrade()'s desire to
528+
* release the hold on its dataset and acquire a new one on the dataset of the
529+
* same name so that it can be partially torn down and reconstructed.
530+
*/
531+
void
532+
dmu_objset_refresh_ownership(objset_t *os, void *tag)
533+
{
534+
dsl_pool_t *dp;
535+
dsl_dataset_t *ds, *newds;
536+
char name[MAXNAMELEN];
537+
538+
ds = os->os_dsl_dataset;
539+
VERIFY3P(ds, !=, NULL);
540+
VERIFY3P(ds->ds_owner, ==, tag);
541+
VERIFY(dsl_dataset_long_held(ds));
542+
543+
dsl_dataset_name(ds, name);
544+
dp = dmu_objset_pool(os);
545+
dsl_pool_config_enter(dp, FTAG);
546+
dmu_objset_disown(os, tag);
547+
VERIFY0(dsl_dataset_own(dp, name, tag, &newds));
548+
VERIFY3P(newds, ==, os->os_dsl_dataset);
549+
dsl_pool_config_exit(dp, FTAG);
550+
}
551+
520552
void
521553
dmu_objset_disown(objset_t *os, void *tag)
522554
{

module/zfs/dmu_send.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ dmu_recv_end_check(void *arg, dmu_tx_t *tx)
16121612
}
16131613
}
16141614
error = dsl_dataset_clone_swap_check_impl(drc->drc_ds,
1615-
origin_head, drc->drc_force);
1615+
origin_head, drc->drc_force, drc->drc_owner, tx);
16161616
if (error != 0) {
16171617
dsl_dataset_rele(origin_head, FTAG);
16181618
return (error);
@@ -1685,6 +1685,9 @@ dmu_recv_end_sync(void *arg, dmu_tx_t *tx)
16851685

16861686
dsl_dataset_rele(origin_head, FTAG);
16871687
dsl_destroy_head_sync_impl(drc->drc_ds, tx);
1688+
1689+
if (drc->drc_owner != NULL)
1690+
VERIFY3P(origin_head->ds_owner, ==, drc->drc_owner);
16881691
} else {
16891692
dsl_dataset_t *ds = drc->drc_ds;
16901693

@@ -1787,8 +1790,10 @@ dmu_recv_new_end(dmu_recv_cookie_t *drc)
17871790
}
17881791

17891792
int
1790-
dmu_recv_end(dmu_recv_cookie_t *drc)
1793+
dmu_recv_end(dmu_recv_cookie_t *drc, void *owner)
17911794
{
1795+
drc->drc_owner = owner;
1796+
17921797
if (drc->drc_newfs)
17931798
return (dmu_recv_new_end(drc));
17941799
else

module/zfs/dsl_dataset.c

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,16 +1669,52 @@ dsl_dataset_rename_snapshot(const char *fsname,
16691669
dsl_dataset_rename_snapshot_sync, &ddrsa, 1));
16701670
}
16711671

1672+
/*
1673+
* If we're doing an ownership handoff, we need to make sure that there is
1674+
* only one long hold on the dataset. We're not allowed to change anything here
1675+
* so we don't permanently release the long hold or regular hold here. We want
1676+
* to do this only when syncing to avoid the dataset unexpectedly going away
1677+
* when we release the long hold.
1678+
*/
1679+
static int
1680+
dsl_dataset_handoff_check(dsl_dataset_t *ds, void *owner, dmu_tx_t *tx)
1681+
{
1682+
boolean_t held;
1683+
1684+
if (!dmu_tx_is_syncing(tx))
1685+
return (0);
1686+
1687+
if (owner != NULL) {
1688+
VERIFY3P(ds->ds_owner, ==, owner);
1689+
dsl_dataset_long_rele(ds, owner);
1690+
}
1691+
1692+
held = dsl_dataset_long_held(ds);
1693+
1694+
if (owner != NULL)
1695+
dsl_dataset_long_hold(ds, owner);
1696+
1697+
if (held)
1698+
return (SET_ERROR(EBUSY));
1699+
1700+
return (0);
1701+
}
1702+
1703+
typedef struct dsl_dataset_rollback_arg {
1704+
const char *ddra_fsname;
1705+
void *ddra_owner;
1706+
} dsl_dataset_rollback_arg_t;
1707+
16721708
static int
16731709
dsl_dataset_rollback_check(void *arg, dmu_tx_t *tx)
16741710
{
1675-
const char *fsname = arg;
1711+
dsl_dataset_rollback_arg_t *ddra = arg;
16761712
dsl_pool_t *dp = dmu_tx_pool(tx);
16771713
dsl_dataset_t *ds;
16781714
int64_t unused_refres_delta;
16791715
int error;
16801716

1681-
error = dsl_dataset_hold(dp, fsname, FTAG, &ds);
1717+
error = dsl_dataset_hold(dp, ddra->ddra_fsname, FTAG, &ds);
16821718
if (error != 0)
16831719
return (error);
16841720

@@ -1694,9 +1730,10 @@ dsl_dataset_rollback_check(void *arg, dmu_tx_t *tx)
16941730
return (SET_ERROR(EINVAL));
16951731
}
16961732

1697-
if (dsl_dataset_long_held(ds)) {
1733+
error = dsl_dataset_handoff_check(ds, ddra->ddra_owner, tx);
1734+
if (error != 0) {
16981735
dsl_dataset_rele(ds, FTAG);
1699-
return (SET_ERROR(EBUSY));
1736+
return (error);
17001737
}
17011738

17021739
/*
@@ -1733,12 +1770,12 @@ dsl_dataset_rollback_check(void *arg, dmu_tx_t *tx)
17331770
static void
17341771
dsl_dataset_rollback_sync(void *arg, dmu_tx_t *tx)
17351772
{
1736-
const char *fsname = arg;
1773+
dsl_dataset_rollback_arg_t *ddra = arg;
17371774
dsl_pool_t *dp = dmu_tx_pool(tx);
17381775
dsl_dataset_t *ds, *clone;
17391776
uint64_t cloneobj;
17401777

1741-
VERIFY0(dsl_dataset_hold(dp, fsname, FTAG, &ds));
1778+
VERIFY0(dsl_dataset_hold(dp, ddra->ddra_fsname, FTAG, &ds));
17421779

17431780
cloneobj = dsl_dataset_create_sync(ds->ds_dir, "%rollback",
17441781
ds->ds_prev, DS_CREATE_FLAG_NODIRTY, kcred, tx);
@@ -1754,11 +1791,26 @@ dsl_dataset_rollback_sync(void *arg, dmu_tx_t *tx)
17541791
dsl_dataset_rele(ds, FTAG);
17551792
}
17561793

1794+
/*
1795+
* If owner != NULL:
1796+
*
1797+
* - The existing dataset MUST be owned by the specified owner at entry
1798+
* - Upon return, dataset will still be held by the same owner, whether we
1799+
* succeed or not.
1800+
*
1801+
* This mode is required any time the existing filesystem is mounted. See
1802+
* notes above zfs_suspend_fs() for further details.
1803+
*/
17571804
int
1758-
dsl_dataset_rollback(const char *fsname)
1805+
dsl_dataset_rollback(const char *fsname, void *owner)
17591806
{
1807+
dsl_dataset_rollback_arg_t ddra;
1808+
1809+
ddra.ddra_fsname = fsname;
1810+
ddra.ddra_owner = owner;
1811+
17601812
return (dsl_sync_task(fsname, dsl_dataset_rollback_check,
1761-
dsl_dataset_rollback_sync, (void *)fsname, 1));
1813+
dsl_dataset_rollback_sync, (void *)&ddra, 1));
17621814
}
17631815

17641816
struct promotenode {
@@ -2276,7 +2328,7 @@ dsl_dataset_promote(const char *name, char *conflsnap)
22762328

22772329
int
22782330
dsl_dataset_clone_swap_check_impl(dsl_dataset_t *clone,
2279-
dsl_dataset_t *origin_head, boolean_t force)
2331+
dsl_dataset_t *origin_head, boolean_t force, void *owner, dmu_tx_t *tx)
22802332
{
22812333
int64_t unused_refres_delta;
22822334

@@ -2305,7 +2357,7 @@ dsl_dataset_clone_swap_check_impl(dsl_dataset_t *clone,
23052357
return (SET_ERROR(ETXTBSY));
23062358

23072359
/* origin_head should have no long holds (e.g. is not mounted) */
2308-
if (dsl_dataset_long_held(origin_head))
2360+
if (dsl_dataset_handoff_check(origin_head, owner, tx))
23092361
return (SET_ERROR(EBUSY));
23102362

23112363
/* check amount of any unconsumed refreservation */

module/zfs/zfs_ioctl.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ zfs_sb_hold(const char *name, void *tag, zfs_sb_t **zsbp, boolean_t writer)
13491349
/*
13501350
* XXX we could probably try again, since the unmounting
13511351
* thread should be just about to disassociate the
1352-
* objset from the zfsvfs.
1352+
* objset from the zsb.
13531353
*/
13541354
rrw_exit(&(*zsbp)->z_teardown_lock, tag);
13551355
return (SET_ERROR(EBUSY));
@@ -3504,13 +3504,13 @@ zfs_ioc_rollback(zfs_cmd_t *zc)
35043504
if (error == 0) {
35053505
int resume_err;
35063506

3507-
error = dsl_dataset_rollback(zc->zc_name);
3507+
error = dsl_dataset_rollback(zc->zc_name, zsb);
35083508
resume_err = zfs_resume_fs(zsb, zc->zc_name);
35093509
error = error ? error : resume_err;
35103510
}
35113511
deactivate_super(zsb->z_sb);
35123512
} else {
3513-
error = dsl_dataset_rollback(zc->zc_name);
3513+
error = dsl_dataset_rollback(zc->zc_name, NULL);
35143514
}
35153515
return (error);
35163516
}
@@ -4038,13 +4038,13 @@ zfs_ioc_recv(zfs_cmd_t *zc)
40384038
* If the suspend fails, then the recv_end will
40394039
* likely also fail, and clean up after itself.
40404040
*/
4041-
end_err = dmu_recv_end(&drc);
4041+
end_err = dmu_recv_end(&drc, zsb);
40424042
if (error == 0)
40434043
error = zfs_resume_fs(zsb, tofs);
40444044
error = error ? error : end_err;
40454045
deactivate_super(zsb->z_sb);
40464046
} else {
4047-
error = dmu_recv_end(&drc);
4047+
error = dmu_recv_end(&drc, NULL);
40484048
}
40494049
}
40504050

@@ -4528,8 +4528,11 @@ zfs_ioc_userspace_upgrade(zfs_cmd_t *zc)
45284528
* objset_phys_t). Suspend/resume the fs will do that.
45294529
*/
45304530
error = zfs_suspend_fs(zsb);
4531-
if (error == 0)
4531+
if (error == 0) {
4532+
dmu_objset_refresh_ownership(zsb->z_os,
4533+
zsb);
45324534
error = zfs_resume_fs(zsb, zc->zc_name);
4535+
}
45334536
}
45344537
if (error == 0)
45354538
error = dmu_objset_userspace_upgrade(zsb->z_os);

0 commit comments

Comments
 (0)