Change:
type RBDUtil struct{} func (util *RBDUtil) MakeGlobalPDName(rbd rbd) string { <del> return makePDNameInternal(rbd.plugin.host, rbd.pool, rbd.image) </del> <ins> return makePDNameInternal(rbd.plugin.host, rbd.Pool, rbd.Image) } func (util *RBDUtil) rbdLock(rbd rbd, lock bool) error { var err error var output, locker string var cmd []byte var secret_opt []string if rbd.Secret != "" { secret_opt = []string{"--key=" + rbd.Secret} } else { secret_opt = []string{"-k", rbd.Keyring} } // construct lock id using host name and a magic prefix lock_id := "kubelet_lock_magic_" + node.GetHostname("") l := len(rbd.Mon) // avoid mount storm, pick a host randomly start := rand.Int() % l // iterate all hosts until mount succeeds. for i := start; i < start+l; i++ { mon := rbd.Mon[i%l] // cmd "rbd lock list" serves two purposes: // for fencing, check if lock already held for this host // this edge case happens if host crashes in the middle of acquiring lock and mounting rbd // for defencing, get the locker name, something like "client.1234" cmd, err = rbd.plugin.execCommand("rbd", append([]string{"lock", "list", rbd.Image, "--pool", rbd.Pool, "--id", rbd.Id, "-m", mon}, secret_opt...)) output = string(cmd) if err != nil { continue } if lock { // check if lock is already held for this host by matching lock_id and rbd lock id if strings.Contains(output, lock_id) { // this host already holds the lock, exit glog.V(1).Infof("rbd: lock already held for %s", lock_id) return nil } // hold a lock: rbd lock add cmd, err = rbd.plugin.execCommand("rbd", append([]string{"lock", "add", rbd.Image, lock_id, "--pool", rbd.Pool, "--id", rbd.Id, "-m", mon}, secret_opt...)) } else { // defencing, find locker name ind := strings.LastIndex(output, lock_id) - 1 for i := ind; i >= 0; i-- { if output[i] == 'n' { locker = output[(i + 1):ind] break } } // remove a lock: rbd lock remove cmd, err = rbd.plugin.execCommand("rbd", append([]string{"lock", "remove", rbd.Image, lock_id, locker, "--pool", rbd.Pool, "--id", rbd.Id, "-m", mon}, secret_opt...)) } if err == nil { //lock is acquired break } } return err } func (util *RBDUtil) persistRBD(rbd rbd, mnt string) error { file := path.Join(mnt, "rbd.json") fp, err := os.Create(file) if err != nil { return fmt.Errorf("rbd: create err %s/%s", file, err) } defer fp.Close() encoder := json.NewEncoder(fp) if err = encoder.Encode(rbd); err != nil { return fmt.Errorf("rbd: encode err: %v.", err) } return nil } func (util *RBDUtil) loadRBD(rbd *rbd, mnt string) error { file := path.Join(mnt, "rbd.json") fp, err := os.Open(file) if err != nil { return fmt.Errorf("rbd: open err %s/%s", file, err) } defer fp.Close() decoder := json.NewDecoder(fp) if err = decoder.Decode(rbd); err != nil { return fmt.Errorf("rbd: decode err: %v.", err) } return nil } func (util *RBDUtil) fencing(rbd rbd) error { // no need to fence readOnly if rbd.ReadOnly { return nil } return util.rbdLock(rbd, true) } func (util *RBDUtil) defencing(rbd rbd) error { // no need to fence readOnly if rbd.ReadOnly { return nil } return util.rbdLock(rbd, false) </ins> } func (util *RBDUtil) AttachDisk(rbd rbd) error { var err error <del> devicePath := strings.Join([]string{"/dev/rbd", rbd.pool, rbd.image}, "/") </del> <ins> devicePath := strings.Join([]string{"/dev/rbd", rbd.Pool, rbd.Image}, "/") </ins> exist := waitForPathToExist(devicePath, 1) if !exist { // modprobe

Discussion:
etcd cluster backing apiserver died spontaneously, after restart apiserver pulled up the pods on different machines. Node storage was backed by ext4 over rbd, which became mounted on several nodes at once. That could have possibly led to data corruption. I guess that the proper way to mount rbd volume is to take a lock on it first, which will at least fail if it's locked somewhere else, requiring manual intervention, but not destroying data. The lock should be optional, in case a proper cluster fs is mounted over the rbd. In this case there was clearly no need for accessing the data from several pods so ext4 is deemed a proper fs.
, Vladimir Pouzanov < :
want to get some detail. How is your pod-to-rbd mapping like? Since rbd image is a block device, it can be used by one pod at a time. I am not sure if locking is a proper way to go - if the pod holds a lock but dies in the middle of mounting, the rbd image (or any other volume type) is then excluded from access. In such case, a high level coordination at apiserver is a better place to resolve this problem.
Here's my rc: I guess it's better to have a lock to be cleaned up manually rather than to have non-cluster fs to be mounted in several locations at once?
thanks, this pod looks good to me. what would cause multiple nodes run the same pod?
I don't know the exact reason of why kubelet didn't unmount the old fs, but after apiserver and scheduler were restarted pod got allocated on different node.
It is a scary thing to see etcd down, it is meant to be reliable...
Unfortunately I don't have long-term logging in test cluster so I have no idea why it actually died. but using kubedns as primary node resolver was clearly a bad idea, once it died, nodes stuck with no resolver at all.
your thought on HA?
Wrong Tim St. Clair?
- you HAVE to be ready to handle network partitions - the old node might still be alive and even using the volume, but the apiserver can't see the node, so it thinks it deletes the pod and starts it elsewhere. If RBD corrupts itslef in this case, it is not useful and we should strip it from the codebase.

, Huamin Chen wrote:
that makes sense. rbd doesn't corrupt itself. This is inconsistency happens when you have two pods mounting the same rbd image. How does GCE PD handle/prevent this case?
It doesn't allow more than one read-write attachment. Multiple read-only attachments is OK. Better to fail than to allow corruption. , Huamin Chen wrote:
That's neat. I have a lock fencing for rbd, testing now.