forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
156 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,11 @@ | |
* Copyright (c) 2024, Rob Norris <[email protected]> | ||
* Copyright (c) 2024, Klara, Inc. | ||
*/ | ||
|
||
/* | ||
* TODO Mav feedback: driver_private correction, zvol_setup_copy_offload() | ||
* why setup, offload, lock. | ||
* Review again: suspend_lock, zil, rangelock, end_bio. | ||
*/ | ||
#include <sys/dataset_kstats.h> | ||
#include <sys/dbuf.h> | ||
#include <sys/dmu_traverse.h> | ||
|
@@ -519,7 +523,7 @@ static void zvol_setup_copy_offload(zv_request_t *zvr) | |
blkptr_t *bps; | ||
size_t maxblocks; | ||
uint64_t inoff, outoff, len = 0; | ||
int error = 0, seg = 1; | ||
int error = EINVAL, seg = 1; | ||
|
||
memset(&uio_src, 0, sizeof (zfs_uio_t)); | ||
memset(&uio_dst, 0, sizeof (zfs_uio_t)); | ||
|
@@ -534,8 +538,7 @@ static void zvol_setup_copy_offload(zv_request_t *zvr) | |
bio->bi_private; | ||
zfs_uio_bvec_init(&uio_src, bio, NULL); | ||
if (len != bio->bi_iter.bi_size) { | ||
rw_exit(&zv_src->zv_suspend_lock); | ||
zvol_end_io(bio, req, -SET_ERROR(error)); | ||
zvol_end_io(NULL, req, -SET_ERROR(error)); | ||
return; | ||
} | ||
if (offload_io && offload_io->driver_private) | ||
|
@@ -548,12 +551,28 @@ static void zvol_setup_copy_offload(zv_request_t *zvr) | |
} | ||
|
||
if (!zv_src || !zv_dst) { | ||
rw_exit(&zv_src->zv_suspend_lock); | ||
zvol_end_io(bio, req, -SET_ERROR(error)); | ||
zvol_end_io(NULL, req, -SET_ERROR(error)); | ||
return; | ||
} | ||
|
||
rw_enter(&zv_dst->zv_suspend_lock, RW_READER); | ||
/* | ||
* ZIL Lock | ||
*/ | ||
if (zv_dst->zv_zilog == NULL) { | ||
rw_exit(&zv_dst->zv_suspend_lock); | ||
rw_enter(&zv_dst->zv_suspend_lock, RW_WRITER); | ||
if (zv_dst->zv_zilog == NULL) { | ||
zv_dst->zv_zilog = zil_open(zv_dst->zv_objset, | ||
zvol_get_data, &zv_dst->zv_kstat.dk_zil_sums); | ||
zv_dst->zv_flags |= ZVOL_WRITTEN_TO; | ||
VERIFY0((zv_dst->zv_zilog->zl_header->zh_flags & | ||
ZIL_REPLAY_NEEDED)); | ||
} | ||
rw_downgrade(&zv_dst->zv_suspend_lock); | ||
} | ||
if (zv_src != zv_dst) | ||
rw_enter(&zv_dst->zv_suspend_lock, RW_READER); | ||
rw_enter(&zv_src->zv_suspend_lock, RW_READER); | ||
|
||
inoff = uio_src.uio_loffset; | ||
outoff = uio_dst.uio_loffset; | ||
|
@@ -632,30 +651,25 @@ static void zvol_setup_copy_offload(zv_request_t *zvr) | |
goto out; | ||
} | ||
|
||
/* | ||
* ZIL Lock | ||
*/ | ||
if (zv_dst->zv_zilog == NULL) { | ||
rw_exit(&zv_dst->zv_suspend_lock); | ||
rw_enter(&zv_dst->zv_suspend_lock, RW_WRITER); | ||
if (zv_dst->zv_zilog == NULL) { | ||
zv_dst->zv_zilog = zil_open(zv_dst->zv_objset, | ||
zvol_get_data, &zv_dst->zv_kstat.dk_zil_sums); | ||
zv_dst->zv_flags |= ZVOL_WRITTEN_TO; | ||
VERIFY0((zv_dst->zv_zilog->zl_header->zh_flags & | ||
ZIL_REPLAY_NEEDED)); | ||
} | ||
rw_downgrade(&zv_dst->zv_suspend_lock); | ||
} | ||
|
||
zilog_dst = zv_dst->zv_zilog; | ||
maxblocks = zil_max_log_data(zilog_dst, sizeof (lr_clone_range_t)) / | ||
sizeof (bps[0]); | ||
bps = vmem_alloc(sizeof (bps[0]) * maxblocks, KM_SLEEP); | ||
inlr = zfs_rangelock_enter(&zv_src->zv_rangelock, inoff, len, | ||
RL_READER); | ||
outlr = zfs_rangelock_enter(&zv_dst->zv_rangelock, outoff, len, | ||
RL_WRITER); | ||
/* | ||
* Maintain predictable lock order. | ||
*/ | ||
if (zv_src < zv_dst || (zv_src == zv_dst && inoff < outoff)) { | ||
inlr = zfs_rangelock_enter(&zv_src->zv_rangelock, inoff, len, | ||
RL_READER); | ||
outlr = zfs_rangelock_enter(&zv_dst->zv_rangelock, outoff, len, | ||
RL_WRITER); | ||
} else { | ||
outlr = zfs_rangelock_enter(&zv_dst->zv_rangelock, outoff, len, | ||
RL_WRITER); | ||
inlr = zfs_rangelock_enter(&zv_src->zv_rangelock, inoff, len, | ||
RL_READER); | ||
} | ||
|
||
while (len > 0) { | ||
uint64_t size, last_synced_txg; | ||
size_t nbps = maxblocks; | ||
|
@@ -693,7 +707,7 @@ static void zvol_setup_copy_offload(zv_request_t *zvr) | |
dmu_tx_commit(tx); | ||
break; | ||
} | ||
zfs_log_clone_range(zilog_dst, tx, TX_CLONE_RANGE, NULL, outoff, | ||
zvol_log_clone_range(zilog_dst, tx, TX_CLONE_RANGE, outoff, | ||
size, zv_src->zv_volblocksize, bps, nbps); | ||
dmu_tx_commit(tx); | ||
inoff += size; | ||
|
@@ -708,10 +722,9 @@ static void zvol_setup_copy_offload(zv_request_t *zvr) | |
} | ||
out: | ||
if (zv_src != zv_dst) | ||
rw_exit(&zv_dst->zv_suspend_lock); | ||
|
||
rw_exit(&zv_src->zv_suspend_lock); | ||
zvol_end_io(bio, req, -SET_ERROR(error)); | ||
rw_exit(&zv_src->zv_suspend_lock); | ||
rw_exit(&zv_dst->zv_suspend_lock); | ||
zvol_end_io(NULL, req, -SET_ERROR(error)); | ||
} | ||
|
||
static void | ||
|
@@ -787,8 +800,6 @@ zvol_request_impl(zvol_state_t *zv, struct bio *bio, struct request *rq, | |
zvol_end_io(bio, rq, -SET_ERROR(EROFS)); | ||
goto out; | ||
} | ||
rw_enter(&zv->zv_suspend_lock, RW_READER); | ||
|
||
if (force_sync) { | ||
zvol_setup_copy_offload(&zvr); | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters