Coverage for libs/sm/drivers/SHMSR.py: 0%
72 statements
« prev ^ index » next coverage.py v7.3.2, created at 2026-07-10 07:59 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2026-07-10 07:59 +0000
1# Copyright (C) Citrix Systems Inc.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU Lesser General Public License as published
5# by the Free Software Foundation; version 2.1 only.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU Lesser General Public License for more details.
11#
12# You should have received a copy of the GNU Lesser General Public License
13# along with this program; if not, write to the Free Software Foundation, Inc.,
14# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16from sm import SR
17from sm import VDI
18from sm.core import util
19import os
20from sm.core import xs_errors
22CAPABILITIES = ["VDI_ATTACH", "VDI_DETACH", "VDI_CLONE", "VDI_SNAPSHOT",
23 "SR_SCAN", "SR_ATTACH", "SR_DETACH"]
24CONFIGURATION = ['location', '/dev/shm subdirectory']
25DRIVER_INFO = {
26 'name': 'SHM',
27 'description': 'Handles shared memory virtual disks',
28 'vendor': 'Citrix Systems Inc.',
29 'copyright': '(c) 2009 Citrix Systems, Inc.',
30 'driver_version': '1.0',
31 'required_api_version': '1.0',
32 'capabilities': CAPABILITIES,
33 'configuration': CONFIGURATION
34 }
36TYPE = "shm"
39class SHMSR(SR.SR):
40 """Shared memory storage repository"""
42 def _loadvdis(self):
43 """Scan the location directory."""
44 if self.vdis:
45 return
47 try:
48 for name in util.listdir(self.dconf['location']):
49 if name != "":
50 self.vdis[name] = SHMVDI(self, util.gen_uuid(), name)
51 except:
52 pass
54 def handles(type):
55 """Do we handle this type?"""
56 if type == TYPE:
57 return True
58 return False
59 handles = staticmethod(handles)
61 def content_type(self, sr_uuid):
62 """Returns the content_type XML"""
63 return super(SHMSR, self).content_type(sr_uuid)
65 def vdi(self, uuid):
66 """Create a VDI class"""
67 if 'vdi_location' in self.srcmd.params:
68 return SHMVDI(self, uuid, self.srcmd.params['vdi_location'])
69 else:
70 return SHMVDI(self, uuid, self.srcmd.params['device_config']['location'])
72 def load(self, sr_uuid):
73 """Initialises the SR"""
74 if 'location' not in self.dconf:
75 raise xs_errors.XenError('ConfigLocationMissing')
77 self.sr_vditype = 'file'
78 self.physical_size = 0
79 self.physical_utilisation = 0
80 self.virtual_allocation = 0
82 def attach(self, sr_uuid):
83 """Std. attach"""
84 self._loadvdis()
86 def detach(self, sr_uuid):
87 """Std. detach"""
88 pass
90 def scan(self, sr_uuid):
91 """Scan"""
92 self._loadvdis()
93 return super(SHMSR, self).scan(sr_uuid)
95 def create(self, sr_uuid, size):
96 self.attach(sr_uuid)
97 self.detach(sr_uuid)
100class SHMVDI(VDI.VDI):
101 def load(self, vdi_uuid):
102 try:
103 stat = os.stat(self.path)
104 self.utilisation = int(stat.st_size)
105 self.size = int(stat.st_size)
106 except:
107 pass
109 def __init__(self, mysr, uuid, filename):
110 self.uuid = uuid
111 self.path = os.path.join(mysr.dconf['location'], filename)
112 VDI.VDI.__init__(self, mysr, None)
113 self.label = filename
114 self.location = filename
115 self.vdi_type = 'file'
116 self.read_only = True
117 self.shareable = True
118 self.sm_config = {}
120 def detach(self, sr_uuid, vdi_uuid):
121 pass
123 def clone(self, sr_uuid, vdi_uuid):
124 return self.get_params()
126 def snapshot(self, sr_uuid, vdi_uuid):
127 return self.get_params()
129# SR registration at import
130SR.registerSR(SHMSR)