diff options
-rw-r--r-- | fsset.py | 6 | ||||
-rw-r--r-- | isys/isys.c | 35 | ||||
-rw-r--r-- | isys/isys.py | 9 | ||||
-rw-r--r-- | partRequests.py | 7 | ||||
-rw-r--r-- | partitions.py | 8 |
5 files changed, 60 insertions, 5 deletions
@@ -1664,7 +1664,8 @@ class RAIDDevice(Device): # members is a list of Device based instances that will be # a part of this raid device - def __init__(self, level, members, minor=-1, spares=0, existing=0): + def __init__(self, level, members, minor=-1, spares=0, existing=0, + chunksize = 64): Device.__init__(self) self.level = level self.members = members @@ -1672,6 +1673,7 @@ class RAIDDevice(Device): self.numDisks = len(members) - spares self.isSetup = existing self.doLabel = None + self.chunksize = chunksize if len(members) < spares: raise RuntimeError, ("you requiested more spare devices " @@ -1715,7 +1717,7 @@ class RAIDDevice(Device): self.device,) entry = entry + "raid-level %d\n" % (self.level,) entry = entry + "nr-raid-disks %d\n" % (self.numDisks,) - entry = entry + "chunk-size 64k\n" + entry = entry + "chunk-size %d\n" %(self.chunksize,) entry = entry + "persistent-superblock 1\n" entry = entry + "nr-spare-disks %d\n" % (self.spares,) i = 0 diff --git a/isys/isys.c b/isys/isys.c index 234115fb1..46c717628 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -75,6 +75,7 @@ static PyObject * doUnLoSetup(PyObject * s, PyObject * args); static PyObject * doLoChangeFd(PyObject * s, PyObject * args); static PyObject * doDdFile(PyObject * s, PyObject * args); static PyObject * doGetRaidSuperblock(PyObject * s, PyObject * args); +static PyObject * doGetRaidChunkSize(PyObject * s, PyObject * args); static PyObject * doDevSpaceFree(PyObject * s, PyObject * args); static PyObject * doRaidStart(PyObject * s, PyObject * args); static PyObject * doRaidStop(PyObject * s, PyObject * args); @@ -118,6 +119,7 @@ static PyMethodDef isysModuleMethods[] = { { "raidstop", (PyCFunction) doRaidStop, METH_VARARGS, NULL }, { "raidstart", (PyCFunction) doRaidStart, METH_VARARGS, NULL }, { "getraidsb", (PyCFunction) doGetRaidSuperblock, METH_VARARGS, NULL }, + { "getraidchunk", (PyCFunction) doGetRaidChunkSize, METH_VARARGS, NULL }, { "lochangefd", (PyCFunction) doLoChangeFd, METH_VARARGS, NULL }, { "losetup", (PyCFunction) doLoSetup, METH_VARARGS, NULL }, { "unlosetup", (PyCFunction) doUnLoSetup, METH_VARARGS, NULL }, @@ -962,6 +964,39 @@ static PyObject * doGetRaidSuperblock(PyObject * s, PyObject * args) { sb.raid_disks, sb.md_minor); } +static PyObject * doGetRaidChunkSize(PyObject * s, PyObject * args) { + int fd; + unsigned long size; + struct md_superblock_s sb; + + if (!PyArg_ParseTuple(args, "i", &fd)) return NULL; + + if (ioctl(fd, BLKGETSIZE, &size)) { + PyErr_SetFromErrno(PyExc_SystemError); + return NULL; + } + + /* put the size in 1k blocks */ + size >>= 1; + + if (lseek64(fd, ((off64_t) 1024) * (off64_t) MD_NEW_SIZE_BLOCKS(size), SEEK_SET) < 0) { + PyErr_SetFromErrno(PyExc_SystemError); + return NULL; + } + + if (read(fd, &sb, sizeof(sb)) != sizeof(sb)) { + PyErr_SetFromErrno(PyExc_SystemError); + return NULL; + } + + if (sb.md_magic != MD_SB_MAGIC) { + PyErr_SetString(PyExc_ValueError, "bad md magic on device"); + return NULL; + } + + return Py_BuildValue("i", sb.chunk_size / 1024); +} + static PyObject * doDevSpaceFree(PyObject * s, PyObject * args) { char * path; struct statfs sb; diff --git a/isys/isys.py b/isys/isys.py index 8961a0072..e1adf8246 100644 --- a/isys/isys.py +++ b/isys/isys.py @@ -87,6 +87,15 @@ def raidsbFromDevice(device): os.close(fd) return rc +def getRaidChunkFromDevice(device): + fd = os.open(device, os.O_RDONLY) + rc = 64 + try: + rc = _isys.getraidchunk(fd) + finally: + os.close(fd) + return rc + def losetup(device, file, readOnly = 0): if readOnly: mode = os.O_RDONLY diff --git a/partRequests.py b/partRequests.py index 3f4e17ce0..d698968d5 100644 --- a/partRequests.py +++ b/partRequests.py @@ -541,13 +541,14 @@ class RaidRequestSpec(RequestSpec): def __init__(self, fstype, format = None, mountpoint = None, raidlevel = None, raidmembers = None, raidspares = None, raidminor = None, - preexist = 0): + preexist = 0, chunksize = None): """Create a new RaidRequestSpec object. fstype is the fsset filesystem type. format is whether or not the partition should be formatted. mountpoint is the mountpoint. raidlevel is the raidlevel (as 'RAID0', 'RAID1', 'RAID5'). + chunksize is the chunksize which should be used. raidmembers is list of ids corresponding to the members of the RAID. raidspares is the number of spares to setup. raidminor is the minor of the device which should be used. @@ -569,6 +570,7 @@ class RaidRequestSpec(RequestSpec): self.raidmembers = raidmembers self.raidspares = raidspares self.raidminor = raidminor + self.chunksize = chunksize def __str__(self): if self.fstype: @@ -602,7 +604,8 @@ class RaidRequestSpec(RequestSpec): self.dev = fsset.RAIDDevice(int(self.raidlevel[-1:]), raidmems, minor = self.raidminor, spares = self.raidspares, - existing = self.preexist) + existing = self.preexist, + chunksize = self.chunksize) return self.dev def getActualSize(self, partitions, diskset): diff --git a/partitions.py b/partitions.py index 335122a95..f02678f20 100644 --- a/partitions.py +++ b/partitions.py @@ -146,6 +146,11 @@ class Partitions: (theDev, devices, level, numActive) = raidDev level = "RAID%s" %(level,) + try: + chunk = isys.getRaidChunkFromDevice(theDev) + except Exception, e: + log("couldn't get chunksize of %s: %s" %(theDev, e)) + chunk = None # is minor always mdN ? minor = int(theDev[2:]) @@ -180,7 +185,8 @@ class Partitions: raidminor = minor, raidspares = spares, mountpoint = mnt, - preexist = 1) + preexist = 1, + chunksize = chunk) spec.size = spec.getActualSize(self, diskset) self.addRequest(spec) |