Cleanup code in source4/torture/basic/misc.c:run_maxfidtest too clever by half?

Richard Sharpe realrichardsharpe at gmail.com
Thu Feb 14 12:44:23 MST 2013


Hi folks,

This function probes the MAX FIX by creating files ... and then
deletes those files with this code:

        maxfid = i;

        torture_comment(tctx, "cleaning up\n");
        for (i=0;i<maxfid/2;i++) {
                asprintf(&fname, MAXFID_TEMPLATE, i/1000, i,(int)getpid());
                if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnums[i]))) {
                        torture_comment(tctx, "Close of fnum %d failed
- %s\n", fnums[i], smbcli_errstr(cli->tree));
                }
                if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
                        torture_comment(tctx, "unlink of %s failed (%s)\n",
                               fname, smbcli_errstr(cli->tree));
                        correct = false;
                }
                free(fname);

                asprintf(&fname, MAXFID_TEMPLATE, (maxfid-i)/1000,
maxfid-i,(int)getpid());
                if (NT_STATUS_IS_ERR(smbcli_close(cli->tree,
fnums[maxfid-i]))) {
                        torture_comment(tctx, "Close of fnum %d failed
- %s\n", fnums[maxfid-i], smbcli_errstr(cli->tree));
                }
                if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
                        torture_comment(tctx, "unlink of %s failed (%s)\n",
                               fname, smbcli_errstr(cli->tree));
                        correct = false;
                }
                free(fname);

                if (torture_setting_bool(tctx, "progress", true)) {
                        torture_comment(tctx, "%6d %6d\r", i, maxfid-i);
                        fflush(stdout);
                }
        }

The problem with this too-clever-by-half approach is that if maxfix
was odd, you have an off-by-one condition and two files are left
behind, which causes the test to fail when trying to delete the test
dir.

What was wrong with simply iterating over all the probed FIDs?

-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)


More information about the samba-technical mailing list