Example #1
0
// Fix this: Move it to utils and make it return string
func getClientFilePath(vinfo *volume.Volinfo, path *string) error {
	vdir := utils.GetVolumeDir(vinfo.Name)

	// Create volume directory (/var/lib/glusterd/vols/<VOLNAME>)
	err := os.MkdirAll(vdir, os.ModeDir|os.ModePerm)
	if err != nil {
		return err
	}

	*path = fmt.Sprintf("%s/trusted-%s.tcp-fuse.vol", vdir, vinfo.Name)
	return err
}
Example #2
0
// GenerateVolfile function will do all task from graph generation to volfile generation
func GenerateVolfile(vinfo *volume.Volinfo) error {
	var cpath string
	var err error
	var f *os.File

	graph := GenerateGraph(vinfo, "CLIENT")

	//Generate client volfile
	err = getClientFilePath(vinfo, &cpath)
	if err != nil {
		return err
	}

	f, err = os.Create(cpath)
	if err != nil {
		return err
	}
	graph.DumpGraph(f)
	f.Close()

	// Generate brick volfiles
	for _, b := range vinfo.Bricks {

		// Create 'vols' directory.
		vdir := utils.GetVolumeDir(vinfo.Name)
		err := os.MkdirAll(vdir, os.ModeDir|os.ModePerm)
		if err != nil {
			return err
		}

		// Get brick volfile path
		cpath = utils.GetBrickVolFilePath(vinfo.Name, b.Hostname, b.Path)

		f, err = os.Create(cpath)
		if err != nil {
			return err
		}

		replacer := strings.NewReplacer(
			"<volume-name>", vinfo.Name,
			"<volume-id>", vinfo.ID.String(),
			"<brick-path>", b.Path)

		_, err = replacer.WriteString(f, brick.VolfileTemplate)
		if err != nil {
			return err
		}

		f.Close()
	}
	return nil
}
Example #3
0
// SocketFile returns path to the brick socket file used for IPC.
func (b *Brick) SocketFile() string {

	if b.socketfilepath != "" {
		return b.socketfilepath
	}

	// This looks a little convoluted but just doing what gd1 did...

	// First we form a fake path to the socket file
	// Example: /var/lib/glusterd/vols/<vol-name>/run/<host-name>-<brick-path>
	brickPathWithoutSlashes := strings.Trim(strings.Replace(b.brickinfo.Path, "/", "-", -1), "-")
	fakeSockFileName := fmt.Sprintf("%s-%s", b.brickinfo.Hostname, brickPathWithoutSlashes)
	volumedir := utils.GetVolumeDir(b.volName)
	fakeSockFilePath := path.Join(volumedir, "run", fakeSockFileName)

	// Then md5sum of the above path shall be the name of socket file.
	// Example: /var/run/gluster/<md5sum-hash>.socket
	checksumData := []byte(fakeSockFilePath)
	glusterdSockDir := path.Join(config.GetString("rundir"), "gluster")
	b.socketfilepath = fmt.Sprintf("%s/%x.socket", glusterdSockDir, md5.Sum(checksumData))

	return b.socketfilepath
}