[27522] in Source-Commits
python-afs commit: Add _volume_status() and _fid()
daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Tue Nov 12 18:27:54 2013
Date: Tue, 12 Nov 2013 18:27:48 -0500
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201311122327.rACNRmHr018652@drugstore.mit.edu>
To: source-commits@MIT.EDU
https://github.com/mit-athena/python-afs/commits/a6aab2c11131a48f67c3a72ac9750c9434d0e5d3
commit a6aab2c11131a48f67c3a72ac9750c9434d0e5d3
Author: Jonathan Reed <jdreed@mit.edu>
Date: Wed Oct 30 09:52:47 2013 -0400
Add _volume_status() and _fid()
"fs examine" is actually a combination of two PIOCTLs (GETVOLSTAT and
GETFID). Add low-level helper functions for those (_volume_status() and
_fid()), as well as the VolumeStatus and VenusFid structs.
afs/_fs.pyx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
afs/_util.pxd | 32 +++++++++++++++++++++++++++++-
2 files changed, 90 insertions(+), 1 deletions(-)
diff --git a/afs/_fs.pyx b/afs/_fs.pyx
index ff4dd00..b97a9cd 100644
--- a/afs/_fs.pyx
+++ b/afs/_fs.pyx
@@ -23,3 +23,62 @@ def _lsmount(char* parent, char* path):
pioctl_write(parent, VIOC_AFS_STAT_MT_PT, path, mtpt, 1)
return mtpt
+
+def _volume_status(char* path):
+ """
+ _volume_status(path) -> tuple()
+
+ Get information about the volume and path, and return it.
+ Returns a tuple with 3 items:
+ - a string containing the human-readable volume name
+ - a string containing the offline message, if any
+ - a dict() whose keys mirror the names of the
+ OpenAFS VolumeStatus struct
+ """
+ cdef VolumeStatus *volstat
+ cdef char volstat_buf[AFS_PIOCTL_MAXSIZE]
+ cdef char *name, *offmsg
+ cdef object py_volstat
+
+ pioctl_read(path, VIOCGETVOLSTAT, volstat_buf, sizeof(volstat_buf), 1)
+ volstat = <VolumeStatus *>volstat_buf
+ # You can't assign a char * to a temporary Python string
+ # (e.g. an array slice)
+ # because it will be deallocated immediately
+ name_slice = volstat_buf[sizeof(VolumeStatus):]
+ name = name_slice
+ offmsg_slice = name_slice[strlen(name) + 1:]
+ offmsg = offmsg_slice
+ # There _has_ to be a better way to turn structs
+ # into objects.
+ py_volstat = dict()
+ py_volstat['Vid'] = volstat.Vid
+ py_volstat['ParentId'] = volstat.ParentId
+ py_volstat['Online'] = volstat.Online
+ py_volstat['InService'] = volstat.InService
+ py_volstat['Blessed'] = volstat.Blessed
+ py_volstat['NeedsSalvage'] = volstat.NeedsSalvage
+ py_volstat['Type'] = volstat.Type
+ py_volstat['MinQuota'] = volstat.MinQuota
+ py_volstat['MaxQuota'] = volstat.MaxQuota
+ py_volstat['BlocksInUse'] = volstat.BlocksInUse
+ py_volstat['PartBlocksAvail'] = volstat.PartBlocksAvail
+ py_volstat['PartMaxBlocks'] = volstat.PartMaxBlocks
+ return (name, offmsg, py_volstat)
+
+def _fid(char *path):
+ """
+ _fid(path) -> dict()
+
+ Return a dict with the VenusFid data for a given path
+ """
+ cdef VenusFid vfid
+ cdef object py_fid
+
+ pioctl_read(path, VIOCGETFID, <char *>&vfid, sizeof(VenusFid), 1)
+ py_fid = dict()
+ py_fid['Volume'] = vfid.Fid.Volume
+ py_fid['Vnode'] = vfid.Fid.Vnode
+ py_fid['Unique'] = vfid.Fid.Unique
+ py_fid['Cell'] = vfid.Cell
+ return py_fid
diff --git a/afs/_util.pxd b/afs/_util.pxd
index c50b479..94a5943 100644
--- a/afs/_util.pxd
+++ b/afs/_util.pxd
@@ -165,7 +165,37 @@ cdef extern from "afs/venus.h":
enum:
# PIOCTLS to Venus that we use
VIOCGETAL, VIOC_GETVCXSTATUS2, VIOCSETAL, VIOC_FILE_CELL_NAME,
- VIOC_AFS_STAT_MT_PT
+ VIOC_AFS_STAT_MT_PT, VIOCGETVOLSTAT, VIOCGETFID
+
+# This is probably a terrible idea, since afsint.h is generated,
+# Specifically, the "real" definition is in afsint.xg, but this
+# should work across Linuxen
+cdef extern from "afs/afsint.h":
+ ctypedef struct VolumeStatus:
+ afs_int32 Vid
+ afs_int32 ParentId
+ char Online
+ char InService
+ char Blessed
+ char NeedsSalvage
+ afs_int32 Type
+ afs_int32 MinQuota
+ afs_int32 MaxQuota
+ afs_int32 BlocksInUse
+ afs_int32 PartBlocksAvail
+ afs_int32 PartMaxBlocks
+
+ ctypedef struct AFSFid:
+ afs_uint32 Volume
+ afs_uint32 Vnode
+ afs_uint32 Unique
+
+# This is from afs.h, but it's in the kernel-only part
+# and Pyrex/Cython is unhappy. So we re-define it here,
+# just like they do in venus/fs.c.
+cdef struct VenusFid:
+ afs_int32 Cell
+ AFSFid Fid
# pioctl doesn't actually have a header, so we have to define it here
cdef extern int pioctl(char *, afs_int32, ViceIoctl *, afs_int32)