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

meta/sql: use binary as column type for xattr #4873

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions pkg/meta/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,15 @@ func testMetaClient(t *testing.T, m Meta) {
if st := m.SetXattr(ctx, inode, "a", []byte("v5"), 5); st != syscall.EINVAL {
t.Fatalf("setxattr: %s", st)
}
if st := m.SetXattr(ctx, inode, "R", []byte("value"), 0); st != 0 {
t.Fatalf("setxattr special: %s", st)
}
if st := m.SetXattr(ctx, inode, "\x8ar", []byte("E$\xfe"), XattrCreate); st != 0 {
t.Fatalf("setxattr special: %s", st)
}
if st := m.GetXattr(ctx, inode, "\x8ar", &value); st != 0 || string(value) != "E$\xfe" {
t.Fatalf("getxattr special: %s", st)
}

var totalspace, availspace, iused, iavail uint64
if st := m.StatFS(ctx, RootInode, &totalspace, &availspace, &iused, &iavail); st != 0 {
Expand Down
16 changes: 8 additions & 8 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ type symlink struct {
type xattr struct {
Id int64 `xorm:"pk bigserial"`
Inode Ino `xorm:"unique(name) notnull"`
Name string `xorm:"unique(name) notnull"`
Name []byte `xorm:"unique(name) varbinary(255) notnull"`
Value []byte `xorm:"blob notnull"`
}

Expand Down Expand Up @@ -3070,7 +3070,7 @@ func (m *dbMeta) GetXattr(ctx Context, inode Ino, name string, vbuff *[]byte) sy
defer m.timeit("GetXattr", time.Now())
inode = m.checkRoot(inode)
return errno(m.roTxn(func(s *xorm.Session) error {
var x = xattr{Inode: inode, Name: name}
var x = xattr{Inode: inode, Name: []byte(name)}
ok, err := s.Get(&x)
if err != nil {
return err
Expand Down Expand Up @@ -3114,8 +3114,8 @@ func (m *dbMeta) ListXattr(ctx Context, inode Ino, names *[]byte) syscall.Errno

func (m *dbMeta) doSetXattr(ctx Context, inode Ino, name string, value []byte, flags uint32) syscall.Errno {
return errno(m.txn(func(s *xorm.Session) error {
var k = &xattr{Inode: inode, Name: name}
var x = xattr{Inode: inode, Name: name, Value: value}
var k = &xattr{Inode: inode, Name: []byte(name)}
var x = xattr{Inode: inode, Name: []byte(name), Value: value}
ok, err := s.ForUpdate().Get(k)
if err != nil {
return err
Expand Down Expand Up @@ -3145,7 +3145,7 @@ func (m *dbMeta) doSetXattr(ctx Context, inode Ino, name string, value []byte, f

func (m *dbMeta) doRemoveXattr(ctx Context, inode Ino, name string) syscall.Errno {
return errno(m.txn(func(s *xorm.Session) error {
n, err := s.Delete(&xattr{Inode: inode, Name: name})
n, err := s.Delete(&xattr{Inode: inode, Name: []byte(name)})
if err != nil {
return err
} else if n == 0 {
Expand Down Expand Up @@ -3281,7 +3281,7 @@ func (m *dbMeta) dumpEntry(s *xorm.Session, inode Ino, typ uint8, e *DumpedEntry
if len(rows) > 0 {
xattrs := make([]*DumpedXattr, 0, len(rows))
for _, x := range rows {
xattrs = append(xattrs, &DumpedXattr{x.Name, string(x.Value)})
xattrs = append(xattrs, &DumpedXattr{string(x.Name), string(x.Value)})
}
sort.Slice(xattrs, func(i, j int) bool { return xattrs[i].Name < xattrs[j].Name })
e.Xattrs = xattrs
Expand Down Expand Up @@ -3375,7 +3375,7 @@ func (m *dbMeta) dumpEntryFast(inode Ino, typ uint8) *DumpedEntry {
if ok && len(rows) > 0 {
xattrs := make([]*DumpedXattr, 0, len(rows))
for _, x := range rows {
xattrs = append(xattrs, &DumpedXattr{x.Name, string(x.Value)})
xattrs = append(xattrs, &DumpedXattr{string(x.Name), string(x.Value)})
}
sort.Slice(xattrs, func(i, j int) bool { return xattrs[i].Name < xattrs[j].Name })
e.Xattrs = xattrs
Expand Down Expand Up @@ -3848,7 +3848,7 @@ func (m *dbMeta) loadEntry(e *DumpedEntry, chs []chan interface{}, aclMaxId *uin
chs[5] <- &symlink{inode, symL}
}
for _, x := range e.Xattrs {
chs[4] <- &xattr{Inode: inode, Name: x.Name, Value: unescape(x.Value)}
chs[4] <- &xattr{Inode: inode, Name: []byte(x.Name), Value: unescape(x.Value)}
}

n.AccessACLId = m.saveACL(loadACL(e.AccessACL), aclMaxId)
Expand Down
Loading