Skip to content

Commit

Permalink
hadoop: do not use local uid/gid if global user/group specified (#2433)
Browse files Browse the repository at this point in the history
* hadoop: do not lookup local for uid2name in sdk

* don't use local uid/gid

Co-authored-by: Davies Liu <[email protected]>
  • Loading branch information
tangyoupeng and davies authored Aug 2, 2022
1 parent 9572b99 commit c274542
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions sdk/java/libjfs/guid.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type pwent struct {
type mapping struct {
sync.Mutex
salt string
local bool
usernames map[string]uint32
userIDs map[uint32]string
groups map[string]uint32
Expand All @@ -46,7 +47,7 @@ func newMapping(salt string) *mapping {
groups: make(map[string]uint32),
groupIDs: make(map[uint32]string),
}
m.update(genAllUids(), genAllGids())
m.update(genAllUids(), genAllGids(), true)
return m
}

Expand All @@ -64,6 +65,9 @@ func (m *mapping) lookupUser(name string) uint32 {
if id, ok := m.usernames[name]; ok {
return id
}
if !m.local {
return m.genGuid(name)
}
u, _ := user.Lookup(name)
if u != nil {
id_, _ := strconv.ParseUint(u.Uid, 10, 32)
Expand All @@ -83,6 +87,9 @@ func (m *mapping) lookupGroup(name string) uint32 {
if id, ok := m.groups[name]; ok {
return id
}
if !m.local {
return m.genGuid(name)
}
g, _ := user.LookupGroup(name)
if g == nil {
id = m.genGuid(name)
Expand All @@ -101,6 +108,9 @@ func (m *mapping) lookupUserID(id uint32) string {
if name, ok := m.userIDs[id]; ok {
return name
}
if !m.local {
return strconv.Itoa(int(id))
}
u, _ := user.LookupId(strconv.Itoa(int(id)))
if u == nil {
u = &user.User{Username: strconv.Itoa(int(id))}
Expand All @@ -120,6 +130,9 @@ func (m *mapping) lookupGroupID(id uint32) string {
if name, ok := m.groupIDs[id]; ok {
return name
}
if !m.local {
return strconv.Itoa(int(id))
}
g, _ := user.LookupGroupId(strconv.Itoa(int(id)))
if g == nil {
g = &user.Group{Name: strconv.Itoa(int(id))}
Expand All @@ -133,9 +146,10 @@ func (m *mapping) lookupGroupID(id uint32) string {
return name
}

func (m *mapping) update(uids []pwent, gids []pwent) {
func (m *mapping) update(uids []pwent, gids []pwent, local bool) {
m.Lock()
defer m.Unlock()
m.local = local
for _, u := range uids {
oldId := m.usernames[u.name]
oldName := m.userIDs[u.id]
Expand Down
2 changes: 1 addition & 1 deletion sdk/java/libjfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func jfs_update_uid_grouping(h uintptr, uidstr *C.char, grouping *C.char) {
}
logger.Debugf("Update groups of %s to %s", w.user, strings.Join(groups, ","))
}
w.m.update(uids, gids)
w.m.update(uids, gids, false)

if w.isSuperuser(w.user, groups) {
w.ctx = meta.NewContext(uint32(os.Getpid()), 0, []uint32{0})
Expand Down
2 changes: 1 addition & 1 deletion sdk/java/src/main/java/io/juicefs/JuiceFileSystemImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public static Libjfs loadLibrary() throws IOException {
LibraryLoader<Libjfs> libjfsLibraryLoader = LibraryLoader.create(Libjfs.class);
libjfsLibraryLoader.failImmediately();

int soVer = 6;
int soVer = 7;
String osId = "so";
String archId = "amd64";
String resourceFormat = "libjfs-%s.%s.gz";
Expand Down

0 comments on commit c274542

Please sign in to comment.