]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - lib/kobject.c
lib/genalloc.c: use vzalloc_node() to allocate the bitmap
[mirror_ubuntu-bionic-kernel.git] / lib / kobject.c
index 763d70a189410cb7307b87474801a662f631f806..7c41d62e11383e538649b5d3ad7a2720cfd4561a 100644 (file)
@@ -37,6 +37,25 @@ const void *kobject_namespace(struct kobject *kobj)
        return kobj->ktype->namespace(kobj);
 }
 
+/**
+ * kobject_get_ownership - get sysfs ownership data for @kobj
+ * @kobj: kobject in question
+ * @uid: kernel user ID for sysfs objects
+ * @gid: kernel group ID for sysfs objects
+ *
+ * Returns initial uid/gid pair that should be used when creating sysfs
+ * representation of given kobject. Normally used to adjust ownership of
+ * objects in a container.
+ */
+void kobject_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
+{
+       *uid = GLOBAL_ROOT_UID;
+       *gid = GLOBAL_ROOT_GID;
+
+       if (kobj->ktype->get_ownership)
+               kobj->ktype->get_ownership(kobj, uid, gid);
+}
+
 /*
  * populate_dir - populate directory with attributes.
  * @kobj: object we're working on.
@@ -127,7 +146,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length)
                int cur = strlen(kobject_name(parent));
                /* back up enough to print this name with '/' */
                length -= cur;
-               strncpy(path + length, kobject_name(parent), cur);
+               memcpy(path + length, kobject_name(parent), cur);
                *(path + --length) = '/';
        }
 
@@ -234,14 +253,12 @@ static int kobject_add_internal(struct kobject *kobj)
 
                /* be noisy on error issues */
                if (error == -EEXIST)
-                       WARN(1, "%s failed for %s with "
-                            "-EEXIST, don't try to register things with "
-                            "the same name in the same directory.\n",
-                            __func__, kobject_name(kobj));
+                       pr_err("%s failed for %s with -EEXIST, don't try to register things with the same name in the same directory.\n",
+                              __func__, kobject_name(kobj));
                else
-                       WARN(1, "%s failed for %s (error: %d parent: %s)\n",
-                            __func__, kobject_name(kobj), error,
-                            parent ? kobject_name(parent) : "'none'");
+                       pr_err("%s failed for %s (error: %d parent: %s)\n",
+                              __func__, kobject_name(kobj), error,
+                              parent ? kobject_name(parent) : "'none'");
        } else
                kobj->state_in_sysfs = 1;
 
@@ -874,9 +891,16 @@ static void kset_release(struct kobject *kobj)
        kfree(kset);
 }
 
+void kset_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
+{
+       if (kobj->parent)
+               kobject_get_ownership(kobj->parent, uid, gid);
+}
+
 static struct kobj_type kset_ktype = {
        .sysfs_ops      = &kobj_sysfs_ops,
-       .release = kset_release,
+       .release        = kset_release,
+       .get_ownership  = kset_get_ownership,
 };
 
 /**