fsck: get rid of channel read closures
Create proper functions instead to declutter the logic.
This commit is contained in:
parent
1a18d8e609
commit
4a73637782
74
fsck.go
74
fsck.go
@ -22,6 +22,8 @@ type fsckObj struct {
|
|||||||
corruptList []string
|
corruptList []string
|
||||||
// Protects corruptList
|
// Protects corruptList
|
||||||
corruptListLock sync.Mutex
|
corruptListLock sync.Mutex
|
||||||
|
// stop a running watchMitigatedCorruptions thread
|
||||||
|
watchDone chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ck *fsckObj) markCorrupt(path string) {
|
func (ck *fsckObj) markCorrupt(path string) {
|
||||||
@ -30,24 +32,28 @@ func (ck *fsckObj) markCorrupt(path string) {
|
|||||||
ck.corruptListLock.Unlock()
|
ck.corruptListLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively check dir for corruption
|
// Watch for mitigated corruptions that occour during OpenDir()
|
||||||
func (ck *fsckObj) dir(path string) {
|
func (ck *fsckObj) watchMitigatedCorruptionsOpenDir(path string) {
|
||||||
//fmt.Printf("ck.dir %q\n", path)
|
|
||||||
ck.xattrs(path)
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case item := <-ck.fs.MitigatedCorruptions:
|
case item := <-ck.fs.MitigatedCorruptions:
|
||||||
fmt.Printf("fsck: corrupt entry in dir %q: %q\n", path, item)
|
fmt.Printf("fsck: corrupt entry in dir %q: %q\n", path, item)
|
||||||
ck.markCorrupt(filepath.Join(path, item))
|
ck.markCorrupt(filepath.Join(path, item))
|
||||||
case <-done:
|
case <-ck.watchDone:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
|
|
||||||
|
// Recursively check dir for corruption
|
||||||
|
func (ck *fsckObj) dir(path string) {
|
||||||
|
//fmt.Printf("ck.dir %q\n", path)
|
||||||
|
ck.xattrs(path)
|
||||||
|
// Run OpenDir and catch transparently mitigated corruptions
|
||||||
|
go ck.watchMitigatedCorruptionsOpenDir(path)
|
||||||
entries, status := ck.fs.OpenDir(path, nil)
|
entries, status := ck.fs.OpenDir(path, nil)
|
||||||
done <- struct{}{}
|
ck.watchDone <- struct{}{}
|
||||||
|
// Also catch non-mitigated corruptions
|
||||||
if !status.Ok() {
|
if !status.Ok() {
|
||||||
ck.markCorrupt(path)
|
ck.markCorrupt(path)
|
||||||
fmt.Printf("fsck: error opening dir %q: %v\n", path, status)
|
fmt.Printf("fsck: error opening dir %q: %v\n", path, status)
|
||||||
@ -85,7 +91,20 @@ func (ck *fsckObj) symlink(path string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check file for corruption
|
// Watch for mitigated corruptions that occour during Read()
|
||||||
|
func (ck *fsckObj) watchMitigatedCorruptionsRead(path string) {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case item := <-ck.fs.MitigatedCorruptions:
|
||||||
|
fmt.Printf("fsck: corrupt file %q (inode %s)\n", path, item)
|
||||||
|
ck.markCorrupt(path)
|
||||||
|
case <-ck.watchDone:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check file for corruption
|
||||||
func (ck *fsckObj) file(path string) {
|
func (ck *fsckObj) file(path string) {
|
||||||
//fmt.Printf("ck.file %q\n", path)
|
//fmt.Printf("ck.file %q\n", path)
|
||||||
ck.xattrs(path)
|
ck.xattrs(path)
|
||||||
@ -98,19 +117,9 @@ func (ck *fsckObj) file(path string) {
|
|||||||
defer f.Release()
|
defer f.Release()
|
||||||
buf := make([]byte, fuse.MAX_KERNEL_WRITE)
|
buf := make([]byte, fuse.MAX_KERNEL_WRITE)
|
||||||
var off int64
|
var off int64
|
||||||
done := make(chan struct{})
|
// Read() through the whole file and catch transparently mitigated corruptions
|
||||||
go func() {
|
go ck.watchMitigatedCorruptionsRead(path)
|
||||||
for {
|
defer func() { ck.watchDone <- struct{}{} }()
|
||||||
select {
|
|
||||||
case item := <-ck.fs.MitigatedCorruptions:
|
|
||||||
fmt.Printf("fsck: corrupt file %q (inode %s)\n", path, item)
|
|
||||||
ck.markCorrupt(path)
|
|
||||||
case <-done:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
defer func() { done <- struct{}{} }()
|
|
||||||
for {
|
for {
|
||||||
result, status := f.Read(buf, off)
|
result, status := f.Read(buf, off)
|
||||||
if !status.Ok() {
|
if !status.Ok() {
|
||||||
@ -126,22 +135,26 @@ func (ck *fsckObj) file(path string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check xattrs on file/dir at path
|
// Watch for mitigated corruptions that occour during ListXAttr()
|
||||||
func (ck *fsckObj) xattrs(path string) {
|
func (ck *fsckObj) watchMitigatedCorruptionsListXAttr(path string) {
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case item := <-ck.fs.MitigatedCorruptions:
|
case item := <-ck.fs.MitigatedCorruptions:
|
||||||
fmt.Printf("fsck: corrupt xattr name on file %q: %q\n", path, item)
|
fmt.Printf("fsck: corrupt xattr name on file %q: %q\n", path, item)
|
||||||
ck.markCorrupt(path + " xattr:" + item)
|
ck.markCorrupt(path + " xattr:" + item)
|
||||||
case <-done:
|
case <-ck.watchDone:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
|
|
||||||
|
// Check xattrs on file/dir at path
|
||||||
|
func (ck *fsckObj) xattrs(path string) {
|
||||||
|
// Run ListXAttr() and catch transparently mitigated corruptions
|
||||||
|
go ck.watchMitigatedCorruptionsListXAttr(path)
|
||||||
attrs, status := ck.fs.ListXAttr(path, nil)
|
attrs, status := ck.fs.ListXAttr(path, nil)
|
||||||
done <- struct{}{}
|
ck.watchDone <- struct{}{}
|
||||||
|
// Also catch non-mitigated corruptions
|
||||||
if !status.Ok() {
|
if !status.Ok() {
|
||||||
fmt.Printf("fsck: error listing xattrs on %q: %v\n", path, status)
|
fmt.Printf("fsck: error listing xattrs on %q: %v\n", path, status)
|
||||||
ck.markCorrupt(path)
|
ck.markCorrupt(path)
|
||||||
@ -167,6 +180,7 @@ func fsck(args *argContainer) {
|
|||||||
fs.MitigatedCorruptions = make(chan string)
|
fs.MitigatedCorruptions = make(chan string)
|
||||||
ck := fsckObj{
|
ck := fsckObj{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
|
watchDone: make(chan struct{}),
|
||||||
}
|
}
|
||||||
ck.dir("")
|
ck.dir("")
|
||||||
wipeKeys()
|
wipeKeys()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user