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) glog.V(0).Infoln("Created Volume", vid, "on", server)
} else { } else {
glog.V(0).Infoln("Failed to assign", vid, "to", servers, "error", err) 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 return nil

View file

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

View file

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

View file

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