-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add blkdiscard support for disk wipe #91
Conversation
// Lets figure out if the drive supports TRIM | ||
var trim bool | ||
for _, cap := range drive.Capabilities { | ||
if strings.HasPrefix(cap.Description, "Data Set Management TRIM supported") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this work across different drives vendors/models?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep worked correctly across a bunch of different vendors/models so far:
I've run hdparm -I /dev/sd?|grep -i -E '(/dev/|model|trim)'
across a bunch of different em plan types that result in:
/dev/sda:
Model Number: MZ7LH480HBHQ0D3
* Data Set Management TRIM supported (limit 8 blocks)
* Deterministic read ZEROs after TRIM
/dev/sdc:
Model Number: MTFDDAV240TDU
* Data Set Management TRIM supported (limit 8 blocks)
* Deterministic read ZEROs after TRIM
/dev/sda:
Model Number: INTEL SSDSC2KB480G8
* Data Set Management TRIM supported (limit 4 blocks)
* Deterministic read ZEROs after TRIM
/dev/sda:
Model Number: Micron_5200_MTFDDAK480TDN
* Data Set Management TRIM supported (limit 8 blocks)
* Deterministic read ZEROs after TRIM
/dev/sda:
Model Number: SSDSCKKB240G8R
* Data Set Management TRIM supported (limit 4 blocks)
* Deterministic read ZEROs after TRIM
/dev/sdb:
Model Number: MZ7LH480HBHQ0D3
* Data Set Management TRIM supported (limit 8 blocks)
* Deterministic read ZEROs after TRIM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm seeing some apparently-conflicting info on this -- on a Micron SSD in an n2.xlarge:
$ hdparm -I /dev/sda | grep -i trim
* Data Set Management TRIM supported (limit 8 blocks)
* Deterministic read ZEROs after TRIM
$ cat /sys/block/sda/queue/discard_zeroes_data
0
I'm not sure offhand what exactly the difference is between what the kernel reports in discard_zeroes_data
and what hdparm reports as "Deterministic read ZEROs after TRIM" -- anyone happen to know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will always return 0. Don't rely on any specific behavior for discards, and don't read this file.
Tracing through some kernel codepaths, it looks like maybe we should be trying to use the BLKZEROOUT
ioctl instead...which is available via blkdiscard --zeroout
, but it doesn't look like ironlib currently passes that flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm seeing some apparently-conflicting info on this -- on a Micron SSD in an n2.xlarge:
$ hdparm -I /dev/sda | grep -i trim * Data Set Management TRIM supported (limit 8 blocks) * Deterministic read ZEROs after TRIM $ cat /sys/block/sda/queue/discard_zeroes_data 0
I'm not sure offhand what exactly the difference is between what the kernel reports in
discard_zeroes_data
and what hdparm reports as "Deterministic read ZEROs after TRIM" -- anyone happen to know?
Will always return 0. Don't rely on any specific behavior for discards, and don't read this file.
Tracing through some kernel codepaths, it looks like maybe we should be trying to use the
BLKZEROOUT
ioctl instead...which is available viablkdiscard --zeroout
, but it doesn't look like ironlib currently passes that flag?
Looks like discard_zeros_data was just internal use to me. That patch series also adds a bunch of code handling REQ_OP_WRITE_ZEROES
and keeps REQ_OP_DISCARD
around:
if (op == REQ_OP_DISCARD)
special_cmd_max_sectors = q->limits.max_discard_sectors;
+ else if (op == REQ_OP_WRITE_ZEROES)
From the blkdiscard manpage:
-z, --zeroout
Zero-fill rather than discard.
which is not what we want 😄 (tried running this and its definitely taking a long time to come finish and is in D+
state). fwiw hdparm gets the data from SG_IO
ioctl:
ioctl(3, SG_IO, {interface_id='S', dxfer_direction=SG_DXFER_FROM_DEV, cmd_len=16, cmdp="\x85\x09\x0e\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\xe0\x2f\x00", mx_sb_len=32, iovec_count=0, dxfer_len=512, timeout=15000, flags=0, dxferp="\x01\x00\x00\x00\x00\x00\x14\x00\x08\x00\x00\x00\x00\x00\x02\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"..., status=0, masked_status=0, msg_status=0, sb_len_wr=0, sbp="", host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
Expand drive wiping capabilities by using blkdiscard for devices that support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving this since the intended efforts are covered @mmlb can create any follow up PRs if required.
Uses ironlib's blkdiscard support to wipe disks that support TRIM.