/[smeserver]/cdrom.image/sme9/updates/storage/devicelibs/dm.py
ViewVC logotype

Annotation of /cdrom.image/sme9/updates/storage/devicelibs/dm.py

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download) (as text)
Sun Oct 20 23:12:54 2013 UTC (10 years, 9 months ago) by charliebrady
Branch: MAIN
Content type: text/x-python
Add devicelibs and formats subdirectories of storage, and contained .py
files, in preparation to modifying to allow degraded RAID install.

1 charliebrady 1.1 #
2     # dm.py
3     # device-mapper functions
4     #
5     # Copyright (C) 2009 Red Hat, Inc. All rights reserved.
6     #
7     # This program is free software; you can redistribute it and/or modify
8     # it under the terms of the GNU General Public License as published by
9     # the Free Software Foundation; either version 2 of the License, or
10     # (at your option) any later version.
11     #
12     # This program is distributed in the hope that it will be useful,
13     # but WITHOUT ANY WARRANTY; without even the implied warranty of
14     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     # GNU General Public License for more details.
16     #
17     # You should have received a copy of the GNU General Public License
18     # along with this program. If not, see <http://www.gnu.org/licenses/>.
19     #
20     # Author(s): Dave Lehman <dlehman@redhat.com>
21     #
22    
23     import os
24    
25     import block
26     import iutil
27     from ..errors import *
28    
29     import gettext
30     _ = lambda x: gettext.ldgettext("anaconda", x)
31    
32     import logging
33     log = logging.getLogger("storage")
34    
35     def name_from_dm_node(dm_node):
36     name = block.getNameFromDmNode(dm_node)
37     if name is not None:
38     return name
39    
40     st = os.stat("/dev/%s" % dm_node)
41     major = os.major(st.st_rdev)
42     minor = os.minor(st.st_rdev)
43     name = iutil.execWithCapture("dmsetup",
44     ["info", "--columns",
45     "--noheadings", "-o", "name",
46     "-j", str(major), "-m", str(minor)],
47     stderr="/dev/tty5")
48     log.debug("name_from_dm(%s) returning '%s'" % (dm_node, name.strip()))
49     return name.strip()
50    
51     def dm_node_from_name(map_name):
52     dm_node = block.getDmNodeFromName(map_name)
53     if dm_node is not None:
54     return dm_node
55    
56     devnum = iutil.execWithCapture("dmsetup",
57     ["info", "--columns",
58     "--noheadings",
59     "-o", "devno",
60     map_name],
61     stderr="/dev/tty5")
62     (major, sep, minor) = devnum.strip().partition(":")
63     if not sep:
64     raise DMError("dm device does not exist")
65    
66     dm_node = "dm-%d" % int(minor)
67     log.debug("dm_node_from_name(%s) returning '%s'" % (map_name, dm_node))
68     return dm_node
69    
70     def dm_is_multipath(info):
71     major = None
72     minor = None
73    
74     if info.has_key('MAJOR'):
75     major = info['MAJOR']
76     elif info.has_key('DM_MAJOR'):
77     major = info['DM_MAJOR']
78     if info.has_key('MINOR'):
79     minor = info['MINOR']
80     elif info.has_key('DM_MINOR'):
81     minor = info['DM_MINOR']
82    
83     if major is None or minor is None:
84     return False
85    
86     for map in block.dm.maps():
87     dev = map.dev
88     if dev.major == int(major) and dev.minor == int(minor):
89     for table in map.table:
90     if table.type == 'multipath':
91     return True
92    
93     def _get_backing_devnums_from_map(map_name):
94     ret = []
95     buf = iutil.execWithCapture("dmsetup",
96     ["info", "--columns",
97     "--noheadings",
98     "-o", "devnos_used",
99     map_name],
100     stderr="/dev/tty5")
101     dev_nums = buf.split()
102     for dev_num in dev_nums:
103     (major, colon, minor) = dev_num.partition(":")
104     ret.append((int(major), int(minor)))
105    
106     return ret
107    
108     def get_backing_devnums(dm_node):
109     #dm_node = dm_node_from_name(map_name)
110     if not dm_node:
111     return None
112    
113     top_dir = "/sys/block"
114     backing_devs = os.listdir("%s/%s/slaves/" % (top_dir, dm_node))
115     dev_nums = []
116     for backing_dev in backing_devs:
117     dev_num = open("%s/%s/dev" % (top_dir, backing_dev)).read().strip()
118     (_major, _minor) = dev_num.split(":")
119     dev_nums.append((int(_major), int(_minor)))
120    
121     return dev_nums
122    
123     def get_backing_devs_from_name(map_name):
124     dm_node = dm_node_from_name(map_name)
125     if not dm_node:
126     return None
127    
128     slave_devs = os.listdir("/sys/block/virtual/%s" % dm_node)
129     return slave_devs
130    

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed