diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index 7c905cdcd..1d34e42c2 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -806,6 +806,20 @@ plugin_transaction_revert_all(clixon_handle h, return retval; /* ignore errors */ } +/*! Revert a commit for failed plugin + * The commit failed is called for only failed plugin before revert all cb. + */ +static int +plugin_transaction_commit_failed(clixon_plugin_t *cp, + clixon_handle h, + transaction_data_t *td) +{ + trans_cb_t *fn; + + if ((fn = clixon_plugin_api_get(cp)->ca_trans_commit_failed) != NULL) + return plugin_transaction_call_one(h, cp, fn, __FUNCTION__, td); + return 0; +} /*! Call single plugin transaction_commit() in a commit transaction * @@ -848,6 +862,8 @@ plugin_transaction_commit_all(clixon_handle h, while ((cp = clixon_plugin_each(h, cp)) != NULL) { i++; if (plugin_transaction_commit_one(cp, h, td) < 0){ + /* First make an effort ro revert transaction for the failed plugin */ + plugin_transaction_commit_failed(cp, h, td); /* Make an effort to revert transaction */ plugin_transaction_revert_all(h, td, i-1); goto done; diff --git a/lib/clixon/clixon_plugin.h b/lib/clixon/clixon_plugin.h index bf2d6655e..b61ff2434 100644 --- a/lib/clixon/clixon_plugin.h +++ b/lib/clixon/clixon_plugin.h @@ -402,6 +402,7 @@ struct clixon_plugin_api{ trans_cb_t *cb_trans_complete; /* Transaction validation complete */ trans_cb_t *cb_trans_commit; /* Transaction commit */ trans_cb_t *cb_trans_commit_done; /* Transaction when commit done */ + trans_cb_t *cb_trans_commit_failed; /* Transaction commit failed*/ trans_cb_t *cb_trans_revert; /* Transaction revert */ trans_cb_t *cb_trans_end; /* Transaction completed */ trans_cb_t *cb_trans_abort; /* Transaction aborted */ @@ -424,6 +425,7 @@ struct clixon_plugin_api{ #define ca_trans_complete u.cau_backend.cb_trans_complete #define ca_trans_commit u.cau_backend.cb_trans_commit #define ca_trans_commit_done u.cau_backend.cb_trans_commit_done +#define ca_trans_commit_failed u.cau_backend.cb_trans_commit_failed #define ca_trans_revert u.cau_backend.cb_trans_revert #define ca_trans_end u.cau_backend.cb_trans_end #define ca_trans_abort u.cau_backend.cb_trans_abort