7141347 - SMF module - need to provide delcust method
authordevjani.ray@oracle.com <devjani.ray@oracle.com>
Sun, 08 Apr 2012 19:52:12 -0400
changeset 831 d3e0d6b7e659
parent 830 93e61e848850
child 832 b4464932f1b5
7141347 - SMF module - need to provide delcust method
usr/src/apis/smf.xml
usr/src/cmd/rad/mod/smf/common.c
--- a/usr/src/apis/smf.xml	Sun Apr 08 16:04:44 2012 -0400
+++ b/usr/src/apis/smf.xml	Sun Apr 08 19:52:12 2012 -0400
@@ -474,8 +474,8 @@
       </summary>
       <doc>
         A list of all directly-attached
-        property groups, including both name
-        and type of each.
+        property groups, including name,
+        type and flags for each.
       </doc>
       <list typeref="PropertyGroup" />
       <error typeref="SmfError">
@@ -518,6 +518,37 @@
       </error>
     </method>
 
+    <method name="deleteCust">
+      <summary>
+	delete administrative customizations
+      </summary>
+      <doc>
+	Delete all administrative customizations
+	applied to a service/instance and its 
+	children, if any exist.
+      </doc>
+      <error typeref="SmfError">
+	<doc>
+	  <para>
+	    Failed to delete the administrative 
+	    customizations applied to a service or
+	    instance.  Cause:
+	  </para>
+	  <list>
+	    <item><code>INTERNAL</code> -
+	    an internal error occurred
+	    </item>
+	    <item><code>DENIED</code> -
+	    insufficient authorization
+	    </item>
+	    <item><code>READONLY</code> -
+	    the repository is read-only
+	    </item>
+	  </list>
+	</doc>
+      </error>
+    </method>
+
     <method name="createPG">
       <summary>
         create a property group
@@ -607,6 +638,45 @@
       </argument>
     </method>
 
+    <method name="deletePGCust">
+      <summary>
+	delete administrative customizations
+      </summary>
+      <doc>
+	Delete all administrative customizations
+	applied to a property group and its children, 
+	if any exist.
+      </doc>
+      <error typeref="SmfError">
+	<doc>
+	  <para>
+	    Failed to delete the administrative customizations
+	    applied to a property group.  Cause:
+	  </para>
+	  <list>
+	    <item><code>INTERNAL</code> -
+	    an internal error occurred
+	    </item>
+	    <item><code>DENIED</code> -
+	    insufficient authorization
+	    </item>
+	    <item><code>READONLY</code> -
+	    the repository is read-only
+	    </item>
+	    <item><code>NOTFOUND</code> -
+	    the property group doesn't
+	    exist
+	    </item>
+	  </list>
+	</doc>
+      </error>
+      <argument type="string" name="pg_name">
+	<summary>
+	  the name of the property group
+	</summary>
+      </argument>
+    </method>
+
     <method name="readProperties">
       <summary>
         reads all properties in a directly-attached
@@ -901,6 +971,49 @@
       </argument>
     </method>
 
+    <method name="deletePropertyCust">
+      <summary>
+	delete administrative customizations
+      </summary>
+      <doc>
+	Delete all administrative customizations
+	applied to this property.
+      </doc>
+      <error typeref="SmfError">
+	<doc>
+	  <para>
+	    Failed to delete the administrative customizations
+	    applied to this property.  Cause:
+	  </para>
+	  <list>
+	    <item><code>INTERNAL</code> -
+	    an internal error occurred
+	    </item>
+	    <item><code>DENIED</code> -
+	    insufficient authorization
+	    </item>
+	    <item><code>READONLY</code> -
+	    the repository is read-only
+	    </item>
+	    <item><code>NOTFOUND</code> -
+	    the property group, or property
+	    doesn't exist (see target)
+	    </item>
+	  </list>
+	</doc>
+      </error>
+      <argument type="string" name="pg_name">
+	<summary>
+	  the name of the property group
+	</summary>
+      </argument>
+      <argument type="string" name="prop_name">
+	<summary>
+	  the name of the property
+	</summary>
+      </argument>
+    </method>
+
     <method name="getCommonName">
       <summary>
         obtain the service/instance's localized
--- a/usr/src/cmd/rad/mod/smf/common.c	Sun Apr 08 16:04:44 2012 -0400
+++ b/usr/src/cmd/rad/mod/smf/common.c	Sun Apr 08 19:52:12 2012 -0400
@@ -165,7 +165,6 @@
 	return (smfu_rtrun(rt_collect_pgs, &pga, data, error));
 }
 
-
 /*ARGSUSED*/
 static svcerr_t
 rt_read_pgs(scf_handle_t *h, void *arg, data_t **ret, data_t **error)
@@ -267,6 +266,54 @@
 
 /*ARGSUSED*/
 static svcerr_t
+rt_invoke_deleteCust(scf_handle_t *h, void *arg, data_t **ret, data_t **error)
+{
+	smfobj_t *smfo = arg;
+	svcerr_t se = SE_OK;
+	smfu_entity_t entity = SMFU_ENTITY_INIT;
+
+	if ((se = smfu_lookup(h, smfo->sname, smfo->iname, &entity)) != SE_OK)
+		goto done;
+
+	int e = (entity.instance != NULL) ?
+	    scf_instance_delcust(entity.instance) :
+	    scf_service_delcust(entity.service);
+
+	if (e != 0) {
+		switch (scf_error()) {
+		case SCF_ERROR_PERMISSION_DENIED:
+			se = error_scf(error, &e__ErrorCode_DENIED, NULL,
+			    NULL, NULL);
+			break;
+		case SCF_ERROR_BACKEND_READONLY:
+			se = error_scf(error, &e__ErrorCode_READONLY, NULL,
+			    NULL, NULL);
+			break;
+		case SCF_ERROR_DELETED:
+			se = error_scf(error, &e__ErrorCode_NOTFOUND, NULL,
+			    (entity.instance != NULL) ? smfo->iname :
+			    smfo->sname, NULL);
+			break;
+		default:
+			se = smfu_maperr(scf_error());
+		}
+	}
+done:
+	smfu_entity_destroy(&entity);
+	return (se);
+}
+
+/*ARGSUSED*/
+conerr_t
+api_entity_invoke_deleteCust(rad_instance_t *inst, adr_method_t *meth,
+    data_t **ret, data_t **args, int count, data_t **error)
+{
+	return (smfu_rtrun(rt_invoke_deleteCust, instance_getdata(inst), NULL,
+	    error));
+}
+
+/*ARGSUSED*/
+static svcerr_t
 rt_invoke_createPG(scf_handle_t *h, void *arg, data_t **ret, data_t **error)
 {
 	radarg_t *ra = arg;
@@ -378,6 +425,61 @@
 
 /*ARGSUSED*/
 static svcerr_t
+rt_invoke_deletePGCust(scf_handle_t *h, void *arg, data_t **ret, data_t **error)
+{
+	radarg_t *ra = arg;
+	smfobj_t *smfo = instance_getdata(ra->inst);
+	const char *pgname = data_to_string(ra->args[0]);
+	svcerr_t se = SE_OK;
+	smfu_entity_t entity = SMFU_ENTITY_INIT;
+	scf_propertygroup_t *pg = scf_pg_create(h);
+
+	if (pg == NULL) {
+		se = SE_FATAL;
+		goto done;
+	}
+
+	if ((se = smfu_lookup(h, smfo->sname, smfo->iname, &entity)) != SE_OK)
+		goto done;
+
+	if ((se = smfu_get_pg(&entity, pgname, pg, error)) != SE_OK)
+		goto done;
+
+	if (scf_pg_delcust(pg) != 0) {
+		switch (scf_error()) {
+		case SCF_ERROR_PERMISSION_DENIED:
+			se = error_scf(error, &e__ErrorCode_DENIED, NULL,
+			    NULL, NULL);
+			break;
+		case SCF_ERROR_BACKEND_READONLY:
+			se = error_scf(error, &e__ErrorCode_READONLY, NULL,
+			    NULL, NULL);
+			break;
+		case SCF_ERROR_DELETED:
+			se = error_scf(error, &e__ErrorCode_NOTFOUND,
+			    &e__ErrorTarget_PROPERTYGROUP, pgname, NULL);
+			break;
+		default:
+			se = smfu_maperr(scf_error());
+		}
+	}
+
+done:
+	scf_pg_destroy(pg);
+	smfu_entity_destroy(&entity);
+	return (se);
+}
+
+/*ARGSUSED*/
+conerr_t
+api_entity_invoke_deletePGCust(rad_instance_t *inst, adr_method_t *meth,
+    data_t **ret, data_t **args, int count, data_t **error)
+{
+	radarg_t ra = { .inst = inst, .args = args };
+	return (smfu_rtrun(rt_invoke_deletePGCust, &ra, NULL, error));
+}
+
+static svcerr_t
 rt_invoke_readProperties(scf_handle_t *h, void *arg, data_t **ret,
     data_t **error)
 {
@@ -415,7 +517,7 @@
 	return (smfu_rtrun(rt_invoke_readProperties, &ra, ret, error));
 }
 
-
+/*ARGSUSED*/
 static svcerr_t
 tx_write_prop(scf_handle_t *h, scf_transaction_t *tx,
     const char *name, scf_type_t type, data_t *values, data_t **error)
@@ -551,8 +653,6 @@
 	return (smfu_rtrun(rt_invoke_writeProperties, &ra, NULL, error));
 }
 
-
-/*ARGSUSED*/
 static svcerr_t
 rt_invoke_readProperty(scf_handle_t *h, void *arg, data_t **ret, data_t **error)
 {
@@ -781,6 +881,112 @@
 	return (smfu_rtrun(rt_invoke_deleteProperty, &ra, NULL, error));
 }
 
+static svcerr_t
+tx_delete_propcust(scf_handle_t *h, scf_transaction_t *tx,
+    const char *name, data_t **error)
+{
+	svcerr_t se = SE_OK;
+	scf_transaction_entry_t *entry = scf_entry_create(h);
+
+	if (entry == NULL)
+		return (SE_FATAL);
+
+	if (scf_transaction_property_delcust(tx, entry, name) == -1) {
+		int e = scf_error();
+		scf_entry_destroy(entry);
+		switch (e) {
+		case SCF_ERROR_PERMISSION_DENIED:
+			se = error_scf(error, &e__ErrorCode_DENIED, NULL,
+			    NULL, NULL);
+			break;
+		case SCF_ERROR_BACKEND_READONLY:
+			se = error_scf(error, &e__ErrorCode_READONLY, NULL,
+			    NULL, NULL);
+			break;
+		case SCF_ERROR_DELETED:
+			se = error_scf(error, &e__ErrorCode_NOTFOUND,
+			    &e__ErrorTarget_PROPERTY, name, NULL);
+			break;
+		default:
+			se = smfu_maperr(e);
+		}
+	}
+	return (se);
+}
+
+/*ARGSUSED*/
+static svcerr_t
+rt_invoke_deletePropertyCust(scf_handle_t *h, void *arg, data_t **ret,
+    data_t **error)
+{
+	radarg_t *ra = arg;
+	smfobj_t *smfo = instance_getdata(ra->inst);
+	const char *pgname = data_to_string(ra->args[0]);
+	const char *propname = data_to_string(ra->args[1]);
+	svcerr_t se = SE_OK;
+	smfu_entity_t entity = SMFU_ENTITY_INIT;
+	scf_propertygroup_t *pg = scf_pg_create(h);
+	scf_transaction_t *tx = scf_transaction_create(h);
+
+	if (pg == NULL || tx == NULL) {
+		se = internal_error(error, NULL);
+		goto done;
+	}
+
+	if ((se = smfu_lookup(h, smfo->sname, smfo->iname, &entity)) != SE_OK)
+		goto done;
+
+	if ((se = smfu_get_pg(&entity, pgname, pg, error)) != SE_OK)
+		goto done;
+
+top:
+	if (scf_transaction_start(tx, pg) == -1)
+		goto txerror;
+
+	if ((se = tx_delete_propcust(h, tx, propname, error)) != SE_OK)
+		goto done;
+
+	int r;
+	if ((r = scf_transaction_commit(tx)) == 1)
+		goto done;
+
+	if (r == 0 && scf_pg_update(pg) != -1) {
+		scf_transaction_destroy_children(tx);
+		scf_transaction_reset(tx);
+		goto top;
+	}
+
+txerror:
+	switch (scf_error()) {
+	case SCF_ERROR_PERMISSION_DENIED:
+		se = error_scf(error, &e__ErrorCode_DENIED, NULL,
+		    NULL, NULL);
+		break;
+	case SCF_ERROR_BACKEND_READONLY:
+		se = error_scf(error, &e__ErrorCode_READONLY, NULL,
+		    NULL, NULL);
+		break;
+	default:
+		se = smfu_maperr(scf_error());
+	}
+
+done:
+	scf_transaction_destroy_children(tx);
+	scf_transaction_destroy(tx);
+	scf_pg_destroy(pg);
+
+	return (se);
+}
+
+/*ARGSUSED*/
+conerr_t
+api_entity_invoke_deletePropertyCust(rad_instance_t *inst, adr_method_t *meth,
+    data_t **ret, data_t **args, int count, data_t **error)
+{
+	radarg_t ra = { .inst = inst, .args = args };
+	return (smfu_rtrun(rt_invoke_deletePropertyCust, &ra, NULL, error));
+}
+
 /*
  * Common retry callback for reading old-style template data from
  * either a service's directly-attached property groups or an