From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=52305 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OM6K8-0005Zy-5x for qemu-devel@nongnu.org; Tue, 08 Jun 2010 17:27:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OM6K7-0007MX-5t for qemu-devel@nongnu.org; Tue, 08 Jun 2010 17:27:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32499) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OM6K6-0007MQ-Tp for qemu-devel@nongnu.org; Tue, 08 Jun 2010 17:27:03 -0400 Date: Tue, 8 Jun 2010 14:26:59 -0700 From: Chris Wright Message-ID: <20100608212659.GS28492@x200.localdomain> References: <20100608191447.4451.47795.stgit@localhost.localdomain> <20100608191535.4451.48702.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100608191535.4451.48702.stgit@localhost.localdomain> Subject: [Qemu-devel] Re: [RFC PATCH 2/6] ram_blocks: Convert to a QLIST List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: chrisw@redhat.com, quintela@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org * Alex Williamson (alex.williamson@redhat.com) wrote: > extern int phys_ram_fd; > -extern uint8_t *phys_ram_dirty; > extern ram_addr_t ram_size; > -extern ram_addr_t last_ram_offset; > + > +typedef struct RAMBlock { > + uint8_t *host; > + ram_addr_t offset; > + ram_addr_t length; > + QLIST_ENTRY(RAMBlock) next; > +} RAMBlock; > + > +typedef struct RAMList { > + uint8_t *phys_dirty; > + ram_addr_t last_offset; > + QLIST_HEAD(ram, RAMBlock) blocks; > +} RAMList; > +extern RAMList ram; such a generic name for global namespace > void *qemu_get_ram_ptr(ram_addr_t addr) > { > - RAMBlock *prev; > - RAMBlock **prevp; > RAMBlock *block; > > - prev = NULL; > - prevp = &ram_blocks; > - block = ram_blocks; > - while (block && (block->offset > addr > - || block->offset + block->length <= addr)) { > - if (prev) > - prevp = &prev->next; > - prev = block; > - block = block->next; > - } > - if (!block) { > - fprintf(stderr, "Bad ram offset %" PRIx64 "\n", (uint64_t)addr); > - abort(); > - } > - /* Move this entry to to start of the list. */ > - if (prev) { > - prev->next = block->next; > - block->next = *prevp; > - *prevp = block; > + QLIST_FOREACH(block, &ram.blocks, next) { > + if (addr - block->offset < block->length) { > + QLIST_REMOVE(block, next); > + QLIST_INSERT_HEAD(&ram.blocks, block, next); > + return block->host + (addr - block->offset); > + } > } > - return block->host + (addr - block->offset); > + > + return NULL; Why not preserve the error message and abort()? In error cases this would now just segfault. Minor nits aside, this too looks like a nice cleanup. Acked-by: Chris Wright