/** * Release space to the free space for the filesystem. * * @param sess SrvSession * @param tree TreeConnection * @param fid int * @param path String * @param alloc long * @exception IOException */ public void releaseSpace(SrvSession sess, TreeConnection tree, int fid, String path, long alloc) throws IOException { // Check if content usage is enabled if (m_usageService.getEnabled() == false) return; // Check if there is a live usage record for the user UserQuotaDetails userQuota = getQuotaDetails(sess, true); if (userQuota != null) { synchronized (userQuota) { // Release the space from the live usage value userQuota.subtractFromCurrentUsage(alloc); } // DEBUG if (logger.isDebugEnabled()) logger.debug("Released " + alloc + " bytes, userQuota=" + userQuota); } else if (logger.isDebugEnabled()) logger.debug("Failed to release " + alloc + " bytes for sess " + sess.getUniqueId()); }
/** * Allocate space on the filesystem. * * @param sess SrvSession * @param tree TreeConnection * @param file NetworkFile * @param alloc long requested allocation size * @return long granted allocation size * @exception IOException */ public long allocateSpace(SrvSession sess, TreeConnection tree, NetworkFile file, long alloc) throws IOException { // Check if content usage is enabled if (m_usageService.getEnabled() == false) return alloc; // Check if there is a live usage record for the user UserQuotaDetails userQuota = getQuotaDetails(sess, true); long allowedAlloc = 0L; if (userQuota != null) { // Check if the user has a usage quota synchronized (userQuota) { if (userQuota.hasUserQuota()) { // Check if the user has enough free space allocation if (alloc > 0 && userQuota.getAvailableSpace() >= alloc) { userQuota.addToCurrentUsage(alloc); allowedAlloc = alloc; } } else { // Update the live usage userQuota.addToCurrentUsage(alloc); allowedAlloc = alloc; } } } else if (logger.isDebugEnabled()) logger.debug("Failed to allocate " + alloc + " bytes for sess " + sess.getUniqueId()); // Check if the allocation was allowed if (allowedAlloc < alloc) { // DEBUG if (logger.isDebugEnabled()) logger.debug("Allocation failed userQuota=" + userQuota); throw new DiskFullException(); } else if (logger.isDebugEnabled()) logger.debug("Allocated " + alloc + " bytes, userQuota=" + userQuota); // Return the allocation size return allowedAlloc; }