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
Fix FibreChannel volume plugin corrupting filesystem on detach #97013
Conversation
@jsafrane: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/priority important-soon |
FibreChannel volume plugin misses one important step when removing a device: "multipath -f". It flushes all multipath buffers to its individual paths. Without it, a filesystem on the device may get corrupted.
58f366e
to
6f8bdb7
Compare
func (util *fcUtil) deleteMultipathDevice(exec utilexec.Interface, dmDevice string) error { | ||
out, err := exec.Command("multipath", "-f", dmDevice).CombinedOutput() | ||
if err != nil { | ||
return fmt.Errorf("failed to flush multipath device %s: %s\n%s", dmDevice, err, string(out)) |
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.
just want to confirm whether in certain cases, it should continue instead of return error (e.g., the error means device no longer exist?)
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.
Good catch! That's why iscsi volume plugin ignores the error code...
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.
If the device is missing:
-
Filesystem volumes: operation_generator.go will stop with "The path isn't device path or doesn't exist. Skip checking device path: /dev/dm-0" and it won't call volume plugin at all. Therefore, if the multipath device is removed, but the individual paths are still there, nothing will remove them.
-
Block volumes: if the device is missing, the next
DetachBlockFCDisk
will stop incheckPathExists
, if not earlier inoperation_generator.go
(did not test it).
kubernetes/pkg/volume/fc/fc_util.go
Line 301 in 6f8bdb7
if pathExists, pathErr := checkPathExists(devicePath); !pathExists || pathErr != nil {
iscsi volume plugin actually ignores the error code from "multipath -f", continuing deleting the device paths. Which may result in volume corruption, if the multipath device still exists.. Now is the question what is actually correct - try to remove the individual paths to fully detach the devices and risk corruption OR do not remove the paths at all? The paths should just sit in /dev, not used by anything.
My gut feeling is to copy iscsi approach and ignore the exit code.
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.
according to manpage
-f Flush (remove) a multipath device map specified as parameter, if unused.
So if multipath -f
fails, there is a good chance the device is still being used and removing it could cause data corruption. In this sense, the implementation in iscsi is indeed risky.
/approve |
func (util *fcUtil) deleteMultipathDevice(exec utilexec.Interface, dmDevice string) error { | ||
out, err := exec.Command("multipath", "-f", dmDevice).CombinedOutput() | ||
if err != nil { | ||
return fmt.Errorf("failed to flush multipath device %s: %s\n%s", dmDevice, err, string(out)) |
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.
nit:
return fmt.Errorf("failed to flush multipath device %s: %v\n%s", dmDevice, err, string(out))
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.
No, %s
is fine for errror
type.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jsafrane, rootfs The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -354,6 +358,9 @@ func (util *fcUtil) DetachBlockFCDisk(c fcDiskUnmapper, mapPath, devicePath stri | |||
if len(dm) != 0 { |
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.
Same link - https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/removing_devices#:~:text=Run%20multipath%20%2Dl%20command%20to,to%20remove%20the%20multipath%20device. recommends that for raw block devices we should call blockdev --flushbufs device
before removing the device. Should we do that as well?
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.
Added as a separate commit.
BTW, we should refactor FC and iSCSI to use the same flush / device deletion. But that's for a separate PR.
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.
yeah lets file that as a separate issue I think.
/test pull-kubernetes-e2e-gce-ubuntu-containerd |
If a FibreChannel device is used as a block volume, we should flush its I/O before deleting its device. It is not strictly necessary when it's used as a filesystem (mount), but it won't hurt either.
/retest |
/retest Review the full test history for this PR. Silence the bot with an |
…13-upstream-release-1.19 Automated cherry pick of #97013: Fix FibreChannel volume plugin corrupting filesystem on
…13-upstream-release-1.18 Automated cherry pick of #97013: Fix FibreChannel volume plugin corrupting filesystem on
…13-upstream-release-1.20 Automated cherry pick of #97013: Fix FibreChannel volume plugin corrupting filesystem on
What type of PR is this?
/kind bug
What this PR does / why we need it:
FibreChannel volume plugin misses one important step when removing a device:
multipath -f
, that flushes all multipath buffers to its individual paths. Without it, a filesystem on the device may get corrupted.Calling
multipath -f
is easy, however, the patch grew a bit by passing all the necessary interfaces down to fc_util.go. The structure copies iscsi_util.goSee https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/removing_devices for details.
Which issue(s) this PR fixes:
Fixes #97014
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: