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 bug on create file #124

Closed
wants to merge 1 commit into from
Closed

Conversation

jessfraz
Copy link

@jessfraz jessfraz commented Apr 13, 2018

Do two calls to open_common one for the create and once for the open.

I don't think this is a correct fix but just opening here for some direction.

The problem is when running touch file on master returns:

touch: file: No such file or directory

It seems like create and open can't be done in one call.

@Nikratio
Copy link
Contributor

Sorry, I'm having trouble following your description. Could you elaborate? What problem is being solved, and how is it triggered? The commit seems to consist mostly of whitespace changes.

@jessfraz
Copy link
Author

So sorry my explanation was terrible. So I was trying to fix a bug here: gl-prototypes/cmd-localfs@d3e65e6

The behavior we were seeing is when the flag O_CREAT was on a open something like running touch $file or echo "hello" > file then it would error like so (but still create an empty file, which lead me to believe it just had to be done in two-step, once for O_CREAT and another to write):

/local # ls
Dockerfile  LICENSE     Makefile    README.md   cmd         cmd-client  data        sshfs
/local # touch non_existent_file
touch: non_existent_file: No such file or directory
/local # touch non_existent_file
/local # echo "hello" > another_non_existent_file
sh: can't create another_non_existent_file: nonexistent directory
/local # echo "hello" > another_non_existent_file
/local # cat another_non_existent_file 
hello
/local # strace touch blah_another_file
execve("/bin/touch", ["touch", "blah_another_file"], 0x7fff641a7e28 /* 7 vars */) = 0
arch_prctl(ARCH_SET_FS, 0x7f21e8e9bb88) = 0
set_tid_address(0x7f21e8e9bbc0)         = 16
mprotect(0x7f21e8e98000, 4096, PROT_READ) = 0
mprotect(0x55c2e834d000, 16384, PROT_READ) = 0
getuid()                                = 0
utimensat(AT_FDCWD, "blah_another_file", NULL, 0) = -1 ENOENT (No such file or directory)
open("blah_another_file", O_RDWR|O_CREAT, 0666) = -1 ENOENT (No such file or directory)
write(2, "touch: blah_another_file: No suc"..., 52touch: blah_another_file: No such file or directory
) = 52
exit_group(1)                           = ?
+++ exited with 1 +++

@jessfraz
Copy link
Author

Then with this fix it works with no error:

/local # ls
Dockerfile  LICENSE     Makefile    README.md   cmd         cmd-client  data        sshfs
/local # touch non_existent_file
/local # echo "hello" > another_non_existent_file
/local # cat another_non_existent_file 
hello

if (fi->flags & O_CREAT){
fi->flags = fi->flags &~ O_CREAT;
return sshfs_open_common(path, mode, fi);
}
Copy link
Author

Choose a reason for hiding this comment

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

This is mostly the logic here, sorry the whitespace is a vim plugin

Do two calls to `open_common` one for the create and once for the remaining
flags.

The behavior we were seeing is when the flag `O_CREAT` is passed on `open`
(via running `touch $file` or `echo "hello" > file`)
then the call will error, as shown below. But, it still create an empty file.

``console
/local # ls
Dockerfile  LICENSE     Makefile    README.md   cmd         cmd-client
data        sshfs
/local # touch non_existent_file
touch: non_existent_file: No such file or directory
/local # touch non_existent_file
/local # echo "hello" > another_non_existent_file
sh: can't create another_non_existent_file: nonexistent directory
/local # echo "hello" > another_non_existent_file
/local # cat another_non_existent_file
hello
/local # strace touch blah_another_file
execve("/bin/touch", ["touch", "blah_another_file"], 0x7fff641a7e28 /*
7 vars */) = 0
arch_prctl(ARCH_SET_FS, 0x7f21e8e9bb88) = 0
set_tid_address(0x7f21e8e9bbc0)         = 16
mprotect(0x7f21e8e98000, 4096, PROT_READ) = 0
mprotect(0x55c2e834d000, 16384, PROT_READ) = 0
getuid()                                = 0
utimensat(AT_FDCWD, "blah_another_file", NULL, 0) = -1 ENOENT (No such
file or directory)
open("blah_another_file", O_RDWR|O_CREAT, 0666) = -1 ENOENT (No such
file or directory)
write(2, "touch: blah_another_file: No suc"..., 52touch:
blah_another_file: No such file or directory
) = 52
exit_group(1)                           = ?
+++ exited with 1 +++
```

Signed-off-by: Jess Frazelle <[email protected]>
@jessfraz
Copy link
Author

And I definitely don't know if this fix is correct but that is the behavior :)

@Nikratio
Copy link
Contributor

I don't think this can be the right solution. You are simply stripping out the O_CREAT flag, which changes the semantics of the operation.

Furthermore, your examples run just fine on my system, so I suspect the problem is actually with your SSH server:

$ sshfs localhost:/tmp mnt/
$ touch mnt/newfile
$ fusermount -u mnt
$ sshd --version
unknown option -- -
OpenSSH_7.4p1 Debian-10+deb9u3, OpenSSL 1.0.2l  25 May 2017
[...]

Which kind of server are you connecting to?

@jessfraz
Copy link
Author

7.7_p1-r2 from this package https://pkgs.alpinelinux.org/package/edge/main/x86_64/openssh

if its the ssh server then I will close this, thanks for the help, i suspected it was a weird fix and wrong

@jessfraz jessfraz closed this Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants