chiark / gitweb /
unit: reduce heap usage for unit objects
[elogind.git] / src / mount.c
index 47422ccf8bafc4a59e9b2af5f3f6ea4041f11f43..f94c0eb278dbe10f12fc83d5c9563761f1d63438 100644 (file)
@@ -108,21 +108,12 @@ static void mount_parameters_done(MountParameters *p) {
 
 static void mount_done(Unit *u) {
         Mount *m = MOUNT(u);
-        Meta *other;
 
         assert(m);
 
         free(m->where);
         m->where = NULL;
 
-        /* Try to detach us from the automount unit if there is any */
-        LIST_FOREACH(units_by_type, other, m->meta.manager->units_by_type[UNIT_AUTOMOUNT]) {
-                Automount *a = (Automount*) other;
-
-                if (a->mount == m)
-                        a->mount = NULL;
-        }
-
         mount_parameters_done(&m->parameters_etc_fstab);
         mount_parameters_done(&m->parameters_proc_self_mountinfo);
         mount_parameters_done(&m->parameters_fragment);
@@ -366,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;
 
@@ -470,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;
 }
@@ -597,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)))
@@ -647,13 +631,18 @@ static int mount_load(Unit *u) {
 static int mount_notify_automount(Mount *m, int status) {
         Unit *p;
         int r;
+        Iterator i;
 
         assert(m);
 
-        if ((r = unit_get_related_unit(UNIT(m), ".automount", &p)) < 0)
-                return r == -ENOENT ? 0 : r;
+        SET_FOREACH(p, m->meta.dependencies[UNIT_TRIGGERED_BY], i)
+                if (p->meta.type == UNIT_AUTOMOUNT) {
+                         r = automount_send_ready(AUTOMOUNT(p), status);
+                         if (r < 0)
+                                 return r;
+                }
 
-        return automount_send_ready(AUTOMOUNT(p), status);
+        return 0;
 }
 
 static void mount_set_state(Mount *m, MountState state) {
@@ -1406,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;
                 }
@@ -1423,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;
                 }
@@ -1848,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"