Skip to content

Commit

Permalink
restore
Browse files Browse the repository at this point in the history
  • Loading branch information
calccrypto committed Jun 11, 2024
1 parent db766fa commit 56c7319
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 50 deletions.
2 changes: 1 addition & 1 deletion include/sys/zia.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int zia_offload_abd(void *provider, abd_t *abd,
size_t size, size_t min_offload_size,
boolean_t *local_offload, boolean_t lock);
int zia_onload_abd(abd_t *abd, size_t size,
boolean_t keep_handle, boolean_t lock);
boolean_t keep_handle);
/* move a handle into an abd */
void zia_move_into_abd(abd_t *dst, void **src);
int zia_free_abd(abd_t *abd, boolean_t lock);
Expand Down
5 changes: 5 additions & 0 deletions module/os/linux/zfs/vdev_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <sys/vdev_trim.h>
#include <sys/abd.h>
#include <sys/fs/zfs.h>
#include <sys/zia.h>
#include <sys/zio.h>
#include <linux/blkpg.h>
#include <linux/msdos_fs.h>
Expand Down Expand Up @@ -793,6 +794,8 @@ __vdev_disk_physio(struct block_device *bdev, zio_t *zio,
return (error);
}

EXPORT_SYMBOL(__vdev_disk_physio);

BIO_END_IO_PROTO(vdev_disk_io_flush_completion, bio, error)
{
zio_t *zio = bio->bi_private;
Expand Down Expand Up @@ -835,6 +838,8 @@ vdev_disk_io_flush(struct block_device *bdev, zio_t *zio)
return (0);
}

EXPORT_SYMBOL(vdev_disk_io_flush);

static int
vdev_disk_io_trim(zio_t *zio)
{
Expand Down
50 changes: 47 additions & 3 deletions module/os/linux/zfs/vdev_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <sys/fcntl.h>
#include <sys/vnode.h>
#include <sys/zfs_file.h>
#include <sys/zia.h>
#ifdef _KERNEL
#include <linux/falloc.h>
#endif
Expand Down Expand Up @@ -161,6 +162,12 @@ vdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
}
#endif

zia_get_props(vd->vdev_spa)->min_offload_size = 2 << *physical_ashift;

/* try to open the file; ignore errors - will fall back to ZFS */
zia_file_open(vd, vd->vdev_path,
vdev_file_open_mode(spa_mode(vd->vdev_spa)), 0);

skip_open:

error = zfs_file_getattr(vf->vf_file, &zfa);
Expand All @@ -184,6 +191,8 @@ vdev_file_close(vdev_t *vd)
if (vd->vdev_reopening || vf == NULL)
return;

zia_file_close(vd);

if (vf->vf_file != NULL) {
(void) zfs_file_close(vf->vf_file);
}
Expand All @@ -203,18 +212,53 @@ vdev_file_io_strategy(void *arg)
void *buf;
loff_t off;
ssize_t size;
int err;
int err = 0;

off = zio->io_offset;
size = zio->io_size;
resid = 0;

if (zio->io_type == ZIO_TYPE_READ) {
buf = abd_borrow_buf(zio->io_abd, zio->io_size);
buf = abd_borrow_buf(zio->io_abd, size);
err = zfs_file_pread(vf->vf_file, buf, size, off, &resid);
abd_return_buf_copy(zio->io_abd, buf, size);
} else {
buf = abd_borrow_buf_copy(zio->io_abd, zio->io_size);
err = EIO;

boolean_t local_offload = B_FALSE;
zia_props_t *zia_props = zia_get_props(zio->io_spa);

if ((zia_props->file_write == 1) &&
(zio->io_can_offload == B_TRUE)) {
if (zia_offload_abd(zia_props->provider, zio->io_abd,
size, zia_props->min_offload_size,
&local_offload, B_TRUE) == ZIA_OK) {
err = zia_file_write(vd, zio->io_abd, size, off,
&resid, &err);
}
}

/* if offload and write succeeded, return here */
if (err == 0) {
zio->io_error = err;
if (resid != 0 && zio->io_error == 0)
zio->io_error = SET_ERROR(ENOSPC);

zio_delay_interrupt(zio);
return;
}

/* if offload or write failed, bring data back into memory */
err = zia_cleanup_abd(zio->io_abd, size, local_offload, B_TRUE);

/* if onload failed, restart the zio with offloading disabled */
if (err == ZIA_ACCELERATOR_DOWN) {
zia_disable_offloading(zio, B_TRUE);
zio_delay_interrupt(zio);
return;
}

buf = abd_borrow_buf_copy(zio->io_abd, size);
err = zfs_file_pwrite(vf->vf_file, buf, size, off, &resid);
abd_return_buf(zio->io_abd, buf, size);
}
Expand Down
8 changes: 8 additions & 0 deletions module/zfs/vdev_raidz.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ vdev_raidz_generate_parity_p(raidz_row_t *rr)
}
}

EXPORT_SYMBOL(vdev_raidz_generate_parity_p);

void
vdev_raidz_generate_parity_pq(raidz_row_t *rr)
{
Expand Down Expand Up @@ -563,6 +565,8 @@ vdev_raidz_generate_parity_pq(raidz_row_t *rr)
}
}

EXPORT_SYMBOL(vdev_raidz_generate_parity_pq);

void
vdev_raidz_generate_parity_pqr(raidz_row_t *rr)
{
Expand Down Expand Up @@ -611,6 +615,8 @@ vdev_raidz_generate_parity_pqr(raidz_row_t *rr)
}
}

EXPORT_SYMBOL(vdev_raidz_generate_parity_pqr);

/*
* Generate RAID parity in the first virtual columns according to the number of
* parity columns available.
Expand Down Expand Up @@ -1417,6 +1423,8 @@ vdev_raidz_reconstruct_general(raidz_row_t *rr, int *tgts, int ntgts)
}
}

EXPORT_SYMBOL(vdev_raidz_reconstruct_general);

static void
vdev_raidz_reconstruct_row(raidz_map_t *rm, raidz_row_t *rr,
const int *t, int nt)
Expand Down
60 changes: 30 additions & 30 deletions module/zfs/zia.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,26 +679,26 @@ zia_offload_abd(void *provider, abd_t *abd,
size_t size, size_t min_offload_size,
boolean_t *local_offload, boolean_t lock)
{
if (!dpusm) {
if (!dpusm || !provider) {
return (ZIA_FALLBACK);
}

if (!abd) {
return (ZIA_ERROR);
}

if (lock) {
mutex_enter(&abd->abd_mtx);
}
if (lock) {
mutex_enter(&abd->abd_mtx);
}

const int rc = zia_offload_abd_offset(provider,
abd, 0, size, min_offload_size, local_offload);

if (lock) {
mutex_exit(&abd->abd_mtx);
}
if (lock) {
mutex_exit(&abd->abd_mtx);
}

return (rc);
return (rc);
}

#ifdef ZIA
Expand Down Expand Up @@ -779,7 +779,7 @@ zia_onload_abd_offset(abd_t *abd, size_t offset,
}

int
zia_onload_abd(abd_t *abd, size_t size, boolean_t keep_handle, boolean_t lock)
zia_onload_abd(abd_t *abd, size_t size, boolean_t keep_handle)
{
if (abd_is_gang(abd)) {
/*
Expand All @@ -803,17 +803,7 @@ zia_onload_abd(abd_t *abd, size_t size, boolean_t keep_handle, boolean_t lock)
ASSERT(size <= original_size);
}

if (lock == B_TRUE) {
mutex_enter(&abd->abd_mtx);
}

const int err = zia_onload_abd_offset(abd, 0, size, keep_handle);

if (lock == B_TRUE) {
mutex_exit(&abd->abd_mtx);
}

return (err);
return (zia_onload_abd_offset(abd, 0, size, keep_handle));
}

void
Expand Down Expand Up @@ -843,7 +833,8 @@ zia_free_abd(abd_t *abd, boolean_t lock)
* if not, onload the data and free the handle
*/
int
zia_cleanup_abd(abd_t *abd, size_t size, boolean_t local_offload, boolean_t lock)
zia_cleanup_abd(abd_t *abd, size_t size,
boolean_t local_offload, boolean_t lock)
{
if (!dpusm) {
return (ZIA_FALLBACK);
Expand All @@ -854,13 +845,22 @@ zia_cleanup_abd(abd_t *abd, size_t size, boolean_t local_offload, boolean_t lock
}

int ret = ZIA_OK;

if (lock == B_TRUE) {
mutex_enter(&abd->abd_mtx);
}

if (local_offload == B_TRUE) {
/* in-memory copy is still valid */
/* lock just in case mirrors clean up at the same time */
ret = zia_free_abd(abd, B_TRUE);
ret = zia_free_abd(abd, B_FALSE);
} else {
/* have to copy data into memory */
ret = zia_onload_abd(abd, size, B_FALSE, lock);
ret = zia_onload_abd(abd, size, B_FALSE);
}

if (lock == B_TRUE) {
mutex_exit(&abd->abd_mtx);
}

return (ret);
Expand Down Expand Up @@ -1020,7 +1020,7 @@ zia_checksum_compute(void *provider, zio_cksum_t *dst, enum zio_checksum alg,

if (zia_offload_abd(provider, zio->io_abd, size,
zia_get_props(zio->io_spa)->min_offload_size,
local_offload, B_FALSE) != ZIA_OK) {
local_offload, B_FALSE) != ZIA_OK) {
return (ZIA_ERROR);
}
} else {
Expand Down Expand Up @@ -1247,7 +1247,7 @@ zia_raidz_alloc(zio_t *zio, raidz_row_t *rr, boolean_t rec,
*/
zia_offload_abd(provider, rc->rc_abd,
rc->rc_abd->abd_size, props->min_offload_size,
NULL, B_FALSE);
NULL, B_FALSE);
handle = ABD_HANDLE(rc->rc_abd);
} else {
/* generating - create new columns */
Expand Down Expand Up @@ -1352,7 +1352,7 @@ zia_raidz_free(raidz_row_t *rr, boolean_t onload_parity)
raidz_col_t *rc = &rr->rr_col[c];
ret = zia_worst_error(ret,
zia_onload_abd(rc->rc_abd,
rc->rc_size, B_FALSE, B_FALSE));
rc->rc_size, B_FALSE));
}
}

Expand Down Expand Up @@ -1519,10 +1519,10 @@ zia_file_open(vdev_t *vdev, const char *path,
return (ZIA_ERROR);
}

zia_props_t *zia_props = zia_get_props(vdev->vdev_spa);
if (zia_props->file_write != 1) {
return (ZIA_FALLBACK);
}
zia_props_t *zia_props = zia_get_props(vdev->vdev_spa);
if (zia_props->file_write != 1) {
return (ZIA_FALLBACK);
}

#ifdef ZIA
void *provider = zia_props->provider;
Expand Down
Loading

0 comments on commit 56c7319

Please sign in to comment.