History

liveupdate: defer FLB module refcounting to active sessions

Stop pinning modules indefinitely upon FLB registration. Instead, dynamically take a module reference when the FLB is actively used in a session (e.g., during preserve and retrieve) and release it when the session concludes. This allows modules providing FLB operations to be cleanly unloaded when not in active use by the live update orchestrator.

Pasha Tatashin committed 7 months ago

Commit 76be9981 parent 6b2b22f1 file · +17 −10Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/liveupdate/luo_flb.c+17−10
@@ -115,10 +115,15 @@ static int luo_flb_file_preserve_one(struct liveupdate_flb *flb) · 114 unmodified lines
115115 struct liveupdate_flb_op_args args = {0};
116116 int err;
117117
118+ if (!try_module_get(flb->ops->owner))
119+ return -ENODEV;
120+
118121 args.flb = flb;
119122 err = flb->ops->preserve(&args);
120− if (err)
123+ if (err) {
124+ module_put(flb->ops->owner);
121125 return err;
126+ }
122127 private->outgoing.data = args.data;
123128 private->outgoing.obj = args.obj;
124129 }
@@ -146,6 +151,7 @@ static void luo_flb_file_unpreserve_one(struct liveupdate_flb *flb) · 21 unmodified lines
146151
147152 private->outgoing.data = 0;
148153 private->outgoing.obj = NULL;
154+ module_put(flb->ops->owner);
149155 }
150156 }
151157 }
@@ -181,12 +187,17 @@ static int luo_flb_retrieve_one(struct liveupdate_flb *flb) · 29 unmodified lines
181187 if (!found)
182188 return -ENOENT;
183189
190+ if (!try_module_get(flb->ops->owner))
191+ return -ENODEV;
192+
184193 args.flb = flb;
185194 args.data = private->incoming.data;
186195
187196 err = flb->ops->retrieve(&args);
188− if (err)
197+ if (err) {
198+ module_put(flb->ops->owner);
189199 return err;
200+ }
190201
191202 private->incoming.obj = args.obj;
192203 private->incoming.retrieved = true;
@@ -220,6 +231,7 @@ static void luo_flb_file_finish_one(struct liveupdate_flb *flb) · 27 unmodified lines
220231 private->incoming.data = 0;
221232 private->incoming.obj = NULL;
222233 private->incoming.finished = true;
234+ module_put(flb->ops->owner);
223235 }
224236 }
225237 }
@@ -395,11 +407,6 @@ int liveupdate_register_flb(struct liveupdate_file_handler *fh, · 169 unmodified lines
395407 goto err_resume;
396408 }
397409
398− if (!try_module_get(flb->ops->owner)) {
399− err = -EAGAIN;
400− goto err_resume;
401− }
402−
403410 list_add_tail(&private->list, &luo_flb_global.list);
404411 luo_flb_global.count++;
405412 }
@@ -476,12 +483,11 @@ int liveupdate_unregister_flb(struct liveupdate_file_handler *fh, · 70 unmodified lines
476483 private->users--;
477484 /*
478485 * If this is the last file-handler with which we are registred, remove
479− * from the global list, and relese module reference.
486+ * from the global list.
480487 */
481488 if (!private->users) {
482489 list_del_init(&private->list);
483490 luo_flb_global.count--;
484− module_put(flb->ops->owner);
485491 }
486492
487493 up_write(&luo_register_rwlock);
@@ -510,7 +516,8 @@ err_resume: · 22 unmodified lines
510516 *
511517 * Return: 0 on success, or a negative errno on failure. -ENODATA means no
512518 * incoming FLB data, -ENOENT means specific flb not found in the incoming
513− * data, and -EOPNOTSUPP when live update is disabled or not configured.
519+ * data, -ENODEV if the FLB's module is unloading, and -EOPNOTSUPP when
520+ * live update is disabled or not configured.
514521 */
515522 int liveupdate_flb_get_incoming(struct liveupdate_flb *flb, void **objp)
516523 {