예제 #1
0
파일: brick.go 프로젝트: kshlm/glusterd2
// Args returns arguments to be passed to brick process during spawn.
func (b *Brick) Args() string {
	if b.args != "" {
		return b.args
	}

	brickPathWithoutSlashes := strings.Trim(strings.Replace(b.brickinfo.Path, "/", "-", -1), "-")
	logFile := path.Join(config.GetString("logdir"), "glusterfs", "bricks", fmt.Sprintf("%s.log", brickPathWithoutSlashes))
	//TODO: For now, getting next available port. Use portmap ?
	brickPort := strconv.Itoa(GetNextAvailableFreePort())
	//TODO: Passing volfile directly for now.
	//Change this once we have volfile fetch support in GD2.
	volfile := utils.GetBrickVolFilePath(b.volName, b.brickinfo.Hostname, b.brickinfo.Path)

	var buffer bytes.Buffer
	buffer.WriteString(fmt.Sprintf(" --volfile %s", volfile))
	buffer.WriteString(fmt.Sprintf(" -p %s", b.PidFile()))
	buffer.WriteString(fmt.Sprintf(" -S %s", b.SocketFile()))
	buffer.WriteString(fmt.Sprintf(" --brick-name %s", b.brickinfo.Path))
	buffer.WriteString(fmt.Sprintf(" --brick-port %s", brickPort))
	buffer.WriteString(fmt.Sprintf(" -l %s", logFile))
	buffer.WriteString(fmt.Sprintf(" --xlator-option *-posix.glusterd-uuid=%s", gdctx.MyUUID))
	buffer.WriteString(fmt.Sprintf(" --xlator-option %s-server.transport.socket.listen-port=%s", b.volName, brickPort))

	b.args = buffer.String()
	return b.args
}
예제 #2
0
파일: core.go 프로젝트: kshlm/glusterd2
// DeleteVolfile deletes the volfiles created for the volume
// XXX: This is a quick and dirty implementation with no error checking.
// A proper implementation will be implemented when volgen is re-implemented.
func DeleteVolfile(vol *volume.Volinfo) error {
	var path string

	_ = getClientFilePath(vol, &path)
	_ = os.Remove(path)

	for _, b := range vol.Bricks {
		path := utils.GetBrickVolFilePath(vol.Name, b.Hostname, b.Path)
		_ = os.Remove(path)
	}
	return nil
}
예제 #3
0
파일: core.go 프로젝트: kshlm/glusterd2
// 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
}