This commit is contained in:
Chris Lu 2013-08-12 23:48:10 -07:00
parent 11b4e0c77d
commit 078118ecba
4 changed files with 23 additions and 12 deletions

View file

@ -207,7 +207,7 @@ func (vg *VolumeGrowth) grow(topo *topology.Topology, vid storage.VolumeId, repT
glog.V(0).Infoln("Created Volume", vid, "on", server)
} else {
glog.V(0).Infoln("Failed to assign", vid, "to", servers, "error", err)
return errors.New("Failed to assign " + vid.String())
return errors.New("Failed to assign " + vid.String() + ", " + err.Error())
}
}
return nil

View file

@ -57,12 +57,14 @@ func (v *Volume) load(alsoLoadIndex bool) error {
fileName := path.Join(v.dir, v.Id.String())
if exists, canRead, canWrite, _ := checkFile(fileName + ".dat"); exists && !canRead {
return fmt.Errorf("cannot read Volume Data file %s.dat", fileName)
} else if canWrite {
} else if !exists || canWrite {
v.dataFile, e = os.OpenFile(fileName+".dat", os.O_RDWR|os.O_CREATE, 0644)
} else {
} else if exists && canRead {
glog.V(0).Infoln("opening " + fileName + ".dat in READONLY mode")
v.dataFile, e = os.Open(fileName + ".dat")
v.readOnly = true
} else {
return fmt.Errorf("Unknown state about Volume Data file %s.dat", fileName)
}
if e != nil {
if !os.IsPermission(e) {

View file

@ -6,7 +6,7 @@ import (
)
const (
VERSION = "0.39"
VERSION = "0.40"
)
var cmdVersion = &Command{

View file

@ -7,6 +7,7 @@ import (
"code.google.com/p/weed-fs/go/storage"
"math/rand"
"mime"
"net"
"net/http"
"os"
"path/filepath"
@ -41,9 +42,10 @@ var (
vMaxCpu = cmdVolume.Flag.Int("maxCpu", 0, "maximum number of CPUs. 0 means all available CPUs")
dataCenter = cmdVolume.Flag.String("dataCenter", "", "current volume server's data center name")
rack = cmdVolume.Flag.String("rack", "", "current volume server's rack name")
whiteList = cmdVolume.Flag.String("whiteList", "", "Ip addresses having write permission. No limit if empty.")
whiteListOption = cmdVolume.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.")
store *storage.Store
store *storage.Store
whiteList []string
)
var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
@ -334,6 +336,9 @@ func runVolume(cmd *Command, args []string) bool {
if *publicUrl == "" {
*publicUrl = *ip + ":" + strconv.Itoa(*vport)
}
if *whiteListOption != "" {
whiteList = strings.Split(*whiteListOption, ",")
}
store = storage.NewStore(*vport, *ip, *publicUrl, folders, maxCounts)
defer store.Close()
@ -383,15 +388,19 @@ func runVolume(cmd *Command, args []string) bool {
func secure(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if *whiteList == "" {
if len(whiteList) == 0 {
f(w, r)
return
}
ip := r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")]
if strings.Contains(*whiteList, ip) {
f(w, r)
return
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err == nil {
for _, ip := range whiteList {
if ip == host {
f(w, r)
return
}
}
}
return
writeJsonQuiet(w, r, map[string]interface{}{"error": "No write permisson from " + host})
}
}