1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
import os
import rcMountsOSF1 as rcMounts
import resFs as Res
from rcUtilities import qcall, protected_mount, getmount
from rcGlobalEnv import rcEnv
import rcExceptions as ex
from stat import *
def try_umount(self):
cmd = ['umount', self.mount_point]
(ret, out, err) = self.vcall(cmd, err_to_warn=True)
if ret == 0:
return 0
if "not currently mounted" in err:
return 0
""" don't try to kill process using the source of a
protected bind mount
"""
if protected_mount(self.mount_point):
return 1
""" best effort kill of all processes that might block
the umount operation. The priority is given to mass
action reliability, ie don't contest oprator's will
"""
cmd = ['sync']
(ret, out, err) = self.vcall(cmd)
for i in range(4):
cmd = ['fuser', '-kcv', self.mount_point]
(ret, out, err) = self.vcall(cmd, err_to_info=True)
self.log.info('umount %s'%self.mount_point)
cmd = ['umount', self.mount_point]
ret = qcall(cmd)
if ret == 0:
break
return ret
class Mount(Res.Mount):
def __init__(self, **kwargs):
self.Mounts = None
Res.Mount.__init__(self, **kwargs)
self.fsck_h = {
'ufs': {
'bin': 'fsck',
'cmd': ['fsck', '-p', self.device], 'allowed_ret': []
},
}
def is_up(self):
self.Mounts = rcMounts.Mounts()
ret = self.Mounts.has_mount(self.device, self.mount_point)
if ret:
return True
if self.fs_type not in ["advfs"] + self.netfs:
# might be a loopback mount
try:
mode = os.stat(self.device)[ST_MODE]
except:
self.log.debug("can not stat %s" % self.device)
return False
return False
def devlist(self):
return self.disklist()
def disklist(self):
if '#' in self.device:
dom, fset = self.device.split('#')
for r in self.svc.get_resources('disk.vg'):
if r.name == dom:
# no need to compute device list: the vg resource will do the job
return set([])
import rcAdvfs
try:
o = rcAdvfs.Fdmns()
d = o.get_fdmn(dom)
except rcAdvfs.ExInit as e:
return set([])
if d is None:
return set([])
return set(d.list_volnames())
else:
return set([self.device])
def can_check_writable(self):
return True
def start(self):
if self.Mounts is None:
self.Mounts = rcMounts.Mounts()
Res.Mount.start(self)
if self.is_up() is True:
self.log.info("%s is already mounted" % self.label)
return 0
self.fsck()
if not os.path.exists(self.mount_point):
os.makedirs(self.mount_point, 0o755)
if self.fs_type != "":
fstype = ['-t', self.fs_type]
else:
fstype = []
if self.mount_options != "":
mntopt = ['-o', self.mount_options]
else:
mntopt = []
cmd = ['mount']+fstype+mntopt+[self.device, self.mount_point]
(ret, out, err) = self.vcall(cmd)
if ret != 0:
raise ex.excError
self.Mounts = None
self.can_rollback = True
def stop(self):
if self.Mounts is None:
self.Mounts = rcMounts.Mounts()
if self.is_up() is False:
self.log.info("%s is already umounted" % self.label)
return
for i in range(3):
ret = try_umount(self)
if ret == 0: break
if ret != 0:
self.log.error('failed to umount %s'%self.mount_point)
raise ex.excError
self.Mounts = None
if __name__ == "__main__":
for c in (Mount,) :
help(c)
|