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: async (background) mount may cause problems #1088

Merged
merged 30 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
75157cc
Adding cli flag to wait after daemonization to ensure child process h…
vibhansa-msft Mar 17, 2023
bec96f5
update
vibhansa-msft Mar 17, 2023
dbac12c
spell correction
vibhansa-msft Mar 17, 2023
be68a5a
Update readme for new cli option
vibhansa-msft Mar 17, 2023
7739601
Correct cli help
vibhansa-msft Mar 17, 2023
8fc9110
fix : mount
cvvz Mar 18, 2023
1494afd
fix
cvvz Mar 18, 2023
9517925
remove timeout
cvvz Mar 18, 2023
84d7f70
fix
cvvz Mar 20, 2023
637f3a3
fix
cvvz Mar 20, 2023
2c817e8
format
cvvz Mar 20, 2023
e6f13bc
make no difference
cvvz Mar 20, 2023
5b93098
do not exit when creating tmp file failed
cvvz Mar 20, 2023
f04ea61
fix
cvvz Mar 20, 2023
597f808
fix
cvvz Mar 20, 2023
3b1f155
fix
cvvz Mar 20, 2023
67d9fd0
Adding wait for mount as an alternative
vibhansa-msft Mar 20, 2023
5ee5f7c
Merge branch 'vibhansa/v2/waitformount' of https://github.com/Azure/a…
cvvz Mar 20, 2023
8d277d1
fix signal
cvvz Mar 20, 2023
4007661
fix for-select code
cvvz Mar 20, 2023
1c304b8
fix errcheck
cvvz Mar 20, 2023
4c9ab71
Use PIPE for communication between child and parent
cvvz Mar 21, 2023
f2e1eac
Correcting the code
vibhansa-msft Mar 21, 2023
d3ac13a
Updating changlog
vibhansa-msft Mar 21, 2023
7a59567
Sync with main
vibhansa-msft Mar 21, 2023
baf70b2
Using daemon context logfile to redirect child's stderr to file
vibhansa-msft Mar 21, 2023
1fd148d
Rolling back go-daemon to standard version
vibhansa-msft Mar 21, 2023
a63ea54
Adding step to rhel 7.5 pipeline to run
vibhansa-msft Mar 21, 2023
62fcf3f
Correcting nightly
vibhansa-msft Mar 21, 2023
c5a23e0
Send signal only if mount was done in background
vibhansa-msft Mar 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"path/filepath"
"runtime"
"runtime/debug"
Expand Down Expand Up @@ -399,6 +400,17 @@ var mountCmd = &cobra.Command{
Umask: 022,
}

if !daemon.WasReborn() {
// redirect libfuse stderr to a temp file
f, err := ioutil.TempFile("", "libfuse_stderr_")
vibhansa-msft marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Err("failed to create temp file for storing libfuse error log [%v]", err)
} else {
defer os.Remove(f.Name())
dmnCtx.LogFileName = f.Name()
}
vibhansa-msft marked this conversation as resolved.
Show resolved Hide resolved
}

ctx, _ := context.WithCancel(context.Background()) //nolint
daemon.SetSigHandler(sigusrHandler(pipeline, ctx), syscall.SIGUSR1, syscall.SIGUSR2)
child, err := dmnCtx.Reborn()
Expand All @@ -415,8 +427,27 @@ var mountCmd = &cobra.Command{

err = runPipeline(pipeline, ctx)
if err != nil {
errMsg, _ := ioutil.ReadFile(dmnCtx.LogFileName)
log.Err("libfuse exit with error message: %s", errMsg)
return err
}
} else {
// set signal handler
sigusr2 := make(chan os.Signal, 1)
signal.Notify(sigusr2, syscall.SIGUSR2)
cvvz marked this conversation as resolved.
Show resolved Hide resolved
sigchild := make(chan os.Signal, 1)
signal.Notify(sigchild, syscall.SIGCHLD)

for {
select {
case <-sigusr2:
log.Info("fuse mount at %s succeed.", options.MountPath)
return nil
case <-sigchild:
errMsg, _ := ioutil.ReadFile(dmnCtx.LogFileName)
return Destroy(fmt.Sprintf("fuse mount failed with error message: %s", errMsg))
}
}
}
} else {
if options.CPUProfile != "" {
Expand Down
30 changes: 30 additions & 0 deletions component/libfuse/libfuse_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ func (lf *Libfuse) destroyFuse() error {

//export libfuse_init
func libfuse_init(conn *C.fuse_conn_info_t, cfg *C.fuse_config_t) (res unsafe.Pointer) {
// fuse started processing requests, no error happened during mounting
vibhansa-msft marked this conversation as resolved.
Show resolved Hide resolved
log.Trace("Libfuse::libfuse_init : notifying parent")
ppid := syscall.Getppid()
vibhansa-msft marked this conversation as resolved.
Show resolved Hide resolved
if ppid != 1 {
syscall.Kill(ppid, syscall.SIGUSR2)
}
log.Trace("Libfuse::libfuse_init : init")
C.populate_uid_gid()

Expand Down Expand Up @@ -353,6 +359,7 @@ func (lf *Libfuse) fillStat(attr *internal.ObjAttr, stbuf *C.stat_t) {
// otherwise, perform necessary permission checking

// libfuse_getattr gets file attributes
//
vibhansa-msft marked this conversation as resolved.
Show resolved Hide resolved
//export libfuse_getattr
func libfuse_getattr(path *C.char, stbuf *C.stat_t, fi *C.fuse_file_info_t) C.int {
name := trimFusePath(path)
Expand Down Expand Up @@ -385,6 +392,7 @@ func libfuse_getattr(path *C.char, stbuf *C.stat_t, fi *C.fuse_file_info_t) C.in
// Directory Operations

// libfuse_mkdir creates a directory
//
//export libfuse_mkdir
func libfuse_mkdir(path *C.char, mode C.mode_t) C.int {
name := trimFusePath(path)
Expand All @@ -404,6 +412,7 @@ func libfuse_mkdir(path *C.char, mode C.mode_t) C.int {
}

// libfuse_opendir opens handle to given directory
//
//export libfuse_opendir
func libfuse_opendir(path *C.char, fi *C.fuse_file_info_t) C.int {
name := trimFusePath(path)
Expand Down Expand Up @@ -433,6 +442,7 @@ func libfuse_opendir(path *C.char, fi *C.fuse_file_info_t) C.int {
}

// libfuse_releasedir opens handle to given directory
//
//export libfuse_releasedir
func libfuse_releasedir(path *C.char, fi *C.fuse_file_info_t) C.int {
handle := (*handlemap.Handle)(unsafe.Pointer(uintptr(fi.fh)))
Expand All @@ -445,6 +455,7 @@ func libfuse_releasedir(path *C.char, fi *C.fuse_file_info_t) C.int {
}

// libfuse_readdir reads a directory
//
//export libfuse_readdir
func libfuse_readdir(_ *C.char, buf unsafe.Pointer, filler C.fuse_fill_dir_t, off C.off_t, fi *C.fuse_file_info_t, flag C.fuse_readdir_flags_t) C.int {
handle := (*handlemap.Handle)(unsafe.Pointer(uintptr(fi.fh)))
Expand Down Expand Up @@ -513,6 +524,7 @@ func libfuse_readdir(_ *C.char, buf unsafe.Pointer, filler C.fuse_fill_dir_t, of
}

// libfuse_rmdir deletes a directory, which must be empty.
//
//export libfuse_rmdir
func libfuse_rmdir(path *C.char) C.int {
name := trimFusePath(path)
Expand Down Expand Up @@ -541,6 +553,7 @@ func libfuse_rmdir(path *C.char) C.int {
}

// File Operations
//
//export libfuse_statfs
func libfuse_statfs(path *C.char, buf *C.statvfs_t) C.int {
name := trimFusePath(path)
Expand Down Expand Up @@ -572,6 +585,7 @@ func libfuse_statfs(path *C.char, buf *C.statvfs_t) C.int {
}

// libfuse_create creates a file with the specified mode and then opens it.
//
//export libfuse_create
func libfuse_create(path *C.char, mode C.mode_t, fi *C.fuse_file_info_t) C.int {
name := trimFusePath(path)
Expand Down Expand Up @@ -606,6 +620,7 @@ func libfuse_create(path *C.char, mode C.mode_t, fi *C.fuse_file_info_t) C.int {
}

// libfuse_open opens a file
//
//export libfuse_open
func libfuse_open(path *C.char, fi *C.fuse_file_info_t) C.int {
name := trimFusePath(path)
Expand Down Expand Up @@ -668,6 +683,7 @@ func libfuse_open(path *C.char, fi *C.fuse_file_info_t) C.int {
}

// libfuse_read reads data from an open file
//
//export libfuse_read
func libfuse_read(path *C.char, buf *C.char, size C.size_t, off C.off_t, fi *C.fuse_file_info_t) C.int {
fileHandle := (*C.file_handle_t)(unsafe.Pointer(uintptr(fi.fh)))
Expand Down Expand Up @@ -703,6 +719,7 @@ func libfuse_read(path *C.char, buf *C.char, size C.size_t, off C.off_t, fi *C.f
}

// libfuse_write writes data to an open file
//
//export libfuse_write
func libfuse_write(path *C.char, buf *C.char, size C.size_t, off C.off_t, fi *C.fuse_file_info_t) C.int {
fileHandle := (*C.file_handle_t)(unsafe.Pointer(uintptr(fi.fh)))
Expand All @@ -727,6 +744,7 @@ func libfuse_write(path *C.char, buf *C.char, size C.size_t, off C.off_t, fi *C.
}

// libfuse_flush possibly flushes cached data
//
//export libfuse_flush
func libfuse_flush(path *C.char, fi *C.fuse_file_info_t) C.int {
fileHandle := (*C.file_handle_t)(unsafe.Pointer(uintptr(fi.fh)))
Expand All @@ -753,6 +771,7 @@ func libfuse_flush(path *C.char, fi *C.fuse_file_info_t) C.int {
}

// libfuse_truncate changes the size of a file
//
//export libfuse_truncate
func libfuse_truncate(path *C.char, off C.off_t, fi *C.fuse_file_info_t) C.int {
name := trimFusePath(path)
Expand All @@ -775,6 +794,7 @@ func libfuse_truncate(path *C.char, off C.off_t, fi *C.fuse_file_info_t) C.int {
}

// libfuse_release releases an open file
//
//export libfuse_release
func libfuse_release(path *C.char, fi *C.fuse_file_info_t) C.int {
fileHandle := (*C.file_handle_t)(unsafe.Pointer(uintptr(fi.fh)))
Expand Down Expand Up @@ -803,6 +823,7 @@ func libfuse_release(path *C.char, fi *C.fuse_file_info_t) C.int {
}

// libfuse_unlink removes a file
//
//export libfuse_unlink
func libfuse_unlink(path *C.char) C.int {
name := trimFusePath(path)
Expand All @@ -828,6 +849,7 @@ func libfuse_unlink(path *C.char) C.int {
// https://man7.org/linux/man-pages/man2/rename.2.html
// errors handled: EISDIR, ENOENT, ENOTDIR, ENOTEMPTY, EEXIST
// TODO: handle EACCESS, EINVAL?
//
//export libfuse_rename
func libfuse_rename(src *C.char, dst *C.char, flags C.uint) C.int {
srcPath := trimFusePath(src)
Expand Down Expand Up @@ -909,6 +931,7 @@ func libfuse_rename(src *C.char, dst *C.char, flags C.uint) C.int {
// Symlink Operations

// libfuse_symlink creates a symbolic link
//
//export libfuse_symlink
func libfuse_symlink(target *C.char, link *C.char) C.int {
name := trimFusePath(link)
Expand All @@ -930,6 +953,7 @@ func libfuse_symlink(target *C.char, link *C.char) C.int {
}

// libfuse_readlink reads the target of a symbolic link
//
//export libfuse_readlink
func libfuse_readlink(path *C.char, buf *C.char, size C.size_t) C.int {
name := trimFusePath(path)
Expand All @@ -955,6 +979,7 @@ func libfuse_readlink(path *C.char, buf *C.char, size C.size_t) C.int {
}

// libfuse_fsync synchronizes file contents
//
//export libfuse_fsync
func libfuse_fsync(path *C.char, datasync C.int, fi *C.fuse_file_info_t) C.int {
if fi.fh == 0 {
Expand Down Expand Up @@ -982,6 +1007,7 @@ func libfuse_fsync(path *C.char, datasync C.int, fi *C.fuse_file_info_t) C.int {
}

// libfuse_fsyncdir synchronizes directory contents
//
//export libfuse_fsyncdir
func libfuse_fsyncdir(path *C.char, datasync C.int, fi *C.fuse_file_info_t) C.int {
name := trimFusePath(path)
Expand All @@ -1005,6 +1031,7 @@ func libfuse_fsyncdir(path *C.char, datasync C.int, fi *C.fuse_file_info_t) C.in
}

// libfuse_chmod changes permission bits of a file
//
//export libfuse_chmod
func libfuse_chmod(path *C.char, mode C.mode_t, fi *C.fuse_file_info_t) C.int {
name := trimFusePath(path)
Expand All @@ -1031,6 +1058,7 @@ func libfuse_chmod(path *C.char, mode C.mode_t, fi *C.fuse_file_info_t) C.int {
}

// libfuse_chown changes the owner and group of a file
//
//export libfuse_chown
func libfuse_chown(path *C.char, uid C.uid_t, gid C.gid_t, fi *C.fuse_file_info_t) C.int {
name := trimFusePath(path)
Expand All @@ -1041,6 +1069,7 @@ func libfuse_chown(path *C.char, uid C.uid_t, gid C.gid_t, fi *C.fuse_file_info_
}

// libfuse_utimens changes the access and modification times of a file
//
//export libfuse_utimens
func libfuse_utimens(path *C.char, tv *C.timespec_t, fi *C.fuse_file_info_t) C.int {
name := trimFusePath(path)
Expand All @@ -1053,6 +1082,7 @@ func libfuse_utimens(path *C.char, tv *C.timespec_t, fi *C.fuse_file_info_t) C.i
}

// blobfuse_cache_update refresh the file-cache policy for this file
//
//export blobfuse_cache_update
func blobfuse_cache_update(path *C.char) C.int {
name := trimFusePath(path)
Expand Down