Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions drivers/resfszfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ func (t *T) mountLegacy() error {
a.Append("-t", "zfs")
mountOptions := t.mountOptions()
if len(mountOptions) > 0 {
a.Append("-o")
a.Append(t.mountOptions()...)
a.Append("-o", strings.Join(mountOptions, ","))
}
a.Append(t.Device, t.MountPoint)
cmd := command.New(
Expand Down
49 changes: 29 additions & 20 deletions util/loop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package loop

import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

"github.com/opensvc/fcntllock"
"github.com/opensvc/flock"
"github.com/rs/zerolog"

"github.com/opensvc/om3/v3/util/command"
"github.com/opensvc/om3/v3/util/sessioncache"
"github.com/opensvc/om3/v3/util/funcopt"
"github.com/opensvc/om3/v3/util/plog"
"github.com/opensvc/om3/v3/util/sessioncache"
"github.com/opensvc/om3/v3/util/udevadm"
)

Expand All @@ -25,19 +25,16 @@ type (
T struct {
log *plog.Logger
}

Info struct {
LoopDevices []InfoEntry `json:"loopdevices"`
}

InfoEntry struct {
Name string `json:"name"` // "/dev/loop1"
SizeLimit int64 `json:"sizelimit"` // 0
Offset int64 `json:"offset"` // 0
AutoClear bool `json:"autoclear"` // true
ReadOnly bool `json:"ro"` // true
BackFile string `json:"back-file"` // "/var/lib/snapd/snaps/gnome-3-34-1804_66.snap"
DirectIO bool `json:"dio"` // false
LogSec int64 `json:"log-sec"` // 512
Name string `json:"name"` // "/dev/loop1"
BackFile string `json:"back-file"` // "/var/lib/snapd/snaps/gnome-3-34-1804_66.snap"
}

InfoEntries []InfoEntry
)

Expand Down Expand Up @@ -91,14 +88,14 @@ func (t T) Get(ctx context.Context, name string) (*InfoEntry, error) {

func (t T) Data(ctx context.Context) (InfoEntries, error) {
var (
out []byte
err error
out []byte
err error
entries InfoEntries
)
data := Info{}
cmd := command.New(
command.WithContext(ctx),
command.WithName(losetup),
command.WithVarArgs("-J"),
command.WithVarArgs("-O", "NAME,BACK-FILE"), // The -J and -n options are not supported by losetup on RHEL 7.
command.WithLogger(t.log),
command.WithCommandLogLevel(zerolog.TraceLevel),
command.WithStdoutLogLevel(zerolog.TraceLevel),
Expand All @@ -111,10 +108,25 @@ func (t T) Data(ctx context.Context) (InfoEntries, error) {
if len(out) == 0 {
return InfoEntries{}, nil
}
if err = json.Unmarshal(out, &data); err != nil {
return nil, err
/*
Output to parse: losetup -O NAME,BACK-FILE
NAME BACK-FILE
/dev/loop0 /tmp/loopfile0 (deleted)
/dev/loop1 /tmp/loopfile1
*/
for line := range strings.Lines(string(out)) {
l := strings.Fields(line)
if len(l) >= 2 {
if l[0] == "NAME" {
continue
}
entries = append(entries, InfoEntry{
Name: l[0],
BackFile: l[1],
})
}
}
return data.LoopDevices, nil
return entries, nil
}

func (t T) Add(ctx context.Context, filePath string) error {
Expand Down Expand Up @@ -189,9 +201,6 @@ func (t InfoEntries) File(s string) *InfoEntry {
if i.BackFile == s {
return &i
}
if i.BackFile == s+" (deleted)" {
return &i
}
}
return nil
}
Expand Down
Loading