未验证 提交 fe6b70f3 编写于 作者: S Sandy Xu 提交者: GitHub

meta: don't return EINVAL when encountering unknown flags (#862)

* meta: don't return EINVAL when encountering unknown flags

* fix tests
上级 4339506b
......@@ -2913,9 +2913,6 @@ func (r *redisMeta) SetXattr(ctx Context, inode Ino, name string, value []byte,
key := r.xattrKey(inode)
return r.txn(ctx, func(tx *redis.Tx) error {
switch flags {
case XattrCreateOrReplace:
_, err := r.rdb.HSet(ctx, key, name, value).Result()
return err
case XattrCreate:
ok, err := tx.HSetNX(c, key, name, value).Result()
if err != nil {
......@@ -2933,8 +2930,10 @@ func (r *redisMeta) SetXattr(ctx Context, inode Ino, name string, value []byte,
}
_, err := r.rdb.HSet(ctx, key, name, value).Result()
return err
default: // XattrCreateOrReplace
_, err := r.rdb.HSet(ctx, key, name, value).Result()
return err
}
return syscall.EINVAL
}, key)
}
......
......@@ -337,7 +337,7 @@ func testMetaClient(t *testing.T, m Meta) {
if st := m.SetXattr(ctx, inode, "a", []byte("v4"), XattrReplace); st != 0 {
t.Fatalf("setxattr: %s", st)
}
if st := m.SetXattr(ctx, inode, "a", []byte("v5"), 5); st != syscall.EINVAL {
if st := m.SetXattr(ctx, inode, "a", []byte("v5"), 5); st != 0 { // unknown flag is ignored
t.Fatalf("setxattr: %s", st)
}
......
......@@ -2547,15 +2547,6 @@ func (m *dbMeta) SetXattr(ctx Context, inode Ino, name string, value []byte, fla
var err error
var n int64
switch flags {
case XattrCreateOrReplace:
n, err = s.Insert(&x)
if err != nil || n == 0 {
if m.engine.DriverName() == "postgres" {
// cleanup failed session
_ = s.Rollback()
}
_, err = s.Update(&x, &xattr{inode, name, nil})
}
case XattrCreate:
n, err = s.Insert(&x)
if err != nil || n == 0 {
......@@ -2567,7 +2558,14 @@ func (m *dbMeta) SetXattr(ctx Context, inode Ino, name string, value []byte, fla
err = ENOATTR
}
default:
return syscall.EINVAL
n, err = s.Insert(&x)
if err != nil || n == 0 {
if m.engine.DriverName() == "postgres" {
// cleanup failed session
_ = s.Rollback()
}
_, err = s.Update(&x, &xattr{inode, name, nil})
}
}
return err
}))
......
......@@ -2394,7 +2394,6 @@ func (m *kvMeta) SetXattr(ctx Context, inode Ino, name string, value []byte, fla
key := m.xattrKey(inode, name)
err := m.txn(func(tx kvTxn) error {
switch flags {
case XattrCreateOrReplace:
case XattrCreate:
v := tx.get(key)
if v != nil {
......@@ -2405,8 +2404,6 @@ func (m *kvMeta) SetXattr(ctx Context, inode Ino, name string, value []byte, fla
if v == nil {
return ENOATTR
}
default:
return syscall.EINVAL
}
tx.set(key, value)
return nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册