Back to index

nbd  3.2
Functions | Variables
make-integrityhuge.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <stdint.h>
#include <unistd.h>
#include "config.h"
#include "cliserv.h"
#include "nbd.h"

Go to the source code of this file.

Functions

static void dowrite (int f, void *buf, size_t len)
static uint64_t getrandomuint64 ()
int main (int argc, char **argv)

Variables

const uint64_t filesize = 50*1000*1000
const uint64_t transactions = 250

Function Documentation

static void dowrite ( int  f,
void *  buf,
size_t  len 
) [inline, static]

Definition at line 21 of file make-integrityhuge.c.

                                                         {
        ssize_t res;

        while(len>0) {
                if((res=write(f, buf, len)) <=0) {
                     perror ("Error writing transactions");
                     exit(1);
                }
                len-=res;
                buf+=res;
        }
}

Here is the caller graph for this function:

static uint64_t getrandomuint64 ( ) [inline, static]

Definition at line 34 of file make-integrityhuge.c.

                                         {
       uint64_t r=0;
        int i;
       /* RAND_MAX may be as low as 2^15 */
       for (i= 1 ; i<=5; i++)
              r ^= random() ^ (r << 15); 
       return r;
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 43 of file make-integrityhuge.c.

                               {
       struct nbd_request req;
       struct nbd_reply rep;
       uint64_t handle;
       int writefd = 1; /*stdout*/

       req.magic = htonl(NBD_REQUEST_MAGIC);
       rep.magic = htonl(NBD_REPLY_MAGIC);
       rep.error = 0;

       for (handle = 0; handle < transactions; handle++)
       {
              uint64_t offset;
              uint64_t length;
              uint64_t flags;
              uint32_t command;

              /* make the length between 0x400 and the length of the disk -08x800, with all
               * the bottom bits clear */
              length = ((getrandomuint64() % (filesize-0x800)) & ~((uint64_t)0x3ff)) + 0x400;
              /* generate an offset that will fit the length */
              offset = (getrandomuint64() % (filesize-length)) & ~((uint64_t)0x3ff);
              flags = getrandomuint64();

              command = (flags & 0x01)?NBD_CMD_READ:NBD_CMD_WRITE;

              if (!(flags & 0x0f))
                     command = NBD_CMD_FLAG_FUA | NBD_CMD_WRITE;

              if (!(flags & 0xf0)) {
                     offset = 0;
                     length = 0;
                     command = NBD_CMD_FLUSH;
              }

              *(uint64_t *)(req.handle) = htonll(handle);
              *(uint64_t *)(rep.handle) = htonll(handle);
              req.type = htonl(command);
              req.from = htonll(offset);
              req.len = htonl(length);

              dowrite(writefd, &req, sizeof(req));
              dowrite(writefd, &rep, sizeof(rep));
       }

       req.type = htonl(NBD_CMD_DISC);
       req.from = 0;
       req.len = 0;
       dowrite(writefd, &req, sizeof(req));
       
       return 0;
}

Here is the call graph for this function:


Variable Documentation

const uint64_t filesize = 50*1000*1000

Definition at line 18 of file make-integrityhuge.c.

const uint64_t transactions = 250

Definition at line 19 of file make-integrityhuge.c.