Skip to content
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

Merged
merged 2 commits into from Dec 9, 2020

Conversation

jsafrane
Copy link
Member

@jsafrane jsafrane commented Dec 2, 2020

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.go

See 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?:

Fixed FibreChannel volume plugin corrupting filesystems on detach of multipath volumes.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Dec 2, 2020
@k8s-ci-robot
Copy link
Contributor

@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 triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. approved Indicates a PR has been approved by an approver from all required OWNERS files. sig/storage Categorizes an issue or PR as relevant to SIG Storage. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Dec 2, 2020
@jsafrane
Copy link
Member Author

jsafrane commented Dec 2, 2020

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Dec 2, 2020
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.
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))
Copy link
Contributor

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?)

Copy link
Member Author

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...

Copy link
Member Author

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 in checkPathExists, if not earlier in operation_generator.go (did not test it).

    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.

Copy link
Contributor

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.

@rootfs
Copy link
Contributor

rootfs commented Dec 2, 2020

/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))
Copy link
Contributor

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))

Copy link
Member Author

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.

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -354,6 +358,9 @@ func (util *fcUtil) DetachBlockFCDisk(c fcDiskUnmapper, mapPath, devicePath stri
if len(dm) != 0 {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

@tsmetana
Copy link
Member

tsmetana commented Dec 3, 2020

/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.
@gnufied
Copy link
Member

gnufied commented Dec 3, 2020

/retest
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 3, 2020
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit f8db0d9 into kubernetes:master Dec 9, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Dec 9, 2020
k8s-ci-robot added a commit that referenced this pull request Dec 15, 2020
…13-upstream-release-1.19

Automated cherry pick of #97013: Fix FibreChannel volume plugin corrupting filesystem on
k8s-ci-robot added a commit that referenced this pull request Dec 15, 2020
…13-upstream-release-1.18

Automated cherry pick of #97013: Fix FibreChannel volume plugin corrupting filesystem on
k8s-ci-robot added a commit that referenced this pull request Dec 15, 2020
…13-upstream-release-1.20

Automated cherry pick of #97013: Fix FibreChannel volume plugin corrupting filesystem on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fibre channel volume plugin corrupts volumes on detach
7 participants