]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - lib/kobject.c
kobject: kset_create_and_add() - fetch ownership info from parent
[mirror_ubuntu-bionic-kernel.git] / lib / kobject.c
index 763d70a189410cb7307b87474801a662f631f806..65edcc8334319c9dbe5aadd7f1c080011008b393 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.
@@ -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,
 };
 
 /**