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

Commit

Permalink
Merge branch 'master' of https://github.com/gluster/glusterd2 into group
Browse files Browse the repository at this point in the history
  • Loading branch information
rishubhjain committed Mar 21, 2018
2 parents 76324c9 + c2deff7 commit c54c2f9
Show file tree
Hide file tree
Showing 19 changed files with 404 additions and 228 deletions.
2 changes: 1 addition & 1 deletion e2e/volume_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func TestVolume(t *testing.T) {
// Run tests that depend on this volume
t.Run("Start", testVolumeStart)
t.Run("Mount", testVolumeMount)
t.Run("Status", testVolumeStatus)
t.Run("Stop", testVolumeStop)
t.Run("List", testVolumeList)
t.Run("Info", testVolumeInfo)
t.Run("Status", testVolumeStatus)

// delete volume
t.Run("Delete", testVolumeDelete)
Expand Down
13 changes: 13 additions & 0 deletions extras/rpms/glusterd2-logrotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Rotate client logs
/var/log/glusterd2/*.log /var/log/glusterd2/store/*.log {
sharedscripts
weekly
rotate 52
missingok
compress
delaycompress
notifempty
postrotate
/usr/bin/killall -HUP glusterd2 > /dev/null 2>&1 || true
endscript
}
31 changes: 21 additions & 10 deletions extras/rpms/glusterd2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
%global with_bundled 1
%endif

%{!?with_debug: %global with_debug 1}

%if 0%{?with_debug}
%global _dwz_low_mem_die_limit 0
%else
Expand All @@ -23,7 +25,7 @@

Name: %{repo}
Version: 4.0.0
Release: 1%{?dist}
Release: 2%{?dist}
Summary: The GlusterFS management daemon (preview)
License: GPLv2 or LGPLv3+
URL: https://%{provider_prefix}
Expand All @@ -32,11 +34,13 @@ Source0: https://%{provider_prefix}/releases/download/v%{version}/%{name}-v%{ver
%else
Source0: https://%{provider_prefix}/releases/download/v%{version}/%{name}-v%{version}-0.tar.xz
%endif
Source1: glusterd2-logrotate

ExclusiveArch: %{go_arches}

BuildRequires: golang >= 1.8.0
BuildRequires: %{?go_compiler:compiler(go-compiler)}%{!?go_compiler:golang}
BuildRequires: systemd

%if ! 0%{?with_bundled}
BuildRequires: golang(github.com/asaskevich/govalidator)
BuildRequires: golang(github.com/cespare/xxhash)
Expand Down Expand Up @@ -68,7 +72,7 @@ BuildRequires: golang(golang.org/x/sys/unix)
BuildRequires: golang(google.golang.org/grpc)
%endif

Requires: glusterfs-server >= 4.0.0
Requires: glusterfs-server >= 4.0.0, glusterfs-server < 4.1.0
Requires: /usr/bin/strings
%{?systemd_requires}

Expand All @@ -91,35 +95,42 @@ pushd src/%{import_path}
popd

%install
#Install glusterd2 & glustercli binaries and the config
# Install glusterd2 & glustercli binaries and the config
%{gd2make} DESTDIR=%{buildroot} install
#Install systemd unit
# Install systemd unit
install -D -p -m 0644 extras/systemd/%{name}.service %{buildroot}%{_unitdir}/%{name}.service
# Create /var/lib/glusterd2
install -d -m 0755 %{buildroot}%{_sharedstatedir}/%{name}
# logdir
# Setup logdir
install -d -m 0755 %{buildroot}%{_localstatedir}/log/%{name}
# Install logrotate config
install -D -p -m 0644 %{SOURCE1} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun %{name}.service

%files
%{_sbindir}/%{name}
%{_sbindir}/glustercli
%config(noreplace) %{_sysconfdir}/%{name}
%{_unitdir}/%{name}.service
%dir %{_sharedstatedir}/%{name}
%dir %{_localstatedir}/log/%{name}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%{_sysconfdir}/bash_completion.d/glustercli.sh

%changelog
* Wed Feb 28 2018 Kaushal M <kshlmster@gmail.com> - 4.0.0
* Wed Mar 14 2018 Kaushal M <kshlmster@gmail.com> - 4.0.0-2
- Add logrotate configuration
- Correct BuildRequires on go_compiler
- Build with unbundled on Fedora
- Fix go_arches for EL
- Require glusterfs-server < 4.1.0

* Wed Feb 28 2018 Kaushal M <kshlmster@gmail.com> - 4.0.0-1
- Update to v4.0.0

* Wed Feb 14 2018 Kaushal M <kshlmster@gmail.com> - 4.0rc0-2
Expand Down
101 changes: 101 additions & 0 deletions glusterd2/brick/glusterfsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
"path"
"strconv"
"strings"
"syscall"
"time"

"github.com/cespare/xxhash"
"github.com/gluster/glusterd2/glusterd2/daemon"
"github.com/gluster/glusterd2/glusterd2/gdctx"
"github.com/gluster/glusterd2/glusterd2/pmap"
"github.com/gluster/glusterd2/pkg/api"
"github.com/gluster/glusterd2/pkg/utils"

config "github.com/spf13/viper"
Expand Down Expand Up @@ -131,3 +135,100 @@ func NewGlusterfsd(binfo Brickinfo) (*Glusterfsd, error) {
func (b *Glusterfsd) ID() string {
return b.brickinfo.Path
}

// BrickStartMaxRetries represents maximum no. of attempts that will be made
// to start brick processes in case of port clashes.
const BrickStartMaxRetries = 3

// Until https://review.gluster.org/#/c/16200/ gets into a release.
// And this is fully safe too as no other well-known errno exists after 132

//anotherEADDRINUSE is errno generated for rpc connection
const anotherEADDRINUSE = syscall.Errno(0x9E) // 158

func errorContainsErrno(err error, errno syscall.Errno) bool {
exiterr, ok := err.(*exec.ExitError)
if !ok {
return false
}
status, ok := exiterr.Sys().(syscall.WaitStatus)
if !ok {
return false
}
if status.ExitStatus() != int(errno) {
return false
}
return true
}

// These functions are used in vol-create, vol-expand and vol-shrink (TBD)

//StartBrick starts glusterfsd process
func (b Brickinfo) StartBrick() error {

brickDaemon, err := NewGlusterfsd(b)
if err != nil {
return err
}

for i := 0; i < BrickStartMaxRetries; i++ {
err = daemon.Start(brickDaemon, true)
if err != nil {
if errorContainsErrno(err, syscall.EADDRINUSE) || errorContainsErrno(err, anotherEADDRINUSE) {
// Retry iff brick failed to start because of port being in use.
// Allow the previous instance to cleanup and exit
time.Sleep(1 * time.Second)
} else {
return err
}
} else {
break
}
}

return nil
}

//StopBrick will stop glusterfsd process
func (b Brickinfo) StopBrick() error {

brickDaemon, err := NewGlusterfsd(b)
if err != nil {
return err
}

return daemon.Stop(brickDaemon, true)
}

//CreateBrickSizeInfo parses size information for response
func CreateBrickSizeInfo(size *SizeInfo) api.SizeInfo {
return api.SizeInfo{
Used: size.Used,
Free: size.Free,
Capacity: size.Capacity,
}
}

//CreateBrickInfo parses brick information for response
func CreateBrickInfo(b *Brickinfo) api.BrickInfo {
return api.BrickInfo{
ID: b.ID,
Path: b.Path,
VolumeID: b.VolumeID,
VolumeName: b.VolumeName,
NodeID: b.NodeID,
Hostname: b.Hostname,
Type: api.BrickType(b.Type),
}
}

//CreateSizeInfo return size of a brick
func CreateSizeInfo(fstat *syscall.Statfs_t) *SizeInfo {
var s SizeInfo
if fstat != nil {
s.Capacity = fstat.Blocks * uint64(fstat.Bsize)
s.Free = fstat.Bfree * uint64(fstat.Bsize)
s.Used = s.Capacity - s.Free
}
return &s
}
19 changes: 19 additions & 0 deletions glusterd2/brick/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ type Brickinfo struct {
Decommissioned bool
}

// SizeInfo represents sizing information.
type SizeInfo struct {
Capacity uint64
Used uint64
Free uint64
}

//Brickstatus gives status of brick
type Brickstatus struct {
Info Brickinfo
Online bool
Pid int
Port int
FS string
MountOpts string
Device string
Size SizeInfo
}

func (b *Brickinfo) String() string {
return b.NodeID.String() + ":" + b.Path
}
Expand Down
81 changes: 27 additions & 54 deletions glusterd2/commands/volumes/bricks-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,44 @@ package volumecommands

import (
"net/http"
"strings"
"syscall"

"github.com/gluster/glusterd2/glusterd2/brick"
"github.com/gluster/glusterd2/glusterd2/daemon"
"github.com/gluster/glusterd2/glusterd2/gdctx"
"github.com/gluster/glusterd2/glusterd2/pmap"
restutils "github.com/gluster/glusterd2/glusterd2/servers/rest/utils"
"github.com/gluster/glusterd2/glusterd2/transaction"
"github.com/gluster/glusterd2/glusterd2/volume"
"github.com/gluster/glusterd2/pkg/api"
"github.com/gluster/glusterd2/pkg/errors"

"github.com/gorilla/mux"
)

const (
brickStatusTxnKey string = "brickstatuses"
)

func checkBricksStatus(ctx transaction.TxnCtx) error {
func registerBricksStatusStepFuncs() {
transaction.RegisterStepFunc(bricksStatus, "bricks-status.Check")
}

func createBrickStatusRsp(brickStatuses []brick.Brickstatus) []*api.BrickStatus {
var brickStatusesRsp []*api.BrickStatus
for _, status := range brickStatuses {
s := &api.BrickStatus{
Info: brick.CreateBrickInfo(&status.Info),
Online: status.Online,
Pid: status.Pid,
Port: status.Port,
FS: status.FS,
MountOpts: status.MountOpts,
Device: status.Device,
Size: brick.CreateBrickSizeInfo(&status.Size),
}
brickStatusesRsp = append(brickStatusesRsp, s)
}
return brickStatusesRsp
}

func bricksStatus(ctx transaction.TxnCtx) error {
var volname string
if err := ctx.Get("volname", &volname); err != nil {
ctx.Logger().WithError(err).Error("Failed to get key from transaction context.")
Expand All @@ -35,61 +51,18 @@ func checkBricksStatus(ctx transaction.TxnCtx) error {
ctx.Logger().WithError(err).Error("Failed to get volume information from store.")
return err
}

mtabEntries, err := getMounts()
brickStatuses, err := volume.CheckBricksStatus(vol)
if err != nil {
ctx.Logger().WithError(err).Error("Failed to read /etc/mtab file.")
ctx.Logger().WithError(err).Error("Failed to get brick status information.")
return err
}

var brickStatuses []*api.BrickStatus
for _, binfo := range vol.GetLocalBricks() {
brickDaemon, err := brick.NewGlusterfsd(binfo)
if err != nil {
return err
}

s := &api.BrickStatus{
Info: createBrickInfo(&binfo),
}

if pidOnFile, err := daemon.ReadPidFromFile(brickDaemon.PidFile()); err == nil {
if _, err := daemon.GetProcess(pidOnFile); err == nil {
s.Online = true
s.Pid = pidOnFile
s.Port = pmap.RegistrySearch(binfo.Path, pmap.GfPmapPortBrickserver)
}
}

var fstat syscall.Statfs_t
if err := syscall.Statfs(binfo.Path, &fstat); err != nil {
ctx.Logger().WithError(err).WithField("path",
binfo.Path).Error("syscall.Statfs() failed")
} else {
s.Size = *(createSizeInfo(&fstat))
}

for _, m := range mtabEntries {
if strings.HasPrefix(binfo.Path, m.mntDir) {
s.MountOpts = m.mntOpts
s.Device = m.fsName
s.FS = m.mntType
}
}

brickStatuses = append(brickStatuses, s)
}

brickStatusesRsp := createBrickStatusRsp(brickStatuses)
// Store the results in transaction context. This will be consumed by
// the node that initiated the transaction.
ctx.SetNodeResult(gdctx.MyUUID, brickStatusTxnKey, brickStatuses)
ctx.SetNodeResult(gdctx.MyUUID, brickStatusTxnKey, brickStatusesRsp)
return nil
}

func registerBricksStatusStepFuncs() {
transaction.RegisterStepFunc(checkBricksStatus, "bricks-status.Check")
}

func volumeBricksStatusHandler(w http.ResponseWriter, r *http.Request) {

ctx := r.Context()
Expand Down Expand Up @@ -140,7 +113,7 @@ func createBricksStatusResp(ctx transaction.TxnCtx, vol *volume.Volinfo) (*api.B
bmap := make(map[string]*api.BrickStatus)
for _, b := range vol.GetBricks() {
bmap[b.ID.String()] = &api.BrickStatus{
Info: createBrickInfo(&b),
Info: brick.CreateBrickInfo(&b),
}
}

Expand Down
Loading

0 comments on commit c54c2f9

Please sign in to comment.