Author: nhosoi
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/ldclt
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv23022
Modified Files:
ldapfct.c ldclt.c ldclt.h ldcltU.c threadMain.c
Log Message:
Resolves: #471138
Summary: LDCLT: add abandon to ldclt
Index: ldapfct.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/ldclt/ldapfct.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ldapfct.c 8 Oct 2008 17:29:04 -0000 1.8
+++ ldapfct.c 17 Nov 2008 23:11:57 -0000 1.9
@@ -1650,7 +1650,7 @@
attribute.mod_type = "cn";
attribute.mod_values = strList1 ("toto cn");
if (addAttrib (attrs, nbAttribs++, &attribute) < 0)
- return (-1);
+ return (-1);
}
if (strcmp (tttctx->buf2, "sn"))
{
@@ -1658,7 +1658,7 @@
attribute.mod_type = "sn";
attribute.mod_values = strList1 ("toto sn");
if (addAttrib (attrs, nbAttribs++, &attribute) < 0)
- return (-1);
+ return (-1);
}
}
@@ -3554,5 +3554,174 @@
return (0);
}
+/* ****************************************************************************
+ FUNCTION : doAbandon
+ PURPOSE : Perform one abandon operation against an async search.
+ INPUT : tttctx = thread context
+ OUTPUT : None.
+ RETURN : -1 if error, 0 else.
+ DESCRIPTION :
+ *****************************************************************************/
+int
+doAbandon (thread_context *tttctx)
+{
+ int ret; /* Return value */
+ LDAPMessage *res; /* LDAP results */
+ char **attrlist; /* Attribs list */
+ struct timeval mytimeout;
+ int msgid;
+
+ /*
+ * Connection to the server
+ * The function connectToServer() will take care of the various connection/
+ * disconnection, bind/unbind/close etc... requested by the user.
+ * The cost is one more function call in this application, but the
+ * resulting source code will be much more easiest to maintain.
+ */
+ if (connectToServer (tttctx) < 0)
+ return (-1);
+ if (!(tttctx->binded))
+ return (0);
+
+ /*
+ * Build the filter
+ */
+ if (buildRandomRdnOrFilter (tttctx) < 0)
+ return (-1);
+
+ attrlist = NULL;
+
+ /*
+ * We use asynchronous search to abandon...
+ *
+ * set (1, 2) to (acyncMin, acyncMax), which combination does not stop write.
+ */
+ mctx.asyncMin = 1;
+ mctx.asyncMax = 2;
+ if (tttctx->pendingNb >= mctx.asyncMin)
+ {
+ mytimeout.tv_sec = 1;
+ mytimeout.tv_usec = 0;
+ ret = ldap_result (tttctx->ldapCtx,
+ LDAP_RES_ANY, LDAP_MSG_ONE, &mytimeout, &res);
+ if (ret < 0)
+ {
+ if (!((mctx.mode & QUIET) && ignoreError (ret)))
+ (void) printErrorFromLdap (tttctx, res, ret, "Cannot ldap_result()");
+ if (addErrorStat (ret) < 0)
+ return (-1);
+ }
+ else
+ {
+ /* ret == 0 --> timeout; op abandoned and no result is returned */
+ tttctx->pendingNb--;
+
+ /*
+ * Don't forget to free the returned message !
+ */
+ if ((ret = ldap_msgfree (res)) < 0)
+ {
+ if (!((mctx.mode & QUIET) && ignoreError (ret)))
+ {
+ printf ("ldclt[%d]: T%03d: Cannot ldap_msgfree(), error=%d (%s)\n",
+ mctx.pid, tttctx->thrdNum, ret, my_ldap_err2string (ret));
+ fflush (stdout);
+ }
+ if (addErrorStat (ret) < 0)
+ return (-1);
+ }
+ }
+ }
+
+ /*
+ * Maybe we may send another request ?
+ * Well... there is no proper way to retrieve the error number for
+ * this, so I guess I may use direct access to the ldap context
+ * to read the field ld_errno.
+ */
+ if (tttctx->pendingNb > mctx.asyncMax)
+ {
+ if ((mctx.mode & VERBOSE) &&
+ (tttctx->asyncHit == 1) &&
+ (!(mctx.mode & SUPER_QUIET)))
+ {
+ tttctx->asyncHit = 1;
+ printf ("ldclt[%d]: T%03d: Max pending request hit.\n",
+ mctx.pid, tttctx->thrdNum);
+ fflush (stdout);
+ }
+ }
+ else
+ {
+ if ((mctx.mode & VERBOSE) &&
+ (tttctx->asyncHit == 1) &&
+ (!(mctx.mode & SUPER_QUIET)))
+ {
+ tttctx->asyncHit = 0;
+ printf ("ldclt[%d]: T%03d: Restart sending.\n",
+ mctx.pid, tttctx->thrdNum);
+ fflush (stdout);
+ }
+
+ msgid = -1;
+ /* for some reasons, it is an error to pass in a zero'd timeval */
+ mytimeout.tv_sec = mytimeout.tv_usec = -1;
+ ret = ldap_search_ext (tttctx->ldapCtx, tttctx->bufBaseDN, mctx.scope,
+ tttctx->bufFilter, attrlist, mctx.attrsonly,
+ NULL, NULL, &mytimeout, -1, &msgid);
+ if (mctx.mode & VERY_VERBOSE)
+ printf ("ldclt[%d]: T%03d: ldap_search(%s)=>%d\n",
+ mctx.pid, tttctx->thrdNum, tttctx->bufFilter, ret);
+
+ if (ret != 0)
+ {
+ if (ldap_get_option (tttctx->ldapCtx, LDAP_OPT_ERROR_NUMBER, &ret) < 0)
+ {
+ printf ("ldclt[%d]: T%03d: Cannot
ldap_get_option(LDAP_OPT_ERROR_NUMBER)\n",
+ mctx.pid, tttctx->thrdNum);
+ fflush (stdout);
+ return (-1);
+ }
+ else
+ {
+ if (!((mctx.mode & QUIET) && ignoreError (ret)))
+ {
+ printf ("ldclt[%d]: T%03d: Cannot ldap_search(), error=%d (%s)\n",
+ mctx.pid, tttctx->thrdNum, ret, my_ldap_err2string (ret));
+ fflush (stdout);
+ }
+ if (addErrorStat (ret) < 0)
+ return (-1);
+ }
+ }
+ else
+ {
+ if (msgid >= 0)
+ {
+ /* ABANDON the search request immediately */
+ (void) ldap_abandon(tttctx->ldapCtx, msgid);
+ }
+
+ /*
+ * Memorize the operation
+ */
+ if (incrementNbOpers (tttctx) < 0)
+ return (-1);
+ tttctx->pendingNb++;
+ if (mctx.mode & VERY_VERBOSE)
+ printf ("ldclt[%d]: T%03d: ldap_abandon(%d)\n",
+ mctx.pid, tttctx->thrdNum, msgid);
+ }
+ }
+
+ if (mctx.mode & VERY_VERBOSE)
+ printf ("ldclt[%d]: T%03d: pendingNb=%d\n",
+ mctx.pid, tttctx->thrdNum, tttctx->pendingNb);
+
+ /*
+ * End of asynchronous operation... and also end of function.
+ */
+ return (0);
+}
/* End of file */
Index: ldclt.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/ldclt/ldclt.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ldclt.c 19 Sep 2007 18:08:12 -0000 1.6
+++ ldclt.c 17 Nov 2008 23:11:57 -0000 1.7
@@ -2115,6 +2115,8 @@
"randomauthidhigh",
#define EP_RANDOMSASLAUTHIDLOW 48
"randomauthidlow",
+#define EP_ABANDON 49
+ "abandon",
NULL
};
@@ -2397,6 +2399,9 @@
case EP_WITH_NEWPARENT: /*JLS 15-12-00*/
mctx.mode |= WITH_NEWPARENT; /*JLS 15-12-00*/
break; /*JLS 15-12-00*/
+ case EP_ABANDON:
+ mctx.mod2 |= M2_ABANDON;
+ break;
default:
fprintf (stderr, "Error: illegal option -e %s\n", subvalue);
return (-1);
@@ -2750,7 +2755,8 @@
fprintf (stderr, "Error: use -f or -e rdn=value for this purpose.\n");
ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
}
- if ((!((mctx.mode & NEED_FILTER) || (mctx.mod2 & M2_GENLDIF)))/*JLS 04-05-01*/
+ if ((!((mctx.mode & NEED_FILTER) || (mctx.mod2 & M2_GENLDIF) ||
+ (mctx.mod2 & M2_NEED_FILTER)))/*JLS 04-05-01*/
&& (mctx.filter != NULL)) /*JLS 04-05-01*/
{ /*JLS 04-05-01*/
fprintf (stderr, "Error: do not need filter -f\n"); /*JLS 04-05-01*/
Index: ldclt.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/ldclt/ldclt.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ldclt.h 19 Sep 2007 18:08:12 -0000 1.5
+++ ldclt.h 17 Nov 2008 23:11:57 -0000 1.6
@@ -277,6 +277,7 @@
#define M2_BINDONLY 0x00000020 /* -e bindonly */ /*JLS 04-05-01*/
#define M2_SASLAUTH 0x00000040 /* -o : SASL authentication */
#define M2_RANDOM_SASLAUTHID 0x00000080 /* -e randomauthid */
+#define M2_ABANDON 0x00000100 /* -e abandon */
/*
* Combinatory defines
@@ -286,10 +287,11 @@
* - VALID_OPERS : valid operations
*/
#define
NEED_FILTER (ADD_ENTRIES|DELETE_ENTRIES|EXACT_SEARCH|RENAME_ENTRIES|ATTR_REPLACE|SCALAB01)
+#define M2_NEED_FILTER (M2_ABANDON)
#define NEED_RANGE (INCREMENTAL|RANDOM)
#define NEED_RND_INCR (ADD_ENTRIES|DELETE_ENTRIES|RENAME_ENTRIES)
#define
VALID_OPERS (ADD_ENTRIES|DELETE_ENTRIES|EXACT_SEARCH|RENAME_ENTRIES|ATTR_REPLACE|SCALAB01)
-#define M2_VALID_OPERS (M2_GENLDIF|M2_BINDONLY)
+#define M2_VALID_OPERS (M2_GENLDIF|M2_BINDONLY|M2_ABANDON)
#define NEED_CLASSES (ADD_ENTRIES)
#define THE_CLASSES (OC_PERSON|OC_EMAILPERSON|OC_INETORGPRSON)
@@ -700,6 +702,7 @@
extern int doBindOnly (thread_context *tttctx); /*JLS 04-05-01*/
extern int doDeleteEntry (thread_context *tttctx);
extern int doExactSearch (thread_context *tttctx);
+extern int doAbandon (thread_context *tttctx);
extern int doGenldif (thread_context *tttctx); /*JLS 19-03-01*/
extern int doRename (thread_context *tttctx);
extern int freeAttrib (LDAPMod **attrs);
Index: ldcltU.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/ldclt/ldcltU.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ldcltU.c 5 Jul 2007 23:53:41 -0000 1.4
+++ ldcltU.c 17 Nov 2008 23:11:57 -0000 1.5
@@ -65,6 +65,7 @@
* -D Bind DN. See -w
* -E Max errors allowed. Default 1000.
* -e Execution parameters:
+ * abandon : abandon asyncronous search requests.
* add : ldap_add() entries.
* append : append entries to the genldif file.
* ascii : ascii 7-bits strings.
@@ -156,35 +157,36 @@
(void) printf (" -D Bind DN. See -w\n");
(void) printf (" -E Max errors allowed. Default
1000.\n");
(void) printf (" -e Execution parameters:\n");
- (void) printf (" add : ldap_add() entries.\n");
- (void) printf (" append : append entries to the genldif file.\n");
- (void) printf (" ascii : ascii 7-bits strings.\n");
+ (void) printf (" abandon : abandon async search requests.\n");
+ (void) printf (" add : ldap_add() entries.\n");
+ (void) printf (" append : append entries to the genldif
file.\n");
+ (void) printf (" ascii : ascii 7-bits strings.\n");
(void) printf (" attreplace=name:mask : replace attribute of existing
entry.\n");
(void) printf (" attrlist=name:name:name : specify list of attribs to
retrieve\n");
- (void) printf (" attrsonly=0|1 : ldap_search() parameter. Set 0 to read
values.\n");
- (void) printf (" bindeach : ldap_bind() for each operation.\n");
- (void) printf (" bindonly : only bind/unbind, no other operation is
performed.\n");
- (void) printf (" close : will close() the fd, rather than
ldap_unbind().\n");
- (void) printf (" cltcertname=name : name of the SSL client certificate\n");
- (void) printf (" commoncounter : all threads share the same
counter.\n");
- (void) printf (" counteach : count each operation not only successful
ones.\n");
- (void) printf (" delete : ldap_delete() entries.\n");
+ (void) printf (" attrsonly=0|1 : ldap_search() parameter. Set 0 to read
values.\n");
+ (void) printf (" bindeach : ldap_bind() for each operation.\n");
+ (void) printf (" bindonly : only bind/unbind, no other operation is
performed.\n");
+ (void) printf (" close : will close() the fd, rather than
ldap_unbind().\n");
+ (void) printf (" cltcertname=name : name of the SSL client
certificate\n");
+ (void) printf (" commoncounter : all threads share the same
counter.\n");
+ (void) printf (" counteach : count each operation not only successful
ones.\n");
+ (void) printf (" delete : ldap_delete() entries.\n");
(void) printf (" dontsleeponserverdown : will loop very fast if server
down.\n");
- (void) printf (" emailPerson : objectclass=emailPerson (-e add
only).\n");
- (void) printf (" esearch : exact search.\n");
- (void) printf (" genldif=filename : generates a ldif file\n");
- (void) printf (" imagesdir=path : specify where are the images.\n");
- (void) printf (" incr : incremental values.\n");
- (void) printf (" inetOrgPerson : objectclass=inetOrgPerson (-e add
only).\n");
- (void) printf (" keydbfile=file : filename of the key database\n");
- (void) printf (" keydbpin=password : password for accessing the key
database\n");
- (void) printf (" noglobalstats : don't print periodical global
statistics\n");
- (void) printf (" noloop : does not loop the incremental
numbers.\n");
- (void) printf (" object=filename : build object from input file\n");
- (void) printf (" person : objectclass=person (-e add
only).\n");
- (void) printf (" random : random filters, etc...\n");
+ (void) printf (" emailPerson : objectclass=emailPerson (-e add
only).\n");
+ (void) printf (" esearch : exact search.\n");
+ (void) printf (" genldif=filename : generates a ldif file\n");
+ (void) printf (" imagesdir=path : specify where are the images.\n");
+ (void) printf (" incr : incremental values.\n");
+ (void) printf (" inetOrgPerson : objectclass=inetOrgPerson (-e add
only).\n");
+ (void) printf (" keydbfile=file : filename of the key database\n");
+ (void) printf (" keydbpin=password : password for accessing the key
database\n");
+ (void) printf (" noglobalstats : don't print periodical global
statistics\n");
+ (void) printf (" noloop : does not loop the incremental
numbers.\n");
+ (void) printf (" object=filename : build object from input file\n");
+ (void) printf (" person : objectclass=person (-e add only).\n");
+ (void) printf (" random : random filters, etc...\n");
(void) printf (" randomattrlist=name:name:name : random select attrib in the
list\n");
- (void) printf (" randombase : random base DN.\n");
+ (void) printf (" randombase : random base DN.\n");
(void) printf (" randombaselow=value : low value for random
generator.\n");
(void) printf (" randombasehigh=value : high value for random
generator.\n");
(void) printf (" randombinddn : random bind DN.\n");
@@ -198,8 +200,8 @@
(void) printf (" scalab01_maxcnxnb : modem pool size.\n");
(void) printf (" scalab01_wait : sleep() between 2 attempts to
connect.\n");
(void) printf (" smoothshutdown : main thread waits till the worker
threads exit.\n");
- (void) printf (" string : create random strings rather than random
numbers.\n");
- (void) printf (" v2 : ldap v2.\n");
+ (void) printf (" string : create random strings rather than
random numbers.\n");
+ (void) printf (" v2 : ldap v2.\n");
(void) printf (" withnewparent : rename with newparent specified as
argument.\n");
(void) printf (" randomauthid : random SASL Authid.\n");
(void) printf (" randomauthidlow=value : low value for random SASL
Authid.\n");
Index: threadMain.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/ldclt/threadMain.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- threadMain.c 5 Jul 2007 23:53:41 -0000 1.3
+++ threadMain.c 17 Nov 2008 23:11:57 -0000 1.4
@@ -954,7 +954,7 @@
* Don't forget the buffers !!
* This should save time while redoing random values
*/
- if ((mctx.mode & NEED_FILTER) || (mctx.mod2 & M2_GENLDIF)) /*JLS 19-03-01*/
+ if ((mctx.mode & NEED_FILTER) || (mctx.mod2 &
(M2_GENLDIF|M2_NEED_FILTER))) /*JLS 19-03-01*/
{
if (mctx.mod2 & M2_RDN_VALUE) /*JLS 23-03-01*/
tttctx->bufFilter = (char *) malloc (MAX_FILTER); /*JLS 23-03-01*/
@@ -1200,6 +1200,15 @@
continue; /*JLS 19-03-01*/
} /*JLS 19-03-01*/
+ if (mctx.mod2 & M2_ABANDON)
+ {
+ if (doAbandon (tttctx) < 0)
+ {
+ go = 0;
+ continue;
+ }
+ }
+
/*
* Check the thread's status
*/