Skip to content

util: include stderr in cryptsetup errors#6036

Merged
mergify[bot] merged 2 commits into
ceph:develfrom
black-dragon74:cryptsetup-err-inc-stderr
Feb 16, 2026
Merged

util: include stderr in cryptsetup errors#6036
mergify[bot] merged 2 commits into
ceph:develfrom
black-dragon74:cryptsetup-err-inc-stderr

Conversation

@black-dragon74

Copy link
Copy Markdown
Member

Describe what this PR does

This patch includes the stderr when an error is encountered in cryptsetup.

This patch additionally fixes a potential memory leak which could occur if WriteString fails inside file package.

@iPraveenParihar iPraveenParihar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Comment thread internal/util/cryptsetup/cryptsetup.go Outdated
return &result
}
// Include stderr if not empty
baseErr := fmt.Sprintf("an error (%v) occurred while running %s args: %v", err, program, sanitizedArgs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
baseErr := fmt.Sprintf("an error (%v) occurred while running %s args: %v", err, program, sanitizedArgs)
baseErr := fmt.Errof("error running %s args: %v: %w", program, sanitizedArgs: err)

Comment thread internal/util/cryptsetup/cryptsetup.go Outdated
size, err := strconv.ParseUint(input, 10, 32)
if err != nil {
return fmt.Errorf("could not parse number from %q: %w", input, err)
return stdout, stderr, fmt.Errorf("%s", baseErr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return stdout, stderr, fmt.Errorf("%s", baseErr)
return stdout, stderr, errors.New(baseErr)

Comment thread internal/util/file/file.go Outdated
@@ -34,6 +34,8 @@ func CreateTempFile(prefix, contents string) (*os.File, error) {
// In case of error, remove the file if it was created
defer func() {
if err != nil {
//nolint:errcheck // may return file already closed in happy path
_ = file.Close()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of closing the file below, sync/flush the contents and always close it in the deferred statement here. The sync/flush error is more important than the close error, which just can be logged.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nixpanic nixpanic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both changes look unrelated, it is probably cleaner to split them into their own commits.

This patch includes the stderr when an error is encountered
in cryptsetup.

Signed-off-by: Niraj Yadav <niryadav@redhat.com>
This patch makes changes which ensure that the content for
tempfile is flushed to disk before returning the handle.

It also silently ignores errors when closing and removing the
file as sync error has more weightage than these.

Signed-off-by: Niraj Yadav <niryadav@redhat.com>
@black-dragon74 black-dragon74 force-pushed the cryptsetup-err-inc-stderr branch from 221263a to 4e6b633 Compare February 12, 2026 09:53
@black-dragon74

Copy link
Copy Markdown
Member Author

Both changes look unrelated, it is probably cleaner to split them into their own commits.

Done

@nixpanic nixpanic requested a review from a team February 16, 2026 13:16
@nixpanic

Copy link
Copy Markdown
Member

@Mergifyio queue

@mergify

mergify Bot commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

Rule: default


This pull request spent 3 hours 43 seconds in the queue, including 3 hours 32 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 2 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • any of:
    • all of:
      • base=devel
      • status-success=codespell
      • status-success=go-test
      • status-success=golangci-lint
      • status-success=lint-extras
      • status-success=mod-check
      • status-success=multi-arch-build
      • status-success=uncommitted-code-check
      • any of:
        • all of:
          • status-success=ci/centos/k8s-e2e-external-storage/1.33
          • status-success=ci/centos/k8s-e2e-external-storage/1.34
          • status-success=ci/centos/k8s-e2e-external-storage/1.35
          • status-success=ci/centos/mini-e2e-helm/k8s-1.33
          • status-success=ci/centos/mini-e2e-helm/k8s-1.34
          • status-success=ci/centos/mini-e2e-helm/k8s-1.35
          • status-success=ci/centos/mini-e2e/k8s-1.33
          • status-success=ci/centos/mini-e2e/k8s-1.34
          • status-success=ci/centos/mini-e2e/k8s-1.35
          • status-success=ci/centos/upgrade-tests-cephfs
          • status-success=ci/centos/upgrade-tests-rbd
        • label=ci/skip/e2e
    • all of:
      • base~=^(release-.+)$
      • any of:
        • label=ci/skip/e2e
        • all of:
          • status-success=ci/centos/k8s-e2e-external-storage/1.32
          • status-success=ci/centos/mini-e2e-helm/k8s-1.32
          • status-success=ci/centos/mini-e2e/k8s-1.32
          • status-success=ci/centos/k8s-e2e-external-storage/1.33
          • status-success=ci/centos/k8s-e2e-external-storage/1.34
          • status-success=ci/centos/mini-e2e-helm/k8s-1.33
          • status-success=ci/centos/mini-e2e-helm/k8s-1.34
          • status-success=ci/centos/mini-e2e/k8s-1.33
          • status-success=ci/centos/mini-e2e/k8s-1.34
          • status-success=ci/centos/upgrade-tests-cephfs
          • status-success=ci/centos/upgrade-tests-rbd
      • status-success=codespell
      • status-success=go-test
      • status-success=golangci-lint
      • status-success=lint-extras
      • status-success=mod-check
      • status-success=multi-arch-build
      • status-success=uncommitted-code-check
    • all of:
      • base=release-v3.15
      • any of:
        • label=ci/skip/e2e
        • all of:
          • status-success=ci/centos/k8s-e2e-external-storage/1.31
          • status-success=ci/centos/k8s-e2e-external-storage/1.32
          • status-success=ci/centos/mini-e2e-helm/k8s-1.31
          • status-success=ci/centos/mini-e2e-helm/k8s-1.32
          • status-success=ci/centos/mini-e2e/k8s-1.31
          • status-success=ci/centos/mini-e2e/k8s-1.32
          • status-success=ci/centos/k8s-e2e-external-storage/1.33
          • status-success=ci/centos/mini-e2e-helm/k8s-1.33
          • status-success=ci/centos/mini-e2e/k8s-1.33
          • status-success=ci/centos/upgrade-tests-cephfs
          • status-success=ci/centos/upgrade-tests-rbd
      • status-success=codespell
      • status-success=go-test
      • status-success=golangci-lint
      • status-success=lint-extras
      • status-success=mod-check
      • status-success=multi-arch-build
      • status-success=uncommitted-code-check
    • all of:
      • base=ci/centos
      • status-success=ci/centos/jjb-validate
      • status-success=ci/centos/job-validation

@mergify mergify Bot added the queued label Feb 16, 2026
mergify Bot added a commit that referenced this pull request Feb 16, 2026
@mergify mergify Bot merged commit 80614c9 into ceph:devel Feb 16, 2026
16 of 17 checks passed
@mergify mergify Bot removed the queued label Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants