Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Nil pointer derefrence on kernel dirent eviction
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Lucas <xavier.lucas@corp.ovh.com>
  • Loading branch information
Xavier Lucas committed Feb 22, 2016
1 parent 0259aef commit bf0163c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 64 deletions.
75 changes: 35 additions & 40 deletions svfs/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
)

var (
FolderRegex = regexp.MustCompile("^.+/$")
DirContentType = "application/directory"
ObjContentType = "application/octet-stream"
FolderRegex = regexp.MustCompile("^.+/$")
DirContentType = "application/directory"
ObjContentType = "application/octet-stream"
EntryCache = new(Cache)
DirectoryLister = new(DirLister)
)

type DirLister struct {
Expand Down Expand Up @@ -53,13 +55,11 @@ func (dl *DirLister) AddTask(o *Object, c chan<- *Object) {
}

type Directory struct {
apex bool
name string
path string
cache *Cache
s *swift.Connection
c *swift.Container
l *DirLister
apex bool
name string
path string
s *swift.Connection
c *swift.Container
}

func (d *Directory) Attr(ctx context.Context, a *fuse.Attr) error {
Expand Down Expand Up @@ -102,7 +102,7 @@ func (d *Directory) Create(ctx context.Context, req *fuse.CreateRequest, resp *f
}

// Force cache eviction
d.cache.Delete(d.c.Name, d.path)
EntryCache.Delete(d.c.Name, d.path)

return node, h, nil
}
Expand All @@ -117,12 +117,12 @@ func (d *Directory) Export() fuse.Dirent {
func (d *Directory) ReadDirAll(ctx context.Context) (entries []fuse.Dirent, err error) {
var (
dirs = make(map[string]bool)
loC = make(chan *Object, d.l.concurrency)
loC = make(chan *Object, DirectoryLister.concurrency)
count = 0
)

// Cache check
if nodes := d.cache.Get(d.c.Name, d.path); nodes != nil {
if nodes := EntryCache.Get(d.c.Name, d.path); nodes != nil {
for _, node := range nodes {
entries = append(entries, node.Export())
}
Expand Down Expand Up @@ -151,12 +151,10 @@ func (d *Directory) ReadDirAll(ctx context.Context) (entries []fuse.Dirent, err
if o.ContentType == DirContentType && !FolderRegex.Match([]byte(o.Name)) {
dirs[fileName] = true
child = &Directory{
s: d.s,
c: d.c,
l: d.l,
cache: d.cache,
path: o.Name + "/",
name: fileName,
s: d.s,
c: d.c,
path: o.Name + "/",
name: fileName,
}
} else if o.PseudoDirectory &&
FolderRegex.Match([]byte(o.Name)) && fileName != "" {
Expand All @@ -165,12 +163,10 @@ func (d *Directory) ReadDirAll(ctx context.Context) (entries []fuse.Dirent, err
if !dirs[realName] {
dirs[realName] = true
child = &Directory{
s: d.s,
c: d.c,
l: d.l,
cache: d.cache,
path: o.Name,
name: realName,
s: d.s,
c: d.c,
path: o.Name,
name: realName,
}
}
} else if !FolderRegex.Match([]byte(o.Name)) {
Expand All @@ -187,7 +183,7 @@ func (d *Directory) ReadDirAll(ctx context.Context) (entries []fuse.Dirent, err
if o.Bytes == 0 &&
!o.PseudoDirectory &&
o.ContentType != DirContentType {
d.l.AddTask(obj, loC)
DirectoryLister.AddTask(obj, loC)
child = nil
count++
} else {
Expand Down Expand Up @@ -215,17 +211,17 @@ func (d *Directory) ReadDirAll(ctx context.Context) (entries []fuse.Dirent, err
}
}

d.cache.Set(d.c.Name, d.path, children)
EntryCache.Set(d.c.Name, d.path, children)

return entries, nil
}

func (d *Directory) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (fs.Node, error) {
var nodes []Node

if nodes = d.cache.Get(d.c.Name, d.path); nodes == nil {
if nodes = EntryCache.Get(d.c.Name, d.path); nodes == nil {
d.ReadDirAll(ctx)
nodes = d.cache.Get(d.c.Name, d.path)
nodes = EntryCache.Get(d.c.Name, d.path)
}

// Find matching child
Expand Down Expand Up @@ -258,15 +254,14 @@ func (d *Directory) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node,
}

// Cache eviction
d.cache.Delete("", d.path)
EntryCache.Delete("", d.path)

// Directory object
return &Directory{
name: req.Name,
path: absPath,
cache: d.cache,
s: d.s,
c: d.c,
name: req.Name,
path: absPath,
s: d.s,
c: d.c,
}, nil
}

Expand All @@ -288,7 +283,7 @@ func (d *Directory) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
}

// Cache eviction
d.cache.Delete(d.c.Name, d.path)
EntryCache.Delete(d.c.Name, d.path)

return nil
}
Expand All @@ -301,14 +296,14 @@ func (d *Directory) Rename(ctx context.Context, req *fuse.RenameRequest, newDir
// Swift move = copy + delete
if t, ok := newDir.(*Container); ok {
d.s.ObjectMove(d.c.Name, d.path+req.OldName, t.c.Name, t.path+req.NewName)
d.cache.Delete(d.c.Name, d.path)
t.cache.Delete(t.c.Name, t.path)
EntryCache.Delete(d.c.Name, d.path)
EntryCache.Delete(t.c.Name, t.path)
return nil
}
if t, ok := newDir.(*Directory); ok {
d.s.ObjectMove(d.c.Name, d.path+req.OldName, t.c.Name, t.path+req.NewName)
d.cache.Delete(d.c.Name, d.path)
t.cache.Delete(t.c.Name, t.path)
EntryCache.Delete(d.c.Name, d.path)
EntryCache.Delete(t.c.Name, t.path)
return nil
}
return nil
Expand Down
22 changes: 8 additions & 14 deletions svfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
// SVFS implements the Swift Virtual File System.
type SVFS struct {
s *swift.Connection
cache *Cache
lister *DirLister
conf *Config
concurrency uint64
}
Expand All @@ -26,9 +24,9 @@ type Config struct {
func (s *SVFS) Init(sc *swift.Connection, conf *Config, cconf *CacheConfig) error {
s.s = sc
s.conf = conf
s.cache = NewCache(cconf)
s.s.ConnectTimeout = conf.ConnectTimeout
s.lister = &DirLister{
EntryCache = NewCache(cconf)
DirectoryLister = &DirLister{
c: s.s,
concurrency: conf.MaxReaddirConcurrency,
}
Expand All @@ -40,7 +38,7 @@ func (s *SVFS) Init(sc *swift.Connection, conf *Config, cconf *CacheConfig) erro
}

// Start directory lister
s.lister.Start()
DirectoryLister.Start()

return nil
}
Expand All @@ -61,21 +59,17 @@ func (s *SVFS) Root() (fs.Node, error) {

return &Container{
Directory: &Directory{
apex: true,
cache: s.cache,
s: s.s,
c: &baseC,
l: s.lister,
apex: true,
s: s.s,
c: &baseC,
},
cs: &segC,
}, nil
}
return &Root{
Directory: &Directory{
apex: true,
cache: s.cache,
s: s.s,
l: s.lister,
apex: true,
s: s.s,
},
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion svfs/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (fh *ObjectHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) e
fh.w.Close()
}
if fh.p != nil {
fh.p.cache.Delete("", fh.p.path)
EntryCache.Delete("", fh.p.path)
}
return nil
}
Expand Down
16 changes: 7 additions & 9 deletions svfs/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *Root) ReadDirAll(ctx context.Context) (entries []fuse.Dirent, err error
)

// Cache hit
if nodes := r.cache.Get("", r.path); nodes != nil {
if nodes := EntryCache.Get("", r.path); nodes != nil {
for _, node := range nodes {
entries = append(entries, node.Export())
}
Expand Down Expand Up @@ -78,11 +78,9 @@ func (r *Root) ReadDirAll(ctx context.Context) (entries []fuse.Dirent, err error

child := Container{
Directory: &Directory{
s: r.s,
c: c,
l: r.l,
cache: r.cache,
name: name,
s: r.s,
c: c,
name: name,
},
cs: segment,
}
Expand All @@ -91,7 +89,7 @@ func (r *Root) ReadDirAll(ctx context.Context) (entries []fuse.Dirent, err error
entries = append(entries, child.Export())
}

r.cache.Set("", r.path, list)
EntryCache.Set("", r.path, list)

return entries, nil
}
Expand All @@ -100,9 +98,9 @@ func (r *Root) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.L
var nodes []Node

// Fill cache if expired
if nodes = r.cache.Get("", r.path); nodes == nil {
if nodes = EntryCache.Get("", r.path); nodes == nil {
r.ReadDirAll(ctx)
nodes = r.cache.Get("", r.path)
nodes = EntryCache.Get("", r.path)
}

for _, item := range nodes {
Expand Down

0 comments on commit bf0163c

Please sign in to comment.