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 11 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
31 changes: 31 additions & 0 deletions component/libfuse/libfuse2_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ func (lf *Libfuse) destroyFuse() error {

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

log.Trace("Libfuse::libfuse2_init : init")
C.populate_uid_gid()

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

// libfuse2_getattr gets file attributes
//
//export libfuse2_getattr
func libfuse2_getattr(path *C.char, stbuf *C.stat_t) C.int {
name := trimFusePath(path)
Expand Down Expand Up @@ -350,6 +358,7 @@ func libfuse2_getattr(path *C.char, stbuf *C.stat_t) 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 @@ -383,6 +392,7 @@ func libfuse_statfs(path *C.char, buf *C.statvfs_t) C.int {
// 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 @@ -402,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 @@ -430,6 +441,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 @@ -441,6 +453,7 @@ func libfuse_releasedir(path *C.char, fi *C.fuse_file_info_t) C.int {
}

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

// 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 @@ -537,6 +551,7 @@ func libfuse_rmdir(path *C.char) C.int {
// File Operations

// 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 @@ -570,6 +585,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 @@ -618,6 +634,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 @@ -653,6 +670,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 @@ -677,6 +695,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 @@ -703,6 +722,7 @@ func libfuse_flush(path *C.char, fi *C.fuse_file_info_t) C.int {
}

// libfuse2_truncate changes the size of a file
//
//export libfuse2_truncate
func libfuse2_truncate(path *C.char, off C.off_t) C.int {
name := trimFusePath(path)
Expand All @@ -726,6 +746,7 @@ func libfuse2_truncate(path *C.char, off C.off_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 @@ -753,6 +774,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 @@ -778,6 +800,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 libfuse2_rename
func libfuse2_rename(src *C.char, dst *C.char) C.int {
srcPath := trimFusePath(src)
Expand Down Expand Up @@ -849,6 +872,7 @@ func libfuse2_rename(src *C.char, dst *C.char) 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 @@ -870,6 +894,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 @@ -895,6 +920,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 @@ -922,6 +948,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 @@ -945,6 +972,7 @@ func libfuse_fsyncdir(path *C.char, datasync C.int, fi *C.fuse_file_info_t) C.in
}

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

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

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

// 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
Loading