Skip to content

Commit

Permalink
Long hold the dataset during upgrade
Browse files Browse the repository at this point in the history
If the receive or rollback is performed while filesystem is upgrading
the objset may be evicted in `dsl_dataset_clone_swap_sync_impl`. This
will lead to NULL pointer dereference when upgrade tries to access
evicted objset.

This commit adds long hold of dataset during whole upgrade process.
The receive and rollback will return an EBUSY error until the
upgrade is not finished.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Arkadiusz Bubała <arkadiusz.bubala@open-e.com>
Closes #5295 
Closes #6837
  • Loading branch information
ab-oe authored and behlendorf committed Nov 10, 2017
1 parent 62df1bc commit c0daec3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
18 changes: 14 additions & 4 deletions module/zfs/dmu_objset.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* Copyright (c) 2015, STRATO AG, Inc. All rights reserved.
* Copyright (c) 2016 Actifio, Inc. All rights reserved.
* Copyright 2017 Nexenta Systems, Inc.
* Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
*/

/* Portions Copyright 2010 Robert Milkowski */
Expand Down Expand Up @@ -79,6 +80,8 @@ int dmu_find_threads = 0;
*/
int dmu_rescan_dnode_threshold = 1 << DN_MAX_INDBLKSHIFT;

static char *upgrade_tag = "upgrade_tag";

static void dmu_objset_find_dp_cb(void *arg);

static void dmu_objset_upgrade(objset_t *os, dmu_objset_upgrade_cb_t cb);
Expand Down Expand Up @@ -704,13 +707,12 @@ dmu_objset_own(const char *name, dmu_objset_type_t type,
return (err);
}

dsl_pool_rele(dp, FTAG);

/* user accounting requires the dataset to be decrypted */
if (dmu_objset_userobjspace_upgradable(*osp) &&
(ds->ds_dir->dd_crypto_obj == 0 || decrypt))
dmu_objset_userobjspace_upgrade(*osp);

dsl_pool_rele(dp, FTAG);
return (0);
}

Expand Down Expand Up @@ -1311,6 +1313,7 @@ dmu_objset_upgrade_task_cb(void *data)
os->os_upgrade_exit = B_TRUE;
os->os_upgrade_id = 0;
mutex_exit(&os->os_upgrade_lock);
dsl_dataset_long_rele(dmu_objset_ds(os), upgrade_tag);
}

static void
Expand All @@ -1319,15 +1322,20 @@ dmu_objset_upgrade(objset_t *os, dmu_objset_upgrade_cb_t cb)
if (os->os_upgrade_id != 0)
return;

ASSERT(dsl_pool_config_held(dmu_objset_pool(os)));
dsl_dataset_long_hold(dmu_objset_ds(os), upgrade_tag);

mutex_enter(&os->os_upgrade_lock);
if (os->os_upgrade_id == 0 && os->os_upgrade_status == 0) {
os->os_upgrade_exit = B_FALSE;
os->os_upgrade_cb = cb;
os->os_upgrade_id = taskq_dispatch(
os->os_spa->spa_upgrade_taskq,
dmu_objset_upgrade_task_cb, os, TQ_SLEEP);
if (os->os_upgrade_id == TASKQID_INVALID)
if (os->os_upgrade_id == TASKQID_INVALID) {
dsl_dataset_long_rele(dmu_objset_ds(os), upgrade_tag);
os->os_upgrade_status = ENOMEM;
}
}
mutex_exit(&os->os_upgrade_lock);
}
Expand All @@ -1343,7 +1351,9 @@ dmu_objset_upgrade_stop(objset_t *os)
os->os_upgrade_id = 0;
mutex_exit(&os->os_upgrade_lock);

taskq_cancel_id(os->os_spa->spa_upgrade_taskq, id);
if ((taskq_cancel_id(os->os_spa->spa_upgrade_taskq, id)) == 0) {
dsl_dataset_long_rele(dmu_objset_ds(os), upgrade_tag);
}
txg_wait_synced(os->os_spa->spa_dsl_pool, 0);
} else {
mutex_exit(&os->os_upgrade_lock);
Expand Down
8 changes: 4 additions & 4 deletions module/zfs/zfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5275,9 +5275,6 @@ zfs_ioc_userobjspace_upgrade(zfs_cmd_t *zc)
if (error != 0)
return (error);

dsl_dataset_long_hold(dmu_objset_ds(os), FTAG);
dsl_pool_rele(dmu_objset_pool(os), FTAG);

if (dmu_objset_userobjspace_upgradable(os)) {
mutex_enter(&os->os_upgrade_lock);
if (os->os_upgrade_id == 0) {
Expand All @@ -5290,11 +5287,14 @@ zfs_ioc_userobjspace_upgrade(zfs_cmd_t *zc)
mutex_exit(&os->os_upgrade_lock);
}

dsl_pool_rele(dmu_objset_pool(os), FTAG);

taskq_wait_id(os->os_spa->spa_upgrade_taskq, os->os_upgrade_id);
error = os->os_upgrade_status;
} else {
dsl_pool_rele(dmu_objset_pool(os), FTAG);
}

dsl_dataset_long_rele(dmu_objset_ds(os), FTAG);
dsl_dataset_rele_flags(dmu_objset_ds(os), DS_HOLD_FLAG_DECRYPT, FTAG);

return (error);
Expand Down
7 changes: 6 additions & 1 deletion module/zfs/zfs_vfsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,13 @@ zfs_fuid_overobjquota(zfsvfs_t *zfsvfs, boolean_t isgroup, uint64_t fuid)
int err;

if (!dmu_objset_userobjspace_present(zfsvfs->z_os)) {
if (dmu_objset_userobjspace_upgradable(zfsvfs->z_os))
if (dmu_objset_userobjspace_upgradable(zfsvfs->z_os)) {
dsl_pool_config_enter(
dmu_objset_pool(zfsvfs->z_os), FTAG);
dmu_objset_userobjspace_upgrade(zfsvfs->z_os);
dsl_pool_config_exit(
dmu_objset_pool(zfsvfs->z_os), FTAG);
}
return (B_FALSE);
}

Expand Down

0 comments on commit c0daec3

Please sign in to comment.