]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
remove disk access locking
authorwessels <>
Wed, 5 Feb 1997 11:40:43 +0000 (11:40 +0000)
committerwessels <>
Wed, 5 Feb 1997 11:40:43 +0000 (11:40 +0000)
src/disk.cc
src/store.cc

index b9909ec5b45b46abfadad7291f5f4b352f8dba41..5e083435bfc6ec94914dceef860f15be943f8721 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: disk.cc,v 1.51 1997/01/07 20:31:20 wessels Exp $
+ * $Id: disk.cc,v 1.52 1997/02/05 04:40:43 wessels Exp $
  *
  * DEBUG: section 6     Disk I/O Routines
  * AUTHOR: Harvest Derived
@@ -139,8 +139,6 @@ disk_init(void)
        file_table[fd].open_stat = FILE_NOT_OPEN;
        file_table[fd].close_request = NOT_REQUEST;
        file_table[fd].write_daemon = NOT_PRESENT;
-       file_table[fd].write_lock = UNLOCK;
-       file_table[fd].access_code = 0;
        file_table[fd].write_pending = NO_WRT_PENDING;
        file_table[fd].write_q = file_table[fd].write_q_tail = NULL;
     }
@@ -177,10 +175,8 @@ file_open(const char *path, int (*handler) _PARAMS((void)), int mode)
     file_table[fd].at_eof = NO;
     file_table[fd].open_stat = FILE_OPEN;
     file_table[fd].close_request = NOT_REQUEST;
-    file_table[fd].write_lock = UNLOCK;
     file_table[fd].write_pending = NO_WRT_PENDING;
     file_table[fd].write_daemon = NOT_PRESENT;
-    file_table[fd].access_code = 0;
     file_table[fd].write_q = NULL;
 
     conn = &fd_table[fd];
@@ -210,7 +206,6 @@ file_close(int fd)
        debug(6, 3, "file_close: FD %d has a write PENDING\n", fd);
     } else {
        file_table[fd].open_stat = FILE_NOT_OPEN;
-       file_table[fd].write_lock = UNLOCK;
        file_table[fd].write_daemon = NOT_PRESENT;
        file_table[fd].filename[0] = '\0';
 
@@ -233,35 +228,6 @@ file_close(int fd)
     return DISK_ERROR;
 }
 
-/* grab a writing lock for file */
-int
-file_write_lock(int fd)
-{
-    if (file_table[fd].write_lock == LOCK) {
-       debug(6, 0, "trying to lock a locked file\n");
-       return DISK_WRT_LOCK_FAIL;
-    } else {
-       file_table[fd].write_lock = LOCK;
-       file_table[fd].access_code += 1;
-       file_table[fd].access_code %= 65536;
-       return file_table[fd].access_code;
-    }
-}
-
-
-/* release a writing lock for file */
-int
-file_write_unlock(int fd, int access_code)
-{
-    if (file_table[fd].access_code == access_code) {
-       file_table[fd].write_lock = UNLOCK;
-       return DISK_OK;
-    } else {
-       debug(6, 0, "trying to unlock the file with the wrong access code\n");
-       return DISK_WRT_WRONG_CODE;
-    }
-}
-
 
 /* write handler */
 static int
@@ -272,7 +238,6 @@ diskHandleWrite(int fd, FileEntry * entry)
 
     if (file_table[fd].at_eof == NO)
        lseek(fd, 0, SEEK_END);
-
     while (entry->write_q) {
        len = write(fd,
            entry->write_q->buf + entry->write_q->cur_offset,
@@ -342,7 +307,6 @@ int
 file_write(int fd,
     char *ptr_to_buf,
     int len,
-    int access_code,
     FILE_WRITE_HD handle,
     void *handle_data,
     void (*free_func) _PARAMS((void *)))
@@ -351,11 +315,6 @@ file_write(int fd,
 
     if (file_table[fd].open_stat == FILE_NOT_OPEN)
        return DISK_ERROR;
-    if ((file_table[fd].write_lock == LOCK) &&
-       (file_table[fd].access_code != access_code)) {
-       debug(6, 0, "file write: FD %d access code checked failed.\n", fd);
-       return DISK_WRT_WRONG_CODE;
-    }
     /* if we got here. Caller is eligible to write. */
     wq = xcalloc(1, sizeof(dwrite_q));
     wq->buf = ptr_to_buf;
@@ -413,7 +372,7 @@ diskHandleRead(int fd, dread_ctrl * ctrl_dat)
                fd, xstrerror());
            ctrl_dat->handler(fd, ctrl_dat->buf,
                ctrl_dat->cur_len, DISK_ERROR,
-               ctrl_dat->client_data, ctrl_dat->offset);
+               ctrl_dat->client_data);
            safe_free(ctrl_dat);
            return DISK_ERROR;
     } else if (len == 0) {
@@ -421,7 +380,7 @@ diskHandleRead(int fd, dread_ctrl * ctrl_dat)
        ctrl_dat->end_of_file = 1;
        /* call handler */
        ctrl_dat->handler(fd, ctrl_dat->buf, ctrl_dat->cur_len, DISK_EOF,
-           ctrl_dat->client_data, ctrl_dat->offset);
+           ctrl_dat->client_data);
        safe_free(ctrl_dat);
        return DISK_OK;
     }
@@ -443,8 +402,7 @@ diskHandleRead(int fd, dread_ctrl * ctrl_dat)
            ctrl_dat->buf,
            ctrl_dat->cur_len,
            DISK_OK,
-           ctrl_dat->client_data,
-           ctrl_dat->offset);
+           ctrl_dat->client_data);
        safe_free(ctrl_dat);
        return DISK_OK;
     }
@@ -459,7 +417,8 @@ int
 file_read(int fd, char *buf, int req_len, int offset, FILE_READ_HD handler, void *client_data)
 {
     dread_ctrl *ctrl_dat;
-
+    if (fd < 0)
+       fatal_dump("file_read: bad FD");
     ctrl_dat = xcalloc(1, sizeof(dread_ctrl));
     ctrl_dat->fd = fd;
     ctrl_dat->offset = offset;
@@ -469,7 +428,6 @@ file_read(int fd, char *buf, int req_len, int offset, FILE_READ_HD handler, void
     ctrl_dat->end_of_file = 0;
     ctrl_dat->handler = handler;
     ctrl_dat->client_data = client_data;
-
     commSetSelect(fd,
        COMM_SELECT_READ,
        (PF) diskHandleRead,
index 725ca0852bcb51fd59e02a1144337afa7f9d6e6d..86824b2c36d26577771220b2b36fca56497263ce 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store.cc,v 1.205 1997/01/31 23:59:56 wessels Exp $
+ * $Id: store.cc,v 1.206 1997/02/05 04:40:45 wessels Exp $
  *
  * DEBUG: section 20    Storeage Manager
  * AUTHOR: Harvest Derived
@@ -216,7 +216,7 @@ static int storeEntryValidLength _PARAMS((const StoreEntry *));
 static void storeGetMemSpace _PARAMS((int));
 static int storeHashDelete _PARAMS((StoreEntry *));
 static int storeShouldPurgeMem _PARAMS((const StoreEntry *));
-static int storeSwapInHandle _PARAMS((int, const char *, int, int, StoreEntry *, int));
+static int storeSwapInHandle _PARAMS((int, const char *, int, int, StoreEntry *));
 static int storeSwapInStart _PARAMS((StoreEntry *, SIH, void *));
 static int swapInError _PARAMS((int, StoreEntry *));
 static mem_ptr new_MemObjectData _PARAMS((void));
@@ -262,7 +262,6 @@ static int store_swap_size = 0;     /* kilobytes !! */
 static int store_swap_high = 0;
 static int store_swap_low = 0;
 static int swaplog_fd = -1;
-static int swaplog_lock = 0;
 static int storelog_fd = -1;
 
 /* key temp buffer */
@@ -495,7 +494,6 @@ storeLog(int tag, const StoreEntry * e)
     file_write(storelog_fd,
        xstrdup(logmsg),
        strlen(logmsg),
-       0,
        NULL,
        NULL,
        xfree);
@@ -1077,7 +1075,7 @@ storeSwapFullPath(int fn, char *fullpath)
 
 /* swapping in handle */
 static int
-storeSwapInHandle(int fd_notused, const char *buf, int len, int flag, StoreEntry * e, int offset_notused)
+storeSwapInHandle(int fd_notused, const char *buf, int len, int flag, StoreEntry * e)
 {
     MemObject *mem = e->mem_obj;
     SIH handler = NULL;
@@ -1099,7 +1097,6 @@ storeSwapInHandle(int fd_notused, const char *buf, int len, int flag, StoreEntry
        return -1;
     }
     debug(20, 5, "storeSwapInHandle: e->swap_offset   = %d\n", mem->swap_offset);
-    debug(20, 5, "storeSwapInHandle: len              = %d\n", len);
     debug(20, 5, "storeSwapInHandle: e->e_current_len = %d\n", mem->e_current_len);
     debug(20, 5, "storeSwapInHandle: e->object_len    = %d\n", e->object_len);
 
@@ -1217,7 +1214,6 @@ storeSwapLog(const StoreEntry * e)
     file_write(swaplog_fd,
        xstrdup(logmsg),
        strlen(logmsg),
-       swaplog_lock,
        NULL,
        NULL,
        xfree);
@@ -1294,7 +1290,6 @@ storeSwapOutHandle(int fd, int flag, StoreEntry * e)
     file_write(mem->swapout_fd,
        mem->e_swap_buf,
        mem->e_swap_buf_len,
-       mem->e_swap_access,
        storeSwapOutHandle,
        e,
        NULL);
@@ -1327,13 +1322,6 @@ storeSwapOutStart(StoreEntry * e)
     debug(20, 5, "storeSwapOutStart: Begin SwapOut '%s' to FD %d FILE %s.\n",
        e->url, fd, swapfilename);
     e->swap_file_number = swapfileno;
-    if ((mem->e_swap_access = file_write_lock(mem->swapout_fd)) < 0) {
-       debug(20, 0, "storeSwapOutStart: Unable to lock swapfile: %s\n",
-           swapfilename);
-       file_map_bit_reset(e->swap_file_number);
-       e->swap_file_number = -1;
-       return -1;
-    }
     e->swap_status = SWAPPING_OUT;
     mem->swap_offset = 0;
     mem->e_swap_buf = get_free_8k_page();
@@ -1347,7 +1335,6 @@ storeSwapOutStart(StoreEntry * e)
     x = file_write(mem->swapout_fd,
        mem->e_swap_buf,
        mem->e_swap_buf_len,
-       mem->e_swap_access,
        storeSwapOutHandle,
        e,
        NULL);
@@ -1517,12 +1504,9 @@ storeRebuiltFromDisk(struct storeRebuild_data *data)
            tmp_filename, swaplog_file, xstrerror());
        fatal_dump("storeRebuiltFromDisk: rename failed");
     }
-    if (file_write_unlock(swaplog_fd, swaplog_lock) != DISK_OK)
-       fatal_dump("storeRebuiltFromDisk: swaplog unlock failed");
     file_close(swaplog_fd);
     if ((swaplog_fd = file_open(swaplog_file, NULL, O_WRONLY | O_CREAT)) < 0)
        fatal_dump("storeRebuiltFromDisk: file_open(swaplog_file) failed");
-    swaplog_lock = file_write_lock(swaplog_fd);
 }
 
 static void
@@ -1556,8 +1540,6 @@ storeStartRebuildFromDisk(void)
     safeunlink(tmp_filename, 1);
     /* close the existing write-only swaplog, and open a temporary
      * write-only swaplog  */
-    if (file_write_unlock(swaplog_fd, swaplog_lock) != DISK_OK)
-       fatal_dump("storeStartRebuildFromDisk: swaplog unlock failed");
     if (swaplog_fd > -1)
        file_close(swaplog_fd);
     sprintf(tmp_filename, "%s.new", swaplog_file);
@@ -1568,7 +1550,6 @@ storeStartRebuildFromDisk(void)
            tmp_filename, xstrerror());
        fatal("storeStartRebuildFromDisk: Can't open tmp swaplog");
     }
-    swaplog_lock = file_write_lock(swaplog_fd);
     /* Open the existing swap log for reading */
     if ((data->log = fopen(swaplog_file, "r")) == (FILE *) NULL) {
        sprintf(tmp_error_buf, "storeRebuildFromDisk: %s: %s",
@@ -2468,7 +2449,6 @@ storeInit(void)
        sprintf(tmp_error_buf, "Cannot open swap logfile: %s", swaplog_file);
        fatal(tmp_error_buf);
     }
-    swaplog_lock = file_write_lock(swaplog_fd);
     if (!opt_zap_disk_store)
        storeStartRebuildFromDisk();
     else
@@ -2665,11 +2645,6 @@ storeWriteCleanLog(void)
        safeunlink(tmp_filename, 0);
        return 0;
     }
-    if (file_write_unlock(swaplog_fd, swaplog_lock) != DISK_OK) {
-       debug(20, 0, "storeWriteCleanLog: Failed to unlock swaplog!\n");
-       debug(20, 0, "storeWriteCleanLog: Current swap logfile not replaced.\n");
-       return 0;
-    }
     if (rename(tmp_filename, swaplog_file) < 0) {
        debug(50, 0, "storeWriteCleanLog: rename failed: %s\n",
            xstrerror());
@@ -2681,7 +2656,6 @@ storeWriteCleanLog(void)
        sprintf(tmp_error_buf, "Cannot open swap logfile: %s", swaplog_file);
        fatal(tmp_error_buf);
     }
-    swaplog_lock = file_write_lock(swaplog_fd);
 
     stop = getCurrentTime();
     r = stop - start;