From: Brian Foster <bfoster@redhat.com>
To: linux-xfs@vger.kernel.org
Cc: Dave Chinner <david@fromorbit.com>
Subject: [PATCH RFC] xfs_io: simple bad buf hack to simulate write failure
Date: Wed, 23 Nov 2022 13:13:22 -0500 [thread overview]
Message-ID: <20221123181322.3710820-1-bfoster@redhat.com> (raw)
Hackily use a NULL buffer for the pwrite command to induce a kernel
write syscall failure. This is posted for reference only and needs a
proper implementation: needs a new flag, probably should be wired
through alloc_buffer(), etc.
Not-Signed-off-by: Brian Foster <bfoster@redhat.com>
---
Posted in prototype form in reference to the discussion here:
https://lore.kernel.org/linux-xfs/Y3e+7XH5gq5gc97u@bfoster/
Brian
io/pwrite.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/io/pwrite.c b/io/pwrite.c
index 467bfa9f8..6e5de3140 100644
--- a/io/pwrite.c
+++ b/io/pwrite.c
@@ -285,12 +285,14 @@ pwrite_f(
int direction = IO_FORWARD;
int c, fd = -1;
int pwritev2_flags = 0;
+ bool fail = false;
+ char *orig_io_buffer = NULL;
Cflag = qflag = uflag = dflag = wflag = Wflag = 0;
init_cvtnum(&fsblocksize, &fssectsize);
bsize = fsblocksize;
- while ((c = getopt(argc, argv, "b:BCdDf:Fi:NqRs:OS:uV:wWZ:")) != EOF) {
+ while ((c = getopt(argc, argv, "b:BCdDfFi:NqRs:OS:uV:wWZ:")) != EOF) {
switch (c) {
case 'b':
tmp = cvtnum(fsblocksize, fssectsize, optarg);
@@ -320,6 +322,8 @@ pwrite_f(
dflag = 1;
break;
case 'f':
+ fail = true;
+ break;
case 'i':
infile = optarg;
break;
@@ -414,6 +418,10 @@ pwrite_f(
exitcode = 1;
return 0;
}
+ if (fail) {
+ orig_io_buffer = io_buffer;
+ io_buffer = NULL;
+ }
c = IO_READONLY | (dflag ? IO_DIRECT : 0);
if (infile && ((fd = openfile(infile, NULL, c, 0, NULL)) < 0)) {
@@ -471,6 +479,8 @@ pwrite_f(
done:
if (infile)
close(fd);
+ if (orig_io_buffer)
+ io_buffer = orig_io_buffer;
return 0;
}
--
2.37.3
reply other threads:[~2022-11-23 18:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221123181322.3710820-1-bfoster@redhat.com \
--to=bfoster@redhat.com \
--cc=david@fromorbit.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox