Skip to content

Commit

Permalink
Default to read-only mode (#55)
Browse files Browse the repository at this point in the history
* Make -readOnly enabled by default

* Add hidden experimental -readWrite option

* Make flags mutually exclusive
  • Loading branch information
kpjensen authored Jan 7, 2021
1 parent fe0d70d commit 28c85d0
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ main
__pycache__
ENV
cmd_results.txt
diff.txt
diff.txt
dxfuse
100 changes: 60 additions & 40 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"io/ioutil"
"log"
"os"
"os/user"
"os/exec"
"os/user"
"path/filepath"
"strconv"
"strings"
Expand All @@ -25,8 +25,8 @@ import (

type Config struct {
mountpoint string
dxEnv dxda.DXEnvironment
options dxfuse.Options
dxEnv dxda.DXEnvironment
options dxfuse.Options
}

var progName = filepath.Base(os.Args[0])
Expand All @@ -36,22 +36,30 @@ func usage() {
fmt.Fprintf(os.Stderr, " %s [options] MOUNTPOINT PROJECT1 PROJECT2 ...\n", progName)
fmt.Fprintf(os.Stderr, " %s [options] MOUNTPOINT manifest.json\n", progName)
fmt.Fprintf(os.Stderr, "options:\n")
flag.PrintDefaults()
// Hide experimental options
flag.VisitAll(func(f *flag.Flag) {
if f.Name == "readOnly" || f.Name == "readWrite" || f.Name == "daemon" {
return
}
name, usage := flag.UnquoteUsage(f)
fmt.Fprintf(os.Stderr, " -%s %s \n\t%s\n", f.Name, name, usage)
})
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "A project can be specified by its ID or name. The manifest is a JSON\n")
fmt.Fprintf(os.Stderr, "file describing the initial filesystem structure.\n")
}

var (
debugFuseFlag = flag.Bool("debugFuse", false, "Tap into FUSE debugging information")
daemon = flag.Bool("daemon", false, "An internal flag, do not use it")
fsSync = flag.Bool("sync", false, "Sychronize the filesystem and exit")
gid = flag.Int("gid", -1, "User group id (gid)")
help = flag.Bool("help", false, "display program options")
readOnly = flag.Bool("readOnly", false, "mount the filesystem in read-only mode")
uid = flag.Int("uid", -1, "User id (uid)")
verbose = flag.Int("verbose", 0, "Enable verbose debugging")
version = flag.Bool("version", false, "Print the version and exit")
daemon = flag.Bool("daemon", false, "An internal flag, do not use it")
fsSync = flag.Bool("sync", false, "Sychronize the filesystem and exit")
help = flag.Bool("help", false, "display program options")
readOnly = flag.Bool("readOnly", true, "DEPRECATED, now the default behavior. Mount the filesystem in read-only mode")
readWrite = flag.Bool("readWrite", false, "mount the filesystem in read-write mode (Experimental, not recommended), default is read-only")
uid = flag.Int("uid", -1, "User id (uid)")
gid = flag.Int("gid", -1, "User group id (gid)")
verbose = flag.Int("verbose", 0, "Enable verbose debugging")
version = flag.Bool("version", false, "Print the version and exit")
)

func lookupProject(dxEnv *dxda.DXEnvironment, projectIdOrName string) (string, error) {
Expand All @@ -71,7 +79,7 @@ func lookupProject(dxEnv *dxda.DXEnvironment, projectIdOrName string) (string, e

func initLog(logFile string) *os.File {
// Redirect the log output to a file
f, err := os.OpenFile(logFile, os.O_RDWR | os.O_CREATE | os.O_APPEND | os.O_TRUNC, 0666)
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND|os.O_TRUNC, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
Expand Down Expand Up @@ -129,9 +137,9 @@ func fsDaemon(

// Fuse mount
cfg := &fuse.MountConfig{
FSName : "dxfuse",
ErrorLogger : logger,
DebugLogger : fuse_logger,
FSName: "dxfuse",
ErrorLogger: logger,
DebugLogger: fuse_logger,

// This option makes writes accumulate in the kernel
// buffers before being handed over to dxfuse for processing.
Expand All @@ -140,8 +148,8 @@ func fsDaemon(
//
// Currently, instead of dxfuse receiving every 4KB synchronously,
// it can get 128KB.
DisableWritebackCaching : false,
Options : mountOptions,
DisableWritebackCaching: false,
Options: mountOptions,
}

logger.Printf("mounting-dxfuse")
Expand Down Expand Up @@ -228,6 +236,21 @@ func parseCmdLineArgs() Config {
usage()
os.Exit(0)
}
// -readOnly and -readWrite flags are mutually exclusive
readOnlyFlagSet := false
readWriteFlagSet := false
flag.Visit(func(f *flag.Flag) {
if f.Name == "readOnly" {
readOnlyFlagSet = true
} else if f.Name == "readWrite" {
readWriteFlagSet = true
}
})
if readWriteFlagSet && readOnlyFlagSet {
fmt.Printf("Cannot provide both -readOnly and -readWrite flags\n")
usage()
os.Exit(2)
}

numArgs := flag.NArg()
if numArgs < 2 {
Expand All @@ -238,11 +261,11 @@ func parseCmdLineArgs() Config {

uid, gid := initUidGid()
options := dxfuse.Options{
ReadOnly: *readOnly,
Verbose : *verbose > 0,
VerboseLevel : *verbose,
Uid : uid,
Gid : gid,
ReadOnly: !*readWrite,
Verbose: *verbose > 0,
VerboseLevel: *verbose,
Uid: uid,
Gid: gid,
}

dxEnv, _, err := dxda.GetDxEnvironment()
Expand All @@ -252,9 +275,9 @@ func parseCmdLineArgs() Config {
}

return Config{
mountpoint : mountpoint,
dxEnv : dxEnv,
options : options,
mountpoint: mountpoint,
dxEnv: dxEnv,
options: options,
}
}

Expand Down Expand Up @@ -311,7 +334,6 @@ func parseManifest(cfg Config) (*dxfuse.Manifest, error) {
}
}


func startDaemon(cfg Config, logFile string) {
// initialize the log file
logf := initLog(logFile)
Expand Down Expand Up @@ -340,35 +362,34 @@ func buildDaemonCommandLine(cfg Config, fullManifestPath string) []string {
var daemonArgs []string
daemonArgs = append(daemonArgs, "-daemon")

if (*debugFuseFlag) {
if *debugFuseFlag {
daemonArgs = append(daemonArgs, "-debugFuse")
}
if (*fsSync) {
if *fsSync {
daemonArgs = append(daemonArgs, "-sync")
}
if (*gid != -1) {
args := []string { "-gid", strconv.FormatInt(int64(*gid), 10) }
if *gid != -1 {
args := []string{"-gid", strconv.FormatInt(int64(*gid), 10)}
daemonArgs = append(daemonArgs, args...)
}
if (*readOnly) {
daemonArgs = append(daemonArgs, "-readOnly")
if *readWrite {
daemonArgs = append(daemonArgs, "-readWrite")
}
if (*uid != -1) {
args := []string { "-uid", strconv.FormatInt(int64(*uid), 10) }
if *uid != -1 {
args := []string{"-uid", strconv.FormatInt(int64(*uid), 10)}
daemonArgs = append(daemonArgs, args...)
}
if (*verbose > 0) {
args := []string { "-verbose", strconv.FormatInt(int64(*verbose), 10) }
if *verbose > 0 {
args := []string{"-verbose", strconv.FormatInt(int64(*verbose), 10)}
daemonArgs = append(daemonArgs, args...)
}

positionalArgs := []string{ cfg.mountpoint, fullManifestPath }
positionalArgs := []string{cfg.mountpoint, fullManifestPath}
daemonArgs = append(daemonArgs, positionalArgs...)

return daemonArgs
}


// We are in the parent process.
//
func startDaemonAndWaitForInitializationToComplete(cfg Config, logFile string) {
Expand Down Expand Up @@ -434,7 +455,6 @@ func main() {
flag.Parse()
cfg := parseCmdLineArgs()
validateConfig(cfg)

logFile := dxfuse.MakeFSBaseDir() + "/" + dxfuse.LogFile
fmt.Printf("The log file is located at %s\n", logFile)

Expand Down
Binary file removed dxfuse
Binary file not shown.
12 changes: 6 additions & 6 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ azure: dxfuse copy_all
dx build correctness -f --destination dxfuse_azure_westus:/applets/correctness

dxfuse : $(wildcard ../**/*)
go build -o /go/bin/dxfuse /go/src/github.com/dnanexus/dxfuse/cli/main.go
go build -o ../dxfuse ../cli/main.go

copy_all : dxfuse bench correct bio correct_downloads

bench : dxfuse
mkdir -p benchmark/resources/usr/bin
cp -f /go/bin/dxfuse benchmark/resources/usr/bin/
cp -f ../dxfuse benchmark/resources/usr/bin/

correct: dxfuse
mkdir -p correctness/resources/usr/bin
cp -f /go/bin/dxfuse correctness/resources/usr/bin/
cp -f ../dxfuse correctness/resources/usr/bin/

correct_downloads: dxfuse
mkdir -p correctness_downloads/resources/usr/bin
cp -f /go/bin/dxfuse correctness_downloads/resources/usr/bin/
cp -f ../dxfuse correctness_downloads/resources/usr/bin/

bio : dxfuse
cp -f /go/bin/dxfuse bio_tools/resources/usr/bin/
cp -f ../dxfuse bio_tools/resources/usr/bin/

clean :
rm -f dxfuse
rm -f ../dxfuse
dx rm -f dxfuse_test_data:/applets/* || true
dx rm -f dxfuse_azure_westus:/applets/* || true
4 changes: 2 additions & 2 deletions test/benchmark/code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ main() {
# download with dxfuse
# Start the dxfuse daemon in the background, and wait for it to initilize.
echo "Mounting dxfuse"
flags=""
flags="-readWrite"
if [[ $verbose != "" ]]; then
flags="-verbose 1"
flags="$flags -verbose 1"
fi
dxfuse $flags $mountpoint $DX_PROJECT_CONTEXT_ID
sleep 1
Expand Down
4 changes: 2 additions & 2 deletions test/correctness/code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,9 @@ main() {

# Start the dxfuse daemon in the background, and wait for it to initilize.
echo "Mounting dxfuse"
flags=""
flags="-readWrite"
if [[ $verbose != "" ]]; then
flags="-verbose 2"
flags="$flags -verbose 2"
fi
$dxfuse $flags $mountpoint dxfuse_test_data dxfuse_test_read_only ArchivedStuff

Expand Down
4 changes: 2 additions & 2 deletions test/local/faux_dirs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ function faux_dirs {

# Start the dxfuse daemon in the background, and wait for it to initilize.
echo "Mounting dxfuse"
flags=""
flags="-readWrite"
if [[ $verbose != "" ]]; then
flags="-verbose 2"
flags="$flags -verbose 2"
fi
$dxfuse $flags $mountpoint dxfuse_test_data dxfuse_test_read_only ArchivedStuff
sleep 1
Expand Down
4 changes: 2 additions & 2 deletions test/local/file_overwrite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ function file_overwrite {

# Start the dxfuse daemon in the background, and wait for it to initilize.
echo "Mounting dxfuse"
flags=""
flags="-readWrite"
if [[ $verbose != "" ]]; then
flags="-verbose 2"
flags="$flags -verbose 2"
fi
$dxfuse $flags $mountpoint dxfuse_test_data
sleep 1
Expand Down
4 changes: 2 additions & 2 deletions test/local/file_write_slow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ function file_write_slow {

# Start the dxfuse daemon in the background, and wait for it to initilize.
echo "Mounting dxfuse"
flags=""
flags="-readWrite"
if [[ $verbose != "" ]]; then
flags="-verbose 2"
flags="$flags -verbose 2"
fi
$dxfuse $flags $mountpoint dxfuse_test_data
sleep 1
Expand Down
4 changes: 2 additions & 2 deletions test/local/fs_test_cases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ function fs_test_cases {

# Start the dxfuse daemon in the background, and wait for it to initilize.
echo "Mounting dxfuse"
flags=""
flags="-readWrite"
if [[ $verbose != "" ]]; then
flags="-verbose 2"
flags="$flags -verbose 2"
fi
$dxfuse $flags $mountpoint dxfuse_test_data dxfuse_test_read_only ArchivedStuff
sleep 1
Expand Down
2 changes: 1 addition & 1 deletion test/local/sync_concurrency_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trap teardown EXIT
# Ensure that only one sync command may run at a time
function sync_concurrency_test {
mkdir -p $mountpoint
$dxfuse $mountpoint $projName
$dxfuse -readWrite $mountpoint $projName
sleep 1
dd if=/dev/urandom of=50MB bs=1M count=50
writeable_dir=$(cat /dev/urandom | env LC_CTYPE=C LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1)
Expand Down
4 changes: 2 additions & 2 deletions test/local/xattr_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ function xattr_test {

# Start the dxfuse daemon in the background, and wait for it to initilize.
echo "Mounting dxfuse"
flags=""
flags="-readWrite"
if [[ $verbose != "" ]]; then
flags="-verbose 2"
flags="$flags verbose 2"
fi
$dxfuse $flags $mountpoint $projName
sleep 1
Expand Down

0 comments on commit 28c85d0

Please sign in to comment.