~jamesodhunt/snappy/add-lsblk-cache

« back to all changes in this revision

Viewing changes to partition/partition.go

  • Committer: Sergio Schvezov
  • Date: 2015-01-29 15:28:06 UTC
  • mfrom: (125.1.2 mount-option-type)
  • Revision ID: sergio.schvezov@canonical.com-20150129152806-xpqknilxhfobex4c
Merge lp:~mvo/snappy/si-progress into lp:snappy

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
 
112
112
//--------------------------------------------------------------------
113
113
 
 
114
type MountOption int
 
115
 
 
116
const (
 
117
        RO MountOption = iota
 
118
        RW
 
119
)
 
120
 
114
121
type PartitionInterface interface {
115
122
        UpdateBootloader() (err error)
116
123
        MarkBootSuccessful() (err error)
120
127
        NextBootIsOther() bool
121
128
 
122
129
        // run the function f with the otherRoot mounted
123
 
        RunWithOther(writable bool, f func(otherRoot string) (err error)) (err error)
 
130
        RunWithOther(rw MountOption, f func(otherRoot string) (err error)) (err error)
124
131
}
125
132
 
126
133
type Partition struct {
404
411
 
405
412
// Mount the other rootfs partition, execute the specified function and
406
413
// unmount "other" before returning.
407
 
func (p *Partition) RunWithOther(writable bool, f func(otherRoot string) (err error)) (err error) {
 
414
func (p *Partition) RunWithOther(option MountOption, f func(otherRoot string) (err error)) (err error) {
408
415
        dual := p.dualRootPartitions()
409
416
 
410
417
        // FIXME: should we simply
412
419
                return f("/")
413
420
        }
414
421
 
415
 
        if writable {
416
 
                if err = p.remountOther(true); err != nil {
 
422
        if option == RW {
 
423
                if err = p.remountOther(RW); err != nil {
417
424
                        return err
418
425
                }
419
426
 
420
427
                defer func() {
421
 
                        err = p.remountOther(false)
 
428
                        err = p.remountOther(RO)
422
429
                }()
423
430
        }
424
431
 
657
664
// XXX: Note that in the case where writable=true, this isn't a simple
658
665
// toggle - if the partition is already mounted read-only, it needs to
659
666
// be unmounted, fsck(8)'d, then (re-)mounted read-write.
660
 
func (p *Partition) remountOther(writable bool) (err error) {
 
667
func (p *Partition) remountOther(option MountOption) (err error) {
661
668
        other := p.otherRootPartition()
662
669
 
663
 
        if writable == true {
 
670
        if option == RW {
664
671
                // r/o -> r/w: initially r/o, so no need to fsck before
665
672
                // switching to r/w.
666
673
                err = p.unmountOtherRootfs()
742
749
                return errors.New("System is not dual root")
743
750
        }
744
751
 
745
 
        if err = p.remountOther(true); err != nil {
 
752
        if err = p.remountOther(RW); err != nil {
746
753
                return err
747
754
        }
748
755
 
758
765
                return err
759
766
        }
760
767
 
761
 
        if err = p.remountOther(false); err != nil {
 
768
        if err = p.remountOther(RO); err != nil {
762
769
                return err
763
770
        }
764
771