aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/lib/pyzfs/common
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2011-02-27 19:41:40 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2011-02-27 19:41:40 +0000
commit10b9d77bf1ccf2f3affafa6261692cb92cf7e992 (patch)
treeef515cadc08bf427e4d3f1360199ec9827b1596b /cddl/contrib/opensolaris/lib/pyzfs/common
parente02dd14a548a89bee6657d9eacb0f992bf61b280 (diff)
downloadsrc-10b9d77bf1ccf2f3affafa6261692cb92cf7e992.tar.gz
src-10b9d77bf1ccf2f3affafa6261692cb92cf7e992.zip
Finally... Import the latest open-source ZFS version - (SPA) 28.
Few new things available from now on: - Data deduplication. - Triple parity RAIDZ (RAIDZ3). - zfs diff. - zpool split. - Snapshot holds. - zpool import -F. Allows to rewind corrupted pool to earlier transaction group. - Possibility to import pool in read-only mode. MFC after: 1 month
Notes
Notes: svn path=/head/; revision=219089
Diffstat (limited to 'cddl/contrib/opensolaris/lib/pyzfs/common')
-rw-r--r--cddl/contrib/opensolaris/lib/pyzfs/common/__init__.py5
-rw-r--r--cddl/contrib/opensolaris/lib/pyzfs/common/allow.py16
-rw-r--r--cddl/contrib/opensolaris/lib/pyzfs/common/dataset.py37
-rw-r--r--cddl/contrib/opensolaris/lib/pyzfs/common/groupspace.py5
-rw-r--r--cddl/contrib/opensolaris/lib/pyzfs/common/holds.py75
-rw-r--r--cddl/contrib/opensolaris/lib/pyzfs/common/ioctl.c117
-rw-r--r--cddl/contrib/opensolaris/lib/pyzfs/common/table.py70
-rw-r--r--cddl/contrib/opensolaris/lib/pyzfs/common/unallow.py5
-rw-r--r--cddl/contrib/opensolaris/lib/pyzfs/common/userspace.py77
-rw-r--r--cddl/contrib/opensolaris/lib/pyzfs/common/util.py13
10 files changed, 249 insertions, 171 deletions
diff --git a/cddl/contrib/opensolaris/lib/pyzfs/common/__init__.py b/cddl/contrib/opensolaris/lib/pyzfs/common/__init__.py
index f4b0f539542f..76b0998a3e7e 100644
--- a/cddl/contrib/opensolaris/lib/pyzfs/common/__init__.py
+++ b/cddl/contrib/opensolaris/lib/pyzfs/common/__init__.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python2.4
+#! /usr/bin/python2.6
#
# CDDL HEADER START
#
@@ -19,8 +19,7 @@
#
# CDDL HEADER END
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
"""
diff --git a/cddl/contrib/opensolaris/lib/pyzfs/common/allow.py b/cddl/contrib/opensolaris/lib/pyzfs/common/allow.py
index d3a03c731868..fa8209f697fd 100644
--- a/cddl/contrib/opensolaris/lib/pyzfs/common/allow.py
+++ b/cddl/contrib/opensolaris/lib/pyzfs/common/allow.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python2.4
+#! /usr/bin/python2.6
#
# CDDL HEADER START
#
@@ -19,8 +19,7 @@
#
# CDDL HEADER END
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
"""This module implements the "zfs allow" and "zfs unallow" subcommands.
@@ -204,8 +203,8 @@ def args_to_perms(parser, options, who, perms):
perms_subcmd = dict(
create=_("Must also have the 'mount' ability"),
destroy=_("Must also have the 'mount' ability"),
- snapshot=_("Must also have the 'mount' ability"),
- rollback=_("Must also have the 'mount' ability"),
+ snapshot="",
+ rollback="",
clone=_("""Must also have the 'create' ability and 'mount'
\t\t\t\tability in the origin file system"""),
promote=_("""Must also have the 'mount'
@@ -217,6 +216,9 @@ perms_subcmd = dict(
mount=_("Allows mount/umount of ZFS datasets"),
share=_("Allows sharing file systems over NFS or SMB\n\t\t\t\tprotocols"),
send="",
+ hold=_("Allows adding a user hold to a snapshot"),
+ release=_("Allows releasing a user hold which\n\t\t\t\tmight destroy the snapshot"),
+ diff=_("Allows lookup of paths within a dataset,\n\t\t\t\tgiven an object number. Ordinary users need this\n\t\t\t\tin order to use zfs diff"),
)
perms_other = dict(
@@ -265,7 +267,7 @@ def print_perms():
print(fmt % (name, _("property"), ""))
def do_allow():
- """Implementes the "zfs allow" and "zfs unallow" subcommands."""
+ """Implements the "zfs allow" and "zfs unallow" subcommands."""
un = (sys.argv[1] == "unallow")
def usage(msg=None):
@@ -320,7 +322,7 @@ def do_allow():
if sys.argv[2] == "-h":
# hack to make "zfs allow -h" work
usage()
- ds = zfs.dataset.Dataset(sys.argv[2])
+ ds = zfs.dataset.Dataset(sys.argv[2], snaps=False)
p = dict()
for (fs, raw) in ds.get_fsacl().items():
diff --git a/cddl/contrib/opensolaris/lib/pyzfs/common/dataset.py b/cddl/contrib/opensolaris/lib/pyzfs/common/dataset.py
index b45173e01f2e..26192e4075d2 100644
--- a/cddl/contrib/opensolaris/lib/pyzfs/common/dataset.py
+++ b/cddl/contrib/opensolaris/lib/pyzfs/common/dataset.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python2.4
+#! /usr/bin/python2.6
#
# CDDL HEADER START
#
@@ -19,8 +19,7 @@
#
# CDDL HEADER END
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
"""Implements the Dataset class, providing methods for manipulating ZFS
@@ -109,7 +108,7 @@ class Dataset(object):
types is an iterable of strings specifying which types
of datasets are permitted. Accepted strings are
- "filesystem" and "volume". Defaults to acceptying all
+ "filesystem" and "volume". Defaults to accepting all
types.
snaps is a boolean specifying if snapshots are acceptable.
@@ -203,3 +202,33 @@ class Dataset(object):
Return a dict("whostr": { "perm" -> None })."""
return zfs.ioctl.get_fsacl(self.name)
+
+ def get_holds(self):
+ """Get the user holds on this Dataset.
+
+ Return a dict("tag": timestamp)."""
+
+ return zfs.ioctl.get_holds(self.name)
+
+def snapshots_fromcmdline(dsnames, recursive):
+ for dsname in dsnames:
+ if not "@" in dsname:
+ raise zfs.util.ZFSError(errno.EINVAL,
+ _("cannot open %s") % dsname,
+ _("operation only applies to snapshots"))
+ try:
+ ds = Dataset(dsname)
+ yield ds
+ except zfs.util.ZFSError, e:
+ if not recursive or e.errno != errno.ENOENT:
+ raise
+ if recursive:
+ (base, snapname) = dsname.split('@')
+ parent = Dataset(base)
+ for child in parent.descendents():
+ try:
+ yield Dataset(child.name + "@" +
+ snapname)
+ except zfs.util.ZFSError, e:
+ if e.errno != errno.ENOENT:
+ raise
diff --git a/cddl/contrib/opensolaris/lib/pyzfs/common/groupspace.py b/cddl/contrib/opensolaris/lib/pyzfs/common/groupspace.py
index 7db4bf3e0c20..9f380fdb89f1 100644
--- a/cddl/contrib/opensolaris/lib/pyzfs/common/groupspace.py
+++ b/cddl/contrib/opensolaris/lib/pyzfs/common/groupspace.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python2.4
+#! /usr/bin/python2.6
#
# CDDL HEADER START
#
@@ -19,8 +19,7 @@
#
# CDDL HEADER END
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
import zfs.userspace
diff --git a/cddl/contrib/opensolaris/lib/pyzfs/common/holds.py b/cddl/contrib/opensolaris/lib/pyzfs/common/holds.py
new file mode 100644
index 000000000000..800e28f974dd
--- /dev/null
+++ b/cddl/contrib/opensolaris/lib/pyzfs/common/holds.py
@@ -0,0 +1,75 @@
+#! /usr/bin/python2.6
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+#
+
+"""This module implements the "zfs holds" subcommand.
+The only public interface is the zfs.holds.do_holds() function."""
+
+import optparse
+import sys
+import errno
+import time
+import zfs.util
+import zfs.dataset
+import zfs.table
+
+_ = zfs.util._
+
+def do_holds():
+ """Implements the "zfs holds" subcommand."""
+ def usage(msg=None):
+ parser.print_help()
+ if msg:
+ print
+ parser.exit("zfs: error: " + msg)
+ else:
+ parser.exit()
+
+ u = _("""holds [-r] <snapshot> ...""")
+
+ parser = optparse.OptionParser(usage=u, prog="zfs")
+
+ parser.add_option("-r", action="store_true", dest="recursive",
+ help=_("list holds recursively"))
+
+ (options, args) = parser.parse_args(sys.argv[2:])
+
+ if len(args) < 1:
+ usage(_("missing snapshot argument"))
+
+ fields = ("name", "tag", "timestamp")
+ rjustfields = ()
+ printing = False
+ gotone = False
+ t = zfs.table.Table(fields, rjustfields)
+ for ds in zfs.dataset.snapshots_fromcmdline(args, options.recursive):
+ gotone = True
+ for tag, tm in ds.get_holds().iteritems():
+ val = {"name": ds.name, "tag": tag,
+ "timestamp": time.ctime(tm)}
+ t.addline(ds.name, val)
+ printing = True
+ if printing:
+ t.printme()
+ elif not gotone:
+ raise zfs.util.ZFSError(errno.ENOENT, _("no matching datasets"))
diff --git a/cddl/contrib/opensolaris/lib/pyzfs/common/ioctl.c b/cddl/contrib/opensolaris/lib/pyzfs/common/ioctl.c
index 4571147a4876..d1f82a7dc888 100644
--- a/cddl/contrib/opensolaris/lib/pyzfs/common/ioctl.c
+++ b/cddl/contrib/opensolaris/lib/pyzfs/common/ioctl.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -29,8 +29,6 @@
#include <strings.h>
#include <unistd.h>
#include <libnvpair.h>
-#include <idmap.h>
-#include <zone.h>
#include <libintl.h>
#include <libzfs.h>
#include <libzfs_impl.h>
@@ -45,10 +43,6 @@ static int zfsdevfd;
#define _(s) dgettext(TEXT_DOMAIN, s)
-#ifdef sun
-extern int sid_to_id(char *sid, boolean_t user, uid_t *id);
-#endif /* sun */
-
/*PRINTFLIKE1*/
static void
seterr(char *fmt, ...)
@@ -66,7 +60,7 @@ seterr(char *fmt, ...)
static char cmdstr[HIS_MAX_RECORD_LEN];
static int
-ioctl_with_cmdstr(unsigned long ioc, zfs_cmd_t *zc)
+ioctl_with_cmdstr(int ioc, zfs_cmd_t *zc)
{
int err;
@@ -138,8 +132,7 @@ dict2nvl(PyObject *d)
nvlist_t *nvl;
int err;
PyObject *key, *value;
-// int pos = 0;
- Py_ssize_t pos = 0;
+ int pos = 0;
if (!PyDict_Check(d)) {
PyErr_SetObject(PyExc_ValueError, d);
@@ -205,7 +198,7 @@ add_ds_props(zfs_cmd_t *zc, PyObject *nvl)
/* On error, returns NULL but does not set python exception. */
static PyObject *
-ioctl_with_dstnv(unsigned long ioc, zfs_cmd_t *zc)
+ioctl_with_dstnv(int ioc, zfs_cmd_t *zc)
{
int nvsz = 2048;
void *nvbuf;
@@ -236,7 +229,7 @@ again:
static PyObject *
py_next_dataset(PyObject *self, PyObject *args)
{
- unsigned long ioc;
+ int ioc;
uint64_t cookie;
zfs_cmd_t zc = { 0 };
int snaps;
@@ -353,6 +346,25 @@ py_set_fsacl(PyObject *self, PyObject *args)
}
static PyObject *
+py_get_holds(PyObject *self, PyObject *args)
+{
+ zfs_cmd_t zc = { 0 };
+ char *name;
+ PyObject *nvl;
+
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return (NULL);
+
+ (void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name));
+
+ nvl = ioctl_with_dstnv(ZFS_IOC_GET_HOLDS, &zc);
+ if (nvl == NULL)
+ seterr(_("cannot get holds for %s"), name);
+
+ return (nvl);
+}
+
+static PyObject *
py_userspace_many(PyObject *self, PyObject *args)
{
zfs_cmd_t zc = { 0 };
@@ -440,80 +452,6 @@ py_userspace_upgrade(PyObject *self, PyObject *args)
}
static PyObject *
-py_sid_to_id(PyObject *self, PyObject *args)
-{
-#ifdef sun
- char *sid;
- int err, isuser;
- uid_t id;
-
- if (!PyArg_ParseTuple(args, "si", &sid, &isuser))
- return (NULL);
-
- err = sid_to_id(sid, isuser, &id);
- if (err) {
- PyErr_SetString(PyExc_KeyError, sid);
- return (NULL);
- }
-
- return (Py_BuildValue("I", id));
-#else /* sun */
- return (NULL);
-#endif /* sun */
-}
-
-/*
- * Translate the sid string ("S-1-...") to the user@domain name, if
- * possible. There should be a better way to do this, but for now we
- * just translate to the (possibly ephemeral) uid and then back again.
- */
-static PyObject *
-py_sid_to_name(PyObject *self, PyObject *args)
-{
-#ifdef sun
- char *sid;
- int err, isuser;
- uid_t id;
- char *name, *domain;
- char buf[256];
-
- if (!PyArg_ParseTuple(args, "si", &sid, &isuser))
- return (NULL);
-
- err = sid_to_id(sid, isuser, &id);
- if (err) {
- PyErr_SetString(PyExc_KeyError, sid);
- return (NULL);
- }
-
- if (isuser) {
- err = idmap_getwinnamebyuid(id,
- IDMAP_REQ_FLG_USE_CACHE, &name, &domain);
- } else {
- err = idmap_getwinnamebygid(id,
- IDMAP_REQ_FLG_USE_CACHE, &name, &domain);
- }
- if (err != IDMAP_SUCCESS) {
- PyErr_SetString(PyExc_KeyError, sid);
- return (NULL);
- }
- (void) snprintf(buf, sizeof (buf), "%s@%s", name, domain);
- free(name);
- free(domain);
-
- return (Py_BuildValue("s", buf));
-#else /* sun */
- return(NULL);
-#endif /* sun */
-}
-
-static PyObject *
-py_isglobalzone(PyObject *self, PyObject *args)
-{
- return (Py_BuildValue("i", getzoneid() == GLOBAL_ZONEID));
-}
-
-static PyObject *
py_set_cmdstr(PyObject *self, PyObject *args)
{
char *str;
@@ -584,12 +522,7 @@ static PyMethodDef zfsmethods[] = {
"Get dataset properties."},
{"get_proptable", py_get_proptable, METH_NOARGS,
"Get property table."},
- /* Below are not really zfs-specific: */
- {"sid_to_id", py_sid_to_id, METH_VARARGS, "Map SID to UID/GID."},
- {"sid_to_name", py_sid_to_name, METH_VARARGS,
- "Map SID to name@domain."},
- {"isglobalzone", py_isglobalzone, METH_NOARGS,
- "Determine if this is the global zone."},
+ {"get_holds", py_get_holds, METH_VARARGS, "Get user holds."},
{NULL, NULL, 0, NULL}
};
diff --git a/cddl/contrib/opensolaris/lib/pyzfs/common/table.py b/cddl/contrib/opensolaris/lib/pyzfs/common/table.py
new file mode 100644
index 000000000000..d2a45a142c29
--- /dev/null
+++ b/cddl/contrib/opensolaris/lib/pyzfs/common/table.py
@@ -0,0 +1,70 @@
+#! /usr/bin/python2.6
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+#
+
+import zfs.util
+
+class Table:
+ __slots__ = "fields", "rjustfields", "maxfieldlen", "lines"
+ __repr__ = zfs.util.default_repr
+
+ def __init__(self, fields, rjustfields=()):
+ # XXX maybe have a defaults, too?
+ self.fields = fields
+ self.rjustfields = rjustfields
+ self.maxfieldlen = dict.fromkeys(fields, 0)
+ self.lines = list()
+
+ def __updatemax(self, k, v):
+ self.maxfieldlen[k] = max(self.maxfieldlen.get(k, None), v)
+
+ def addline(self, sortkey, values):
+ """values is a dict from field name to value"""
+
+ va = list()
+ for f in self.fields:
+ v = str(values[f])
+ va.append(v)
+ self.__updatemax(f, len(v))
+ self.lines.append((sortkey, va))
+
+ def printme(self, headers=True):
+ if headers:
+ d = dict([(f, f.upper()) for f in self.fields])
+ self.addline(None, d)
+
+ self.lines.sort()
+ for (k, va) in self.lines:
+ line = str()
+ for i in range(len(self.fields)):
+ if not headers:
+ line += va[i]
+ line += "\t"
+ else:
+ if self.fields[i] in self.rjustfields:
+ fmt = "%*s "
+ else:
+ fmt = "%-*s "
+ mfl = self.maxfieldlen[self.fields[i]]
+ line += fmt % (mfl, va[i])
+ print(line)
diff --git a/cddl/contrib/opensolaris/lib/pyzfs/common/unallow.py b/cddl/contrib/opensolaris/lib/pyzfs/common/unallow.py
index 1458dc1328fd..cbdd4dd73f6f 100644
--- a/cddl/contrib/opensolaris/lib/pyzfs/common/unallow.py
+++ b/cddl/contrib/opensolaris/lib/pyzfs/common/unallow.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python2.4
+#! /usr/bin/python2.6
#
# CDDL HEADER START
#
@@ -19,8 +19,7 @@
#
# CDDL HEADER END
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
import zfs.allow
diff --git a/cddl/contrib/opensolaris/lib/pyzfs/common/userspace.py b/cddl/contrib/opensolaris/lib/pyzfs/common/userspace.py
index c269d51e1db7..33646bca5b7f 100644
--- a/cddl/contrib/opensolaris/lib/pyzfs/common/userspace.py
+++ b/cddl/contrib/opensolaris/lib/pyzfs/common/userspace.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python2.4
+#! /usr/bin/python2.6
#
# CDDL HEADER START
#
@@ -19,21 +19,22 @@
#
# CDDL HEADER END
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
"""This module implements the "zfs userspace" and "zfs groupspace" subcommands.
The only public interface is the zfs.userspace.do_userspace() function."""
-import zfs.util
-import zfs.ioctl
-import zfs.dataset
import optparse
import sys
import pwd
import grp
import errno
+import solaris.misc
+import zfs.util
+import zfs.ioctl
+import zfs.dataset
+import zfs.table
_ = zfs.util._
@@ -58,9 +59,6 @@ def skiptype(options, prop):
return True
return False
-def updatemax(d, k, v):
- d[k] = max(d.get(k, None), v)
-
def new_entry(options, isgroup, domain, rid):
"""Return a dict("field": value) for this domain (string) + rid (int)"""
@@ -70,9 +68,9 @@ def new_entry(options, isgroup, domain, rid):
idstr = "%u" % rid
(typename, mapfunc) = {
- (1, 1): ("SMB Group", lambda id: zfs.ioctl.sid_to_name(id, 0)),
+ (1, 1): ("SMB Group", lambda id: solaris.misc.sid_to_name(id, 0)),
(1, 0): ("POSIX Group", lambda id: grp.getgrgid(int(id)).gr_name),
- (0, 1): ("SMB User", lambda id: zfs.ioctl.sid_to_name(id, 1)),
+ (0, 1): ("SMB User", lambda id: solaris.misc.sid_to_name(id, 1)),
(0, 0): ("POSIX User", lambda id: pwd.getpwuid(int(id)).pw_name)
}[isgroup, bool(domain)]
@@ -102,8 +100,8 @@ def new_entry(options, isgroup, domain, rid):
v["quota.sort"] = 0
return v
-def process_one_raw(acct, maxfieldlen, options, prop, elem):
- """Update the acct and maxfieldlen dicts to incorporate the
+def process_one_raw(acct, options, prop, elem):
+ """Update the acct dict to incorporate the
information from this elem from Dataset.userspace(prop)."""
(domain, rid, value) = elem
@@ -111,7 +109,7 @@ def process_one_raw(acct, maxfieldlen, options, prop, elem):
if options.translate and domain:
try:
- rid = zfs.ioctl.sid_to_id("%s-%u" % (domain, rid),
+ rid = solaris.misc.sid_to_id("%s-%u" % (domain, rid),
not isgroup)
domain = None
except KeyError:
@@ -134,10 +132,6 @@ def process_one_raw(acct, maxfieldlen, options, prop, elem):
v[field] = str(value)
else:
v[field] = zfs.util.nicenum(value)
- for k in v.keys():
- # some of the .sort fields are integers, so have no len()
- if isinstance(v[k], str):
- updatemax(maxfieldlen, k, len(v[k]))
def do_userspace():
"""Implements the "zfs userspace" and "zfs groupspace" subcommands."""
@@ -156,7 +150,7 @@ def do_userspace():
defaulttypes = "posixgroup,smbgroup"
fields = ("type", "name", "used", "quota")
- ljustfields = ("type", "name")
+ rjustfields = ("used", "quota")
types = ("all", "posixuser", "smbuser", "posixgroup", "smbgroup")
u = _("%s [-niHp] [-o field[,...]] [-sS field] ... \n") % sys.argv[1]
@@ -209,38 +203,23 @@ def do_userspace():
ds = zfs.dataset.Dataset(dsname, types=("filesystem"))
- if ds.getprop("jailed") and zfs.ioctl.isglobalzone():
+ if ds.getprop("jailed") and solaris.misc.isglobalzone():
options.noname = True
if not ds.getprop("useraccounting"):
print(_("Initializing accounting information on old filesystem, please wait..."))
ds.userspace_upgrade()
- acct = dict()
- maxfieldlen = dict()
-
# gather and process accounting information
+ # Due to -i, we need to keep a dict, so we can potentially add
+ # together the posix ID and SID's usage. Grr.
+ acct = dict()
for prop in props.keys():
if skiptype(options, prop):
continue;
for elem in ds.userspace(prop):
- process_one_raw(acct, maxfieldlen, options, prop, elem)
-
- # print out headers
- if not options.noheaders:
- line = str()
- for field in options.fields:
- # make sure the field header will fit
- updatemax(maxfieldlen, field, len(field))
-
- if field in ljustfields:
- fmt = "%-*s "
- else:
- fmt = "%*s "
- line += fmt % (maxfieldlen[field], field.upper())
- print(line)
-
- # custom sorting func
+ process_one_raw(acct, options, prop, elem)
+
def cmpkey(val):
l = list()
for (opt, field) in options.sortfields:
@@ -261,17 +240,7 @@ def do_userspace():
l.append(n)
return l
- # print out data lines
- for val in sorted(acct.itervalues(), key=cmpkey):
- line = str()
- for field in options.fields:
- if options.noheaders:
- line += val[field]
- line += "\t"
- else:
- if field in ljustfields:
- fmt = "%-*s "
- else:
- fmt = "%*s "
- line += fmt % (maxfieldlen[field], val[field])
- print(line)
+ t = zfs.table.Table(options.fields, rjustfields)
+ for val in acct.itervalues():
+ t.addline(cmpkey(val), val)
+ t.printme(not options.noheaders)
diff --git a/cddl/contrib/opensolaris/lib/pyzfs/common/util.py b/cddl/contrib/opensolaris/lib/pyzfs/common/util.py
index 14d05a8bc12f..a33c6693ee00 100644
--- a/cddl/contrib/opensolaris/lib/pyzfs/common/util.py
+++ b/cddl/contrib/opensolaris/lib/pyzfs/common/util.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python2.4
+#! /usr/bin/python2.6
#
# CDDL HEADER START
#
@@ -19,8 +19,7 @@
#
# CDDL HEADER END
#
-# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
"""This module provides utility functions for ZFS.
@@ -29,6 +28,7 @@ zfs.util.dev -- a file object of /dev/zfs """
import gettext
import errno
import os
+import solaris.misc
# Note: this module (zfs.util) should not import zfs.ioctl, because that
# would introduce a circular dependency
@@ -37,8 +37,11 @@ errno.ENOTSUP = 48
dev = open("/dev/zfs", "w")
-_ = gettext.translation("SUNW_OST_OSLIB", "/usr/lib/locale",
- fallback=True).gettext
+try:
+ _ = gettext.translation("SUNW_OST_OSLIB", "/usr/lib/locale",
+ fallback=True).gettext
+except:
+ _ = solaris.misc.gettext
def default_repr(self):
"""A simple __repr__ function."""