chiark / gitweb /
unit: reduce heap usage for unit objects
[elogind.git] / src / mount.c
index f72c50afb7530d867b67d4c9d44193b13211c22c..f94c0eb278dbe10f12fc83d5c9563761f1d63438 100644 (file)
@@ -357,10 +357,6 @@ static int mount_add_fstab_links(Mount *m) {
                 after = SPECIAL_LOCAL_FS_PRE_TARGET;
         }
 
-        if (!path_equal(m->where, "/"))
-                if ((r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true)) < 0)
-                        return r;
-
         if ((r = manager_load_unit(m->meta.manager, target, NULL, NULL, &tu)) < 0)
                 return r;
 
@@ -461,24 +457,23 @@ static int mount_add_device_links(Mount *m) {
 
 static int mount_add_default_dependencies(Mount *m) {
         int r;
+        MountParameters *p;
 
         assert(m);
 
-        if (m->meta.manager->running_as == MANAGER_SYSTEM &&
-            !path_equal(m->where, "/")) {
-                MountParameters *p;
-
-                p = get_mount_parameters_configured(m);
+        if (m->meta.manager->running_as != MANAGER_SYSTEM)
+                return 0;
 
-                if (p && needs_quota(p)) {
-                        if ((r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_WANTS, SPECIAL_QUOTACHECK_SERVICE, NULL, true)) < 0 ||
-                            (r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_WANTS, SPECIAL_QUOTAON_SERVICE, NULL, true)) < 0)
-                                return r;
-                }
+        p = get_mount_parameters_configured(m);
+        if (p && needs_quota(p)) {
+                if ((r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_WANTS, SPECIAL_QUOTACHECK_SERVICE, NULL, true)) < 0 ||
+                    (r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_WANTS, SPECIAL_QUOTAON_SERVICE, NULL, true)) < 0)
+                        return r;
+        }
 
+        if (!path_equal(m->where, "/"))
                 if ((r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true)) < 0)
                         return r;
-        }
 
         return 0;
 }
@@ -588,8 +583,6 @@ static int mount_load(Unit *u) {
 
                 if (m->meta.fragment_path)
                         m->from_fragment = true;
-                else if (m->from_etc_fstab)
-                        m->meta.default_dependencies = false;
 
                 if (!m->where)
                         if (!(m->where = unit_name_to_path(u->meta.id)))
@@ -1402,13 +1395,16 @@ static int mount_add_one(
         if (!is_path(where))
                 return 0;
 
-        if (!(e = unit_name_from_path(where, ".mount")))
+        e = unit_name_from_path(where, ".mount");
+        if (!e)
                 return -ENOMEM;
 
-        if (!(u = manager_get_unit(m, e))) {
+        u = manager_get_unit(m, e);
+        if (!u) {
                 delete = true;
 
-                if (!(u = unit_new(m))) {
+                u = unit_new(m, sizeof(Mount));
+                if (!u) {
                         free(e);
                         return -ENOMEM;
                 }
@@ -1419,7 +1415,8 @@ static int mount_add_one(
                 if (r < 0)
                         goto fail;
 
-                if (!(MOUNT(u)->where = strdup(where))) {
+                MOUNT(u)->where = strdup(where);
+                if (!MOUNT(u)->where) {
                         r = -ENOMEM;
                         goto fail;
                 }
@@ -1844,6 +1841,7 @@ DEFINE_STRING_TABLE_LOOKUP(mount_exec_command, MountExecCommand);
 
 const UnitVTable mount_vtable = {
         .suffix = ".mount",
+        .object_size = sizeof(Mount),
         .sections =
                 "Unit\0"
                 "Mount\0"