diff options
author | Noriko Hosoi <nhosoi@redhat.com> | 2008-11-17 23:11:57 +0000 |
---|---|---|
committer | Noriko Hosoi <nhosoi@redhat.com> | 2008-11-17 23:11:57 +0000 |
commit | 3bf8e6819c951a2d0e4e0719f0332acb3154de7f (patch) | |
tree | 834a6abbd0b8c000a7f808cf787b4d7525068e06 /ldap/servers/slapd/tools | |
parent | eb75a8d7d65af98bfb01b1380d53fce2da972db6 (diff) | |
download | ds-3bf8e6819c951a2d0e4e0719f0332acb3154de7f.tar.gz ds-3bf8e6819c951a2d0e4e0719f0332acb3154de7f.tar.xz ds-3bf8e6819c951a2d0e4e0719f0332acb3154de7f.zip |
Resolves: #471138
Summary: LDCLT: add abandon to ldclt
Diffstat (limited to 'ldap/servers/slapd/tools')
-rw-r--r-- | ldap/servers/slapd/tools/ldclt/ldapfct.c | 173 | ||||
-rw-r--r-- | ldap/servers/slapd/tools/ldclt/ldclt.c | 8 | ||||
-rw-r--r-- | ldap/servers/slapd/tools/ldclt/ldclt.h | 5 | ||||
-rw-r--r-- | ldap/servers/slapd/tools/ldclt/ldcltU.c | 56 | ||||
-rw-r--r-- | ldap/servers/slapd/tools/ldclt/threadMain.c | 11 |
5 files changed, 221 insertions, 32 deletions
diff --git a/ldap/servers/slapd/tools/ldclt/ldapfct.c b/ldap/servers/slapd/tools/ldclt/ldapfct.c index b2e1f764..e58a41e1 100644 --- a/ldap/servers/slapd/tools/ldclt/ldapfct.c +++ b/ldap/servers/slapd/tools/ldclt/ldapfct.c @@ -1650,7 +1650,7 @@ buildNewEntry ( 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 @@ buildNewEntry ( attribute.mod_type = "sn"; attribute.mod_values = strList1 ("toto sn"); if (addAttrib (attrs, nbAttribs++, &attribute) < 0) - return (-1); + return (-1); } } @@ -3554,5 +3554,174 @@ doExactSearch ( 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 */ diff --git a/ldap/servers/slapd/tools/ldclt/ldclt.c b/ldap/servers/slapd/tools/ldclt/ldclt.c index 8c9f04e0..5346e241 100644 --- a/ldap/servers/slapd/tools/ldclt/ldclt.c +++ b/ldap/servers/slapd/tools/ldclt/ldclt.c @@ -2115,6 +2115,8 @@ char *execParams[] = { "randomauthidhigh", #define EP_RANDOMSASLAUTHIDLOW 48 "randomauthidlow", +#define EP_ABANDON 49 + "abandon", NULL }; @@ -2397,6 +2399,9 @@ decodeExecParams ( 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 @@ main ( 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*/ diff --git a/ldap/servers/slapd/tools/ldclt/ldclt.h b/ldap/servers/slapd/tools/ldclt/ldclt.h index f4dae41c..0ed8ef8e 100644 --- a/ldap/servers/slapd/tools/ldclt/ldclt.h +++ b/ldap/servers/slapd/tools/ldclt/ldclt.h @@ -277,6 +277,7 @@ dd/mm/yy | Author | Comments #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 @@ dd/mm/yy | Author | Comments * - 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 doAttrReplace (thread_context *tttctx); /*JLS 21-11-00*/ 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); diff --git a/ldap/servers/slapd/tools/ldclt/ldcltU.c b/ldap/servers/slapd/tools/ldclt/ldcltU.c index c4ec8892..aa5fb705 100644 --- a/ldap/servers/slapd/tools/ldclt/ldcltU.c +++ b/ldap/servers/slapd/tools/ldclt/ldcltU.c @@ -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 usage () (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 usage () (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"); diff --git a/ldap/servers/slapd/tools/ldclt/threadMain.c b/ldap/servers/slapd/tools/ldclt/threadMain.c index f5af4bf7..32df9b70 100644 --- a/ldap/servers/slapd/tools/ldclt/threadMain.c +++ b/ldap/servers/slapd/tools/ldclt/threadMain.c @@ -954,7 +954,7 @@ threadMain ( * 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 @@ threadMain ( 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 */ |