X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Ftracefile-array.c;h=05ce3ad34520c9f09c7bb91fe2b235684c2a106d;hp=bcbee5c557103b042544f936f82e8d99b12089fd;hb=505b2d90aa87592186ecc2a119cf67fb3f90d168;hpb=a44ca2ca85e4b64729f7b88b1919fd6737dfff8a diff --git a/src/bin/lttng-relayd/tracefile-array.c b/src/bin/lttng-relayd/tracefile-array.c index bcbee5c55..05ce3ad34 100644 --- a/src/bin/lttng-relayd/tracefile-array.c +++ b/src/bin/lttng-relayd/tracefile-array.c @@ -1,21 +1,10 @@ /* - * Copyright (C) 2015 - Mathieu Desnoyers + * Copyright (C) 2015 Mathieu Desnoyers * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2 only, as - * published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE #define _LGPL_SOURCE #include #include @@ -63,7 +52,24 @@ void tracefile_array_destroy(struct tracefile_array *tfa) free(tfa); } -void tracefile_array_file_rotate(struct tracefile_array *tfa) +void tracefile_array_reset(struct tracefile_array *tfa) +{ + size_t count, i; + + count = tfa->count; + for (i = 0; i < count; i++) { + tfa->tf[i].seq_head = -1ULL; + tfa->tf[i].seq_tail = -1ULL; + } + tfa->seq_head = -1ULL; + tfa->seq_tail = -1ULL; + tfa->file_head_read = 0; + tfa->file_head_write = 0; + tfa->file_tail = 0; +} + +void tracefile_array_file_rotate(struct tracefile_array *tfa, + enum tracefile_rotate_type type) { uint64_t *headp, *tailp; @@ -71,42 +77,56 @@ void tracefile_array_file_rotate(struct tracefile_array *tfa) /* Not in tracefile rotation mode. */ return; } - /* Rotate to next file. */ - tfa->file_head = (tfa->file_head + 1) % tfa->count; - if (tfa->file_head == tfa->file_tail) { - /* Move tail. */ - tfa->file_tail = (tfa->file_tail + 1) % tfa->count; - } - headp = &tfa->tf[tfa->file_head].seq_head; - tailp = &tfa->tf[tfa->file_head].seq_tail; - /* - * If we overwrite a file with content, we need to push the tail - * to the position following the content we are overwriting. - */ - if (*headp != -1ULL) { - tfa->seq_tail = tfa->tf[tfa->file_tail].seq_tail; + switch (type) { + case TRACEFILE_ROTATE_READ: + /* + * Rotate read head to write head position, thus allowing + * reader to consume the newly rotated head file. + */ + tfa->file_head_read = tfa->file_head_write; + break; + case TRACEFILE_ROTATE_WRITE: + /* Rotate write head to next file, pushing tail if needed. */ + tfa->file_head_write = (tfa->file_head_write + 1) % tfa->count; + if (tfa->file_head_write == tfa->file_tail) { + /* Move tail. */ + tfa->file_tail = (tfa->file_tail + 1) % tfa->count; + } + headp = &tfa->tf[tfa->file_head_write].seq_head; + tailp = &tfa->tf[tfa->file_head_write].seq_tail; + /* + * If we overwrite a file with content, we need to push the tail + * to the position following the content we are overwriting. + */ + if (*headp != -1ULL) { + tfa->seq_tail = tfa->tf[tfa->file_tail].seq_tail; + } + /* Reset this file head/tail (overwrite). */ + *headp = -1ULL; + *tailp = -1ULL; + break; + default: + abort(); } - /* Reset this file head/tail (overwrite). */ - *headp = -1ULL; - *tailp = -1ULL; } -void tracefile_array_commit_seq(struct tracefile_array *tfa) +void tracefile_array_commit_seq(struct tracefile_array *tfa, + uint64_t new_seq_head) { uint64_t *headp, *tailp; /* Increment overall head. */ - tfa->seq_head++; - /* If we are committing our first index overall, set tail to 0. */ + tfa->seq_head = new_seq_head; + /* If we are committing our first index overall, set tail to head. */ if (tfa->seq_tail == -1ULL) { - tfa->seq_tail = 0; + tfa->seq_tail = new_seq_head; } if (!tfa->count) { /* Not in tracefile rotation mode. */ return; } - headp = &tfa->tf[tfa->file_head].seq_head; - tailp = &tfa->tf[tfa->file_head].seq_tail; + headp = &tfa->tf[tfa->file_head_write].seq_head; + tailp = &tfa->tf[tfa->file_head_write].seq_tail; /* Update head tracefile seq_head. */ *headp = tfa->seq_head; /* @@ -118,9 +138,9 @@ void tracefile_array_commit_seq(struct tracefile_array *tfa) } } -uint64_t tracefile_array_get_file_index_head(struct tracefile_array *tfa) +uint64_t tracefile_array_get_read_file_index_head(struct tracefile_array *tfa) { - return tfa->file_head; + return tfa->file_head_read; } uint64_t tracefile_array_get_seq_head(struct tracefile_array *tfa)