Skip to content

vfs/sftpfs: Fix error handling [PoC] - #5163

Open
tuffnatty wants to merge 5 commits into
MidnightCommander:masterfrom
tuffnatty:sftp-error-handling
Open

tuffnatty wants to merge 5 commits into
MidnightCommander:masterfrom
tuffnatty:sftp-error-handling

Conversation

@tuffnatty

@tuffnatty tuffnatty commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes

It's a proof-of-concept patch to fix error handling in vfs/sftpfs.

The first two commits implement @zyv 's suggestions about blocking mode and file write API usage from #3654.

The third patch fixes a couple of typos in comments.

The fourth patch improves error handling. It tries to always set an errno for the calling code, not try to return -errno instead of -1 as it's not handled by the calling code, display an additional SFTP-specific error message only when no exactly corresponding errno exists.
The error handling patch has not been tested well enough but seems to mostly work for me.

The fifth patch changes vfs_s_get_path() to keep verrno set by open_archive() VFS method and only reset it to EIO if a failed open_archive() call has not set any.

This PR has conflicts with my other sftpfs PRs. I'm going to fix these conflicts one by one if something gets merged to master.

Checklist

  • I have referenced the issue(s) resolved by this PR (if any)
  • I have signed-off my contribution with git commit --amend -s
  • Lint and unit tests pass locally with my changes (make indent && make check)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@github-actions github-actions Bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels Sep 24, 2026
@github-actions github-actions Bot added this to the Future Releases milestone Sep 24, 2026
@zyv

zyv commented Sep 24, 2026

Copy link
Copy Markdown
Member

Wow, what you are doing here is massive. Very impressive. This, all in all, would finally actually make SFTP usable, performant, and reliable after all these decades since its introduction.

It's a real shame that I've burned all my credits on #5156, which is now ready to merge in as far as I'm concerned. If I had more, I could have actually off-loaded the grunt work to the agents and had everything reviewed even while still preparing for the exams 😭

@zyv zyv added area: vfs Virtual File System support and removed needs triage Needs triage by maintainers labels Sep 25, 2026
Comment thread src/vfs/sftpfs/connection.c
Comment thread src/vfs/sftpfs/internal.c Outdated
Comment thread src/vfs/sftpfs/sftpfs.c

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

I did what I could here, and hope this helps. My suggestions are to build and run tested.

One observation is that some messages show the suffix twice; otherwise, all seems to work correctly:

sftp: connection to server failed: Connection refused (111) (111)

Comment thread src/vfs/sftpfs/dir.c
Comment thread src/vfs/sftpfs/connection.c Outdated
Comment thread src/vfs/sftpfs/connection.c Outdated
Comment thread src/vfs/sftpfs/sftpfs.c Outdated
Comment thread src/vfs/sftpfs/sftpfs.c Outdated
Comment thread src/vfs/sftpfs/sftpfs.c Outdated
Comment thread src/vfs/sftpfs/sftpfs.c Outdated
Comment thread src/vfs/sftpfs/sftpfs.c Outdated
Comment thread src/vfs/sftpfs/file.c Outdated
Comment thread src/vfs/sftpfs/sftpfs.c Outdated
Signed-off-by: Phil Krylov <phil@krylov.eu>
Signed-off-by: Phil Krylov <phil@krylov.eu>
Signed-off-by: Phil Krylov <phil@krylov.eu>
@tuffnatty

Copy link
Copy Markdown
Contributor Author

I've applied most review suggestions, added localization for the error messages, and tried to fix the errno reset to EIO in vfs_s_get_path().

@tuffnatty

Copy link
Copy Markdown
Contributor Author

I've fixed missing known_hosts to return E_REMOTE for now, until #5161 gets merged.

Comment thread src/vfs/sftpfs/internal.c Outdated
Comment thread src/vfs/sftpfs/internal.c Outdated

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

I've built and run-tested my suggestions, and if you agree with them, I think that this is ready for merge in as far as I'm concerned. Thank you very much for your work on this!

@mc-worker, can you possibly test if this fixes the Android stuff for you? It seems that you were able to reproduce it?

Comment thread src/vfs/sftpfs/connection.c Outdated
Comment thread src/vfs/sftpfs/connection.c Outdated
Comment thread src/vfs/sftpfs/internal.c Outdated
Comment thread src/vfs/sftpfs/internal.c Outdated
Comment thread src/vfs/sftpfs/internal.c Outdated
Comment thread src/vfs/sftpfs/internal.c Outdated
Comment thread src/vfs/sftpfs/sftpfs.c Outdated
Comment thread src/vfs/sftpfs/sftpfs.c Outdated
@zyv zyv modified the milestones: Future Releases, 4.9.0 Sep 27, 2026
tuffnatty and others added 2 commits September 27, 2026 22:37
The errors which can be represented with `errno` without losing detail
are handled by the calling code. The libssh/SFTP-specific errors which
cannot be cleanly mapped to an `errno` are displayed as a separate popup
the same way as earlier, and a `E_REMOTE` is returned to the calling
code.

Signed-off-by: Phil Krylov <phil@krylov.eu>
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Some VFSes try hard to set a correct verrno in their open_archive()
method, some don't. vfs_s_get_path(), the only consumer of the method,
has historically set verrno to EIO on any error.

From now on, set verrno to EIO in vfs_get_path() only when the method
has not set any other verrno, so that a more specific error message
than "I/O error" is shown.

Signed-off-by: Phil Krylov <phil@krylov.eu>
@tuffnatty

Copy link
Copy Markdown
Contributor Author

@zyv Yes, I've merged all your suggestions and added a comment in sftpfs_cb_open_archive() regarding the double error message.

@tuffnatty tuffnatty changed the title vfs/sftpfs: Fix error handling [PoC] WIP: vfs/sftpfs: Fix error handling [PoC] Sep 28, 2026
@tuffnatty tuffnatty changed the title WIP: vfs/sftpfs: Fix error handling [PoC] vfs/sftpfs: Fix error handling [PoC] Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: vfs Virtual File System support prio: medium Has the potential to affect progress

Development

Successfully merging this pull request may close these issues.

More Descriptive Error Messages sftp file uploads/downloads hang or break on RPi, SSHDroid, Remarkable, etc.

3 participants