[SSSD] [PATCH 0/1] Simplify writing update functions

Sumit Bose sbose at redhat.com
Mon Nov 19 11:37:26 UTC 2012


On Wed, Nov 14, 2012 at 09:17:53AM -0500, Simo Sorce wrote:
> While approaching the problem of updating the DB after a patch I am working
> on I noticed that we do have a lot of biolerplate code in there that could
> very simply be tucked into 2 helper functions, simplifying writing upgrade
> functions and making it less likely a typo or copy&paste error will create
> issues with version numbers.
> 
> I love the 425 deletions :-)
> 
> I tried to have a light hand in changing existing code to avoid introducing
> bugs but I have added an example skeleton so that future upgrade functions
> can stop using a tmp_ctx memory context and just use the new upgrade_ctx as
> their local memory context.
> 
> Simo Sorce (1):
>   Simplify writing db update functions
> 
>  src/db/sysdb_upgrade.c |  621 +++++++++++++++---------------------------------
>  1 files changed, 196 insertions(+), 425 deletions(-)

ACK. Nevertheless I think you do not need 'struct upgrade_ctx **ctx' for
finish_upgrade(), 'struct upgrade_ctx *ctx' should be sufficient. The
attached patch adds the needed changes.

bye,
Sumit

> 
> _______________________________________________
> sssd-devel mailing list
> sssd-devel at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/sssd-devel
-------------- next part --------------
From 1b3fe38f413307c5ff5540a3aa2311524ab26a74 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Mon, 19 Nov 2012 12:34:03 +0100
Subject: [PATCH] Simplify finish_upgrade()

---
 src/db/sysdb_upgrade.c |   36 ++++++++++++++++++------------------
 1 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/db/sysdb_upgrade.c b/src/db/sysdb_upgrade.c
index 10c4e57..9942ed7 100644
--- a/src/db/sysdb_upgrade.c
+++ b/src/db/sysdb_upgrade.c
@@ -105,20 +105,20 @@ done:
     return ret;
 }
 
-static int finish_upgrade(int ret, struct upgrade_ctx **ctx, const char **ver)
+static int finish_upgrade(int ret, struct upgrade_ctx *ctx, const char **ver)
 {
     int lret;
 
     if (ret == EOK) {
-        lret = ldb_transaction_commit((*ctx)->ldb);
+        lret = ldb_transaction_commit(ctx->ldb);
         ret = sysdb_error_to_errno(lret);
         if (ret == EOK) {
-            *ver = (*ctx)->new_version;
+            *ver = ctx->new_version;
         }
     }
 
     if (ret != EOK) {
-        lret = ldb_transaction_cancel((*ctx)->ldb);
+        lret = ldb_transaction_cancel(ctx->ldb);
         if (lret != LDB_SUCCESS) {
             DEBUG(SSSDBG_CRIT_FAILURE,
                   ("Could not cancel transaction! [%s]\n",
@@ -130,7 +130,7 @@ static int finish_upgrade(int ret, struct upgrade_ctx **ctx, const char **ver)
         }
     }
 
-    talloc_zfree(*ctx);
+    talloc_zfree(ctx);
     return ret;
 }
 
@@ -254,7 +254,7 @@ int sysdb_upgrade_01(struct ldb_context *ldb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -633,7 +633,7 @@ int sysdb_upgrade_03(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -706,7 +706,7 @@ int sysdb_upgrade_04(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -774,7 +774,7 @@ int sysdb_upgrade_05(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -830,7 +830,7 @@ int sysdb_upgrade_06(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -886,7 +886,7 @@ int sysdb_upgrade_07(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -948,7 +948,7 @@ int sysdb_upgrade_08(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -1005,7 +1005,7 @@ int sysdb_upgrade_09(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -1110,7 +1110,7 @@ int sysdb_upgrade_10(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -1211,7 +1211,7 @@ int sysdb_upgrade_11(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -1268,7 +1268,7 @@ int sysdb_upgrade_12(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     talloc_free(tmp_ctx);
     return ret;
 }
@@ -1356,7 +1356,7 @@ int sysdb_upgrade_13(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     return ret;
 }
 
@@ -1383,7 +1383,7 @@ int sysdb_upgrade_13(struct sysdb_ctx *sysdb, const char **ver)
     ret = update_version(ctx);
 
 done:
-    ret = finish_upgrade(ret, &ctx, ver);
+    ret = finish_upgrade(ret, ctx, ver);
     return ret;
 }
 #endif
-- 
1.7.7.6



More information about the sssd-devel mailing list