Send better syscall status codes
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
This commit is contained in:
parent
3b9690103b
commit
955e1323ce
@ -126,6 +126,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
files, err := myfs.ReadDir(n.path)
|
files, err := myfs.ReadDir(n.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE ReadDir failed").Str("path", n.path).Err(err).Send()
|
log.Error("FUSE ReadDir failed").Str("path", n.path).Err(err).Send()
|
||||||
|
// TODO we probably should figure out why it failed
|
||||||
return nil, syscall.ENOENT
|
return nil, syscall.ENOENT
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +210,6 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
|
|||||||
return child, 0
|
return child, 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, syscall.ENOENT
|
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// FS object
|
// FS object
|
||||||
@ -290,6 +290,8 @@ var _ fs.FileWriter = (*bytesFileWriteHandle)(nil)
|
|||||||
func (fh *bytesFileWriteHandle) Write(ctx context.Context, data []byte, off int64) (written uint32, errno syscall.Errno) {
|
func (fh *bytesFileWriteHandle) Write(ctx context.Context, data []byte, off int64) (written uint32, errno syscall.Errno) {
|
||||||
log.Info("Executing Write").Str("path", fh.path).Int("prev_size", len(fh.content)).Int("next_size", len(data)).Send()
|
log.Info("Executing Write").Str("path", fh.path).Int("prev_size", len(fh.content)).Int("next_size", len(data)).Send()
|
||||||
if off != int64(len(fh.content)) {
|
if off != int64(len(fh.content)) {
|
||||||
|
log.Error("FUSE Write file size changed unexpectedly").Int("expect", int(off)).Int("received", len(fh.content)).Send()
|
||||||
|
return 0, syscall.ENXIO
|
||||||
}
|
}
|
||||||
fh.content = append(fh.content[:], data[:]...)
|
fh.content = append(fh.content[:], data[:]...)
|
||||||
return uint32(len(data)), 0
|
return uint32(len(data)), 0
|
||||||
@ -320,17 +322,17 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Flush failed during write").Str("path", fh.path).Err(err).Send()
|
log.Error("FUSE Flush failed during write").Str("path", fh.path).Err(err).Send()
|
||||||
fp.Close()
|
fp.Close()
|
||||||
return syscall.EROFS
|
return syscall.EIO
|
||||||
}
|
}
|
||||||
if int(nread) != len(fh.content) {
|
if int(nread) != len(fh.content) {
|
||||||
log.Error("FUSE Flush failed during write").Str("path", fh.path).Int("expect", len(fh.content)).Int("got", int(nread)).Send()
|
log.Error("FUSE Flush failed during write").Str("path", fh.path).Int("expect", len(fh.content)).Int("got", int(nread)).Send()
|
||||||
fp.Close()
|
fp.Close()
|
||||||
return syscall.EROFS
|
return syscall.EIO
|
||||||
}
|
}
|
||||||
err = fp.Close()
|
err = fp.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Flush failed during close").Str("path", fh.path).Err(err).Send()
|
log.Error("FUSE Flush failed during close").Str("path", fh.path).Err(err).Send()
|
||||||
return syscall.EROFS
|
return syscall.EIO
|
||||||
}
|
}
|
||||||
log.Debug("FUSE Flush done").Str("path", fh.path).Int("size", len(fh.content)).Send()
|
log.Debug("FUSE Flush done").Str("path", fh.path).Int("size", len(fh.content)).Send()
|
||||||
|
|
||||||
@ -381,6 +383,7 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
log.Debug("FUSE Opening for read").Str("path", f.path).Send()
|
log.Debug("FUSE Opening for read").Str("path", f.path).Send()
|
||||||
fp, err := myfs.Open(f.path)
|
fp, err := myfs.Open(f.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// TODO we probably should figure out why it failed
|
||||||
log.Error("FUSE: Opening failed").Str("path", f.path).Err(err).Send()
|
log.Error("FUSE: Opening failed").Str("path", f.path).Err(err).Send()
|
||||||
return nil, 0, syscall.EROFS
|
return nil, 0, syscall.EROFS
|
||||||
}
|
}
|
||||||
@ -400,7 +403,7 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Read failed").Str("path", f.path).Err(err).Send()
|
log.Error("FUSE Read failed").Str("path", f.path).Err(err).Send()
|
||||||
fp.Close()
|
fp.Close()
|
||||||
return nil, 0, syscall.EROFS
|
return nil, 0, syscall.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
fh = &bytesFileReadHandle{
|
fh = &bytesFileReadHandle{
|
||||||
@ -422,7 +425,8 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
sub_ctx, cancel := context.WithCancel(ctx)
|
sub_ctx, cancel := context.WithCancel(ctx)
|
||||||
ans, err := value.gen(sub_ctx)
|
ans, err := value.gen(sub_ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, syscall.EROFS
|
// TODO we probably should figure out why it failed
|
||||||
|
return nil, 0, syscall.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
fh = &sensorFileReadHandle{
|
fh = &sensorFileReadHandle{
|
||||||
@ -433,7 +437,7 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, 0, syscall.EROFS
|
return nil, 0, syscall.EINVAL
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ fs.NodeCreater = (*ITNode)(nil)
|
var _ fs.NodeCreater = (*ITNode)(nil)
|
||||||
@ -480,6 +484,7 @@ func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.
|
|||||||
Str("path", path).
|
Str("path", path).
|
||||||
Err(err).
|
Err(err).
|
||||||
Send()
|
Send()
|
||||||
|
// TODO we probably should figure out why it failed
|
||||||
return nil, syscall.EROFS
|
return nil, syscall.EROFS
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,6 +510,10 @@ func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.
|
|||||||
|
|
||||||
var _ fs.NodeRenamer = (*ITNode)(nil)
|
var _ fs.NodeRenamer = (*ITNode)(nil)
|
||||||
func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbedder, newName string, flags uint32) syscall.Errno {
|
func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbedder, newName string, flags uint32) syscall.Errno {
|
||||||
|
if f.kind != 2 {
|
||||||
|
return syscall.EROFS
|
||||||
|
}
|
||||||
|
|
||||||
p1 := f.path + "/" + name
|
p1 := f.path + "/" + name
|
||||||
p2 := newParent.EmbeddedInode().Path(nil)[2:] + "/" + newName
|
p2 := newParent.EmbeddedInode().Path(nil)[2:] + "/" + newName
|
||||||
|
|
||||||
@ -516,7 +525,8 @@ func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbe
|
|||||||
Err(err).
|
Err(err).
|
||||||
Send()
|
Send()
|
||||||
|
|
||||||
return syscall.EROFS
|
// TODO we probably should figure out why it failed
|
||||||
|
return syscall.EIO
|
||||||
}
|
}
|
||||||
log.Debug("FUSE Rename sucess").
|
log.Debug("FUSE Rename sucess").
|
||||||
Str("src", p1).
|
Str("src", p1).
|
||||||
@ -532,6 +542,10 @@ func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbe
|
|||||||
|
|
||||||
var _ fs.NodeUnlinker = (*ITNode)(nil)
|
var _ fs.NodeUnlinker = (*ITNode)(nil)
|
||||||
func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno {
|
func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno {
|
||||||
|
if f.kind != 2 {
|
||||||
|
return syscall.EROFS
|
||||||
|
}
|
||||||
|
|
||||||
delete(inodemap, f.path + "/" + name)
|
delete(inodemap, f.path + "/" + name)
|
||||||
err := myfs.Remove(f.path + "/" + name)
|
err := myfs.Remove(f.path + "/" + name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -540,7 +554,8 @@ func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno {
|
|||||||
Err(err).
|
Err(err).
|
||||||
Send()
|
Send()
|
||||||
|
|
||||||
return syscall.EROFS
|
// TODO we probably should figure out why it failed
|
||||||
|
return syscall.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("FUSE Unlink success").
|
log.Debug("FUSE Unlink success").
|
||||||
|
Loading…
Reference in New Issue
Block a user