~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/os/os0file.c

  • Committer: Brian Aker
  • Date: 2010-12-07 09:12:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1985.
  • Revision ID: brian@tangent.org-20101207091212-1m0w20tck6z7632m
This is a fix for bug lp:686197

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (C) 2009, Percona Inc.
 
3
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
 
4
Copyright (c) 2009, Percona Inc.
5
5
 
6
6
Portions of this file contain modifications contributed and copyrighted
7
7
by Percona Inc.. Those modifications are
662
662
                if (errno == EAGAIN || errno == EACCES) {
663
663
                        fprintf(stderr,
664
664
                                "InnoDB: Check that you do not already have"
665
 
                                " another drizzled process\n"
 
665
                                " another mysqld process\n"
666
666
                                "InnoDB: using the same InnoDB data"
667
667
                                " or log files.\n");
668
668
                }
940
940
 
941
941
        strcpy(info->name, ent->d_name);
942
942
 
943
 
        full_path = static_cast<char* >(ut_malloc(strlen(dirname) + strlen(ent->d_name) + 10));
 
943
        full_path = ut_malloc(strlen(dirname) + strlen(ent->d_name) + 10);
944
944
 
945
945
        sprintf(full_path, "%s/%s", dirname, ent->d_name);
946
946
 
1298
1298
os_file_set_nocache(
1299
1299
/*================*/
1300
1300
        int             fd,             /*!< in: file descriptor to alter */
1301
 
        const char*     file_name,      /*!< in: used in the diagnostic message */
1302
 
        const char*     operation_name)
1303
 
                                        /*!< in: "open" or "create"; used in the
 
1301
        const char*     file_name,      /*!< in: file name, used in the
 
1302
                                        diagnostic message */
 
1303
        const char*     operation_name) /*!< in: "open" or "create"; used in the
1304
1304
                                        diagnostic message */
1305
1305
{
1306
1306
        /* some versions of Solaris may not have DIRECTIO_ON */
1488
1488
        int             create_flag;
1489
1489
        ibool           retry;
1490
1490
        const char*     mode_str        = NULL;
 
1491
        const char*     type_str        = NULL;
 
1492
        const char*     purpose_str     = NULL;
1491
1493
 
1492
1494
try_again:
1493
1495
        ut_a(name);
1507
1509
                ut_error;
1508
1510
        }
1509
1511
 
1510
 
        ut_a(type == OS_LOG_FILE || type == OS_DATA_FILE);
1511
 
        ut_a(purpose == OS_FILE_AIO || purpose == OS_FILE_NORMAL);
1512
 
 
 
1512
        if (type == OS_LOG_FILE) {
 
1513
                type_str = "LOG";
 
1514
        } else if (type == OS_DATA_FILE) {
 
1515
                type_str = "DATA";
 
1516
        } else {
 
1517
                ut_error;
 
1518
        }
 
1519
 
 
1520
        if (purpose == OS_FILE_AIO) {
 
1521
                purpose_str = "AIO";
 
1522
        } else if (purpose == OS_FILE_NORMAL) {
 
1523
                purpose_str = "NORMAL";
 
1524
        } else {
 
1525
                ut_error;
 
1526
        }
 
1527
 
 
1528
#if 0
 
1529
        fprintf(stderr, "Opening file %s, mode %s, type %s, purpose %s\n",
 
1530
                name, mode_str, type_str, purpose_str);
 
1531
#endif
1513
1532
#ifdef O_SYNC
1514
1533
        /* We let O_SYNC only affect log files; note that we map O_DSYNC to
1515
1534
        O_SYNC because the datasync options seemed to corrupt files in 2001
1937
1956
        /* Write up to 1 megabyte at a time. */
1938
1957
        buf_size = ut_min(64, (ulint) (desired_size / UNIV_PAGE_SIZE))
1939
1958
                * UNIV_PAGE_SIZE;
1940
 
        buf2 = static_cast<unsigned char *>(ut_malloc(buf_size + UNIV_PAGE_SIZE));
 
1959
        buf2 = ut_malloc(buf_size + UNIV_PAGE_SIZE);
1941
1960
 
1942
1961
        /* Align the buffer for possible raw i/o */
1943
 
        buf = static_cast<unsigned char *>(ut_align(buf2, UNIV_PAGE_SIZE));
 
1962
        buf = ut_align(buf2, UNIV_PAGE_SIZE);
1944
1963
 
1945
1964
        /* Write buffer full of zeros */
1946
1965
        memset(buf, 0, buf_size);
2404
2423
        ulint           i;
2405
2424
#endif /* !UNIV_HOTBACKUP */
2406
2425
 
2407
 
        /* On 64-bit Windows, ulint is 64 bits. But offset and n should be
2408
 
        no more than 32 bits. */
2409
2426
        ut_a((offset & 0xFFFFFFFFUL) == offset);
2410
 
        ut_a((n & 0xFFFFFFFFUL) == n);
2411
2427
 
2412
2428
        os_n_file_reads++;
2413
2429
        os_bytes_read_since_printout += n;
2533
2549
        ulint           i;
2534
2550
#endif /* !UNIV_HOTBACKUP */
2535
2551
 
2536
 
        /* On 64-bit Windows, ulint is 64 bits. But offset and n should be
2537
 
        no more than 32 bits. */
2538
2552
        ut_a((offset & 0xFFFFFFFFUL) == offset);
2539
 
        ut_a((n & 0xFFFFFFFFUL) == n);
2540
2553
 
2541
2554
        os_n_file_reads++;
2542
2555
        os_bytes_read_since_printout += n;
2668
2681
        ulint           i;
2669
2682
#endif /* !UNIV_HOTBACKUP */
2670
2683
 
2671
 
        /* On 64-bit Windows, ulint is 64 bits. But offset and n should be
2672
 
        no more than 32 bits. */
2673
 
        ut_a((offset & 0xFFFFFFFFUL) == offset);
2674
 
        ut_a((n & 0xFFFFFFFFUL) == n);
 
2684
        ut_a((offset & 0xFFFFFFFF) == offset);
2675
2685
 
2676
2686
        os_n_file_writes++;
2677
2687
 
3215
3225
#ifdef WIN_ASYNC_IO
3216
3226
        OVERLAPPED*     over;
3217
3227
#elif defined(LINUX_NATIVE_AIO)
3218
 
        struct io_event*        aio_event = NULL;
 
3228
        struct io_event*        io_event = NULL;
3219
3229
#endif
3220
3230
        ut_a(n > 0);
3221
3231
        ut_a(n_segments > 0);
3222
3232
 
3223
 
        array = static_cast<os_aio_array_t *>(ut_malloc(sizeof(os_aio_array_t)));
 
3233
        array = ut_malloc(sizeof(os_aio_array_t));
3224
3234
 
3225
3235
        array->mutex            = os_mutex_create();
3226
3236
        array->not_full         = os_event_create(NULL);
3232
3242
        array->n_segments       = n_segments;
3233
3243
        array->n_reserved       = 0;
3234
3244
        array->cur_seg          = 0;
3235
 
        array->slots            = static_cast<os_aio_slot_t *>(ut_malloc(n * sizeof(os_aio_slot_t)));
 
3245
        array->slots            = ut_malloc(n * sizeof(os_aio_slot_t));
3236
3246
#ifdef __WIN__
3237
3247
        array->handles          = ut_malloc(n * sizeof(HANDLE));
3238
3248
#endif
3250
3260
        /* Initialize the io_context array. One io_context
3251
3261
        per segment in the array. */
3252
3262
 
3253
 
        array->aio_ctx = (io_context**) ut_malloc(n_segments *
 
3263
        array->aio_ctx = ut_malloc(n_segments *
3254
3264
                                   sizeof(*array->aio_ctx));
3255
3265
        for (i = 0; i < n_segments; ++i) {
3256
3266
                if (!os_aio_linux_create_io_ctx(n/n_segments,
3266
3276
        }
3267
3277
 
3268
3278
        /* Initialize the event array. One event per slot. */
3269
 
        aio_event = (io_event*) ut_malloc(n * sizeof(io_event));
3270
 
        memset(aio_event, 0x0, sizeof(io_event) * n);
3271
 
        array->aio_events = aio_event;
 
3279
        io_event = ut_malloc(n * sizeof(*io_event));
 
3280
        memset(io_event, 0x0, sizeof(*io_event) * n);
 
3281
        array->aio_events = io_event;
3272
3282
 
3273
3283
skip_native_aio:
3274
3284
#endif /* LINUX_NATIVE_AIO */
3410
3420
 
3411
3421
        os_aio_validate();
3412
3422
 
3413
 
        os_aio_segment_wait_events = static_cast<os_event_t *>(ut_malloc(n_segments * sizeof(void*)));
 
3423
        os_aio_segment_wait_events = ut_malloc(n_segments * sizeof(void*));
3414
3424
 
3415
3425
        for (i = 0; i < n_segments; i++) {
3416
3426
                os_aio_segment_wait_events[i] = os_event_create(NULL);
3634
3644
        ulint           slots_per_seg;
3635
3645
        ulint           local_seg;
3636
3646
 
3637
 
#ifdef WIN_ASYNC_IO
3638
 
        ut_a((len & 0xFFFFFFFFUL) == len);
3639
 
#endif
3640
 
 
3641
3647
        /* No need of a mutex. Only reading constant fields */
3642
3648
        slots_per_seg = array->n_slots / array->n_segments;
3643
3649
 
3702
3708
        slot->name     = name;
3703
3709
        slot->len      = len;
3704
3710
        slot->type     = type;
3705
 
        slot->buf      = static_cast<unsigned char *>(buf);
 
3711
        slot->buf      = buf;
3706
3712
        slot->offset   = offset;
3707
3713
        slot->offset_high = offset_high;
3708
3714
        slot->io_already_done = FALSE;
4015
4021
        ut_ad(n % OS_FILE_LOG_BLOCK_SIZE == 0);
4016
4022
        ut_ad(offset % OS_FILE_LOG_BLOCK_SIZE == 0);
4017
4023
        ut_ad(os_aio_validate());
4018
 
#ifdef WIN_ASYNC_IO
4019
 
        ut_ad((n & 0xFFFFFFFFUL) == n);
4020
 
#endif
4021
4024
 
4022
4025
        wake_later = mode & OS_AIO_SIMULATED_WAKE_LATER;
4023
4026
        mode = mode & (~OS_AIO_SIMULATED_WAKE_LATER);
4295
4298
                                            __FILE__, __LINE__);
4296
4299
#endif
4297
4300
 
4298
 
                ut_a((slot->len & 0xFFFFFFFFUL) == slot->len);
4299
 
 
4300
4301
                switch (slot->type) {
4301
4302
                case OS_FILE_WRITE:
4302
4303
                        ret = WriteFile(slot->file, slot->buf,
4303
 
                                        (DWORD) slot->len, &len,
 
4304
                                        slot->len, &len,
4304
4305
                                        &(slot->control));
4305
4306
 
4306
4307
                        break;
4307
4308
                case OS_FILE_READ:
4308
4309
                        ret = ReadFile(slot->file, slot->buf,
4309
 
                                       (DWORD) slot->len, &len,
 
4310
                                       slot->len, &len,
4310
4311
                                       &(slot->control));
4311
4312
 
4312
4313
                        break;
4797
4798
                combined_buf = slot->buf;
4798
4799
                combined_buf2 = NULL;
4799
4800
        } else {
4800
 
                combined_buf2 = static_cast<unsigned char *>(ut_malloc(total_len + UNIV_PAGE_SIZE));
 
4801
                combined_buf2 = ut_malloc(total_len + UNIV_PAGE_SIZE);
4801
4802
 
4802
4803
                ut_a(combined_buf2);
4803
4804
 
4804
 
                combined_buf = static_cast<unsigned char *>(ut_align(combined_buf2, UNIV_PAGE_SIZE));
 
4805
                combined_buf = ut_align(combined_buf2, UNIV_PAGE_SIZE);
4805
4806
        }
4806
4807
 
4807
4808
        /* We release the array mutex for the time of the i/o: NOTE that