Skip to content

Commit 6379d4e

Browse files
author
Paul Dagnelie
committed
Enable zhack to work properly with 4k sector size disks
Signed-off-by: Paul Dagnelie <[email protected]>
1 parent 833b2bb commit 6379d4e

File tree

7 files changed

+19
-9
lines changed

7 files changed

+19
-9
lines changed

cmd/zhack.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ static __attribute__((noreturn)) void
7070
usage(void)
7171
{
7272
(void) fprintf(stderr,
73-
"Usage: zhack [-c cachefile] [-d dir] <subcommand> <args> ...\n"
73+
"Usage: zhack [-o tunable] [-c cachefile] [-d dir] <subcommand> "
74+
"<args> ...\n"
7475
"where <subcommand> <args> is one of the following:\n"
7576
"\n");
7677

@@ -1169,7 +1170,7 @@ main(int argc, char **argv)
11691170
dprintf_setup(&argc, argv);
11701171
zfs_prop_init();
11711172

1172-
while ((c = getopt(argc, argv, "+c:d:")) != -1) {
1173+
while ((c = getopt(argc, argv, "+c:d:o:")) != -1) {
11731174
switch (c) {
11741175
case 'c':
11751176
g_importargs.cachefile = optarg;
@@ -1178,6 +1179,10 @@ main(int argc, char **argv)
11781179
assert(g_importargs.paths < MAX_NUM_PATHS);
11791180
g_importargs.path[g_importargs.paths++] = optarg;
11801181
break;
1182+
case 'o':
1183+
if (handle_tunable_option(optarg, B_FALSE) != 0)
1184+
exit(1);
1185+
break;
11811186
default:
11821187
usage();
11831188
break;

include/sys/zfs_file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void zfs_file_close(zfs_file_t *fp);
4646

4747
int zfs_file_write(zfs_file_t *fp, const void *buf, size_t len, ssize_t *resid);
4848
int zfs_file_pwrite(zfs_file_t *fp, const void *buf, size_t len, loff_t off,
49-
ssize_t *resid);
49+
uint8_t ashift, ssize_t *resid);
5050
int zfs_file_read(zfs_file_t *fp, void *buf, size_t len, ssize_t *resid);
5151
int zfs_file_pread(zfs_file_t *fp, void *buf, size_t len, loff_t off,
5252
ssize_t *resid);

lib/libzpool/kernel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ zfs_file_write(zfs_file_t *fp, const void *buf, size_t count, ssize_t *resid)
12381238
*/
12391239
int
12401240
zfs_file_pwrite(zfs_file_t *fp, const void *buf,
1241-
size_t count, loff_t pos, ssize_t *resid)
1241+
size_t count, loff_t pos, uint8_t ashift, ssize_t *resid)
12421242
{
12431243
ssize_t rc, split, done;
12441244
int sectors;
@@ -1248,8 +1248,8 @@ zfs_file_pwrite(zfs_file_t *fp, const void *buf,
12481248
* system calls so that the process can be killed in between.
12491249
* This is used by ztest to simulate realistic failure modes.
12501250
*/
1251-
sectors = count >> SPA_MINBLOCKSHIFT;
1252-
split = (sectors > 0 ? rand() % sectors : 0) << SPA_MINBLOCKSHIFT;
1251+
sectors = count >> ashift;
1252+
split = (sectors > 0 ? rand() % sectors : 0) << ashift;
12531253
rc = pwrite64(fp->f_fd, buf, split, pos);
12541254
if (rc != -1) {
12551255
done = rc;

man/man1/zhack.1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ Search for
161161
members in
162162
.Ar dir .
163163
Can be specified more than once.
164+
.It Fl o Ar var Ns = Ns Ar value
165+
Set the given tunable to the provided value.
164166
.El
165167
.
166168
.Sh EXAMPLES

module/os/freebsd/zfs/zfs_file_os.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ zfs_file_write(zfs_file_t *fp, const void *buf, size_t count, ssize_t *resid)
164164

165165
int
166166
zfs_file_pwrite(zfs_file_t *fp, const void *buf, size_t count, loff_t off,
167-
ssize_t *resid)
167+
uint8_t ashift, ssize_t *resid)
168168
{
169+
(void) ashift;
169170
return (zfs_file_write_impl(fp, buf, count, &off, resid));
170171
}
171172

module/os/linux/zfs/zfs_file_os.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ zfs_file_write(zfs_file_t *fp, const void *buf, size_t count, ssize_t *resid)
115115
*/
116116
int
117117
zfs_file_pwrite(zfs_file_t *fp, const void *buf, size_t count, loff_t off,
118-
ssize_t *resid)
118+
uint8_t ashift, ssize_t *resid)
119119
{
120+
(void) ashift;
120121
ssize_t rc;
121122

122123
rc = kernel_write(fp, buf, count, &off);

module/zfs/vdev_file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ vdev_file_io_strategy(void *arg)
228228
abd_return_buf_copy(zio->io_abd, buf, size);
229229
} else {
230230
buf = abd_borrow_buf_copy(zio->io_abd, zio->io_size);
231-
err = zfs_file_pwrite(vf->vf_file, buf, size, off, &resid);
231+
err = zfs_file_pwrite(vf->vf_file, buf, size, off,
232+
vd->vdev_ashift, &resid);
232233
abd_return_buf(zio->io_abd, buf, size);
233234
}
234235
zio->io_error = err;

0 commit comments

Comments
 (0)