return uidobjs;
}
-/* Get the objset name.
- buf must have at least MAXNAMELEN bytes */
-void udmu_objset_name_get(udmu_objset_t *uos, char *buf)
-{
- dmu_objset_name(uos->os, buf);
-}
-
-static int udmu_userprop_setup(udmu_objset_t *uos, const char *prop_name,
- char **os_name, char **real_prop)
-{
- if (os_name != NULL) {
- *os_name = kmem_alloc(MAXNAMELEN, KM_SLEEP);
- udmu_objset_name_get(uos, *os_name);
- }
-
- *real_prop = kmem_alloc(MAXNAMELEN, KM_SLEEP);
-
- if (snprintf(*real_prop, MAXNAMELEN, "lustre:%s", prop_name) >=
- MAXNAMELEN) {
- if (os_name != NULL)
- kmem_free(*os_name, MAXNAMELEN);
- kmem_free(*real_prop, MAXNAMELEN);
-
- CERROR("property name too long: %s\n", prop_name);
- return ENAMETOOLONG;
- }
-
- return 0;
-}
-
-static void udmu_userprop_cleanup(char **os_name, char **real_prop)
-{
- if (os_name != NULL)
- kmem_free(*os_name, MAXNAMELEN);
- kmem_free(*real_prop, MAXNAMELEN);
-}
-
-/* Set ZFS user property 'prop_name' of objset 'uos' to string 'val' */
-int udmu_userprop_set_str(udmu_objset_t *uos, const char *prop_name,
- const char *val)
-{
- char *os_name;
- char *real_prop;
- int rc;
-
- rc = udmu_userprop_setup(uos, prop_name, &os_name, &real_prop);
- if (rc != 0)
- return rc;
-
- rc = dsl_prop_set(os_name, real_prop, ZPROP_SRC_LOCAL, 1,
- strlen(val) + 1, val);
- udmu_userprop_cleanup(&os_name, &real_prop);
-
- return rc;
-}
-
-/* Get ZFS user property 'prop_name' of objset 'uos' into buffer 'buf' of size
- 'buf_size' */
-int udmu_userprop_get_str(udmu_objset_t *uos, const char *prop_name, char *buf,
- size_t buf_size)
-{
- char *real_prop;
- char *nvp_val;
- size_t nvp_len;
- nvlist_t *nvl = NULL;
- nvlist_t *nvl_val;
- nvpair_t *elem = NULL;
- int rc;
-
- rc = udmu_userprop_setup(uos, prop_name, NULL, &real_prop);
- if (rc != 0)
- return rc;
-
- /* We can't just pass buf_size to dsl_prop_get() because it expects the
- exact value size (zap_lookup() requirement), so we must get all props
- and extract the one we want. */
- rc = dsl_prop_get_all(uos->os, &nvl);
- if (rc != 0) {
- nvl = NULL;
- goto out;
- }
-
- while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
- const char *name = nvpair_name(elem);
- if (strcmp(name, real_prop) != 0)
- continue;
-
- /* Got the property we were looking for, but the val is not the
- string yet, it's an nvlist */
-
- rc = nvpair_value_nvlist(elem, &nvl_val);
- if (rc != 0)
- goto out;
-
- rc = nvlist_lookup_string(nvl_val, ZPROP_VALUE, &nvp_val);
- if (rc != 0)
- goto out;
-
- nvp_len = strlen(nvp_val);
- if (buf_size < nvp_len + 1) {
- rc = EOVERFLOW;
- goto out;
- }
- strcpy(buf, nvp_val);
- goto out;
- }
- /* Not found */
- rc = ENOENT;
-out:
- if (nvl != NULL)
- nvlist_free(nvl);
- udmu_userprop_cleanup(NULL, &real_prop);
-
- return rc;
-}
-
/* We don't actually have direct access to the zap_hashbits() function
* so just pretend like we do for now. If this ever breaks we can look at
* it at that time. */