Exemple #1
0
func watchDaemon(mdbFileName string, mdbChannel chan<- *mdb.Mdb,
	logger *log.Logger) {
	var lastStat syscall.Stat_t
	var lastMdb *mdb.Mdb
	for ; ; time.Sleep(time.Second) {
		var stat syscall.Stat_t
		if err := syscall.Stat(mdbFileName, &stat); err != nil {
			logger.Printf("Error stating file: %s\t%s\n", mdbFileName, err)
			continue
		}
		stat.Atim = lastStat.Atim
		if stat != lastStat {
			mdb := loadFile(mdbFileName, logger)
			if mdb == nil {
				continue
			}
			compareStartTime := time.Now()
			if lastMdb == nil || !compare(lastMdb, mdb) {
				if lastMdb != nil {
					mdbCompareTimeDistribution.Add(time.Since(compareStartTime))
				}
				mdbChannel <- mdb
				lastMdb = mdb
			}
			lastStat = stat
		}
	}
}
Exemple #2
0
// GetAttr - FUSE call
func (f *virtualFile) GetAttr(a *fuse.Attr) fuse.Status {
	var st syscall.Stat_t
	err := syscall.Lstat(f.parentFile, &st)
	if err != nil {
		fmt.Printf("Lstat %q: %v\n", f.parentFile, err)
		return fuse.ToStatus(err)
	}
	st.Ino = f.ino
	st.Size = int64(len(f.content))
	st.Mode = syscall.S_IFREG | 0400
	st.Nlink = 1
	a.FromStat(&st)
	return fuse.OK
}
Exemple #3
0
func TestMemUnionResetDelete(t *testing.T) {
	wd, ufs, clean := setupMemUfs(t)
	defer clean()
	ioutil.WriteFile(wd+"/ro/todelete", []byte{42}, 0644)

	var before, after, afterReset syscall.Stat_t
	syscall.Lstat(wd+"/mnt/todelete", &before)
	before.Ino = 0
	os.Remove(wd + "/mnt/todelete")
	syscall.Lstat(wd+"/mnt/todelete", &after)
	testEq(t, after, before, false)
	ufs.Reset()
	syscall.Lstat(wd+"/mnt/todelete", &afterReset)
	afterReset.Ino = 0
	testEq(t, afterReset, before, true)
}
Exemple #4
0
func (constor *Constor) Lstat(li int, id string, stat *syscall.Stat_t) error {
	path := constor.getPath(li, id)
	if err := syscall.Lstat(path, stat); err != nil {
		return err
	}
	count := 1
	linksbyte, err := Lgetxattr(path, LINKSXATTR)
	if err == nil && len(linksbyte) != 0 {
		linksstr := string(linksbyte)
		linksint, err := strconv.Atoi(linksstr)
		if err != nil {
			constor.error("%s : %s", id, err)
			return err
		}
		count = linksint
	}
	stat.Nlink = uint64(count)
	stat.Ino = idtoino(id)
	return nil
}
Exemple #5
0
func (constor *Constor) GetAttr(input *fuse.GetAttrIn, out *fuse.AttrOut) (code fuse.Status) {
	stat := syscall.Stat_t{}
	inode := constor.inodemap.findInodePtr(input.NodeId)
	if inode == nil {
		constor.error("%d not in inodemap", input.NodeId)
		return fuse.ENOENT
	}
	if inode.id == ROOTID && inode.layer == -1 {
		inode.layer = constor.getLayer(inode.id)
		if inode.layer == -1 {
			constor.error("Unable to find root inode")
			return fuse.ENOENT
		}
	}
	F := constor.fdlookup(inode.id, input.Pid)
	var err error
	// FIXME check to see if F.layer needs to be changed
	if F == nil {
		if inode.layer == -1 {
			constor.error("layer is -1 for %s", inode.id)
			return fuse.ENOENT
		}
		constor.log("Lstat on %s", inode.id)
		err = constor.Lstat(inode.layer, inode.id, &stat)
	} else {
		constor.log("Fstat on %s", inode.id)
		err = syscall.Fstat(F.fd, &stat)
		stat.Ino = idtoino(F.id)
		// FIXME take care of hard links too
	}
	if err != nil {
		constor.error("%s: %s", inode.id, err)
		return fuse.ToStatus(err)
	}
	attr := (*fuse.Attr)(&out.Attr)
	attr.FromStat(&stat)
	out.AttrValid = 1000
	constor.log("%s", inode.id)
	return fuse.OK
}
Exemple #6
0
func watchDaemon(mdbFileName string, mdbChannel chan *Mdb, logger *log.Logger) {
	var lastStat syscall.Stat_t
	var lastMdb *Mdb
	for ; ; time.Sleep(time.Second) {
		var stat syscall.Stat_t
		if err := syscall.Stat(mdbFileName, &stat); err != nil {
			logger.Printf("Error stating file: %s\t%s\n", mdbFileName, err)
			continue
		}
		stat.Atim = lastStat.Atim
		if stat != lastStat {
			file, err := os.Open(mdbFileName)
			if err != nil {
				logger.Printf("Error opening file\t%s\n", err)
				continue
			}
			decoder := json.NewDecoder(file)
			var mdb Mdb
			decodeStartTime := time.Now()
			if err = decoder.Decode(&mdb.Machines); err != nil {
				logger.Printf("Error decoding\t%s\n", err)
				continue
			}
			sortStartTime := time.Now()
			mdbDecodeTimeDistribution.Add(sortStartTime.Sub(decodeStartTime))
			sort.Sort(&mdb)
			compareStartTime := time.Now()
			mdbSortTimeDistribution.Add(compareStartTime.Sub(sortStartTime))
			if lastMdb == nil || !compare(lastMdb, &mdb) {
				if lastMdb != nil {
					mdbCompareTimeDistribution.Add(time.Since(compareStartTime))
				}
				mdbChannel <- &mdb
				lastMdb = &mdb
			}
			lastStat = stat
		}
	}
}
Exemple #7
0
func (constor *Constor) LstatInode(path string, stat *syscall.Stat_t, inode *Inode) error {
	li := inode.layer
	if li == -1 {
		li = constor.getLayer(path)
		if li == -1 {
			return syscall.ENOENT
		}
		inode.layer = li
	}
	pathl := Path.Join(constor.layers[li], path)
	err := syscall.Lstat(pathl, stat)
	if err != nil {
		return err
	}
	if li != 0 {
		// INOXATTR valid only for layer-0
		return nil
	}
	// var inobyte []byte
	// inobyte = make([]byte, 100, 100)
	// size, err := syscall.Getxattr(pathl, INOXATTR, inobyte)
	inobyte, err := Lgetxattr(pathl, INOXATTR)
	if err != nil {
		return nil
	}
	if len(inobyte) == 0 {
		return nil
	}
	inostr := string(inobyte)
	ino, err := strconv.Atoi(inostr)
	if err != nil {
		return err
	}
	stat.Ino = uint64(ino)
	if inode.ino == 1 {
		stat.Ino = 1
	}
	return nil
}
Exemple #8
0
func (self *fileInfo) Sys() interface{} {
	var statbuf syscall.Stat_t = *self.FileInfo.Sys().(*syscall.Stat_t)
	statbuf.Dev = self.dev
	statbuf.Rdev = self.rdev
	return &statbuf
}